This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Multiple Device Tree SPI definitions for a single hardware interface

Hello,

I am in the process of porting application code from the old nRF 15.x SDK to the new zephyr based ncs 1.5.0 SDK and would like to do all hardware configurations in the device tree now that one is available.

My current hardware application utilizes multiple sensors on different physical pins eg: device 1 on pins 15, 16, 17 ,18 and device 2 on pins 11, 12, 13 ,14 and a single spi peripheral was multiplexed between them using two different spi configs through the old SDK's nrf_spi_mngr.c.

The config looks like the following example

nrfx_spim_config_t device1_config =
{
    .sck_pin        = 15,
    .mosi_pin       = 16,
    .miso_pin       = 17,
    .ss_pin         = 18,
    .irq_priority   = APP_IRQ_PRIORITY_MID,
    .orc            = 0x00,
    .frequency      = NRF_SPIM_FREQ_8M,
    .mode           = NRF_SPIM_MODE_3,
    .bit_order      = NRF_SPIM_BIT_ORDER_MSB_FIRST
};

nrfx_spim_config_t device2_config =
{
    .sck_pin        = 11,
    .mosi_pin       = 12,
    .miso_pin       = 13,
    .ss_pin         = 14,
    .irq_priority   = APP_IRQ_PRIORITY_MID,
    .orc            = 0x00,
    .frequency      = NRF_SPIM_FREQ_8M,
    .mode           = NRF_SPIM_MODE_3,
    .bit_order      = NRF_SPIM_BIT_ORDER_MSB_FIRST
};

In one device driver there is a block of code like the following.

nrf_spi_mngr_transaction_t spim_transaction =
{   .begin_callback = NULL,
    .end_callback = device1_xfer_complete,
    .number_of_transfers = 1,
    .p_required_spi_cfg = &device1_config,
    .p_user_data = NULL,
    .p_transfers = &transfer
};

nrf_spi_mngr_schedule(&m_nrf_spi_mngr, xfer);

and in another driver the same code but using the device2_config is used

nrf_spi_mngr_transaction_t spim_transaction =
{   .begin_callback = NULL,
    .end_callback = device1_xfer_complete,
    .number_of_transfers = 1,
    .p_required_spi_cfg = &device2_config,
    .p_user_data = NULL,
    .p_transfers = &transfer
};

nrf_spi_mngr_schedule(&m_nrf_spi_mngr, xfer);

When testing with zephyr I am able to get a single spi peripheral working using the following device tree config

&spi1 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <15>;
	mosi-pin = <16>;
	miso-pin = <17>;
};

and use them in code with

spi_dev = device_get_binding("SPI_1");

but I am not sure how I would go about creating multiple sub nodes since the pin configs are part of the top level spi node.

Is there an established way to achieve this through the device tree?

Related