Want to detect the number of times a switch value is used through stm32
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-10 1: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.
- Labels:
-
STM32F4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-10 2: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.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-10 1:25 AM
https://community.st.com/t5/stm32-mcus-products/eeprom-emulation/m-p/719118
https://community.st.com/t5/stm32-mcus-products/flash-memory/m-p/672904
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-10 1:27 AM
To add, this variable of mine changes while the program is running. and needs to be stored in flash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-10 1:31 AM
Yes, that is addressed in the threads I linked.
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-10 2: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.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
TimerCallback tutorial! | UART and DMA Idle tutorial!
If you find my solution useful, please click the Accept as Solution so others see the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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。
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-11 12:33 AM
Yes
An external EEPROM would be a better solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-11 3: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
- A signal (interrupt?) to tell you when the power had been turned off, and
- Enough backup/reserve power to be able to complete a flash write.
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-11 5: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.
