cancel
Showing results for 
Search instead for 
Did you mean: 

Want to detect the number of times a switch value is used through stm32

zhaowhong
Associate III

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

 

1 ACCEPTED SOLUTION

Accepted Solutions

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

10 REPLIES 10
zhaowhong
Associate III

To add, this variable of mine changes while the program is running. and needs to be stored in flash

Yes, that is addressed in the threads I linked.

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

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。

Yes  

An external EEPROM would be a better solution.

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

  1. A signal (interrupt?) to tell you when the power had been turned off, and
  2. Enough backup/reserve power to be able to complete a flash write.

 

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.