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

Beginner's questions on persistent storage manager

I need to keep track of an integer array in an nRF51822 BLE peripheral (SoftDevice 8.0.0) between power cycles, and I try to use persistent storage manager for this task. The goal is quite simple: if a data space in non-volatile memory is invalid (happens when the device is powered on for the first time), initialize the non-volatile memory space and write some initial values; if the data space is valid, then update the content. I read the SDK API documentation here, and have a couple of questions:

  1. In the SDK, I can use pstorage_register() to get the reference handle of the requested non-volatile memory space, and use pstorage_block_identifier_get() to further get the reference of data blocks. But how do I keep these handle information between power cycles? Or is it better to access with hard coded address? (and how?)

  2. What is the difference between pstorage_store() and pstorage_update()? It seems I can just use pstorage_store() to overwrite old data if I need a data update.

    1. Your base handle for pstorage memory chunk will be same if the registration process does not change order (for example with other module like device manager or any other if used).

    When you write something to integer array, this must be stored in a block (size and count is specified while pstorage registration). The block number for your array (in your case it can be only one block with the size of your array) needs to be remembered and is not difficult. The base_handle is same between power recylces if you do not change the pstorage registration order.

    1. pstorage_store is just a write command to NVMC, this assumes that the destination memory is untouched (contains 0XFFFFFFFF). If the destination memory contains some value other than that, then your write will corrupt the destination.

    pstorage_update on the other hand will work even if the destination memory is not clean (contains something else than 0XFFFFFFFF). Update will copy the page, erase the page, copy back the contents to the erased page+ the contents needs to be updated. This is very expensive in terms of time and might fail on systems with high RADIO activity.

    You cannot use pstorage_store to overwrite old data, you need pstorage_update
    
  • Thanks for your reply. For the first question, I want to write to a specific block in flash memory between two predetermined addresses, but I don't see how to use pstorage_register() to register such a block. The pstorage_handle_t variable passed to pstorage_register() is to be assigned by the function. Would you please advise? Thanks.

  • in pstorage_platform.h file which is configuration based on your needs you can set PSTORAGE_DATA_START_ADDR to the address you need to write. by default it points to the page below the swap pages.

Related