SDK 15.2




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);


Any idea why this could be happening??

Thanks for the help

  • 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,

  • Hey! I tried to check nrf_fstorage_sys_evt_handler() and it actually never enters that function.

    I tested the previous code without the for loop and commenting wait_for_flash_ready. It actually works when i want to write just a part of the array, but when i add the for loop i get a fatal error.

    EDIT: in nrf_fstorage_sd.c i modified the is_busy function 

    static bool is_busy(nrf_fstorage_t const * p_fs)
        if(m_flags.state == NRF_FSTORAGE_STATE_OP_EXECUTING)
            test_value ++;
        return (m_flags.state != NRF_FSTORAGE_STATE_IDLE);

    the code never stops and the test value is always increasing.

  • Not sure exactly what is the problem here, but there are some old examples here that still may be useful:

    Also there is the documentation you may refer to:

  • 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".