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

NVMC timing: Flash access blocked during low latency BT communication?

Hi,

my question is related to this question: devzone.nordicsemi.com/.../

Erasing Flash pages takes a pretty long time (and the CPU is blocked during this time). For the nRF52, up to 89.7 ms (!!) are specified in the manual.

Considering I have application code running that does not provide an interval that long without Bluetooth communication:

  • A Broadcaster role that continuously advertises at maximum speed (20ms)
  • A minimum connection interval (7.5 ms) which is used continuously
  • A Observer role that is scanning 100% of the time

What will happen if I try to erase a page that cannot be erased during two radio events? Will the request wait forever? Will it be impossible to erase a page in this scenario? Or will Bluetooth operation be affected by the flash erase operation? (I could not find any information about this scenario in the documentation available.)

In other words: Will I have to shutdown my Bluetooth communication to erase a flash page?

Update:

After trying it out with SoftDevice s132_nrf52_2.0.0-4.alpha_softdevice.hex, In most cases I immediately (=no noticeable delay in the Segger RTT log) get an error message NRF_EVT_FLASH_OPERATION_ERROR. But sometimes it seems the operation finishes successfully (erasing a page as well as writing one or two words), but I get the error message NRF_EVT_FLASH_OPERATION_VERIFY_FAILED although the flash location holds the valid data?!

When I activate advertising at 10 seconds interval and I immediately want to erase a page (just some lines after starting the advertising), I also get NRF_EVT_FLASH_OPERATION_ERROR. If I retry the function call a second later, it works fine.

If i activate both advertising (10s interval) and scanning (100% duty), and then I disable scanning before and re-enable it after flash access, it first seemes to work fine (except for the first page erase operation like mentioned above). I continue writing 1-2 words and erasing the page continuously with a 1 second delay between the operations. But after a minute or so, I suddely get NRF_EVT_FLASH_OPERATION_VERIFY_FAILED errors (although data has been written successfully) and sometimes NRF_EVT_FLASH_OPERATION_ERROR errors (in this case, the flash has not been altered). And no operation returns NRF_EVT_FLASH_OPERATION_SUCCESS anymore. I wonder what ist broken here...

Did you run a high load / stress test with the NVMC interface to ensure reliable operation?

