cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Flash overwrite

kqian
Associate II
Posted on May 21, 2014 at 19:53

Hey,

I am using STM32F405 as the controller in my project. We have hundreds parameters needed to be saved in the Flash memory and this parameters will be modified one by one during the running. The problem is the flash memory must be erased by section and rewrite the whole section even if we just want to change one byte in the memory. It takes long time and has to stop the access the all parameters during the updating. 

Is there fast method that we can overwrite the one byte/ byte?
2 REPLIES 2
Posted on May 21, 2014 at 20:03

Is there fast method that we can overwrite the one byte/ byte?

Not really, what you'd really want is two regions, and then use a journaling method to write new copies of your structure, erase the old region after you've transitioned to the new one, and a method to recover the most recent entry.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
re.wolff9
Senior
Posted on May 24, 2014 at 22:49

I would personally go for an assymmetric construct:

Initialize one page (or more) as the parameter page. Save the ''current'' version there.

Then use one page (or more) as the ''changes'' log. Save any changes to the parameters there.

Use 0xffff as a marker to indicate: no more changes. Clear the changes page, so you get the marker in the first position, Then log records: ''parameter x changed to y'' until the changes page is full. You only need to write a few bytes to achieve this. The bad news is that you'll need to rewrite the ''current parameters'' page every now and then. Oh, and you'll need to escape ''0xff''.  or ''0xffff'' whatever datasize you chose to use.

If you can't trust the power to stay applied during this, some extra care is required. e.g. write a NEW page with the current version of the parameters, then invalidate the old one, and then erase the old one.