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

How to reliably save data using pstorage?

Hello,

I have quite a few of setting on my nodes and I want to save some of these permanently. Currently I am using the pstorage module and everything works as expected. There are quite some limitations:

  • Pstorage does not perform wear leveling,so I cannot save new data very often.
  • Flash operations take some time, so I probably can't do anything when the power drops off.

If the pstorage library works as documented, I assume the following: Updating a small block that shares a page with other blocks will:

  • Erase the swap area page

  • copy the contents of all other blocks to the swap area (why not the affected block as well?)

  • erase the page where the block was stored

  • => at this point, if the device is reset, it will irreversably loose the saved data from our block?

  • write the other blocks from flash and the one block from RAM

  • I don't think that the pstorage library will recover a lost page if it was not written back?

So does that mean that I have to implement the swapping, etc... myself if I want a reliable library that can guarantee me consistent data at all times? E.g. by adding a flag or a crc checksum to pages that is checked during boot and reading from a different page when this checksum is incorrect?

Thanks, Marius

Parents
  • Hi Marius

    Thank you for your message.

    I think you are correct in all your assumptions. The pstorage module is currently not designed to reliably handle sudden power cuts during pstorage operation. We have recommended so far that when i.e. battery is close to empty that you shut down gracefully before the supply voltage drops below 1.8V, so that ongoing flash operations will be completed.

    No, you are correct, there is no mechanism available from Nordic that handles the limited erase/write cycles allowed. If you write/erase the same page/pages very often, then you would need to implement a mechanism to spread the write/erase cycles on multiple pages.

    I think your thread is a good summary of improvement suggestions for the pstorage module. I will report this as such.

  • If an 'application' requests 16 128-byte blocks, it will get 2 pages. The documentations says, "Clear operation results in clearing all storage blocks allocated to the application." Does that mean that a clear will really erase both pages even if I do pstorage_clear(&base_handle, 1024). I hope that is not the case and that it will only clear page one. And that pstorage_clear(&block8_handle, 1024) would then only clear page two. Is this how it works?

Reply
  • If an 'application' requests 16 128-byte blocks, it will get 2 pages. The documentations says, "Clear operation results in clearing all storage blocks allocated to the application." Does that mean that a clear will really erase both pages even if I do pstorage_clear(&base_handle, 1024). I hope that is not the case and that it will only clear page one. And that pstorage_clear(&block8_handle, 1024) would then only clear page two. Is this how it works?

Children
No Data
Related