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

'sd_flash_page_erase' mass flash erase usage, with sd110

Hi Nordic DEV Team,

In my application, I would like to use sd_flash_page_erase to erase like 100 pages user data; the problem of pstorage is that I cannot specify the page ranges to erase, so choose to use sd_flash_page_erase function.

But when I use - for(uint32_t i = 108; i < 252; ++i){ err_code = sd_flash_page_erase(i); APP_ERROR_CHECK(err_code); } It doesn't work, so how to handle this kind of usage case properly? Need to wait until an application level SUCCESS flag returned by softdevice of one erase command and then do another?

Thanks.

  • Correct. You need to register for sys event notifications. You check for flash operation success and start the next page erase. Here's an example:

    softdevice_sys_evt_handler_set(sys_evt_dispatch);
    
    static void sys_evt_dispatch(uint32_t sys_evt)
    {
        switch(sys_evt)
        {
            case NRF_EVT_FLASH_OPERATION_SUCCESS:
                // erase next page here
                break;
             case NRF_EVT_FLASH_OPERATION_ERROR:
                // error handling here (perhaps retry)
                break;
            default:
                break;
        }
    }
    
Related