NCS - Devicetree & nrfx coexistence

Hi,

I have an application based on the "peripheral_uart" sample code (nRF52840DK, NCS2.70)

As I use interchangeably the same pins as GPIOs and UARTE1, I use UARTE1 with NRFX drivers:

nrfx_uarte_t uarte1_inst = NRFX_UARTE_INSTANCE(1)

This seems to work well.  Note that UARTE1 is not defined in the default devicetree file (nrf52840dk_nrf52840.dts) so I didn't modify app.overlay

My questions are -

  1. What should I do if I want to use NRFX peripherals that ARE defined in the default dts file (specifically - TWIM0 & TWIM1)
    I added the following to prj.cnf
    CONFIG_I2C=y
    CONFIG_I2C_NRFX=y
    CONFIG_NRFX_TWI0=y
    CONFIG_NRFX_TWI1=y
    But I fail to instantiate TWI instance:
        nrfx_twim_t twim_inst = NRFX_TWIM_INSTANCE(0); // Macro expansion error
  2. Is there a way to make a 'pure' NRFX project and get rid of all Devicetree references?

Thanks

  • Hello Eyelasko,

    As I use interchangeably the same pins as GPIOs and UARTE1, I use UARTE1 with NRFX drivers:

    So if I understand you correctly, you want to use nrfx because you want to programmatically change when you use the same pins for multiple different peripherals?

    I have to say also that creating a pure nrfx project without dts is not recommended. NCS relies on Zephyr, which is heavily dependent on dts. Disabling a few specific peripherals in order to take control with nrfx however is considered fine.

    What should I do if I want to use NRFX peripherals that ARE defined in the default dts file (specifically - TWIM0 & TWIM1)

    I believe you would have to change the dts to disable these peripherals, so that nrfx can take control of them directly. Ie. something like this:

    &i2c0 {
        status = "disabled";
    };
    
    &i2c1 {
        status = "disabled";
    };

    Regards,

    Elfving

  • Thanks   for your reply.

    The answer lies in this post -  Turning on TWIM/TWIS without devicetree

    in short -

    • Add the following to app.overlay
      &i2c0 {
          status = "okay";
          compatible = "nordic,nrf-twim"; // this is the secret (apparently)
      };

      &i2c1 {
          status = "okay";
          compatible = "nordic,nrf-twim";
      };

    • add the following to prj.conf
      CONFIG_I2C=y
  • Oh, I see.

    Glad you found a solution that worked for you, and thanks for sharing it in case anyone else runs into the same problem Slight smile

    Regards,

    Elfving

Related