FlashStorage_STM32 Library to use emulated-EEPROM. Now supports STM32 core v2.0.0
-
- Posts: 102
- Joined: Thu Feb 27, 2020 7:54 am
- Location: Toronto
FlashStorage_STM32 Library to use emulated-EEPROM. Now supports STM32 core v2.0.0
FlashStorage_STM32 Library
How To Install Using Arduino Library Manager
Why do we need this FlashStorage_STM32 Library
Features
The FlashStorage_STM32 library, inspired from Cristian Maglie's FlashStorage, provides a convenient way to store and retrieve user's data using emulated-EEPROM, from the non-volatile flash memory of STM32F/L/H/G/WB/MP1.
The flash memory, generally used to store the firmware code, can also be used to store / retrieve more user's data and faster than from EEPROM. Thanks to the buffered data writing and reading, the flash access time is greatly reduced to increase the life of the flash.
Currently supported Boards
1. STM32F/L/H/G/WB/MP1 boards with / without integrated EEPROM
- Nucleo-144
- Nucleo-64
- Nucleo-32
- Discovery
- Generic STM32F0, STM32F1, STM32F2, STM32F3, STM32F4, STM32F7
- STM32L0, STM32L1, STM32L4, STM32L5
- STM32G0, STM32G4
- STM32H7
- STM32WB
- STM32MP1
- LoRa boards
- 3-D printer boards
- Generic Flight Controllers
- Midatronics boards
Changelog
Releases v1.0.0
1. Initial release to support STM32F/L/H/G/WB/MP1 board with / without integrated EEPROM
How To Install Using Arduino Library Manager
Why do we need this FlashStorage_STM32 Library
Features
The FlashStorage_STM32 library, inspired from Cristian Maglie's FlashStorage, provides a convenient way to store and retrieve user's data using emulated-EEPROM, from the non-volatile flash memory of STM32F/L/H/G/WB/MP1.
The flash memory, generally used to store the firmware code, can also be used to store / retrieve more user's data and faster than from EEPROM. Thanks to the buffered data writing and reading, the flash access time is greatly reduced to increase the life of the flash.
Currently supported Boards
1. STM32F/L/H/G/WB/MP1 boards with / without integrated EEPROM
- Nucleo-144
- Nucleo-64
- Nucleo-32
- Discovery
- Generic STM32F0, STM32F1, STM32F2, STM32F3, STM32F4, STM32F7
- STM32L0, STM32L1, STM32L4, STM32L5
- STM32G0, STM32G4
- STM32H7
- STM32WB
- STM32MP1
- LoRa boards
- 3-D printer boards
- Generic Flight Controllers
- Midatronics boards
Changelog
Releases v1.0.0
1. Initial release to support STM32F/L/H/G/WB/MP1 board with / without integrated EEPROM
Last edited by khoih-prog on Tue Apr 27, 2021 3:15 am, edited 2 times in total.
Re: FlashStorage_STM32 Library to use emulated-EEPROM
Thanks @khoih-prog
You made a lot of libraries
Very nice
You made a lot of libraries

