Electronic – Preserving state of variables in RAM on Power Failure

armdata storageflashnon-volatile-memory

I'm developing a code with Nuc240(ARM Cortex M0) Microcontroller.
Where I need to store the value in some of the variables to the Internal Data Flash.
I use ISP procedure for this, but i have seen the following statement in the datasheet of the Microcontroller ,about the Data Flash.

'The size of each erase unit is 512 bytes.'

The Data Flash Memory starts form 0x20000,and if I need to update this location I will have to erase this location first, does this mean that if I erase 0x20000 – memory till 0x20200 will be also erased? and that might result in other values stored in these locations. How can I overcome this situation?

Best Answer

Well, if you want to preserve data in erase block you should first read that block, store it in ram, do whatever changes you need to do, erase flash block, write block from ram. Simple enough.