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

Can anyone explain this SPI SDK example sdk_config.h? Sloppy code?

Looking at

\NORDIC\SDK\examples\peripheral\spi\pca10040\blank\config\sdk_config.h

These lines repeat over and over. Was there a reason for this? The first time the infdef runs it'll define a value, then the rest will get ignored. Is this just a sloppy copy and paste job - or is there something else going on here?

#ifndef SPI_MISO_PIN
#define SPI_MISO_PIN 28
#endif

...

#ifndef SPI_MISO_PIN
#define SPI_MISO_PIN 31
#endif

...

#ifndef SPI_MISO_PIN
#define SPI_MISO_PIN 31
#endif

...

<occurs a total of 9 times in the same file>

  • hahah! That's not all yet man! You'll need more defines to get it to compile.

  • Their SPI example built fine for me. It's just a terrible header for an example people are supposed to use.

  • Their example compiles for sure since it already have the sdk_config.h with all defines set for it.  If you create a new project from scratch or change to a different SPI number.  Then... see all the defines bellow for enabling SPI. Just enable SPI_ENABLED is not enough to compile you have to enable SPI number for the code to compile.  Sloppy code, you bet.  Every single source file in the SDK has that kind of define guarding it from compilation.  So just adding the source to your project is not enough to get it compiles.  Imagine that sdk_config.h has over 3000 lines!!!  

    // <e> SPI_ENABLED - nrf_drv_spi - SPI/SPIM peripheral driver
    //==========================================================
    #ifndef SPI_ENABLED
    #define SPI_ENABLED 0
    #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
    
    // <e> SPI0_ENABLED - Enable SPI0 instance
    //==========================================================
    #ifndef SPI0_ENABLED
    #define SPI0_ENABLED 0
    #endif
    // <q> SPI0_USE_EASY_DMA  - Use EasyDMA
     
    
    #ifndef SPI0_USE_EASY_DMA
    #define SPI0_USE_EASY_DMA 1
    #endif
    
    // <o> SPI0_DEFAULT_FREQUENCY  - SPI frequency
     
    // <33554432=> 125 kHz 
    // <67108864=> 250 kHz 
    // <134217728=> 500 kHz 
    // <268435456=> 1 MHz 
    // <536870912=> 2 MHz 
    // <1073741824=> 4 MHz 
    // <2147483648=> 8 MHz 
    
    #ifndef SPI0_DEFAULT_FREQUENCY
    #define SPI0_DEFAULT_FREQUENCY 1073741824
    #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
    
    // <o> SPI1_DEFAULT_FREQUENCY  - SPI frequency
     
    // <33554432=> 125 kHz 
    // <67108864=> 250 kHz 
    // <134217728=> 500 kHz 
    // <268435456=> 1 MHz 
    // <536870912=> 2 MHz 
    // <1073741824=> 4 MHz 
    // <2147483648=> 8 MHz 
    
    #ifndef SPI1_DEFAULT_FREQUENCY
    #define SPI1_DEFAULT_FREQUENCY 1073741824
    #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
    
    // <o> SPI2_DEFAULT_FREQUENCY  - SPI frequency
     
    // <33554432=> 125 kHz 
    // <67108864=> 250 kHz 
    // <134217728=> 500 kHz 
    // <268435456=> 1 MHz 
    // <536870912=> 2 MHz 
    // <1073741824=> 4 MHz 
    // <2147483648=> 8 MHz 
    
    #ifndef SPI2_DEFAULT_FREQUENCY
    #define SPI2_DEFAULT_FREQUENCY 1073741824
    #endif
    
    // </e>
    

Related