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

The sdk_config.h file is not being parsed by the compiler

I cannot get the scope of the sdk_config.h file to encompass all modules. Process

  • Start with example project using the file system as per the install.
  • After compiling and running on the DK, copy the example files over to a new folder for inclusion into revision control.
  • Edit the project file to make sure the relative paths have been properly modified to reflect the new project folder
  • Make sure the project still compiles and runs.
  • Make an edit that includes a new module, in this case the TWIM
  • dutifully edit the sdk_config.h file to enable the TWIM module
  • Compiler error in main at this line: static const nrfx_twim_t twi0 = NRFX_TWIM_INSTANCE(TWI_INSTANCE_ID);
  • When expanding the macro the compiler cannot find a definition for "NRFX_TWIM0_INST_IDX" because it is not enumerated in nrfx_twim.h because NRFX_TWIM0_ENABLED is not defined
  • Go back and check the nrf_config.h file and it is indeed enabled.
  • Find out that disabling other modules in the nrf_config.h file doesn't have an effect, ergo the nrf_config.h file is not being used.
  • To make sure the pathways are not pointing to another version, disable (rename) all other nrf_config.h files in the file system - no effect.
  • Explicitly define NRFX_TWIM0_ENABLED in nrfx_twim.h and everything compiles fine.
  • make a test header file with just that line and include it in main - no effect.
  • include that same test header file in nrfx_twim.h file, everything compiles fine
  • remove the test include and include the sdk_config.h file in the nrfx_twim.h file, compile fails again

