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
  • Hi!

    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.

    Could you show how you are "resetting manually m_ble_evt_handler" ? 

    It could be that the way you are doing it now, is the correct and most "clean" way to do it.

Children
  • Hi!

    I mean, in terms of code it looks kind of clean, since i just added these three lines at the end of softdevice_handler.c:

    void custom_function_null_ble_handler(void){
        m_ble_evt_handler = NULL;
    }
    

    What bothers me is that I added this extra function at the end of an SDK lib, and i would appreciate a "canonical" way to reset the pointer. Besides, do you happen to know if this is a common error when dealing with ble and pstorage libs? Or at least if it's an expectable/ordinary bug.

    I'm using SDK v10

    Thanks for all.

  • Hi, sorry to bother, but is anyone still reading this?

  • 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. 

Related