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

BLE stack initialization stucks

Hello,

I want to use the code from the BLE template in my own application and so I copied all necessary files into the project, but the code stucks at

err_code = nrf_sdh_enable_request();

I have debugged the project and found out that the code never returns from

SVCALL(SD_SOFTDEVICE_ENABLE, uint32_t, sd_softdevice_enable(nrf_clock_lf_cfg_t const * p_clock_lf_cfg, nrf_fault_handler_t fault_handler));

in "nrf_sdm.h".

I use the following code:

static void Init_Log(void)
{
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();
}

static void Init_Timer(void)
{
    APP_ERROR_CHECK(app_timer_init());
}

static void Init_PowerManagement(void)
{
    NRF_LOG_INFO("Initialize Power Management...");

    APP_ERROR_CHECK(nrf_pwr_mgmt_init());
}

static void Init_BLE(void)
{
    ret_code_t err_code;
    uint32_t ram_start = 0;

    NRF_LOG_INFO("Initialize BLE...");

    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    APP_ERROR_CHECK(nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start));

    // Enable BLE stack.
    APP_ERROR_CHECK(nrf_sdh_ble_enable(&ram_start));

    // Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, BLE_Event_Handler, NULL);
}

How can I fix this issue?

Parents
  • Hello,

    It's almost always a problem with the clock source selection when the program hangs in sd_softdevice_enable(). Does your board have a 32KHz crystal mounted? If not, the p_clock_lf_cfg argument which specifies what clock source the Softdevice shall use must be set to use the LFRC.

    sdk_config.h settings to use internal RC oscillator with periodic calibration:

    //==========================================================
    
    // <h> Clock - SoftDevice clock configuration
    
    //==========================================================
    // <o> NRF_SDH_CLOCK_LF_SRC  - SoftDevice clock source.
     
    // <0=> NRF_CLOCK_LF_SRC_RC 
    // <1=> NRF_CLOCK_LF_SRC_XTAL 
    // <2=> NRF_CLOCK_LF_SRC_SYNTH 
    
    #ifndef NRF_SDH_CLOCK_LF_SRC
    #define NRF_SDH_CLOCK_LF_SRC 0
    #endif
    
    // <o> NRF_SDH_CLOCK_LF_RC_CTIV - SoftDevice calibration timer interval. 
    #ifndef NRF_SDH_CLOCK_LF_RC_CTIV
    #define NRF_SDH_CLOCK_LF_RC_CTIV 2
    #endif
    
    // <o> NRF_SDH_CLOCK_LF_RC_TEMP_CTIV - SoftDevice calibration timer interval under constant temperature. 
    // <i> How often (in number of calibration intervals) the RC oscillator shall be calibrated
    // <i>  if the temperature has not changed.
    
    #ifndef NRF_SDH_CLOCK_LF_RC_TEMP_CTIV
    #define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 16
    #endif
    
    // <o> NRF_SDH_CLOCK_LF_ACCURACY  - External clock accuracy used in the LL to compute timing.
     
    // <0=> NRF_CLOCK_LF_ACCURACY_250_PPM 
    // <1=> NRF_CLOCK_LF_ACCURACY_500_PPM 
    // <2=> NRF_CLOCK_LF_ACCURACY_150_PPM 
    // <3=> NRF_CLOCK_LF_ACCURACY_100_PPM 
    // <4=> NRF_CLOCK_LF_ACCURACY_75_PPM 
    // <5=> NRF_CLOCK_LF_ACCURACY_50_PPM 
    // <6=> NRF_CLOCK_LF_ACCURACY_30_PPM 
    // <7=> NRF_CLOCK_LF_ACCURACY_20_PPM 
    // <8=> NRF_CLOCK_LF_ACCURACY_10_PPM 
    // <9=> NRF_CLOCK_LF_ACCURACY_5_PPM 
    // <10=> NRF_CLOCK_LF_ACCURACY_2_PPM 
    // <11=> NRF_CLOCK_LF_ACCURACY_1_PPM 
    
    #ifndef NRF_SDH_CLOCK_LF_ACCURACY
    #define NRF_SDH_CLOCK_LF_ACCURACY 1
    #endif
    

    Best regards,

    Vidar

  • Hello,

    yes a 32 kHz crystal is mounted and I update the config file according to your example.

  • Hello,

    Ok, so it still hangs after you've changed the clock source? Is it a custom board or a nordic DK? Maybe you post a screenshot showing the CPU registers and disassembly when it hangs?

  • Hello,

    sorry I missed it again...
    It is an nRF52 DK with no modifications. Please take a look at the screenshot. I hope it helps.

  • Hello,

    The application is supposed to run on top of the Softdevice as you can see from the memory layout here in the Softdevice specification: Memory resource map and usage. So you will need to change the linker settings of your app so it doesn't overlap with the Softdevice.

    Relevant linker settings from BLE template example in SDK 17.0.2

    And the setting to make Embedded Studio program the Softdevice toghether with the application image

  • Hello,

    thank you for the help. The application doesn´t stuck anymore but will jump into the error handler(error 4097).

Reply Children
Related