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

flash update / swap

Dear developers,

As we know, nrf51 has a maximum flash erase / write cycles of 20.000 times. So, in my code, I have implemented a counter that checks if max. flash write cycles has been reached. If so, my code will write in the next consecutive address.

At this point, just a question: Since I am using p_storage API, and the API uses a swap space to update the flash on every write, does the API write in different addresses in the swap page to avoid overwrittings?

In case of API always writes in the same addresses, could be possible update the flash without using swap?

Thank you.

  • To update a value in flash it needs to be erased first as the write operation can only change existing one's into zeroes and not the other way around. Also, flash erase has to be done 1024 bytes at a time (size of flash page on 51). So in order to update a single word in flash you would have to erase the entire flash page first followed by the write. Thus, frequent update data at the same address is not ideal for long flash endurance.

    Pstorage may not be the best option in your case if you expect the number of cycles to exceed 20,000. An alternative could be to use the softdevice's flash API directly, and write each updated value to the subsequent address in order to fill the flash page before erasing the page.

    The SDK team has also released two new modules for handling of persitent memory that toghether reduces the number of page erases: fstorage and fds. But note that these modules are currently releases as experimental.

Related