This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

sd_flash_page_erase will not trigger system event?

Hi,

I'm using pstorage, but found some problem. sd_flash_page_erase will not trigger system event after the operation is complete.

In my code, I registered the system event handler, according to the instruction in pstorage.

err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
APP_ERROR_CHECK(err_code);

And I also fix the bug reported in pstorage.

static void sys_evt_dispatch(uint32_t sys_evt)
{
	if ((sys_evt == NRF_EVT_FLASH_OPERATION_SUCCESS) ||
            (sys_evt == NRF_EVT_FLASH_OPERATION_ERROR)) {
		pstorage_sys_event_handler(sys_evt);
    }
}

The pstorage callback reset the flash operation in progress flag.

static void pstorage_callback(pstorage_handle_t *  p_handle,
                                  uint8_t              op_code,
                                  uint32_t             result,
                                  uint8_t *            p_data,
                                  uint32_t             data_len)
{
	/** @note sys_evt_dispatch --> pstorage_sys_event_handler --> pstorage_callback */
	if (result == NRF_EVT_FLASH_OPERATION_SUCCESS)
	{
		m_flash_opblock = false;
	} else
	{
		APP_ERROR_CHECK(result);
	}
}

In the very beginning, my code ran into pstorage_init(). It contains an operation of erasing all swap area by using sd_flash_page_erase(). This function returned successfully. However, it will never trigger the system event handler, and thus my flag cannot be reset.

Any idea about this?

  • Try this:

    uint32_t    ops_count;
    do
    {
        app_sched_execute();
        err_code = pstorage_access_status_get(&ops_count);
        APP_ERROR_CHECK(err_code);  
    }
    while(ops_count != 0);
    

    Instead of this:

    uint32_t    ops_count;
    do
    {
        err_code = pstorage_access_status_get(&ops_count);
        APP_ERROR_CHECK(err_code);  
    }
    while(ops_count != 0);
    
Related