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

lfclk, rtc issue on SDK13

I am trying to set up RTC2 by following an example github.com/.../saadc_low_power I ported it to my project which is running a softdevice on nRF52. It works perfectly fine on SDK11 but has problems on SDK13.0 / 13.1. Seems like nrf_drv_clock_init() or nrf_drv_rtc_init() has conflict with the BLE stack. Any idea what has changed from SDK11 to SDK13?

  • const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(2); sdk_config.h probably too large to upload. I just change the followings in a ble_app_hrs or ble_app_hts example. everything else stays the same except lfclk_config(), rtc_config(void) added.

    #define CLOCK_ENABLED 1
    #define RTC_ENABLED 1
    #define RTC2_ENABLED 1
    
  • Hi,

    You can't call nrf_drv_rtc_init() with p_config = NULL. There is an assert inside the function that checks if p_config is set, but this is not firing for some reason. If called without config, the priority will not be set to one of the allowed levels for use with softdevice.

    You should get default config from sdk_config.h like this:

    static void rtc_config(void)
    {
        uint32_t err_code;
    
        //Initialize RTC instance
        nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG;
        err_code = nrf_drv_rtc_init(&rtc, &config, rtc_handler);
        APP_ERROR_CHECK(err_code);
    }
    

    Best regards,

    Jørgen

  • After some debugging I come to the conclusion there is a condition check in sd_softdevice_enable on lfclk that does not allow lfclk to be enabled outside of softdevice. It raises an exception if so.

  • I have the same problem with SDK 14.1. If I initialize CLOCK and RTC driver before BLE stack I have an error in return of nrf_sdh_enable_request():

    <error> app: ERROR 4097 [Unknown error code] 
    

    If I initialize BLE stack first, I can initialize CLOCK (nrf_drv_clock_init()) but RTC initialization fails (nrf_drv_rtc_init()) with the error:

    <error> app: SOFTDEVICE: INVALID MEMORY ACCESS
    

    RTC section of sdk_config.h:

    // <e> RTC_ENABLED - nrf_drv_rtc - RTC peripheral driver
    //==========================================================
    #ifndef RTC_ENABLED
    #define RTC_ENABLED 1
    #endif
    // <o> RTC_DEFAULT_CONFIG_FREQUENCY - Frequency  <16-32768> 
    
    
    #ifndef RTC_DEFAULT_CONFIG_FREQUENCY
    #define RTC_DEFAULT_CONFIG_FREQUENCY 32768
    #endif
    
    // <q> RTC_DEFAULT_CONFIG_RELIABLE  - Ensures safe compare event triggering
     
    
    #ifndef RTC_DEFAULT_CONFIG_RELIABLE
    #define RTC_DEFAULT_CONFIG_RELIABLE 0
    #endif
    
    // <o> RTC_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 RTC_DEFAULT_CONFIG_IRQ_PRIORITY
    #define RTC_DEFAULT_CONFIG_IRQ_PRIORITY 7
    #endif
    
    // <q> RTC0_ENABLED  - Enable RTC0 instance
     
    
    #ifndef RTC0_ENABLED
    #define RTC0_ENABLED 0
    #endif
    
    // <q> RTC1_ENABLED  - Enable RTC1 instance
     
    
    #ifndef RTC1_ENABLED
    #define RTC1_ENABLED 0
    #endif
    
    // <q> RTC2_ENABLED  - Enable RTC2 instance
     
    
    #ifndef RTC2_ENABLED
    #define RTC2_ENABLED 1
    #endif
    
    // <o> NRF_MAXIMUM_LATENCY_US - Maximum possible time[us] in highest priority interrupt 
    #ifndef NRF_MAXIMUM_LATENCY_US
    #define NRF_MAXIMUM_LATENCY_US 2000
    #endif
    
  • Error 4097 (0x1001) corresponds to NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION. The second error (INVALID MEMORY ACCESS) indicates that the function is accessing a peripheral restricted or blocked by the softdevice, without using the softdevice API. Can you upload the project for review of the code and debugging?

Related