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

'NRFX_TWI0_INST_IDX' undeclared - possible solution and bug found

A while back I was working on I2C and came across the compiler error " 'NRFX_TWI0_INST_IDX' undeclared ", which seemed to be related to NRF drivers vs NRFX drivers confusion. I recall researching here and not finding anything. I am sorry I don't recall every little detail, but still wanted to share:

I wonder whether there is a bug in apply_old_config.h line 1116 in SDK16.0.0

It reads "#if defined(TWI_ENABLED)", and in this case #undef's a number of NRFX related defines.

Since in the sdk_config.h file (at least in many examples), TWI_ENABLED is almost always #defined (just sometimes a 0), the above statement is almost always true.

I believe the line should read something along the lines of 

#if defined(TWI_ENABLED) && (TWI_ENABLED==1)

I also recall, that apply_old_config.h is unconditionally included through many levels, starting with #include "nrfx_twi.h" in my main.c and cascading into nrfx_glue.h . Ie, you can't avoid the line above in apply_old_config.h .

An alternate solution for me was, to change the sdk_config.h line 

// <e> TWI_ENABLED - nrf_drv_twi - TWI/TWIM peripheral driver - legacy layer
//==========================================================
#ifndef TWI_ENABLED
#define TWI_ENABLED 0
#endif

to

//#define TWI_ENABLED 0

Hope this is of help to someone. And maybe Nordic can review the #define in apply_old_config.h

Parents
  • I am summarizing the great help by Simon since it did get a bit lengthy (all credits of course to Simon !). I found out in the meantime that pretty much the exact same thing applies to SPI as well.

    The key was to not use the NRFX drivers directly, and to not get discouraged by the term "legacy driver". "Legacy" is more to be interpreted as "proven and established". Behind the scenes, the legacy nrf_drv_twi.h driver itself uses the NRFX layer. A welcome side effect is then, that simply by setting TWIx_USE_EASY_DMA appropriately, you can switch to the DMA assisted driver (and it appears to me well worth doing so).

    Use nrf_drv_twi.h, and add nrfx_twi.c or nrfx_twim.c to your project. 

Reply
  • I am summarizing the great help by Simon since it did get a bit lengthy (all credits of course to Simon !). I found out in the meantime that pretty much the exact same thing applies to SPI as well.

    The key was to not use the NRFX drivers directly, and to not get discouraged by the term "legacy driver". "Legacy" is more to be interpreted as "proven and established". Behind the scenes, the legacy nrf_drv_twi.h driver itself uses the NRFX layer. A welcome side effect is then, that simply by setting TWIx_USE_EASY_DMA appropriately, you can switch to the DMA assisted driver (and it appears to me well worth doing so).

    Use nrf_drv_twi.h, and add nrfx_twi.c or nrfx_twim.c to your project. 

Children
No Data
Related