2024-10-10 01:19 AM
Hi
Because power-off protection is required, the times or variables need to be stored in flash。
Is my solution reasonable?
Create a space inside the flash to define variables, and read the data after powering on the computer. Then there is a problem with data accumulation , inside the my program the define variables be accumulated, because the data is stored inside the flash. Does the change of data require special processing? HAL_FLASH_Unlock()
How to define variables inside flash, please give a program example。
Thank you
Solved! Go to Solution.
2024-10-10 02:24 AM
NVRAM / BKPRAM might be more practical.
FLASH sectors on the F4 are quite large and time consuming to erase
You'd need to carve holes to use the smaller 16KB sectors.
You can journal writes across the sector, and the enumerate at next startup to find the last saved data.
2024-10-10 01:25 AM
2024-10-10 01:27 AM
To add, this variable of mine changes while the program is running. and needs to be stored in flash
2024-10-10 01:31 AM
Yes, that is addressed in the threads I linked.
2024-10-10 02:24 AM
NVRAM / BKPRAM might be more practical.
FLASH sectors on the F4 are quite large and time consuming to erase
You'd need to carve holes to use the smaller 16KB sectors.
You can journal writes across the sector, and the enumerate at next startup to find the last saved data.
2024-10-11 12:20 AM
@zhaowhong wrote:To add, this variable of mine changes while the program is running. and needs to be stored in flash
How often will this variable be save to Flash? I believe on average the STM32 flash can be written at 10K cycles, but can change to temperature. An external EEPROM would be a better solution as they have around 100K write cycles.
2024-10-11 12:32 AM
YES
I read some documents that must be erased when writing. I originally planned to use RAM variables to record. And wanted the CPU to write to FLASH before powering off, but the demand is not sure when to power off, and powering off is uncontrollable.
It seems that methods such as external feram are better。
2024-10-11 12:33 AM
Yes
An external EEPROM would be a better solution.
2024-10-11 03:18 AM
You haven't said what STM32 you're using.
Some have the facility for battery-backup of a portion of RAM...
@zhaowhong wrote:, but the demand is not sure when to power off, and powering off is uncontrollable.
So what you'd need is
2024-10-11 05:40 PM
Hi
STM32F407 .You said this method is very feasible.How can we let the CPU know when the power is off? How can this be achieved?Your method detects a power outage and directly enters the interrupt and writes to flash.