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

NRFX_SPI instantiation fails using NRFX, why?

Hello,

I am facing a really annoying issue when updating my SPI settings from the old nrf_drv_ towards the newer one nrfx , in SDK15.  I am following the recommendtations of this link, but I am getting stuck when trying to create the SPI instance.

I follow these steps, the instantiation of the SPI is done like this

#define SPI_INSTANCE_2 2/**< SPI instance/
static const nrfx_spi_t spi = NRFX_SPI_INSTANCE(SPI_INSTANCE_2);  /**< SPI instance. */
static volatile bool spi_xfer_done;  /**< Flag used to indicate that SPI instance completed the transfer. */

I have enabled the interface in the sdk_config.h like this

// <e> NRFX_SPI_ENABLED - nrfx_spi - SPI peripheral driver
//==========================================================
#ifndef NRFX_SPI_ENABLED
#define NRFX_SPI_ENABLED 1
#endif
// <q> NRFX_SPI0_ENABLED  - Enable SPI0 instance
// <q> NRFX_SPI0_ENABLED  - Enable SPI0 instance
 

#ifndef NRFX_SPI0_ENABLED
#define NRFX_SPI0_ENABLED 0
#endif

// <q> NRFX_SPI1_ENABLED  - Enable SPI1 instance
 

#ifndef NRFX_SPI1_ENABLED
#define NRFX_SPI1_ENABLED 0
#endif

// <q> NRFX_SPI2_ENABLED  - Enable SPI2 instance
 

#ifndef NRFX_SPI2_ENABLED
#define NRFX_SPI2_ENABLED 1
#endif

And I am getting the error while compiling, shown as well in the image

'NRFX_SPI2_INST_IDX' undeclared here (not in a function)

in definition of macro 'NRFX_CONCAT_3_'

in expansion of macro 'NRFX_CONCAT_3'

in expansion of macro 'NRFX_SPI_INSTANCE'

Why do I get this error and how can I ride of it? Furthermore, why is not a clear documentation of how to use the new driver ? I can reproduce the exact same problem in the SPI example if I change the SPI instance from 0 to 2 ( previously enabling SPI Instance 2 on the sdk_config.h)

Thanks

Parents
  • I have the same problem, and just spent an hour tracking it down. It is caused by the legacy adapter code in apply_old_config.h, which is included from nrf_glue.h, which is included from nrfx.h, which is included from just about everything peripheral-related.

    If you're not using the legacy interface, this should leave your NRFX_SPI0_ENABLED etc. unchanged, but unfortunately it does not. If you don't also have SPI0_ENABLED, it redefines NRFX_SPI0_ENABLED to 0. In my opinion, this is a serious defect in the SDK; using the new NRFX drivers shouldn't require having the legacy defines also set.

    The workaround is to define SPI<n>_ENABLED to have the same value as NRFX_SPI<n>_ENABLED, to prevent apply_old_config from changing it.

Reply
  • I have the same problem, and just spent an hour tracking it down. It is caused by the legacy adapter code in apply_old_config.h, which is included from nrf_glue.h, which is included from nrfx.h, which is included from just about everything peripheral-related.

    If you're not using the legacy interface, this should leave your NRFX_SPI0_ENABLED etc. unchanged, but unfortunately it does not. If you don't also have SPI0_ENABLED, it redefines NRFX_SPI0_ENABLED to 0. In my opinion, this is a serious defect in the SDK; using the new NRFX drivers shouldn't require having the legacy defines also set.

    The workaround is to define SPI<n>_ENABLED to have the same value as NRFX_SPI<n>_ENABLED, to prevent apply_old_config from changing it.

Children
  • The problem is that almost all of the SDK configuration tests are done using #if, but for no good reason, apply_old_config.h is testing some of the configuration using #ifdef, which evaluates as true even if the define is zero.  These #ifdef in apply_old_config.h should be changed to #if. That will not break anything, because #if will still evaluate a configuration as false if it is not defined.

Related