What on earth is going on? I've searched up and down the project settings thinking that the config file is disabled somehow, but nothing. 

  • Hi,

    It sounds like the problem may be caused by the "apply_old_config" header located in the /<SDK>/integration directory. This file is responsible for making sure NRFX_ configurations correspond to their respective legacy NRF_ configurations. I.e.,  override the NRFX_ setting whenever the legacy setting is different. 

    TWI legacy settings

    // <e> TWI_ENABLED - nrf_drv_twi - TWI/TWIM peripheral driver - legacy layer
    //==========================================================
    #ifndef TWI_ENABLED
    #define TWI_ENABLED 1
    #endif
    // <o> TWI_DEFAULT_CONFIG_FREQUENCY  - Frequency
     
    // <26738688=> 100k 
    // <67108864=> 250k 
    // <104857600=> 400k 
    
    #ifndef TWI_DEFAULT_CONFIG_FREQUENCY
    #define TWI_DEFAULT_CONFIG_FREQUENCY 26738688
    #endif
    
    // <q> TWI_DEFAULT_CONFIG_CLR_BUS_INIT  - Enables bus clearing procedure during init
     
    
    #ifndef TWI_DEFAULT_CONFIG_CLR_BUS_INIT
    #define TWI_DEFAULT_CONFIG_CLR_BUS_INIT 0
    #endif
    
    // <q> TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT  - Enables bus holding after uninit
     
    
    #ifndef TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT
    #define TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT 0
    #endif
    
    // <o> TWI_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 TWI_DEFAULT_CONFIG_IRQ_PRIORITY
    #define TWI_DEFAULT_CONFIG_IRQ_PRIORITY 6
    #endif
    
    // <e> TWI0_ENABLED - Enable TWI0 instance
    //==========================================================
    #ifndef TWI0_ENABLED
    #define TWI0_ENABLED 1
    #endif
    // <q> TWI0_USE_EASY_DMA  - Use EasyDMA (if present)
     
    
    #ifndef TWI0_USE_EASY_DMA
    #define TWI0_USE_EASY_DMA 1
    #endif
    
    // </e>
    
    // <e> TWI1_ENABLED - Enable TWI1 instance
    //==========================================================
    #ifndef TWI1_ENABLED
    #define TWI1_ENABLED 0
    #endif
    // <q> TWI1_USE_EASY_DMA  - Use EasyDMA (if present)
     
    
    #ifndef TWI1_USE_EASY_DMA
    #define TWI1_USE_EASY_DMA 0
    #endif
    
    // </e>
    
    // <q> TWIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED  - Enables nRF52 anomaly 109 workaround for TWIM.
     
    
    // <i> The workaround uses interrupts to wake up the CPU by catching
    // <i> the start event of zero-frequency transmission, clear the 
    // <i> peripheral, set desired frequency, start the peripheral, and
    // <i> the proper transmission. See more in the Errata document or
    // <i> Anomaly 109 Addendum located at https://infocenter.nordicsemi.com/
    
    #ifndef TWIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED
    #define TWIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 0
    #endif

    And the corresponding TWI NRFX settings

     

    // <e> NRFX_TWIM_ENABLED - nrfx_twim - TWIM peripheral driver
    //==========================================================
    #ifndef NRFX_TWIM_ENABLED
    #define NRFX_TWIM_ENABLED 1
    #endif
    // <q> NRFX_TWIM0_ENABLED  - Enable TWIM0 instance
     
    
    #ifndef NRFX_TWIM0_ENABLED
    #define NRFX_TWIM0_ENABLED 0
    #endif
    
    // <q> NRFX_TWIM1_ENABLED  - Enable TWIM1 instance
     
    
    #ifndef NRFX_TWIM1_ENABLED
    #define NRFX_TWIM1_ENABLED 0
    #endif
    
    // <o> NRFX_TWIM_DEFAULT_CONFIG_FREQUENCY  - Frequency
     
    // <26738688=> 100k 
    // <67108864=> 250k 
    // <104857600=> 400k 
    
    #ifndef NRFX_TWIM_DEFAULT_CONFIG_FREQUENCY
    #define NRFX_TWIM_DEFAULT_CONFIG_FREQUENCY 26738688
    #endif
    
    // <q> NRFX_TWIM_DEFAULT_CONFIG_HOLD_BUS_UNINIT  - Enables bus holding after uninit
     
    
    #ifndef NRFX_TWIM_DEFAULT_CONFIG_HOLD_BUS_UNINIT
    #define NRFX_TWIM_DEFAULT_CONFIG_HOLD_BUS_UNINIT 0
    #endif
    
    // <o> NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY 6
    #endif
    

    Is the TWI_ENABLED symbol defined in your sdk_config file, and is it set to '1'? In any case, If you are not using the legacy APIs for the TWI driver, I would suggest that you instead remove the legacy symbols from your configuration file and only use the NRFX_TWIM_ configurations. That will prevent the settings from being overridden. 

    Best regards,

    Vidar

  • TWI_ENABLED was indeed set but unsetting it didnt help and there is no TWI_present setting.

  • It should be defined in the nrf52840_peripherals.h header located in /modules/nrfx/mdk/

  • OK, commenting the TWI_PRESENT line in the file nrf52840_peripherals.h did the trick. so help me understand what your rationale is behind having these compiler directives scattered all over the SDK? I would be nice, I think, if the local sdk_config.h were the ONE place where we could go to figure out what's being compiled and what's not, because there's no easy way to track these down. For future reference am I expected to go to nrf52840_peripherals.h and update those settings as well? And also for future edification, please list ALL the files where these directives and overrides can be found - I now know of sdk_config.h, nrfx_config.h, nrf52840_peripherals.h - are there others? It would also be nice to list all the places in the SES settings where these directives can be found as well, and what all the path macros and presets mean. This information would be golden and in this case could have saved me a couple days worth of frustration. Thanks.

    Tony

  • I'm sorry to hear that. It's unfortunate that you had spend this much time to resolve the issue.  sdk_config.h is indeed supposed to be the one place where you configure the SDK modules. nrf52840_peripherals.h is a part of our MDK distribution which specifies what peripherals the 52840 has. It should never have to be modified. Maybe the TWI0_USE_EASY_DMA option was disabled earlier? That would make the integration layer enable the TWI driver (without the 'M') instead of TWIM with EasyDMA.

    You should include the nrfx_config.h file from \integration\nrfx\ when you use nrfx with the nRF5 SDK.

Related