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

wait_for_flash_ready(&fstorage)

SDK 15.2

SES

nrf52832

Hello!

I´m trying to store an array in the memory. When the devices starts advertising or it is connected the code loops in wait_for_flash_ready(&fstorage);

for(uint32_t i=0; i<10; i++)
{
    ret_code_t rc= nrf_fstorage_write(&fstorage, my_addr+(i*4), &my_array[i], 4, NULL);
    APP_ERROR_CHECK(rc);

    wait_for_flash_ready(&fstorage);
    NRF_LOG_INFO("Done.");
}

Any idea why this could be happening??

Thanks for the help

Parents
  • Hello,

    I assume you have a nrf_fstorage_sys_evt_handler(), and when there is much BLE activity you may experience NRF_EVT_FLASH_OPERATION_ERROR (operation timeout due to other higher level priorities in the softdevice) instead of NRF_EVT_FLASH_OPERATION_SUCCESS.

    When receiving NRF_EVT_FLASH_OPERATION_ERROR you should retry the nrf_fstorage_write().

    Best regards,
    Kenneth

  • Hello,

    I've had exactly the same problem with nrf_storage_erase() never erasing the flash and with the nrf_storage event callback function never being called.

    I am using SDK v15.0.0 with SoftDevice enabled.

    It turned out that the problem was with how SoftDevice (SD) events were handled. I started my project out of the Nordic USBD BLE UART Example. In that project, sdk_config.h has the following configuration:

    #define NRF_SDH_DISPATCH_MODEL 1   /* SoftDevice events are scheduled using @ref app_scheduler */

    And using the code from the example, actually SD events are never polled.

    Since the nrf_storage events are a consequence of SD events (when the SoftDevice is used as a backend for nrf_storage library) it is the SD event handler that will call the nrf_storage event callback function.

    Consequently, if SD events are not handled, the nrf_storage event callback function will in turn never be called.

    A simple solution to the problem is to change how SoftDevice events are handled (in sdk_config.h):

    #define NRF_SDH_DISPATCH_MODEL 0   /* SoftDevice events are passed to the application from the interrupt context */

    In fact, this is the standard configuration in the Nordic example "Flash Storage Example", where flash erasing works!

    At this point you can check by placing a breakpoint at the function SD_EVT_IRQHandler() (in file nrf_sdh.c) and you will see that it is from here that nrf_storage events are handled.

    And a final remark: don't confuse the "Flash Data Storage" library (and functions) with "Flash Storage" library (as I did Wink).

    Even if you have "Flash Data Storage" properly initialized and running, you still have to separately and properly initialize "Flash Storage" in order to use functions such as nrf_storage_erase(), nrf_storage_write(). The best way to do this is to copy it from the "Flash Storage Example".

Reply
  • Hello,

    I've had exactly the same problem with nrf_storage_erase() never erasing the flash and with the nrf_storage event callback function never being called.

    I am using SDK v15.0.0 with SoftDevice enabled.

    It turned out that the problem was with how SoftDevice (SD) events were handled. I started my project out of the Nordic USBD BLE UART Example. In that project, sdk_config.h has the following configuration:

    #define NRF_SDH_DISPATCH_MODEL 1   /* SoftDevice events are scheduled using @ref app_scheduler */

    And using the code from the example, actually SD events are never polled.

    Since the nrf_storage events are a consequence of SD events (when the SoftDevice is used as a backend for nrf_storage library) it is the SD event handler that will call the nrf_storage event callback function.

    Consequently, if SD events are not handled, the nrf_storage event callback function will in turn never be called.

    A simple solution to the problem is to change how SoftDevice events are handled (in sdk_config.h):

    #define NRF_SDH_DISPATCH_MODEL 0   /* SoftDevice events are passed to the application from the interrupt context */

    In fact, this is the standard configuration in the Nordic example "Flash Storage Example", where flash erasing works!

    At this point you can check by placing a breakpoint at the function SD_EVT_IRQHandler() (in file nrf_sdh.c) and you will see that it is from here that nrf_storage events are handled.

    And a final remark: don't confuse the "Flash Data Storage" library (and functions) with "Flash Storage" library (as I did Wink).

    Even if you have "Flash Data Storage" properly initialized and running, you still have to separately and properly initialize "Flash Storage" in order to use functions such as nrf_storage_erase(), nrf_storage_write(). The best way to do this is to copy it from the "Flash Storage Example".

Children
No Data
Related