Multiple nexus nodes, and using I2C on a nexus node

Hello:

I am developing a board and shields based on nRF5340 (but this question is not really specific to nRF5340, it also applies to most other nRF5x chips). The main-board has 4 identical connectors, and I have defined a nexus node for each of the connectors. For simplicity assume each connector has 6 pins, pwr, gnd, and 4 gpios.

I have several different shields, lets say an accelerometer (i2c and irq), and a LED display with 4 LEDs (4 gpios).

I would like to plug a shield into any one of these connectors and be able to plug several of the same shields onto the main-board (lets say 3 LED shields, and one accelerometer shield).

1) My first issue is how do I write a CMakeLists.txt which tells the build system I have a LED shield plugged into CON2? I can write an overlay for the LED board plugged into  CON2, but I would need 4 (slightly different) overlay files to describe the 4 places that the LED shield could be plugged in (only the nexus node name changes). I have this working.  What I really want to do is have one overlay for LED shields and pass a variable into the overlay describing which connector (nexus node) it is plugged into.  I think the variable could be defined in prj.conf, CMakeLists.txt or app.overlay. How can I pass a variable into the shield overlay so that the shield overlay can put the correct nexus node name into the overlay?

2) my second issue is the NRF_PSEL macro doesn't accept nexus nodes  the parameters are type (TWIM_SDA, TWIM_SCL, etc.), bank (0 or 1), and port (0-31). Ideally the NRF_PSEL macro should accept a nexus node, which would be translated by the nexus node to the bank and port. Nexus node translations work fine for gpios and int-gpios. Is there a way to get NRF_PSEL to do nexus node translations?

&pinctrl {
    // TODO: these should reference CON2 pins 4 and 5. not
    // the pins directly on the processor. eventually
    // it should be configurable for CONx
    i2c1_default: i2c1_default {
        group1 {
            // psels = <NRF_PSEL(TWIM_SDA, &my_cpu_con2, 5)>,
            //         <NRF_PSEL(TWIM_SCL, &my_cpu_con2, 4)>;
            psels = <NRF_PSEL(TWIM_SDA, 1, 2)>,
                    <NRF_PSEL(TWIM_SCL, 1, 3)>;
            bias-pull-up;
        };
    };
};

Parents
  • I have figured out that the correct way to do this is with shield variants, Unfortunately....

    I am having difficulty getting shield variants to work. I read the documentation here docs.zephyrproject.org/.../shields.html . I have locally setup the directory `zephyr/boards/shields/myshield/`  with two files `myshield_v1.overlay` and `myshield_v2.overlay`, but I always get a compile error "Invalid SHIELD" when I add "--shield myshield_v2" to the west build command. myshield is in the list of shields to choose from, but the two variants are not. Is there something else I need to add (maybe a CMakeLists.txt?) to make shield variants work? I couldn't find an example to copy.

  • Followup: by following the example at https://github.com/zephyrproject-rtos/zephyr/tree/main/boards/shields/st_b_lcd40_dsi1_mb1166 I was able to get variants working. 

    I can now select which host connector the shield is connected to by accessing a variant. example: myshield_con1 or myshield_con2.

    since I now have variants, each one calling a different overlay, I can define in the overlay which connector is in use, then call a common .dtsi that is the same for all of the variants.

    similarly the nexus file can define several i2c different pinctrl sections and the shield overlay doesn't need know where the i2c is connected on the processor, the  shield just needs to know which pinctrl to access. All of the cpu board connectivity information is hidden in the nexus file, the shields don't need to know about the board wiring.

    example shield overlay:

    #define CONNECTOR mycpu_con2
    #define I2C_DEFAULT i2c_con2_default
    #define I2C_SLEEP i2c_con2_sleep
    #include "myshield.dtsi"

    I then use CONNECTOR, I2C_DEFAULT, and I2C_SLEEP in myshield.dtsi.

Reply
  • Followup: by following the example at https://github.com/zephyrproject-rtos/zephyr/tree/main/boards/shields/st_b_lcd40_dsi1_mb1166 I was able to get variants working. 

    I can now select which host connector the shield is connected to by accessing a variant. example: myshield_con1 or myshield_con2.

    since I now have variants, each one calling a different overlay, I can define in the overlay which connector is in use, then call a common .dtsi that is the same for all of the variants.

    similarly the nexus file can define several i2c different pinctrl sections and the shield overlay doesn't need know where the i2c is connected on the processor, the  shield just needs to know which pinctrl to access. All of the cpu board connectivity information is hidden in the nexus file, the shields don't need to know about the board wiring.

    example shield overlay:

    #define CONNECTOR mycpu_con2
    #define I2C_DEFAULT i2c_con2_default
    #define I2C_SLEEP i2c_con2_sleep
    #include "myshield.dtsi"

    I then use CONNECTOR, I2C_DEFAULT, and I2C_SLEEP in myshield.dtsi.

Children
No Data
Related