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

How to update a 32-bit word in flash - SDK13.1

Hi everybody,

I was looking for a better way to update a data, like a 32-bit-word, without the need to erase the entire page. Part of this question is already been asked HERE but for some different reasons has not been answered. If I need to store different values and I want to update only one of them at time now I have to backup my data before erasing the flash page and then re-write everithing back with the new value of the only one data I wanted to update originally.

There must be a better way! Is there one?

Thanks in advance

Massimo Pilia

  • The reason why it wasn't answered probably is because requested didn't want to accept the answer which is: you can write to any flash memory address as much as you want but you will never turn single bit from 0 back to 1 unless you erase whole page. That's how flash technology works, you cannot workaround the physics. You can still do certain smart things like:

    • Dedicate one (or more) page to all writes, erase it once and then just have some mechanism how to find out which was the last written address and where you can continue.
    • Use some more sophisticated "file system" which can use several pages and thanks to smart write policy minimize number of erases needed (but this needs o have many assumptions about the intended use to have it really effective...)

    (and your "There must be a better way!" reminds passengers on sinking ship screaming "it cannot be true, this cannot happen to us!":)

  • Hi Endnode and thanks for your reply.

    You said "you cannot wokaround the physics" but why, working on the nRF51 chip with SDK11 and s130, I could update single 32-bit word with the function pstorage_update? Has flash technology changed?

    Anyway, thank you for your advices.

    Massimo Pilia

  • I'm sorry to disappoint you but nRF51 works the same as nRF52: there are flash pages (nRF51 has 1kB size while nRF52 4kB) and you need to erase whole page in order to change any bit from 0 to 1. Again you might have written just once and then it works fine of course and you can also write multiple times but then only bits from 1 to 0 will flip, all others won't be written (so in case you write random bytes to certain flash area again and again it eventually will be full of zeros). And before you will continue in argument just kindly read Non-Volatile Memory Controller part in nRF51 and nRF52 specifications, it's crystal clear there.

Related