I want to store 3 integer values in the flash memory of the microcontroller so that these values are not lost if the device has a power outage.
I am trying to understand which type of memory to use for this purpose and how exactly how can I write to and read from this memory block.
I am doing a hobby project to use a HMI to input data to a PLC which will then drive several motors to control the movement of toy quadcopter.
I am using the Keil uvision IDE.
Some additional notes:
- The values will be changed once every 2-3 months.
- There can be power outage during the value update process.
- Its not critical if process is interrupted and we lose the latest value entered.
Best Answer
You can use so called
EEPROM emulation
, which uses a part of the Flash memory to be used as EEPROM.You can read all about it for the STM40x/STM41x in the following document:
https://www.st.com/resource/en/application_note/dm00036065-eeprom-emulation-in-stm32f40x-stm32f41x-microcontrollers-stmicroelectronics.pdf
Of course this EEPROM memory will reduce from the regular Flash memory. It will be needed to assign a full page (not sure how many bytes), but one page is more than enough for your 3 bytes.
Note to think about wear levelling in case you need to store those 3 values often (use different pages if so).
For others: There are different application notes for other STM32 models.