how to reset m_ble_evt_handler?

I'm trying to send a parameter over BLE, but once i've stopped using the BLE stacked (and unininited softdevice) I can't seem to save the parameter recieved with pstorage.

Investigating i've found that if i reset m_ble_evt_handler i can correctly save the parameter with pstorage.

pstorage_update works correctly in normal conditions, but once i use the function softdevice_ble_evt_handler_set(ble_evt_dispatch); pstorage_update no longer works, it just tries to save forever, never ending the process.

With these things in mind, i tried resetting manually m_ble_evt_handler, tried to use pstorage_update after it, and it worked correctly. Now i need to know if there's a "clean" way to reset m_ble_evt_handler because i've done it by adding an extra line in softdevice_handler.c.

The ble_stack_init(); function i'm using is literally copypasted from the ble_uart example from the sdk folder.

/**@brief Function for the S110 SoftDevice initialization.
 *
 * @details This function initializes the S110 SoftDevice and the BLE event interrupt.
 */
static void ble_stack_init(void)
{
    uint32_t err_code;

    // Initialize SoftDevice.
    softdevice_init();

    // Enable BLE stack.
    ble_enable_params_t ble_enable_params;
    memset(&ble_enable_params, 0, sizeof(ble_enable_params));
#if (defined(S130) || defined(S132))
    ble_enable_params.gatts_enable_params.attr_tab_size   = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT;
#endif
    ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT;
    err_code = sd_ble_enable(&ble_enable_params);
    APP_ERROR_CHECK(err_code);

    // Subscribe for BLE events.
    err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
    APP_ERROR_CHECK(err_code);
}

I'm using sdk v10 with s110, and it's not currently a possibility to update to v11 or v12.

Parents Reply Children
  • Are you calling softdevice_sys_evt_handler_set() anywhere?

    Snippet:

    static void sys_evt_dispatch(uint32_t sys_evt)
    {
        pstorage_sys_event_handler(sys_evt);
    }
    
    
    static void ble_stack_init(void)
    {
    .
    .
    .
    
       // Register with the SoftDevice handler module for System events.
        err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
        APP_ERROR_CHECK(err_code);
        
        
    }

  • Yes I am. Inside my ble_stack_init function i call softdevice_init, which calls softdevice_sys_evt_handler_set:

    void softdevice_init()
    {
        uint8_t is_enabled;
        sd_softdevice_is_enabled(&is_enabled);
    
        if(is_enabled)
            return;
    
        // Initialize SoftDevice.
        SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_16000MS_CALIBRATION, NULL);
    
        // Register with the SoftDevice handler module for System events. Needed for settings.
        uint32_t retval = softdevice_sys_evt_handler_set(sys_evt_dispatch);
        APP_ERROR_CHECK(retval);
    }

  • but once i've stopped using the BLE stacked (and unininited softdevice) I can't seem to save the parameter recieved with pstorage.

    Could you explain the motivation behind disabling the Softdevice in the first place? The pstorage module (except for the pstorage_nosd variant) is expected to be used when the SoftDevice is enabled. 

    It’s also difficult for us to speculate on why your application hangs when ble_evt_dispatch is not NULL without seeing the full code. 

  • i uninit softdevice because i need to uninit ble stack. i re-init it to use pstorage. do you know i was asked this? i think it might help

    Are you calling softdevice_sys_evt_handler_set() anywhere?
  • The question is why you need to uninit the ble stack in the first place.

    julian24 said:
    do you know i was asked this? i think it might help

    Probably to verify that system events from the Softdevice were propagated to the pstorage module. Forgetting to forward these events to the module was one of the common mistakes one could make when integrating the module in a BLE application.

Related