2
\$\begingroup\$

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?

\$\endgroup\$
1
  • \$\begingroup\$ You might consider a microcontroller that uses random-access non-volatile memory (e.g., FRAM) instead of flash. \$\endgroup\$
    – CL.
    Dec 31, 2016 at 13:56

2 Answers 2

0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Can you comment an example? \$\endgroup\$ Dec 31, 2016 at 13:14
3
\$\begingroup\$

You need to do a read-modify-write (RMW) operation, in which you read out the entire 512-byte page to RAM, change the value(s) that need to be updated, then erase and rewrite the flash page.

There is a concern that power could fail while this procedure is executing, so more elaborate schemes that "bounce" the data between two separate flash pages have been designed that are much more robust against this. However, the system overall must still handle the possibility that the update may or may not have happened before the power failure.

This is especially critical when the data in question is the processor's own instructions (i.e., remote firmware update). You must guarantee that no matter where in the process the power fails, the system can always get back to a working state, running either the original firmware or the new firmware. Otherwise, you end up "bricking" the system.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.