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

  • I've talked around internally and we've came to the same conclusion, that the migration guide for nrfx drivers is misleading. The following statement is not true:

    The legacy layer will no longer be supported in future SDK releases.

    Also, there is not any reason to migrate to the NRFX drivers, since it will just create an unnecessary hassle and the legacy (nrf_drv..) works well for all intents and purposes. I have pushed internally and will see that the documentation gets updated as soon as possible.

    Best regards,

    Simon

Related