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

Using pstroage with different data sizes.

In our application, we need to save a group of data objects, how many data objects in a group is dynamic. also each data object has different sizes, a few bytes up to 100+ bytes.

The size of data is not known in advance.

It seems unrealistic to call pstorage_register multiple times to register block for different size because:

  1. we don't know the data size in advance
  2. it's a nightmare to maintain dynamic number of pstorage handle

So what is my option then?

It seems pstorage raw mode also would not help, since it also needs to register block size and block amount in advance.

pstorage source code shows that it actually uses sd_flash_page_erase adn sd_flash_flash,

can I use these flash function directly?

Parents
  • In my opinion, you can always convert your data objects to a 8-bit array by using type conversion. You can register only one pstorage handle, and implement some data structure, such as linked list, hash table, etc. Each data unit contains not only the data object itself, but also some fields indicating the length and data type. You can use pstorage functions (not raw) to read/write the uint8_t array, and interpret it to what you want.

  • I think scytulip made a good suggestion. I may be a bit biased because I implemented exactly that solution in my project. I need to store a bunch of different sized data in nvram. Everything from device serial number, password, and calibration coefficients. So, I implemented a byte array where the data consisted of tag-length-value entries so each entry could be whatever size it needed. Whenever a value is changed, the entire array is re-written to the nvram. This works well for me since most of the data is written very infrequently, this probably wouldn't be a good solution for data that updates frequently.

    This way, I can store everything with a single handle to access the flash via pstorage.

Reply
  • I think scytulip made a good suggestion. I may be a bit biased because I implemented exactly that solution in my project. I need to store a bunch of different sized data in nvram. Everything from device serial number, password, and calibration coefficients. So, I implemented a byte array where the data consisted of tag-length-value entries so each entry could be whatever size it needed. Whenever a value is changed, the entire array is re-written to the nvram. This works well for me since most of the data is written very infrequently, this probably wouldn't be a good solution for data that updates frequently.

    This way, I can store everything with a single handle to access the flash via pstorage.

Children
No Data
Related