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?
..
..
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:
The 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)...
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.