Skip to main content
TMich.1
Associate III
April 6, 2023
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?

  • April 6, 2023
  • 4 replies
  • 3419 views

..

This topic has been closed for replies.
Best answer by SStor

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

4 replies

AScha.3
Super User
April 6, 2023

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
April 6, 2023
SStorBest answer
Senior
April 6, 2023

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
April 12, 2023

thank you, that is very smart

Tobe
Senior III
April 11, 2023

Why not the eeprom?

TMich.1
TMich.1Author
Associate III
April 12, 2023

i read about very limited write cycles allowed?

Tobe
Senior III
April 12, 2023

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