Storing sensor data as circular buffer in non volatile memory

Hey guys,

I want to store sensor data as circular buffer in non volatile memory. I saw
https://docs.nordicsemi.com/bundle/zephyr-apis-latest/page/group_file_system_storage.html and https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/services/storage/index.html. But researching here in the devzone I can see that users have issues like here https://devzone.nordicsemi.com/f/nordic-q-a/110506/nrf5340-fcb-flash-circular-buffer-on-external-flash/530085

I was trying to use NVS but it seems that it overwrites data as stated here https://github.com/nrfconnect/sdk-zephyr/blob/a1d9a8db0ea4bbee2e69feec1140e6ce20e62f5e/samples/subsys/nvs/src/main.c#L30
But of course I need the complete history of my data.

So my question is what is currently the best approach for this?

Best

Parents
  • Hi Artnia,

    You can use nvs_read_hist() to read past values. However, the past values are still gone when the current flash page for NVS is full, and a garbage collection and page switch is done.

    Other than that, you store the entire circular buffer that you wish to track as the object. Please keep in mind though that this increase flash write size, shortening the flash erase cycle, and consequently shorten the flash life span.

    Best,

    Hieu

Reply
  • Hi Artnia,

    You can use nvs_read_hist() to read past values. However, the past values are still gone when the current flash page for NVS is full, and a garbage collection and page switch is done.

    Other than that, you store the entire circular buffer that you wish to track as the object. Please keep in mind though that this increase flash write size, shortening the flash erase cycle, and consequently shorten the flash life span.

    Best,

    Hieu

Children
Related