Flash/NV Memory writing

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Flash/NV Memory writing

1,346 Views
danes
Contributor I

I am new to Freescale technology and want to be able to write a byte to NV RAM or Flash memory.  Through several searches and manuals I have found methods, but all of these seem more difficult than necessary.  Many of the examples are in assembly language.  Is there a good and easy example of writing a single byte to NV RAM or Flash (preferably that does not require resets and changing clock frequency dividers)?  I am use to MCUs that have EEPROMs, so something this simple would be great.  I am using a MC9S08AW60 using the internal oscillator at 8MHz.

 

Thanks,

Labels (1)
Tags (1)
0 Kudos
Reply
2 Replies

571 Views
danes
Contributor I
The amount of code presently written for this application is small, but the IO is pretty much maxed out (so external EEPROM not easily implemented).  I noticed the NVRAM registers.  Is there an easy way to write to these?
0 Kudos
Reply

571 Views
Lundin
Senior Contributor IV
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
0 Kudos
Reply