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

how to save data in flash memory?

Hello,

I am using SDK v11, SoftDevice v132 and Keil Uvision 5 to program on my nrf52832 SOC on the development kit(PCA10040) for our project. I need to save a few uint32_t variables to the flash memory (32 variables and each around 4 Bytes long). These variables will hold the status of the device and they keep on getting updated once a day atleast. I have a few questions regarding the flash write and read functions:

  1. What is the best way to save the data to the flash? (I am guessing pstorage functions) and is there a good tutorial or example that I can refer to understand how it is implemented? or what functions do I use to write data, read data, delete data and update data?

  2. What are the page numbers/block numbers? How do i know where to save the values? Assuming I have to save 960 Bytes/1 KB of information in total (32 variables and where each variable is 4 Bytes long) in the last page/part of the memory, how can I reference the variables or what would be the addresses that I would be giving to each variable?

  3. Do I have to erase the entire page each time I want to update a single variable? If yes, how can I get around this issue?

Thanks In Advance.

Related