Saving Variables to Non-Volatile Memory

Hello,

I am trying to figure out how to save a small number of counters to local non-volatile memory on the nRF9160. I have a few questions.

1) How do I determine whether a section of memory is safe to use as storage? Can I just use any location from my storage or scratchpad partitions that I defined in my device tree files? Will that location be stable through a power-on-reset? Do I have to worry about the partitions moving address locations over time as my program changes? Do I need to worry about my application code overwriting that location?

2) How do I actually read and write that location? Are there limitations on reading and writing those locations? Is the Zephyr Flash Interface the best way to do this, or are there others? the Nordic NVMC seems to only allow writing and erasing. 

I have looked at https://devzone.nordicsemi.com/f/nordic-q-a/61931/nrf9160-flash-access. It seems to support that I can use the Flash Interface, but it does not answer a number of my above questions.

I am using an nRF9160 on a custom board. SDK version 1.6.1.

Parents
  • Hello Jeremy,

    1) How do I determine whether a section of memory is safe to use as storage? Can I just use any location from my storage or scratchpad partitions that I defined in my device tree files? Will that location be stable through a power-on-reset? Do I have to worry about the partitions moving address locations over time as my program changes? Do I need to worry about my application code overwriting that location?

    You can check the resulting partitions in the generated pm.yml file, which gives you a dynamic partition allocation. This will remain on restart, but won't be safe if you decide to to add something to your application and re-build. However, you can then create a new pm_static.yml file in which you can modify and create your own partitions. The partitions defined in a pm_static.yml file won't change on start-up etc. There you could create your own partitions for storage. For more info see here.

    2) How do I actually read and write that location? Are there limitations on reading and writing those locations? Is the Zephyr Flash Interface the best way to do this, or are there others? the Nordic NVMC seems to only allow writing and erasing. 

    Well there is the Zephyr Flash Interface, which you mentioned. There is an example available here. I believe the NVMC is used to deal with secure partitions from an non-secure one - not exactly what you are looking for. Though let me get back to you on both that, and what flash interface is preferred.

    Regards,

    Elfving

Reply Children
No Data
Related