BLE interfering with pstorage_update?

Hello everyone,

I have a problem using pstorage_update. Normally it does as it should, but once i call ble_stack_init(); on my code, pstorage_update doesn't work anymore, it just doesn't take action, does anybody know why? I even reinitialized the softdevice before using pstorage_update but it was no use. I'm using the ble stack init provided in the sdk example codes.

/**@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_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);

    // 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);
}

Parents
  • Hi,

    Which SDK version are you using? When using pstorage that in turn use SoftDevice APIs for writing to flash. The SoftDevice will schedule flash write operations in between BLE events as the CPU and radio cannot be used while writing to flash. If the connection parameters are tight for instance, the SoftDevice wills truggle with schedulign the write operation. It could also be a configuration issue of some sort (this is quite old stuff that I must admitt I don't recall that well). You may want to refer to this old unofficial sample showing usage of pstorage and SoftDevice.

  • apparently the problem is on this line:


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


    i made a custom function to make the pointer of the ble handler point to NULL after stopping advertising, and it doesn't seem to bother anymore.

    i still dont know why it happens this way, so id really like information on the topic.

    if i leave the pointer pointing to my ble dispatcher, pstorage_update never ends the memory saving

  • I already explained that. As i said, this is the function i added, which i call in my main code:

    void custom_function_null_ble_handler(void){
        m_ble_evt_handler = NULL;
    }

    I added this function in softdevice_handler.c with the corresponding header in softdevice_handler.h
    When i use my custom function i get tu use pstorage_update correctly. this is the only thing i changed as i already explained.

  • That was you intended fix/workaround, was it not? What did you do that indtroduced the issue? (This question is based on the assumption that as you are using a very old SDK this must be legacy code, please let me know if that is not the case).

  • well i did that because i checked example codes that use BLE, and even though they work, this lines makes pstorage unable to update memory.

        // Subscribe for BLE events.
        err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
        APP_ERROR_CHECK(err_code);
     
    Literally second line makes everything go wrong, so when i checked the implementation of that function, i saw that i just sets m_ble_evt_handler.
    uint32_t softdevice_ble_evt_handler_set(ble_evt_handler_t ble_evt_handler)
    {
        if (ble_evt_handler == NULL)
        {
            return NRF_ERROR_NULL;
        }
    
        m_ble_evt_handler = ble_evt_handler;
    
        return NRF_SUCCESS;
    }

    so i manually point m_ble_evt_handler to NULL to revert the changes after using ble. I did this because when the pointer points to a handler function my code doesn't work, but it does when it stops pointing.

  • So you used an example and added this, and that was it? Which example are you using?

    PS: May I ask why you are using such an old SDK? (The latest SDK which support for the nRF51 series is 12.3)

  • Yes, other than this i just set some gpios as outputs or clear them. I've seen that there are more cases of people saying that the two libraries overlap sometimes. My code normally does pstorage_update correctly but with this ble thing it stops working. it loops waiting for the operation to be completed.

Reply Children
Related