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

No callbacks from pstorage

I'm following the official tutorial for using pstorage and this the simplest test code I've come up with:

static pstorage_handle_t base_handle;

static void test_pstorage_cb_handler(pstorage_handle_t * p_handle,
                                     uint8_t             op_code,
                                     uint32_t            result,
                                     uint8_t           * p_data,
                                     uint32_t            data_len)
{

}

void pstorage_test(void)
{
    uint32_t res;

    res = pstorage_init();
    APP_ERROR_CHECK(res);

    pstorage_module_param_t param;
    memset(&param, 0, sizeof(param));      
    param.block_size  = 24;
    param.block_count = 10;
    param.cb          = test_pstorage_cb_handler;
        
    res = pstorage_register(&param, &base_handle);
    APP_ERROR_CHECK(res);

    pstorage_handle_t block_handle;
    res = pstorage_block_identifier_get(&base_handle, fault_id, &block_handle);
    APP_ERROR_CHECK(res);

    res = pstorage_clear(&block_handle, 24 * 10);
    APP_ERROR_CHECK(res);
}

Despite all function call returning NRF_SUCCESS, I never get callbacks and pstorage_access_status_get() continuously returns 1.

What could I be doing wrong?

EDIT:

My main():

int main(void)
{
    timers_init();
    gpiote_init();
    ble_stack_init();
    bsp_module_init();
    scheduler_init();
    gap_params_init();
    advertising_init();
    services_init();
    conn_params_init();
    sec_params_init();
    
    pstorage_test();
    
    while (1) app_sched_execute();
}
Parents
    1. If you execute pstorage_test in some interrupt context, then pstorage does not work well. There has been many issues noted here on devzone if you execute pstorage functions other than in main context. Use scheduler for that.

    2. your callback is empty, if you have optimizations enabled in the code, then the callback function is likely to be optimized away.

  • Ok, so I looked into pstorage.c and ASAIU, there are two pathways leading to sd_flash_page_erase():

    1. ? -> pstorage_sys_event_handler() -> cmd_queue_dequeue() -> cmd_process() -> sd_flash_page_erase()

    2. pstorage_clear() -> cmd_queue_enqueue() -> m_cmd_queue.flash_access==true -> cmd_process() -> sd_flash_page_erase()

    In my case m_cmd_queue.flash_access is always false (since it was set so in pstorage_init() -> cmd_queue_init()) and pstorage_sys_event_handler() is never called, so nothing ends up happening.

    SOLUTION:

    Add call to pstorage_sys_event_handler() to sys_evt_dispatch().

Reply
  • Ok, so I looked into pstorage.c and ASAIU, there are two pathways leading to sd_flash_page_erase():

    1. ? -> pstorage_sys_event_handler() -> cmd_queue_dequeue() -> cmd_process() -> sd_flash_page_erase()

    2. pstorage_clear() -> cmd_queue_enqueue() -> m_cmd_queue.flash_access==true -> cmd_process() -> sd_flash_page_erase()

    In my case m_cmd_queue.flash_access is always false (since it was set so in pstorage_init() -> cmd_queue_init()) and pstorage_sys_event_handler() is never called, so nothing ends up happening.

    SOLUTION:

    Add call to pstorage_sys_event_handler() to sys_evt_dispatch().

Children
No Data
Related