Help Writing to Flash

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

Help Writing to Flash

640 Views
northernboy
Contributor I


Hello,

I am a beginner who is working on a project that I want to write a simple array to Flash so it is retained during power lose or reset.

I have been looking for examples on how to do this but have came up with alot of information that doesn't work or is not made for my setup.

I am presently using CW 5.9.0 with Freescale university board which uses on MC9S12DG128. Also using the Serial Port Monitor that was provided.

Anyone have a good example on how to do this?

 

Thanks

NB

Labels (1)
0 Kudos
4 Replies

470 Views
chrissolomon
Contributor III

Hi Peter,

I'm not sure you approach is going to work - even if you figure out how to write to the flash from code (which is generally possible for bootloading new FW images), the flash only has an endurance of about 10K write cycles.

In my experience manufactures are conservative with that figure, but not by that much, also your firmware is in flash, so there is always the risk that a bug could brick a product (since you are talking about using a dev board I doubt that's an issue right now, but it would be a concern for production).

If you have an array that you need to load and rewrite on every power up, I would suggest you consider an I2C eprom chip, such as the Atmel AT24C01D?

They are cheap and easy to use, and have 1M write cycle endurance. (And come in different sizes.)

Good luck

Chris

470 Views
northernboy
Contributor I

Thank you Chris, I took your advise and found an old I2C EEPROM. Took a bit to get the code right but it does work as I want it to. I agree it is a better solution than writing to the processor flash and safer.

Thanks Again.

Peter

0 Kudos

470 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hello Peter,

You can allocate a constant variable at an absolute address using the @ modifier.

For example allocating a constant called VersionNbr at address 0xF000 and initializing it to 2 is done as follows:

    const int VersionNbr @0xF000 = 2;

Same notation can be used for a constant string as follows

    const char VersionStr[] @0xF000 ="Version 5.1";

if no @0xF000 keyword. CW will allocation a ROM address to const variable automatically.

As this version number is not used anywhere in the application, you have to instruct the Linker to link it to the application even though it is not used.

This is done specifying the constant name in the .prm file ENTRIES block.

For example:

ENTRIES

  VersionNbr VersionStr

END

Last, please enable –Cc option in Compiler option setting panel.

===========================================

this answer is for you. if it helps, please click on "correct answer" button. thanks!

Best Regards.

Zhang Jun

0 Kudos

470 Views
northernboy
Contributor I


Zhang,

Thank you for your responce. Your example is for a constant that is not needed to be changed by code I think....

The Array that I would like to save to flash is modified by code and then saved so on the next start/power up it retains values it has calculated before.

I don't think this can be done with const, unless I am wrong, please advise as I am a beginner and don't know all the tricks.

Thanks.

0 Kudos