Why to erase flash before writing data

Hello,

I used the nrf53832,

and I'm looking to discharge my battery. Occasionally, I notice that the settings page in the flash gets erased during the drainage. I wanted to inquire if it's possible to skip the earsing process and directly write to the flash.

Thank you, Hadar

Parents
  • Hi Hadar,

    The way flash memory works, writes can only flip bits from '1' to '0'. Therefore, in order to write "new" data that could contain a '1' where there were previously a '0' there is a need to perform an erase before overwriting existing data

    This seeings page you refer to, is it the bootloader settings page, or some other data? If so, how is this data stored and updated? Can you share more about the problem (including which SDK you use, and which file system or storage libraries etc)?

    Einar

  • Hi Einar,

    Thank you for your response. We're currently using SDK 17.2.

    I'm working on maintaining treatment data such as events to flash during device operation. I have two types of data:

    1. Settings - Whenever I modify one of the 72 settings, I erase and then write to flash.

    2. Events log - For all device operations, I directly write to flash. Before the device goes to sleep, I erase and write again.

    However, I'm encountering a problem. To drain the battery, I need the voltage to be at 1.2. At this voltage, I attempted to erase and write, but upon waking up, all the settings are erased.

    I hope this clarifies my issue.

    Thanks, Hadar

  • Hi Hadar,

    I would recommend that you use a file system suited for flash instead of erasing and re-writing to the same page every time. This will significantly reduce the amount of times you need to do page erase, it will prevent you from loosing data (if you store data temporarily in RAM before writing back and have a rest), and it will give you basic ware-leveling. In the nRF5 SDK we have FDS, which I suggest you use for that (if you use Bluetooth bonding. you are already using it as it is used by the peer manager).

    If you have enough flash to set aside a few extra pages, you don't need to do garbage collection very often, and this is the only time there are page erases. In this case, maybe you can ensure that you only do garbage collection at opportune times. You will not avoid page erases at all though, as that would only be possible if you never need to re-write data in the same location (so if you write and update very little data during the life-time of the product, it might be theoretically possible, but for most products it will not). In other words, you will likely need to ensure that you have a power supply that can handle page erase operations.

Reply
  • Hi Hadar,

    I would recommend that you use a file system suited for flash instead of erasing and re-writing to the same page every time. This will significantly reduce the amount of times you need to do page erase, it will prevent you from loosing data (if you store data temporarily in RAM before writing back and have a rest), and it will give you basic ware-leveling. In the nRF5 SDK we have FDS, which I suggest you use for that (if you use Bluetooth bonding. you are already using it as it is used by the peer manager).

    If you have enough flash to set aside a few extra pages, you don't need to do garbage collection very often, and this is the only time there are page erases. In this case, maybe you can ensure that you only do garbage collection at opportune times. You will not avoid page erases at all though, as that would only be possible if you never need to re-write data in the same location (so if you write and update very little data during the life-time of the product, it might be theoretically possible, but for most products it will not). In other words, you will likely need to ensure that you have a power supply that can handle page erase operations.

Children
No Data
Related