hi,
How can I access flash memory of nRF52840 while using softdevice ?
I just want to read and update two integer values? is there any simple way to do this?
Thank you !
Hi,
For flash, it is important to note that erase operations can only be done for full flash pages (4 kB on the nRF52 series). The erase will set all bits to 1, i.e. all bytes will be 0xFF after the erase, and writes can then flip bits to 0 (but not back to 1 again.) Any update that means a bit should go from 0 to 1, means the full flash page must be erased, then re-written. The issue with rewrites is that flash gets worn down after several thousand write/erase cycles. In order to work within those limitations, it is usually best to use a library that provides an abstraction to write/update/delete flash records, and not use flash addresses directly.
In nRF5 SDK you will find the Flash Data Storage (FDS) library, which lets you write "records" to flash, where you identify data not by the address where it is located, but using two sets of identifiers called "File ID" and "Record Key". It is up to you how you want to use one or both of those identifiers to organize your data. FDS can run with two different backends, one for when you do not use a SoftDevice, and one for when you do have a SoftDevice. See also the Flash Data Storage Example.
If for some reason you do need to write data to a specific flash location, you could have a look at the Flash Storage (fstorage) library. It lets you access flash directly, but it also means you must take care of all the details yourself regarding how flash works and how many erase cycles are guaranteed to work before bits may start misbehaving.
Regards,
Terje
Hi,
For flash, it is important to note that erase operations can only be done for full flash pages (4 kB on the nRF52 series). The erase will set all bits to 1, i.e. all bytes will be 0xFF after the erase, and writes can then flip bits to 0 (but not back to 1 again.) Any update that means a bit should go from 0 to 1, means the full flash page must be erased, then re-written. The issue with rewrites is that flash gets worn down after several thousand write/erase cycles. In order to work within those limitations, it is usually best to use a library that provides an abstraction to write/update/delete flash records, and not use flash addresses directly.
In nRF5 SDK you will find the Flash Data Storage (FDS) library, which lets you write "records" to flash, where you identify data not by the address where it is located, but using two sets of identifiers called "File ID" and "Record Key". It is up to you how you want to use one or both of those identifiers to organize your data. FDS can run with two different backends, one for when you do not use a SoftDevice, and one for when you do have a SoftDevice. See also the Flash Data Storage Example.
If for some reason you do need to write data to a specific flash location, you could have a look at the Flash Storage (fstorage) library. It lets you access flash directly, but it also means you must take care of all the details yourself regarding how flash works and how many erase cycles are guaranteed to work before bits may start misbehaving.
Regards,
Terje