By the way, I directly use the SoftDevice SoC interface functions sd_flash_page_erase() and sd_flash_write().

  • Hi,

    The reason for the increased flash page erase time on the nRF52 is that the flash page size is increased to 4 kB. It was 1 kB on the nRF51.

    The SoftDevice will try to schedule the flash operation, but it might not be able to do so. The request will result in an NRF_EVT_FLASH_OPERATION_ERROR event if the SoftDevice is unable to scedule the flash operation within a certain time-out. This is what happens when you set up advertising and try a flash operation immediately afterwards. You should be able to perform the flash operation if you continuously retry on the NRF_EVT_FLASH_OPERATION_ERROR event. Implementing your own time out on the retries (in the form of a maximum number of retries before giving up) might be a good idea to prevent infinite retries.

    You will not be able to perform a flash erase when scanning at 100 % duty. You may also get the NRF_EVT_FLASH_OPERATION_ERROR (because of busy SoftDevice leading to time out) directly after disabling the scanning. The same strategy as before (retrying) should work in the case of recently disabled scanning as well.

    Regarding writing 1-2 words and erasing the (same) page continuously, do note that the specification states 10,000 write/erase cycles. (See the nRF52 Absolute Maximum Ratings.) The FLASH memory is not inteded for a scenario where the same location is rewritten as quickly as in your example. With one write/erase cycle every second, the 10,000 cycles will take less than three hours...

    edit: In some cases you may get NRF_EVT_FLASH_OPERATION_VERIFY_FAILED events in early s132 alpha releases. These are no longer present in s132_nrf52_2.0.0-7.alpha, so I recommend upgrading to that SoftDevice version.

    Regards, Terje

  • Hi Terje,

    thanks for the reply. This explains how the NVMC interface is supposed to work (maybe you want to put that information into the official documentation). I want to point out that the high write/erase ratio is just a test scenario on a development system and will not be implemented in the official software.

    What I still find confusing is the NRF_EVT_FLASH_OPERATION_VERIFY_FAILED error message (both by writing words and erasing pages). Can you give some information about this error and when it is reported, and why it is reported even if a write or erase operation has been performed successfully?

    Further, your reply doesn't explain how it comes to the error scenario when writing and erasing every second suddely fails after a minute or so. This cannot be explained with the limit of 10,000 write/erase cycles.

    Thanks, Michael

  • Both SDK 11 and SoftDevice s132 are still in alpha, and nRF52 is not yet fully released, so there are some areas that are not yet fully documented. I will try to find answers to these issues as well, and update my answer accordingly. When you do not get any more SUCCESS events, do you still get ERROR events and if so which ones?

  • Today, the software behaved differently. It took about 15-17 minutes until the error condition appeared (no SUCCESS messages anymore but many VERIFY_FAILED messages). It also seems to be related to some MCU state because a reset by the debugger (loading the SoftDevice vector table start offset) did not reset the error condition, I had to unplug the development kit (power cycle) and restart the debugger. . Concerning your question, I still get NRF_EVT_FLASH_OPERATION_ERROR messages once in a while which seem to be related to the advertising (10s interval) in background. But the NRF_EVT_FLASH_OPERATION_SUCCESS messages seem to be replaced by NRF_EVT_FLASH_OPERATION_VERIFY_FAILED messages now. I will post a short section of my log, just when the error condition starts appearing (please note that the memory dumps show correct flash updates):

  • Log:

    Flash dump: FFFFFFFF FFFFFFFF FFFFFFFF
    Erasing flash page... OK
    SYS Event 2: NRF_EVT_FLASH_OPERATION_SUCCESS
    Flash dump: FFFFFFFF FFFFFFFF FFFFFFFF
    Writing first word to 0x12345678... OK
    SYS Event 2: NRF_EVT_FLASH_OPERATION_SUCCESS
    Flash dump: 12345678 FFFFFFFF FFFFFFFF
    Writing first word to 0x00000000 and second word to 0x9abcdef0... OK
    SYS Event 2: NRF_EVT_FLASH_OPERATION_SUCCESS
    Flash dump: 00000000 9ABCDEF0 FFFFFFFF
    Erasing flash page... OK
    SYS Event 3: NRF_EVT_FLASH_OPERATION_ERROR
    Flash dump: 00000000 9ABCDEF0 FFFFFFFF
    
    Flash dump: 00000000 9ABCDEF0 FFFFFFFF
    Erasing flash page... OK
    SYS Event 3: NRF_EVT_FLASH_OPERATION_ERROR
    Flash dump: 00000000 9ABCDEF0 FFFFFFFF
    Writing first word to 0x12345678... OK
    SYS Event 4: NRF_EVT_FLASH_OPERATION_VERIFY_FAILED
    Flash dump: 00000000 9ABCDEF0 FFFFFFFF
    Writing first word to 0x00000000 and second word to 0x9abcdef0... OK
    SYS Event 4: NRF_EVT_FLASH_OPERATION_VERIFY_FAILED
    Flash dump: 00000000 9ABCDEF0 FFFFFFFF
    Erasing flash page... OK
    SYS Event 4: NRF_EVT_FLASH_OPERATION_VERIFY_FAILED
    Flash dump: FFFFFFFF FFFFFFFF FFFFFFFF
    
    Flash dump: FFFFFFFF FFFFFFFF FFFFFFFF
    Erasing flash page... OK
    SYS Event 4: NRF_EVT_FLASH_OPERATION_VERIFY_FAILED
    Flash dump: FFFFFFFF FFFFFFFF FFFFFFFF
    Writing first word to 0x12345678... OK
    SYS Event 4: NRF_EVT_FLASH_OPERATION_VERIFY_FAILED
    Flash dump: 12345678 FFFFFFFF FFFFFFFF
    Writing first word to 0x00000000 and second word to 0x9abcdef0... OK
    SYS Event 4: NRF_EVT_FLASH_OPERATION_VERIFY_FAILED
    Flash dump: 00000000 9ABCDEF0 FFFFFFFF
    Erasing flash page... OK
    SYS Event 4: NRF_EVT_FLASH_OPERATION_VERIFY_FAILED
    Flash dump: FFFFFFFF FFFFFFFF FFFFFFFF
    
Related