fstorage erase is not working

Hi,

I am using fstorage functions in the ANT broadcast RX project.

I am doing the fstorage write function when the ANT device is connected (Inside RX EVENT of ANT event handler, only one write) and I am calling erase function during any button interrupt.

But I am having one problem:

Erase function is not happening if any write function has happened before.

If I reset the device and try only erase function, then it's happening.

And I am not getting any fstorage events.

Please provide us the solution for this issue.

Regards,

Aslam

Parents
  • it seems like you might be encountering an issue with the order of operations or the timing of your fstorage function calls.
    In a similar post, a user reported a similar issue where the nrf_fstorage_evt() callback was not triggered when BLEInit() was called. The user was able to resolve the issue by changing the order of their code.
    In this thread, a user reported that their device was randomly erasing data when Fstorage was executed. They were able to resolve the issue by increasing the NRF_FSTORAGE_SD_QUEUE_SIZE.
    It's also important to note that the nrf_fstorage_write() and nrf_fstorage_erase() functions are asynchronous. This means that they return immediately, and the operation is performed in the background. You can use the nrf_fstorage_is_busy() function to check if an operation is ongoing.
    Here is an example of how you might structure your code:
    uint32_t rc;
    
    // Erase the flash.
    rc = nrf_fstorage_erase(&fstorage, FSTORAGE_START_ADDR, 1, NULL);
    APP_ERROR_CHECK(rc);
    
    // Wait for the erase operation to complete.
    while (nrf_fstorage_is_busy(&fstorage));
    
    // Write to the flash.
    rc = nrf_fstorage_write(&fstorage, FSTORAGE_START_ADDR, &data, sizeof(data), NULL);
    APP_ERROR_CHECK(rc);
    
    // Wait for the write operation to complete.
    while (nrf_fstorage_is_busy(&fstorage));
Reply
  • it seems like you might be encountering an issue with the order of operations or the timing of your fstorage function calls.
    In a similar post, a user reported a similar issue where the nrf_fstorage_evt() callback was not triggered when BLEInit() was called. The user was able to resolve the issue by changing the order of their code.
    In this thread, a user reported that their device was randomly erasing data when Fstorage was executed. They were able to resolve the issue by increasing the NRF_FSTORAGE_SD_QUEUE_SIZE.
    It's also important to note that the nrf_fstorage_write() and nrf_fstorage_erase() functions are asynchronous. This means that they return immediately, and the operation is performed in the background. You can use the nrf_fstorage_is_busy() function to check if an operation is ongoing.
    Here is an example of how you might structure your code:
    uint32_t rc;
    
    // Erase the flash.
    rc = nrf_fstorage_erase(&fstorage, FSTORAGE_START_ADDR, 1, NULL);
    APP_ERROR_CHECK(rc);
    
    // Wait for the erase operation to complete.
    while (nrf_fstorage_is_busy(&fstorage));
    
    // Write to the flash.
    rc = nrf_fstorage_write(&fstorage, FSTORAGE_START_ADDR, &data, sizeof(data), NULL);
    APP_ERROR_CHECK(rc);
    
    // Wait for the write operation to complete.
    while (nrf_fstorage_is_busy(&fstorage));
Children
  • Hi Susheel,

    Thanks for the suggestion.

    But I have calling the  nrf_fstorage_write() and nrf_fstorage_erase() functions inside the interrupt.

    If I call nrf_fstorage_is_busy function inside the ISR, the device getting hanged.

    And also, I have tried calling this nrf_fstorage_is_busy function inside the main after calling the ANT INIT, and this nrf_fstorage_is_busy(&fstorage) function is always giving "true" means the program gets stuck in this line and flash storage is always busy.

    Regards,

    Aslam

  • Hi Susheel,

    Adding to the previous point, If I write before soft device initialization, then nrf_fstorage_is_busy(&fstorage) function is giving false after some time (means flash write is happening correctly).

    But if I write something after soft device initialization, then nrf_fstorage_is_busy(&fstorage) function is always giving "true" means the program gets stuck in this line.

    Regards,

    Aslam

  • Mohamed, 

    I will ask the ANT expert to see if there are any pitfalls in writing to flash with ANT. Will write back to you soon with his comments.

    In the meantime, I would suggest you to start your program in debugger and run it for a while with the setup where nrf_fstorage_is_busy is called from main and always returns true. After running the debugger for a while, please halt the debugger and see if the code is looping in some context. If we can get this context, then we can try to understand why that happens.

  • ANT expert says that it should be fine to use fstorage the way you are using and we are not sure why you are not getting any events. Have you declared NRF_FSTORAGE_DEF in your application?

  • Hi Susheel,

    "Have you declared NRF_FSTORAGE_DEF in your application?"

    Yes, I have declared NRF_FSTORAGE_DEF in my application.

    And I have observed that Writing to flash before soft device initialization results in successful flash writes and flash events being triggered.

    However, writing to flash after soft device initialization does not result in flash writes and flash events are not triggered. I have checked in debug mode, the program seems to be stuck on the line where nrf_fstorage_is_busy function is called.

    Regards,

    Aslam

Related