Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

"NRFX_SPI0_INST_IDX" is undefined (IAR)

Hi,

Can't get rid of compilation error about undefined NRFX_SPI0_INST_IDX after adding nrfx_spi driver. Searched the forums and found similar issues but none of the suggested actions seems to work for me. The steps taken to add the driver:

  1. nrfx_spi.c added to project
  2. #define NRFX_SPI_ENABLED 1 and #define NRFX_SPI0_ENABLED 1 in sdk_config.h
  3. Include file search paths updated as far as I can tell (no complaints about missing files)

Using a very similar configuration for TWI/TWI0 which I managed to get working. I had issues with this as well but managed to solve it by defining TWI_ENABLED 1 and TWI0_ENABLED 1 as well. The corresponding thing does not work with SPI though.

Using IAR compiler and SDK 15.0.0, nRF52832

BR

/Ola

Parents
  • Hi,

    Try also enable this:

    #ifndef SPI_ENABLED
    #define SPI_ENABLED 1//0
    #endif

    and make sure that no others peripherals (as far as I know at least TWI) lays on same instance.

    I.e. if you defined SPI on 0, other (TWI) have to be on 1.

    Also make sure you added next file to project:

    nrf_drv_spi.c 

    Regards

  • Thank you for your reply, I've tried all suggestions. Unfortunately, no success. Still complaining about the undefined SPI instance (except it's NRFX_SPI1_INST_IDX now after moving to another instance).

    It might be some IAR related thing that affect expansion of NRFX_CHECK macro? ... but still the same construction is used and is working for TWI. I'm puzzled...

  • I suggest you open the SPI example from SDK15 and compare the included files and sdk_config to your project. 

  • Ok, I've studied the NRFX_SPIM example (The SPI example was using the legacy drivers). It compiles fine on my system. This example does not include any legacy drivers, nor enabling them in the sdk_config.h. Obviously I have something in my project that screws things up.  

  • Do a search for NRFX_SPI0_INST_IDX in your project, you should find a reference to the header file it is located in, if not then you're missing a header file. If you do find it but it is not in the compilers scope, then either the header file is not included in the source file you try to compile or it is disabled with a #ifdef SomeDefinition.

    Then you need to search your project for SomeDefinition and find where the file it is defined in, and why it is not defined. It could also be a missing pre-processor flag/definition. 

  • Here is an update after a lot of head scratching and finally getting forward. Summary of things I had to do to get it compiling:

    1. Removed everything I did using NRFX_SPI and instead tried NRFX_SPIM
    2. Different instances used;  TWI0 and SPIM1
    3. Legacy driver c file (nrf_drv_spi.c) added to project but it compiles also without. Don't know if it makes a difference at a later stage
    4. Relevant stuff from sdk_config.h looks like this:

    // <e> NRFX_SPI_ENABLED - nrfx_spi - SPI peripheral driver
    //==========================================================
    #ifndef NRFX_SPI_ENABLED
    #define NRFX_SPI_ENABLED 0
    #endif
    // <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 0
    #endif
    
    // <e> NRFX_SPIM_ENABLED - nrfx_spim - SPIM peripheral driver
    //==========================================================
    #ifndef NRFX_SPIM_ENABLED
    #define NRFX_SPIM_ENABLED 1
    #endif
    // <q> NRFX_SPIM0_ENABLED  - Enable SPIM0 instance
     
    
    #ifndef NRFX_SPIM0_ENABLED
    #define NRFX_SPIM0_ENABLED 0
    #endif
    
    // <q> NRFX_SPIM1_ENABLED  - Enable SPIM1 instance
     
    
    #ifndef NRFX_SPIM1_ENABLED
    #define NRFX_SPIM1_ENABLED 1
    #endif
    
    // <q> NRFX_SPIM2_ENABLED  - Enable SPIM2 instance
     
    
    #ifndef NRFX_SPIM2_ENABLED
    #define NRFX_SPIM2_ENABLED 0
    #endif
    
    // <e> SPI_ENABLED - nrf_drv_spi - SPI/SPIM peripheral driver - legacy layer
    //==========================================================
    #ifndef SPI_ENABLED
    #define SPI_ENABLED 1
    #endif
    
    // <e> SPI1_ENABLED - Enable SPI1 instance
    //==========================================================
    #ifndef SPI1_ENABLED
    #define SPI1_ENABLED 1
    #endif

    The interesting part I think is that just by using SPIM rather than SPI, doing only what is necessary for that, it seems to work. I can't think of anything else than some issue in the SDK. Haven't investigated further.

    Let's see what happens when starting to actually use the interface. Lots of trouble just to get through compilation...

  • I understand your frustration, SDK15 is a bit confusing with the introduction of the nrfx wrappers and sdk_config.h definitions. 

Reply Children
No Data
Related