cancel
Showing results for 
Search instead for 
Did you mean: 

How the best method to save user data on flash's STM32F4 series?

Marcus Nguyen
Associate II

Hi everyone,

I'm handling project on STM32F411CEUx and I have got a trouble with save my setting into internal flash. When I used STM32F1 series, this issue was very easy because the page size was very small than F4 series. In F1, I could use some RAMs to got all the specified structure after then I adjusted the variables that I would to change value and erase all the sector. Finally, I wrote whole back into that page. But I think I can't use this way on F4, the page size of it is very large (e.g 128kb) so it leads to the eraser timing too high and it will be affect to real time of my system. I know that have one method to prevent that problems, it is EMULATION EFFROM. I understood how the way it was implemented. It used the ID to decide the specified variable but I think it has some disadvantages:

  1. It was be limited number of variable. It have just over 65000 if using 2 bytes ID and absolutely you can only use 2 bytes size for each variables. I know we can change the number of bytes ID and variables to write higher number.
  2. The main problem I want to ask is here. How about the strings with variable length? I have not yet find the best way to resolve them

Could you give some advice or some algorithm to work better on it?

Thanks so much!

8 REPLIES 8
Uwe Bonnes
Principal II

How much do you need to store, how often will change happen? Can backup RAM in some F4 help?

Ozone
Lead

> But I think I can't use this way on F4, the page size of it is very large (e.g 128kb) so it leads to the eraser timing too high and it will be affect to real time of my system.

Not only will execution usually stall while erasing/writing, the duration strongly depends on temperature.

The most hassle-free method would involve an external memory, like a serial EEPROM or MRAM device.

The write could be implemented as asynchronous process, without much effect on real-time behavior.

I wouldn't ask the specified issue, I want to know a global solution. It is the best algorithm or impossible. Anw, the backup RAM absolutely evaporate when the power off so as isn't suitable for that.

Thank you!

The external memory the most common method. I don't want to waste more any external IC and Is it impossible?

Bob S
Principal

"in general" there is no best solution. It depends on how much data you need to store and how much Flash you need for your executable firmware image. For example, the F411CE has several FLASH sectors that are 16K bytes. If you need to store less than 16K of data and if you can rearrange your code so your code doesn't use 2 of those sectors, you can ping-pong between the two. Some of the STM32 parts have the ability to run from some Flash sectors while programming other Flash sectors without stalling the CPU. I don't know if the 411 has that same ability. If the 411 can't do that, then see if you can move your critical code into RAM (if you have enough RAM space). If you can't run from RAM then using internal Flash will stall your firmware during the erase and program operations. If that is not tolerable, then an external part is your only option.

Tend to put a boot loader up front, and carve out a couple of the 16K sectors for configuration/storage, the app pushes out to 64KB or 128KB boundary depending on the loader functionality.

If the loader won't fit in 16KB, you'll need to carve a hole in it so it doesn't use the sectors you want to put data into.

I personally find the EEPROM emulation code to be unnecessarily complex/fragile, and it is far simpler/safer to use the FLASH memory as designed/intended.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

One can of course also use the 128KB sectors, say at the far end of space, but they are VERY SLOW, and are likely to impede real-time operation of the device. I tend to use them to stage firmware updates.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I agree with you, I think that don't have any better method than external flash

Thanks!