There is no easy way, Freescale flash memory is very dumb.
Typically, you will have to first copy down your code into RAM (very questionable from a safety point-of-view) because you can't execute the code from the same flash "bank" that you are writing to. One bank is typically the whole friggin memory of the MCU. Newer MCUs have "data flash" that you can write directly too without downloading the code into RAM.
Next problem is that banks are divided into big blocks of 128, 256 or 512 bytes. You must erase a whole block to write a single byte. This means you must also copy down a huge amount of data to RAM, alter the cell you want to change, then write it back.
All of this takes lots of execution time, and you will want to consider what will happen if the MCU loses power into the middle of the write. Not pretty at all. You will need to implement checksums and perhaps also mirror memory segments, to preserve data integrity. Even more execution time.
Note that the new "data flash" solves neither the block size problem or the power loss problem, it is equally huge (128 bytes). The competition has smarter data flash that works like old eeproms.
Practically, all of this means you have two sensible options. I use either of them when I have the same requirements as you have:
- Switch to a derivate with (emulated) eeprom, like the S08D or S12D families. Or
- Switch to Renesas for the particular project.
Message Edited by Lundin on 2009-11-24 04:29 PM
Message Edited by Lundin on 2009-11-24 04:30 PM