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

Soft device_enable returns err code 2 .

I have taken ble_app_ancs_c_s130_pca10028 example and modified the application to run on our custom board. The custom board uses NRF51822 (NRF51 IC revision 3). The following two changes were made to the example.

1.change the target to nrf51822. 2.Changed the clock source to RC clock source as follows.

nrf_clock_lf_cfg_t rc_cfg = {

.source = NRF_CLOCK_LF_SRC_RC,
.rc_ctiv = 0, //
.rc_temp_ctiv = 0,
.xtal_accuracy =NRF_CLOCK_LFCLKSRC_RC_250_PPM_250MS_CALIBRATION, };

The softdevice_enable function returns err_code 2. I also tried running the example available in nrf51822 example available in github link:

github.com/.../nRF51_SDK_v11
Tools: SDK11
version:2.0.0
softdevice: s130
Kiel version: 5.17
Please let me know what could be the possible reason for the error and how to resolve it.

  • Are you absolutely sure that the error number is is correct? If you are sure then it means NRF_ERROR_SOFTDEVICE_NOT_ENABLED.

    If you see nrf_soc.h, you see that in enum NRF_SOC_SVCS -> SD_MUTEX_NEW = SOC_SVC_BASE_NOT_AVAILABLE. This means that from SVC number 0x2B you need to have softdevice enabled for sd_xxx calls to work.

    SD_SOFTDEVICE_ENABLE is a SVC call with number 0x10. And it cannot return that error as you cannot have softdevice enabled before calling sd_softdevice_enable. If you have really ended up here then most likely the stack is corrupted in your application. After making sd_softdevice_enable call, the value of svc number somehow got changed (which can happen in stack corruption). First thing that you should check is if you have a stack overflow and/or stack corruption. You can do this by stepping in your assembly code.

  • I checked for the stack overflow error in assembly code, but nothing as such occurs. The reason for the error #2 was, I had by mistake commented the softdevice_handler initialization function, sorry for the confusion.

    Now the error I am facing is error 4 - No Memory for operation, for the below function sd_ble_enable(p_ble_enable_params, &app_ram_base);
    I tried increasing the RAM size to maximum 0x4000, but still I am facing the same error.

    Following is the ble_stack_init function.

    static void ble_stack_init(void) {
    nrf_clock_lf_cfg_t rc_cfg = { .source = NRF_CLOCK_LF_SRC_RC, .rc_ctiv = 0, .rc_temp_ctiv = 0, .xtal_accuracy =NRF_CLOCK_LFCLKSRC_RC_250_PPM_250MS_CALIBRATION, }; SOFTDEVICE_HANDLER_INIT(&rc_cfg,NULL);

    ble_enable_params_t ble_enable_params;
    err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT,
                                                    &ble_enable_params);
    APP_ERROR_CHECK(err_code);
    
    ble_enable_params.common_enable_params.vs_uuid_count = VENDOR_SPECIFIC_UUID_COUNT;
    //Check the ram settings against the used number of links
    CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT);
    
    // Enable BLE stack.
    err_code = softdevice_enable(&ble_enable_params);
    APP_ERROR_CHECK(err_code);
    
    // Register with the SoftDevice handler module for BLE events.
    err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
    APP_ERROR_CHECK(err_code);
    
    // Register with the SoftDevice handler module for System events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
    

    }

  • sorry for late response.

     @retval ::NRF_ERROR_NO_MEM         The amount of memory assigned to the SoftDevice by *p_app_ram_base is not
     *                                    large enough to fit this configuration's memory requirement. Check *p_app_ram_base
     *                                    and set the start address of the application RAM region accordingly.
    

    if you are still facing problem, i would suggest you to open a support case and upoad your project there so that i can have a quick look.

Related