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 think the intention is that the legacy definitions should be the dominant ones, meaning that if both TWI_ENABLED and NRFX_TWI_ENABLED are defined, it should always choose TWI_ENABLED. No matter if TWI_ENABLED is set to 0 or 1.

    That is the reason #if defined(TWI_ENABLED) is used. It will check if it is defined, and change the NRFX_TWI_ENABLED accordingly.

    Best regards,

    Simon

  • Simon,

    I had the impression that the way to configure sdk_config.h was to enable and disable functionality. Even example applications contain both the NRF and the NRFX defines in there. The fact that the pure presence of a define (even if defined as 0) has implications was unexpected to me. I feel example apps should then either contain NRF or NRFX defines. My 2 cents.

Reply
  • Simon,

    I had the impression that the way to configure sdk_config.h was to enable and disable functionality. Even example applications contain both the NRF and the NRFX defines in there. The fact that the pure presence of a define (even if defined as 0) has implications was unexpected to me. I feel example apps should then either contain NRF or NRFX defines. My 2 cents.

Children
Related