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 Reply Children
  • We're about to release a new series of SDKs called nRF Connect SDK, I believe we will only have the nRFX drivers on those SDKs. 

  • And yet here we are, 8 months later and the #ifdef issue is still in the apply_old_config.h and still causing customers problems.

    For example, the "#ifdef  SPI_ENABLED" causes the undefine of the NRFX_SPIM_ENABLE, which prevents the use of the NRFX module which is the only code that allows customers to use the SPIM3 hardware. The Legacy nrf libraries don't support SPIM3.

    This happens regardless of whether SPI_ENABLED  is set to 0 or 1 in sdk_config.h

    Only by going into sdk_config.h and commenting out the line defining SPI_ENABLED can this erroneous behaviour be overridden and the NRFX drivers for SPIM3 control be enabled.

  • You need to add the following code snippet to line 142 of nrf_drv_spi.h:

    #if NRFX_CHECK(NRFX_SPIM3_ENABLED)
        #define NRF_DRV_SPI_INSTANCE_3 \
            { 3, { .spim = NRFX_SPIM_INSTANCE(3) }, true }
    #elif NRFX_CHECK(NRFX_SPI2_ENABLED)
        #define NRF_DRV_SPI_INSTANCE_3 \
            { 3, { .spi = NRFX_SPI_INSTANCE(3) }, false }
    #endif


    I used the SPI example from SDK15.3 with the PCA10056 as the target. Enabled NRFX_SPIM3_ENABLED under nRF_Drivers/NRFX_SPIM_ENABLED/ in sdk_config.h. 
    Then I set SPI_INSTANCE to 3 and compiled successfully. 

  • Interesting.
    I have questions

    I'm guessing that line 4 of that was supposed to say NRFX_SPI3_ENABLED rather than the typo NRFX_SPI2_ENABLED?

    Will your modification be added to future SDK releases?

    Does the nrf_drv_spi code actually support EasyDMA Lists for SPIM3, and the extended SPIM features of hardware SS control the way the NRFX drivers do?

    How do we work-around the fact that the type nrf_drv_spi_config_t doesn't contained the necessary extended configuration parameters (use_hw_ss, dcx_pin, etc) that the nrfx_spim_config_t type does.

    How would EasyDMA Lists be enabled using the nrf_drv_spi library?
    Currently I am using the following code to enable it with the NRFX drivers:
      // Enable the use of EasyDMA ArrayList
      spim3.p_reg->TXD.LIST = 1;

Related