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.

Parents
  • Hi Sunil,

    We have an example in the SDK here.

    It accesses the Flash directly.

    You save the data using address. When you erase a page, you provide the address to first word in that page. Please have a look at chapter 11 in the product specification. If you one to update data at an address in flash, you need to erase the page. You may need to backup the other data on the same page before you erase, then write them back after you erase and update the data. Another option is to use file system.

    If you use the softdevice, direct access to flash is restricted. We suggest you to use the fds library. fds is a simple file system, you don't have to worry about the address you store the variable or how you back up data when erasing a page. Fds is used in our ble example in the SDK, I also made a small example here.

  • Hi, if I write a file using the fds library, will it persist after a I make reset to an nRF52?

Reply Children
No Data
Related