Skip to main content
TMich.1
Associate III
Apr 6, 2023 3:21 PM UTC
Solved

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?

..

This topic has been closed for replies.
SStorBest answer
Senior
Apr 6, 2023 6:04 PM UTC

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)...

8 replies

AScha.3
Super User
Apr 6, 2023 4:24 PM UTC

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 on " Best Answer ".
MM..1
Super User
Apr 6, 2023 5:26 PM UTC
SStorBest answer
Senior
Apr 6, 2023 6:04 PM UTC

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)...

TMich.1
TMich.1Author
Associate III
Apr 12, 2023 7:18 PM UTC

thank you, that is very smart

Tobe
Senior III
Apr 11, 2023 4:35 PM UTC

Why not the eeprom?

TMich.1
TMich.1Author
Associate III
Apr 12, 2023 7:18 PM UTC

i read about very limited write cycles allowed?

Tobe
Senior III
Apr 12, 2023 8:23 PM UTC

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