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 II

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

 

4 REPLIES 4
zhaowhong
Associate II

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