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

sd_flash_write writes corrupted data when BLE is enabled

Hi,

I wrote some code that writes to the flash perfectly when BLE is not enabled but when it is enabled, some of the data are correct while others are either missing or shifted to a later address. Below is a snippet of the code:

uint32_t retval;
while(NRF_ERROR_BUSY == (retval = sd_flash_write(p_dst, p_src, num_words)));
ASSERT(NRF_SUCCESS == retval);

I'm trying to avoid pstorage since I'm want to write to a contiguous block of flash much greater then the page size.

Thanks.

Parents
  • Well that code looks like it should work, but sitting in a tight loop waiting for sd_flash_write() not to return NRF_ERROR_BUSY must be banging the hell out of the sd flash writing code, it's a bit brutal isn't it, if there's a bug in there (what SD version by the way) that kind of code may well uncover it.

    There's also no guarantee even when that code returns success that the flash operation actually happens, you can still get an error reported.

    It would probably help to rewrite that to use the softdevice flash events (NRF_EVT_FLASH_OPERATION_SUCCESS/ERROR) to send your writes only when the SD is ready for them and to check for errors. Either an interrupt handler routine or even sd_app_event_wait() would do that for you.

Reply
  • Well that code looks like it should work, but sitting in a tight loop waiting for sd_flash_write() not to return NRF_ERROR_BUSY must be banging the hell out of the sd flash writing code, it's a bit brutal isn't it, if there's a bug in there (what SD version by the way) that kind of code may well uncover it.

    There's also no guarantee even when that code returns success that the flash operation actually happens, you can still get an error reported.

    It would probably help to rewrite that to use the softdevice flash events (NRF_EVT_FLASH_OPERATION_SUCCESS/ERROR) to send your writes only when the SD is ready for them and to check for errors. Either an interrupt handler routine or even sd_app_event_wait() would do that for you.

Children
  • I'm using SD v7.1.0 s110. I'll try using softdevice_sys_evt_handler_set and report back.

  • I've tried rewriting it with the sys_evt_handler. The code now looks like this:

    while(!flash_done);
    flash_done = false;
    retval = sd_flash_write(p_dst, p_src, num_words);
    ASSERT(NRF_SUCCESS == retval || NRF_ERROR_BUSY == retval);
    wait_us(500);
    

    Inside the handler, if I receive a NRF_EVT_FLASH_OPERATION_SUCCESS then I set flash_done = true. I've noticed that when the handler is called the flash process is still not finished so a I had to add a small delay to make back to back writes work. Also, the sys_evt_handler is not called if I'm servicing the ble_evt_handler so the above snippet will get stuck in the loop if I'm trying to, for example, log the connection info when onConnectionCallback() is called.

Related