This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Flash erase

Dear all,

I am a little confused about erasing data contained in a flash block. In this link the clear example shows that it is possible to clear bytes from a specified block. However, when we scroll down we can read in the "Specifics and limitations of the SDK implementation" section that SDK don't allow clearing of blocks.

Would any one please like to explain to me ?

Thank you.

Parents
  • Hi boss,

    Flash on Nordic's nRF51 works as follows:

    • You can erase it by page (1024B) or all (256x1024B). This will set all bits to 1 (all bytes = 0xFF).
    • You can write word by word (32-bit architecture) meaning that by "writing" you can turn any bit to 0 but not the other way.
    • Theoretically you can be writing to the same word again and again but result will be superposition of written data (all bits set to 0 in any write will be zeros).

    So depends on your use case when you want to erase particular page (and potentially backup the content and then use it during write) and when you allow writing. Note that erase operation is the most time consuming (in reality erasing 128kB takes ~3 seconds on nRF51822).

    Cheers Jan

  • Hi mohBoss,

    What do you exactly mean by "block"? If it is whole 1kB page than it is trivial (erase and write whole block). If it is different size then you need to do some logic. Either you have lot of memory then dedicate 1kB page to each of them or you will be smarter and you place them into one page in one structure (then these variables even do not need to be same size) and before the update you read whole page, update the part you need in RAM (e.g. in local variable on stack) and then you erase the page and apply new value. Obviously you are then in risk of losing data in case of power off between erase and write so you might consider having mirror pages and integrity checks (e.g. CRC supported natively by nRF1 chips). But this is rather generic software engineering topic on embedded systems for which you can find many specialized articles and books elsewhere...

    Cheers Jan

Reply
  • Hi mohBoss,

    What do you exactly mean by "block"? If it is whole 1kB page than it is trivial (erase and write whole block). If it is different size then you need to do some logic. Either you have lot of memory then dedicate 1kB page to each of them or you will be smarter and you place them into one page in one structure (then these variables even do not need to be same size) and before the update you read whole page, update the part you need in RAM (e.g. in local variable on stack) and then you erase the page and apply new value. Obviously you are then in risk of losing data in case of power off between erase and write so you might consider having mirror pages and integrity checks (e.g. CRC supported natively by nRF1 chips). But this is rather generic software engineering topic on embedded systems for which you can find many specialized articles and books elsewhere...

    Cheers Jan

Children
No Data
Related