Re: FlashStorage_STM32 Library to use emulated-EEPROM
Khoi Hoang, if you played with STM32 NVM controller, could you try to make ArduinoOTA library InternalStorage implementation for STM32?
https://github.com/jandrassy/ArduinoOTA/issues/4
https://github.com/jandrassy/ArduinoOTA/issues/4
-
- Posts: 102
- Joined: Thu Feb 27, 2020 7:54 am
- Location: Toronto
Re: FlashStorage_STM32 Library to use emulated-EEPROM
HI @fpiSTM
Thanks for your nice words. Those libs are so simple compared to what you have done to support complex STM32 boards.
Just in the process of making a library, I get into some features I wish provided by certain lib, then add in the long bucket list.
Hi @Juraj,
I just have some little experience with ESP OTA only, and haven't looked at your good ArduinoOTA Library
Will definitely spend some time to check if I could find my way and do anything in the STM32 maze.
Thanks for your nice words. Those libs are so simple compared to what you have done to support complex STM32 boards.
Just in the process of making a library, I get into some features I wish provided by certain lib, then add in the long bucket list.
Hi @Juraj,
I just have some little experience with ESP OTA only, and haven't looked at your good ArduinoOTA Library
Will definitely spend some time to check if I could find my way and do anything in the STM32 maze.
-
- Posts: 102
- Joined: Thu Feb 27, 2020 7:54 am
- Location: Toronto
Re: FlashStorage_STM32 Library to use emulated-EEPROM
Just got an interesting info from a user of this library EEPROM write works only in a fully erased Bluepill with Chinese clone micro CS32F103C8T6.
So beware of cheap and cloned STM32 products.
I really don't know what wrong with it: the chip (I guess) or hardware design.I have a blue pill with chinese CS32F103C8T6 in it. EEPROM write (commit and put) works only after I completely erase the chip using STM32CubeProgrammer. Once there is any data other than 0xFF in any location, it will no longer write to any location. Every sample programs failed, after the initial run in that chip. Everything is working as it should on my other bluepill with Genuine (I hope) STM32F103C8T6.
So beware of cheap and cloned STM32 products.
Re: FlashStorage_STM32 Library to use emulated-EEPROM
Wow this is helpful. This EEProm emulator actually works with my Nucleo F767zi (after updating the STM core and arduino IDE)
I haven't been able to get the built-in version (EEPROM on STM32 core) to work on F7 processors.
BTW, It worked with a Nucleo F103rb also.
I haven't been able to get the built-in version (EEPROM on STM32 core) to work on F7 processors.
BTW, It worked with a Nucleo F103rb also.
Re: FlashStorage_STM32 Library to use emulated-EEPROM
@bockesj
https://github.com/stm32duino/STM32Exam ... EEPROM.ino
It seems strange as the FlashStorage_STM32 library simply used the buitl-in EEPROM one. It uses the buffered api that's probably why you do not able to get it working. As on F7 the Flash page is huge it take a while to read and write if you used direct API. That's why buffered API has been created... Anyway direct API works but it is very long. You can check the STM32Examples library to see how buffered API works:bockesj wrote: Sat Feb 06, 2021 10:07 pm I haven't been able to get the built-in version (EEPROM on STM32 core) to work on F7 processors.
https://github.com/stm32duino/STM32Exam ... EEPROM.ino
Writing to a flash is very expensive operation, since a
whole flash page needs to be written, even if you only
want to access the flash byte-wise.
The STM32 Arduino core provides a buffered access API
to the emulated EEPROM. The library has allocated the
buffer even if you don't use the buffered API, so
it's strongly suggested to use the buffered API anyhow.
-
- Posts: 102
- Joined: Thu Feb 27, 2020 7:54 am
- Location: Toronto
Re: FlashStorage_STM32 Library to use emulated-EEPROM
Major Releases v1.1.0
1. Add support to new STM32 core v2.0.0
2. Add support to new STM32L5 and many new STM32F/L/H/G/WB/MP1 boards
Debug Terminal Output Samples
1. The following is the sample terminal output when running example MQTT_ThingStream_Ethernet_STM32_LAN8720 on BLACK_F407VE board with LAN8720 Ethernet & STM32Ethernet Library demonstrating FlashStorage_STM32 feature to be used to store persistent data.
1.1. Without correct ThingStream MQTT Credentials. Enter Config Portal
1.2. Got correct ThingStream MQTT Credentials from Config Portal and saved to persistent EEPROM-emulated Flash
1. Add support to new STM32 core v2.0.0
2. Add support to new STM32L5 and many new STM32F/L/H/G/WB/MP1 boards
Debug Terminal Output Samples
1. The following is the sample terminal output when running example MQTT_ThingStream_Ethernet_STM32_LAN8720 on BLACK_F407VE board with LAN8720 Ethernet & STM32Ethernet Library demonstrating FlashStorage_STM32 feature to be used to store persistent data.
1.1. Without correct ThingStream MQTT Credentials. Enter Config Portal
Code: Select all
Start MQTT_ThingStream_Ethernet_STM32_LAN8720 on BLACK_F407VE
Ethernet Shield type : LAN8720 Ethernet & STM32Ethernet Library
Ethernet_Manager_STM32 v1.3.0
DoubleResetDetector_Generic v1.0.3
EEPROM size = 16384, start = 0
Flag read = 0xd0d01234
doubleResetDetected
ClearFlag write = 0xd0d04321
[ETM] =====================
[ETM] DRD. Run ConfigPortal
[ETM] =====================
[ETM] EEPROMsz:4096
[ETM] EEPROM Length():16384
[ETM] CCSum=0x77e,RCSum=0x77e
[ETM] ChkCrR:CrCCsum=0x215e,CrRCsum=0x215e
[ETM] CrCCSum=215e,CrRCSum=215e
[ETM] Valid Stored Dynamic Data
[ETM] ======= Start Stored Config Data =======
[ETM] Header=STM32, BoardName=STM32-Ethernet
[ETM] StaticIP=
[ETM] Start connectEthernet using DHCP
[ETM] MAC:FE-98-FD-D6-DB-BA
[ETM] Dynamic IP OK, connected
[ETM] IP:192.168.2.149
[ETM] bg: isForcedConfigPortal = false
[ETM] bg:Stay forever in CP:DRD/MRD
Connected! IP address: 192.168.2.149
***************************************
esp32-sniffer/12345678/ble
***************************************
[ETM] h:Updating EEPROM. Please wait for reset
[ETM] SaveEEPROM,Sz=16384,DataSz=248,WCSum=0x8a9
[ETM] CrCCSum=0x2785
[ETM] h:Rst
1.2. Got correct ThingStream MQTT Credentials from Config Portal and saved to persistent EEPROM-emulated Flash
Code: Select all
Start MQTT_ThingStream_Ethernet_STM32_LAN8720 on BLACK_F407VE
Ethernet Shield type : LAN8720 Ethernet & STM32Ethernet Library
Ethernet_Manager_STM32 v1.3.0
DoubleResetDetector_Generic v1.0.3
EEPROM size = 16384, start = 0
Flag read = 0xd0d04321
No doubleResetDetected
SetFlag write = 0xd0d01234
[ETM] EEPROMsz:4096
[ETM] EEPROM Length():16384
[ETM] CCSum=0x8a9,RCSum=0x8a9
[ETM] ChkCrR:CrCCsum=0x2785,CrRCsum=0x2785
[ETM] CrCCSum=2785,CrRCSum=2785
[ETM] Valid Stored Dynamic Data
[ETM] ======= Start Stored Config Data =======
[ETM] Header=STM32, BoardName=STM32-Ethernet
[ETM] StaticIP=192.168.2.220
[ETM] Start connectEthernet using Static IP =192.168.2.220
[ETM] MAC:FE-98-FD-D6-DF-BA
[ETM] IP:192.168.2.220
[ETM] begin:Ethernet Connected.
Connected! IP address: 192.168.2.220
***************************************
esp32-sniffer/12345678/ble
***************************************
Your stored Credentials :
MQTT Server = mqtt.thingstream.io
Port = 1883
MQTT UserName = user_name
MQTT PWD = password
Client ID = device:12345678-1234-1234-1234-123456789abc
Attempting MQTT connection to mqtt.thingstream.io
...connected
Published connection message successfully!
Subcribed to: esp32-sniffer/12345678/ble
HStop doubleResetDetecting
ClearFlag write = 0xd0d04321
MQTT Message Send : esp32-sniffer/12345678/ble => Hello from MQTT_ThingStream on BLACK_F407VE with LAN8720 Ethernet & STM32Ethernet Library
H
MQTT Message receive [esp32-sniffer/12345678/ble] Hello from MQTT_ThingStream on BLACK_F407VE with LAN8720 Ethernet & STM32Ethernet Library
-
- Posts: 102
- Joined: Thu Feb 27, 2020 7:54 am
- Location: Toronto
Re: FlashStorage_STM32 Library to use emulated-EEPROM. Now supports STM32 core v2.0.0
FYI, for STMF1/F3, and CH/CS32F103, it's better now to use the new FlashStorage_STM32F1 Library
Features
The FlashStorage_STM32F1 library, provides a convenient way to store and retrieve user's data using emulated-EEPROM, from the non-volatile flash memory of STM32F1/F3, including non-genuine CH32F103xx, CS32F103xx, etc. boards.
Currently, the library supports both new STM32 core v2.0.0 and previous STM32 core v1.9.0
Features
The FlashStorage_STM32F1 library, provides a convenient way to store and retrieve user's data using emulated-EEPROM, from the non-volatile flash memory of STM32F1/F3, including non-genuine CH32F103xx, CS32F103xx, etc. boards.
Currently, the library supports both new STM32 core v2.0.0 and previous STM32 core v1.9.0