cancel
Showing results for 
Search instead for 
Did you mean: 

on my stm32g473 I need to save a variable permanently, even on reboot. I want to use it to control the volume of my dac, and use up and down buttons to change the gain. This variable has to be remembered ater reboot, should I write to flash?

TMich.1
Associate III
 
1 ACCEPTED SOLUTION

Accepted Solutions
SStor
Senior

You can save all your parameters in flash permanently.

To minimize flash writes, load parameters from flash to RAM during startup and then also erase the data flash mmediatley (to prepare it for write).

Then you can work with RAM data parameters during runtime.

On shutdown save RAM parameters back to flash with write command.

To detect power shutdown use a GPIO or ADC input:


_legacyfs_online_stmicro_images_0693W00000bhgRmQAI.pngThe large capacitor behind diode buffers the supply voltage for a short time. So there is enough time to write flash data on shutdown.

For more safety you can also use double flash buffering (e.g. for very short on/off switching)...

View solution in original post

8 REPLIES 8
AScha.3
Chief III

you need a backup 3v3 cell, Vbat. then backup registers can keep content...


_legacyfs_online_stmicro_images_0693W00000bhgDLQAY.png

If you feel a post has answered your question, please click "Accept as Solution".
MM..1
Chief III
SStor
Senior

You can save all your parameters in flash permanently.

To minimize flash writes, load parameters from flash to RAM during startup and then also erase the data flash mmediatley (to prepare it for write).

Then you can work with RAM data parameters during runtime.

On shutdown save RAM parameters back to flash with write command.

To detect power shutdown use a GPIO or ADC input:


_legacyfs_online_stmicro_images_0693W00000bhgRmQAI.pngThe large capacitor behind diode buffers the supply voltage for a short time. So there is enough time to write flash data on shutdown.

For more safety you can also use double flash buffering (e.g. for very short on/off switching)...

Tobe
Senior III

Why not the eeprom?

i read about very limited write cycles allowed?

thank you, that is very smart

Where did you read about the limited write cycles? There is no eeprom at all as i found out...

see datasheet: 10.000 erase/write cycles are guaranteed for internal flash:


_legacyfs_online_stmicro_images_0693W00000bhyVSQAY.png