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

Weird errors in header file

Hello, this will be a bit of a long-winded explanation but here goes: I'm building an SPI driver that reads data from an external ADC and writes to a PWM signal. I got the PWM part of the code working with the example code 'pwm_library' and got the SPI driver working with the 'spi' example code. However, the two projects still existed independently of one another, so I copy and pasted my SPI driver code to my PWM project, (including the include files). I have been troubleshooting for a few hours now and reduced my errors down to a handful:

Compiling file: main.c
In file included from ../../../main.c:1:0:
../../../../../../integration/nrfx/legacy/nrf_drv_spi.h:120:37: error: 'NRF_DRV_SPI_INSTANCE_0' undeclared here (not in a function); did you mean 'NRF_DRV_SPI_INSTANCE_'?
 #define NRF_DRV_SPI_INSTANCE_(id)   NRF_DRV_SPI_INSTANCE_ ## id
                                     ^
../../../../../../integration/nrfx/legacy/nrf_drv_spi.h:119:37: note: in expansion of macro 'NRF_DRV_SPI_INSTANCE_'
 #define NRF_DRV_SPI_INSTANCE(id)    NRF_DRV_SPI_INSTANCE_(id)
                                     ^~~~~~~~~~~~~~~~~~~~~
../../../main.c:43:34: note: in expansion of macro 'NRF_DRV_SPI_INSTANCE'
 static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */
                                  ^~~~~~~~~~~~~~~~~~~~
../../../main.c: In function 'main':
../../../../../../integration/nrfx/legacy/nrf_drv_spi.h:220:21: error: 'SPI_DEFAULT_CONFIG_IRQ_PRIORITY' undeclared (first use in this function); did you mean 'TIMER_DEFAULT_CONFIG_IRQ_PRIORITY'?
     .irq_priority = SPI_DEFAULT_CONFIG_IRQ_PRIORITY,         \
                     ^
../../../main.c:92:39: note: in expansion of macro 'NRF_DRV_SPI_DEFAULT_CONFIG'
     nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../../../integration/nrfx/legacy/nrf_drv_spi.h:220:21: note: each undeclared identifier is reported only once for each function it appears in
     .irq_priority = SPI_DEFAULT_CONFIG_IRQ_PRIORITY,         \
                     ^
../../../main.c:92:39: note: in expansion of macro 'NRF_DRV_SPI_DEFAULT_CONFIG'
     nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
make: *** [_build/nrf52832_xxaa/main.c.o] Error 1

BUILD FAILED (exit value 2, total time: 579ms)

All of the errors seem to be originating from inside the "nrf_drv_spi.h" file. Any idea why this might be happening? I wasn't getting any errors in the spi driver example and as far as I can see they're configured the same way.

  • Hi,

    It looks like you have not included (or enabled) the SPI peripheral in your sdk_config.h file. You need to include this code from the SPI example:

    // <e> SPI_ENABLED - nrf_drv_spi - SPI/SPIM peripheral driver - legacy layer
    //==========================================================
    #ifndef SPI_ENABLED
    #define SPI_ENABLED 1
    #endif
    // <o> SPI_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    
    // <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef SPI_DEFAULT_CONFIG_IRQ_PRIORITY
    #define SPI_DEFAULT_CONFIG_IRQ_PRIORITY 7
    #endif
    
    // <o> NRF_SPI_DRV_MISO_PULLUP_CFG  - MISO PIN pull-up configuration.
     
    // <0=> NRF_GPIO_PIN_NOPULL 
    // <1=> NRF_GPIO_PIN_PULLDOWN 
    // <3=> NRF_GPIO_PIN_PULLUP 
    
    #ifndef NRF_SPI_DRV_MISO_PULLUP_CFG
    #define NRF_SPI_DRV_MISO_PULLUP_CFG 1
    #endif
    
    // <e> SPI0_ENABLED - Enable SPI0 instance
    //==========================================================
    #ifndef SPI0_ENABLED
    #define SPI0_ENABLED 1
    #endif
    // <q> SPI0_USE_EASY_DMA  - Use EasyDMA
     
    
    #ifndef SPI0_USE_EASY_DMA
    #define SPI0_USE_EASY_DMA 1
    #endif
    
    // </e>
    
    // <e> SPI1_ENABLED - Enable SPI1 instance
    //==========================================================
    #ifndef SPI1_ENABLED
    #define SPI1_ENABLED 0
    #endif
    // <q> SPI1_USE_EASY_DMA  - Use EasyDMA
     
    
    #ifndef SPI1_USE_EASY_DMA
    #define SPI1_USE_EASY_DMA 1
    #endif
    
    // </e>
    
    // <e> SPI2_ENABLED - Enable SPI2 instance
    //==========================================================
    #ifndef SPI2_ENABLED
    #define SPI2_ENABLED 0
    #endif
    // <q> SPI2_USE_EASY_DMA  - Use EasyDMA
     
    
    #ifndef SPI2_USE_EASY_DMA
    #define SPI2_USE_EASY_DMA 1
    #endif
    
    // </e>
    
    // <q> SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED  - Enables nRF52 anomaly 109 workaround for SPIM.
     
    
    // <i> The workaround uses interrupts to wake up the CPU by catching
    // <i> a start event of zero-length transmission to start the clock. This 
    // <i> ensures that the DMA transfer will be executed without issues and
    // <i> that the proper transfer will be started. See more in the Errata 
    // <i> document or Anomaly 109 Addendum located at 
    // <i> https://infocenter.nordicsemi.com/
    
    #ifndef SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED
    #define SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 0
    #endif
    
    // </e>

    Best regards,
    Jørgen

Related