GithubHelp home page GithubHelp logo

khoih-prog / flashstorage_stm32 Goto Github PK

View Code? Open in Web Editor NEW
33.0 3.0 12.0 147 KB

The FlashStorage_STM32 library aims to provide a convenient way to store and retrieve user's data using the non-volatile flash memory of STM32F/L/H/G/WB/MP1. It's using the buffered read and write to minimize the access to Flash. It now supports writing and reading the whole object, not just byte-and-byte. New STM32 core v2.0.0 is also supported now. Useful if the EEPROM is not available or too small. Currently, STM32F/L/H/G/WB/MP1 are supported.

License: MIT License

C++ 4.26% C 95.68% Shell 0.06%
flash flash-storage storage eeprom emulated-eeprom samd data stm32 flashstorage-stm32 stm32f

flashstorage_stm32's Introduction

FlashStorage_STM32 Library

arduino-library-badge GitHub release GitHub contributions welcome GitHub issues

Donate to my libraries using BuyMeACoffee



Table of Contents



Important Change from v1.2.0

Please have a look at HOWTO Fix Multiple Definitions Linker Error



Why do we need this FlashStorage_STM32 library

Features

The FlashStorage_STM32 library, inspired by 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, the library supports both new STM32 core v2.0.0+ and previous STM32 core v1.9.0-


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


Prerequisites

  1. Arduino IDE 1.8.19+ for Arduino. GitHub release
  2. Arduino Core for STM32 v2.3.0+ for STM32 boards. GitHub release


Installation

Use Arduino Library Manager

The best and easiest way is to use Arduino Library Manager. Search for FlashStorage_STM32, then select / install the latest version. You can also use this link arduino-library-badge for more detailed instructions.

Manual Install

Another way to install is to:

  1. Navigate to FlashStorage_STM32 page.
  2. Download the latest release FlashStorage_STM32-main.zip.
  3. Extract the zip file to FlashStorage_STM32-main directory
  4. Copy whole FlashStorage_STM32-main folder to Arduino libraries' directory such as ~/Arduino/libraries/.

VS Code & PlatformIO

  1. Install VS Code
  2. Install PlatformIO
  3. Install FlashStorage_STM32 library by using Library Manager. Search for FlashStorage_STM32 in Platform.io Author's Libraries
  4. Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File


Packages' Patches

1. For STM32 boards to use LAN8720

For Generic STM32F4 series boards, such as STM32F407VE, using LAN8720, please use STM32 core v2.2.0 as breaking core v2.3.0 creates the compile error.


To use LAN8720 on some STM32 boards

  • Nucleo-144 (F429ZI, NUCLEO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG)
  • Discovery (DISCO_F746NG)
  • STM32F4 boards (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE_Mini, DIYMORE_F407VGT, FK407M1)

you have to copy the files stm32f4xx_hal_conf_default.h and stm32f7xx_hal_conf_default.h into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system) to overwrite the old files.

Supposing the STM32 stm32 core version is 2.2.0. These files must be copied into the directory:

  • ~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h for STM32F4.
  • ~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h for Nucleo-144 STM32F7.

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, these files must be copied into the corresponding directory:

  • ~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/system/STM32F4xx/stm32f4xx_hal_conf_default.h
  • `~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/system/STM32F7xx/stm32f7xx_hal_conf_default.h

2. For STM32 boards to use Serial1

To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards, you have to copy the files STM32 variant.h into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.3.0). You have to modify the files corresponding to your boards, this is just an illustration how to do.

Supposing the STM32 stm32 core version is 2.3.0. These files must be copied into the directory:

  • ~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/NUCLEO_F767ZI/variant.h for Nucleo-144 NUCLEO_F767ZI.
  • ~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/NUCLEO_L053R8/variant.h for Nucleo-64 NUCLEO_L053R8.

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, these files must be copied into the corresponding directory:

  • ~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/variants/NUCLEO_F767ZI/variant.h
  • ~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/variants/NUCLEO_L053R8/variant.h


HOWTO Fix Multiple Definitions Linker Error

The current library implementation, using xyz-Impl.h instead of standard xyz.cpp, possibly creates certain Multiple Definitions Linker error in certain use cases.

You can include this .hpp file

// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "FlashStorage_STM32.hpp"     //https://github.com/khoih-prog/FlashStorage_STM32

in many files. But be sure to use the following .h file in just 1 .h, .cpp or .ino file, which must not be included in any other file, to avoid Multiple Definitions Linker Error

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "FlashStorage_STM32.h"           //https://github.com/khoih-prog/FlashStorage_STM32

Check the new multiFileProject example for a HOWTO demo.

Have a look at the discussion in Different behaviour using the src_cpp or src_h lib #80



Limited number of writes

The flash memory has a limited amount of write cycles. Typical flash memories can perform about 10000 writes cycles to the same flash block before starting to "wear out" and begin to lose the ability to retain data.

So BEWARE: IMPROPER USE OF THIS LIBRARY CAN QUICKLY AND PERMANENTLY DESTROY THE FLASH MEMORY OF YOUR MICRO, in particular you should avoid to call the put() orcommit() functions too often and make sure that in the entire life of the micro the number of calls to put() orcommit() stay well below the above limit of 10000 (it's a good rule-of-thumb to keep that number in mind even if the manufacturer of the micro guarantees a bigger number of cycles).



Usage

Using the alternative EEPROM-like API

Include FlashStorage_STM32.h to get an EEPROM emulation with the internal flash memory.

See EmulateEEPROM sketch for an example.

The API is very similar to the well known Arduino EEPROM.h API but with 4 additional functions:

  • bool isValid() returns true if data in the emulated-EEPROM is valid (the data written to flash at least once by EEPROM.commit() or EEPROM.put()). Otherwise emulated-EEPROM data is "undefined" and the function returns false.
  • void commit() store the EEPROM data in flash. Use this with care: Every call writes the complete emulated-EEPROM data to flash. This will reduce the remaining flash-write-cycles. Don't call this method in a loop or you will kill your flash soon.
  • void setCommitASAP(bool value = true) to set or clear the _commitASAP private variable (default is true to be safe). If _commitASAP is false, the call to EEPROM.put() won't force the EEPROM.commit() to extend the flash life. You'll have to remember to call EEPROM.commit() manually to save the emulated-EEPROM data into flash or data will be lost.
  • bool getCommitASAP() to return the current value of _commitASAP.


Examples

  1. EEPROM_Clear
  2. EEPROM_CRC
  3. EEPROM_get
  4. EEPROM_iteration
  5. EEPROM_put
  6. EEPROM_read
  7. EEPROM_update
  8. EEPROM_write
  9. EmulateEEPROM
  10. FlashStoreAndRetrieve
  11. StoreNameAndSurname
  12. multiFileProject New

Examples from other libraries

  1. STM32_WiFi
  2. STM32_WiFi_MQTT
  1. STM32_WiFiNINA
  2. STM32_WiFiNINA_MQTT
  1. AM2315_Ethernet_STM32
  2. DHT11_Ethernet_STM32
  3. Ethernet_STM32
  4. MQTT_ThingStream_Ethernet_STM32

4. Library ESP_AT_WM_Lite

  1. STM32_ESP8266Shield
  1. BI_Ethernet_Blynk

  2. BI_Ethernet_Blynk_Email

  3. BI_Ethernet_WM_Config

  4. LAN8720_Ethernet_Blynk

  5. LAN8720_Ethernet_Blynk_Email

  6. LAN8720_Ethernet_WM_Config

    ......

and many more to libraries come.



// Demonstrate how to use FlashStorage_STM32 with an API that is similar to the EEPROM library to Store and retrieve structured data.
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include <FlashStorage_STM32.h>
const int WRITTEN_SIGNATURE = 0xBEEFDEED;
// Create a structure that is big enough to contain a name
// and a surname. The "valid" variable is set to "true" once
// the structure is filled with actual data for the first time.
typedef struct
{
char name[100];
char surname[100];
} Person;
void setup()
{
Serial.begin(115200);
while (!Serial);
delay(200);
Serial.print(F("\nStart StoreNameAndSurname on "));
Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
Serial.print("EEPROM length: ");
Serial.println(EEPROM.length());
// Check signature at address 0
int signature;
// Create a "Person" variable and call it "owner"
uint16_t storedAddress = 0;
Person owner;
EEPROM.get(storedAddress, signature);
// If the EEPROM is empty then no WRITTEN_SIGNATURE
if (signature == WRITTEN_SIGNATURE)
{
EEPROM.get(storedAddress + sizeof(signature), owner);
// Say hello to the returning user!
Serial.print("Hi ");
Serial.print(owner.name);
Serial.print(" ");
Serial.print(owner.surname);
Serial.println(", nice to see you again :-)");
Serial.println("Clearing WRITTEN_SIGNATURE for next try");
EEPROM.put(0, 0);
Serial.println("Done clearing signature in emulated EEPROM. You can reset now");
}
else
{
Serial.println("EEPROM is empty, writing WRITTEN_SIGNATURE and some example data:");
EEPROM.put(storedAddress, WRITTEN_SIGNATURE);
// ...in this case we ask for user data.
Serial.setTimeout(30000);
Serial.print("Insert your name : ");
String name = Serial.readStringUntil('\n');
Serial.println(name);
Serial.print("Insert your surname : ");
String surname = Serial.readStringUntil('\n');
Serial.println(surname);
// Fill the "owner" structure with the data entered by the user...
name.toCharArray(owner.name, 100);
surname.toCharArray(owner.surname, 100);
// ...and finally save everything into emulated-EEPROM
EEPROM.put(storedAddress + sizeof(signature), owner);
// Print a confirmation of the data inserted.
Serial.print("<< Your name: ");
Serial.print(owner.name);
Serial.print(". Your surname: ");
Serial.print(owner.surname);
Serial.println(" >> have been saved. Thank you!");
}
}
void loop()
{
// Do nothing...
}



Debug Terminal Output Samples

1. Ethernet_STM32_LAN8720 on BLACK_F407VE using LAN8720 Ethernet and STM32Ethernet Library

The following is the sample terminal output when running example Ethernet_STM32_LAN8720 on STM32F4 BLACK_F407VE with LAN8720 Ethernet using STM32Ethernet Library.

1.1 DoubleReset Detected => Enter Config Portal

Start Ethernet_STM32_LAN8720 on BLACK_F407VE
Ethernet Shield type : LAN8720 Ethernet & STM32Ethernet Library
Ethernet_Manager_STM32 v1.3.2
DoubleResetDetector_Generic v1.8.1

EEPROM size = 16384, start = 0
Flag read = 0xd0d04321
No doubleResetDetected
SetFlag write = 0xd0d01234
[ETM] EEPROMsz:4096
[ETM] EEPROM Length():16384
[ETM] CCSum=0xaed,RCSum=0x4d385471
[ETM] ChkCrR:CrCCsum=0x21dd,CrRCsum=0x3338
[ETM] InitCfgFile,sz=60
[ETM] SaveEEPROM,Sz=16384,DataSz=0,WCSum=0x569
[ETM] CrCCSum=0xc30
[ETM] Start connectEthernet using DHCP
[ETM] MAC:FE-98-FC-DD-D9-BA
[ETM] Dynamic IP OK, connected
[ETM] IP:192.168.2.169
[ETM] bg: isForcedConfigPortal = false
[ETM] bg:Stay forever in CP:No ConfigDat
Connected! IP address: 192.168.2.169

Your stored Credentials :
MQTT Server = blank
Port = blank
MQTT UserName = blank
MQTT PWD = blank
Subs Topics = blank
Pubs Topics = blank
HStop doubleResetDetecting
ClearFlag write = 0xd0d04321
HHHHH[ETM] h:Updating EEPROM. Please wait for reset
[ETM] SaveEEPROM,Sz=16384,DataSz=0,WCSum=0x729
[ETM] CrCCSum=0x1087
[ETM] h:Rst

1.2 Config Data Saved => Running normally

Start Ethernet_STM32_LAN8720 on BLACK_F407VE
Ethernet Shield type : LAN8720 Ethernet & STM32Ethernet Library
Ethernet_Manager_STM32 v1.3.2
DoubleResetDetector_Generic v1.8.1

EEPROM size = 16384, start = 0
Flag read = 0xd0d04321
No doubleResetDetected
SetFlag write = 0xd0d01234
[ETM] EEPROMsz:4096
[ETM] EEPROM Length():16384
[ETM] CCSum=0x729,RCSum=0x729
[ETM] ChkCrR:CrCCsum=0x1087,CrRCsum=0x1087
[ETM] CrCCSum=1087,CrRCSum=1087
[ETM] Valid Stored Dynamic Data
[ETM] ======= Start Stored Config Data =======
[ETM] Header=STM32, BoardName=Black_V407VE
[ETM] StaticIP=blank
[ETM] Start connectEthernet using DHCP
[ETM] MAC:FE-98-FD-D6-DA-BA
[ETM] Dynamic IP OK, connected
[ETM] IP:192.168.2.170
[ETM] begin:Ethernet Connected.
Connected! IP address: 192.168.2.170

Your stored Credentials :
MQTT Server = mqtt_server
Port = 1883
MQTT UserName = mqtt_user
MQTT PWD = mqtt_pass
Subs Topics = Subs
Pubs Topics = Pubs
HStop doubleResetDetecting
ClearFlag write = 0xd0d04321
HSetFlag write = 0xd0d01234
[ETM] EEPROMsz:4096
[ETM] EEPROM Length():16384
[ETM] CCSum=0x729,RCSum=0x729
[ETM] ChkCrR:CrCCsum=0x1087,CrRCsum=0x1087
[ETM] CrCCSum=1087,CrRCSum=1087
[ETM] Valid Stored Dynamic Data
[ETM] ======= Start Stored Config Data =======
[ETM] Header=STM32, BoardName=Black_V407VE
[ETM] StaticIP=blank
[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] begin:Ethernet Connected.
Connected! IP address: 192.168.2.149

Your stored Credentials :
MQTT Server = mqtt_server
Port = 1883
MQTT UserName = mqtt_user
MQTT PWD = mqtt_pass
Subs Topics = Subs
Pubs Topics = Pubs
HStop doubleResetDetecting
ClearFlag write = 0xd0d04321
HHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH
HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH
HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH
HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH H

2. StoreNameAndSurname on NUCLEO_H743ZI2 with 16KB emulated-EEPROM

The following is the sample terminal output when running example StoreNameAndSurname on STM32H7 Nucleo-144 NUCLEO_H743ZI2

2.1 First Start

Start StoreNameAndSurname on NUCLEO_H743ZI2
FlashStorage_STM32 v1.2.0
EEPROM length: 16384
EEPROM is empty, writing WRITTEN_SIGNATURE and some example data:
Insert your name : My_Name

Insert your surname : My_Surname

<< Your name: My_Name
. Your surname: My_Surname
 >> have been saved. Thank you!

2.2 After reset

Start StoreNameAndSurname on NUCLEO_H743ZI2
FlashStorage_STM32 v1.2.0
EEPROM length: 16384
Hi My_Name
 My_Surname
, nice to see you again :-)
Clearing WRITTEN_SIGNATURE for next try
Done clearing signature in emulated EEPROM. You can reset now

3. StoreNameAndSurname on NUCLEO_L552ZE_Q with 2KB emulated-EEPROM

The following is the sample terminal output when running example StoreNameAndSurname on STM32L5 Nucleo-144 NUCLEO_L552ZE_Q

3.1 First Start

Start StoreNameAndSurname on NUCLEO_L552ZE_Q
FlashStorage_STM32 v1.2.0
EEPROM length: 2048
EEPROM is empty, writing WRITTEN_SIGNATURE and some example data:
Insert your name : My_Name

Insert your surname : My_Surname

<< Your name: My_Name
. Your surname: My_Surname
 >> have been saved. Thank you!

3.2 After reset

Start StoreNameAndSurname on NUCLEO_L552ZE_Q
FlashStorage_STM32 v1.2.0
EEPROM length: 2048
Hi My_Name
 My_Surname
, nice to see you again :-)
Clearing WRITTEN_SIGNATURE for next try
Done clearing signature in emulated EEPROM. You can reset now

4. StoreNameAndSurname on NUCLEO_F767ZI with 16KB emulated-EEPROM

The following is the sample terminal output when running example StoreNameAndSurname on STM32F7 Nucleo-144 NUCLEO_F767ZI

4.1 First Start

Start StoreNameAndSurname on NUCLEO_F767ZI
FlashStorage_STM32 v1.2.0
EEPROM length: 16384
EEPROM is empty, writing WRITTEN_SIGNATURE and some example data:
Insert your name : My_Name

Insert your surname : My_Surname

<< Your name: My_Name
. Your surname: My_Surname
 >> have been saved. Thank you!

4.2 After reset

Start StoreNameAndSurname on NUCLEO_F767ZI
FlashStorage_STM32 v1.2.0
EEPROM length: 16384
Hi My_Name
 My_Surname
, nice to see you again :-)
Clearing WRITTEN_SIGNATURE for next try
Done clearing signature in emulated EEPROM. You can reset now


FAQ

Can I use a single object to store more stuff?

Yes, you can declare a struct with more fields and call a EEPROM.put() to store the entire structure. See the StoreNameAndSurname for how to do it.

The content of the FlashStorage is erased each time a new sketch is uploaded?

Not with STM32.

Do you recommend to use FLASH instead of EEPROM?

No. If your board provides an integrated-EEPROM, it's advisable to use that because EEPROM has longer lifetime, number of write cycles, etc.).

In the absence of an integrated-EEPROM or its size is too small for your use-case, you can use this library to use a small portion flash memory as emulated-EEPROM, provided that you keep in mind the limits as in Limited number of writes



Troubleshooting

If you get compilation errors, more often than not, you may need to install a newer version of the core for Arduino boards.

Sometimes, the library will only work if you update the board core to the latest version because I am using newly added functions.



Issues

Submit issues to: FlashStorage_STM32 issues


TO DO

  1. Search for bug and improvement.
  2. Similar features for remaining Arduino boards

DONE

  1. Basic emulated-EEPROM for STM32F/L/H/G/WB/MP1.
  2. Add support to new STM32 core v1.9.0
  3. Similar features for remaining Arduino boards such as SAMD21, SAMD51, etc.
  4. Add Table of Contents
  5. Add support to new STM32 core v2.2.0+
  6. Fix multiple-definitions linker error.
  7. Add astyle using allman style. Restyle the library


Contributions and Thanks

Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.

  1. Inspired by Cristian Maglie's FlashStorage.
cmaglie
⭐️ Cristian Maglie


Contributing

If you want to contribute to this project:

  • Report bugs and errors
  • Ask for enhancements
  • Create issues and pull requests
  • Tell other people about this library

License

  • The library is licensed under MIT

Copyright

Copyright (c) 2021- Khoi Hoang

flashstorage_stm32's People

Contributors

khoih-prog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flashstorage_stm32's Issues

EEPROM write works only in a fully erased Bluepill with Chinese clone micro CS32F103C8T6.

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.

library not working on STM32F1

Hi, i am trying to use this library on STM32F1, i found this library through this site https://forum.arduino.cc/t/flashstorage-stm32-library-to-use-emulated-eeprom-now-supports-new-stm32-core-v2-0-0/693118 . There is shown STM32F1 as one of supported boards. However if i try to compile it it says that STM32F1 is not supported, so i would like to ask if i am reading it wrong or i am missing something? Also its giving me error for missing library stm32_def.h, dunno if its related.

If its just wrong library, do you know which is the right one?

STM32L432KBU6 – EEPROM will not retain after first cycle

First off, great library! Thank you very much.

Works perfectly on a Nucleo L476RG, however...

Standalone STM32L432KBU6 with full chip erase, will write to EEPROM using EEPROM.update() and EERPOM.commit(), and retains perfectly after FIRST update/write with commit, but any update/write to the EEPROM after will not be retained after cycling power. The EEPROM is updated but it will not be retained after cycling power.

Arduino Core for STM32 2.3.0
Arduino 1.8.9

Let me know if there's anything else you need from me.

Many thanks,
Caleb

error i got

dear sir or mam
i got this error
C:\Users\ali\Documents\Arduino\libraries\FlashStorage_STM32\src/utility/stm32_eeprom.h:61:23: fatal error: stm32_def.h: No such file or directory
#include "stm32_def.h"

error when compiling after ONLY include library to main.cpp

Hi, after include h file in main.cpp, can't compile project:
#include <FlashStorage_STM32.h>

I'm using platformio.

Processing blackpill_f401cc (platform: ststm32@^15.2.0; board: blackpill_f401cc; framework: arduino)

[{
"resource": "/d:/Dane/Grzegorz/PROGRAMOWANIE/Platformio/sterSzklarniSoft/.pio/libdeps/blackpill_f401cc/FlashStorage_STM32/src/FlashStorage_STM32.hpp",
"owner": "cpp",
"severity": 8,
"message": "redefinition of 'class EEPROMClass'",
"startLineNumber": 49,
"startColumn": 9,
"endLineNumber": 49,
"endColumn": 9
},{
"resource": "/d:/Dane/Grzegorz/PROGRAMOWANIE/Platformio/sterSzklarniSoft/.pio/libdeps/blackpill_f401cc/FlashStorage_STM32/src/FlashStorage_STM32.hpp",
"owner": "cpp",
"severity": 8,
"message": "redefinition of 'EEPROMClass EEPROM'",
"startLineNumber": 198,
"startColumn": 22,
"endLineNumber": 198,
"endColumn": 22
},{
"resource": "/d:/Dane/Grzegorz/PROGRAMOWANIE/Platformio/sterSzklarniSoft/.pio/libdeps/blackpill_f401cc/FlashStorage_STM32/src/utility/stm32_eeprom_Impl.h",
"owner": "cpp",
"severity": 8,
"message": "call of overloaded 'eeprom_buffered_read_byte(const uint32_t&)' is ambiguous",
"startLineNumber": 199,
"startColumn": 39,
"endLineNumber": 199,
"endColumn": 39
},{
"resource": "/d:/Dane/Grzegorz/PROGRAMOWANIE/Platformio/sterSzklarniSoft/.pio/libdeps/blackpill_f401cc/FlashStorage_STM32/src/utility/stm32_eeprom_Impl.h",
"owner": "cpp",
"severity": 8,
"message": "call of overloaded 'eeprom_buffered_write_byte(const uint32_t&, const uint8_t&)' is ambiguous",
"startLineNumber": 225,
"startColumn": 40,
"endLineNumber": 225,
"endColumn": 40
},{
"resource": "/d:/Dane/Grzegorz/PROGRAMOWANIE/Platformio/sterSzklarniSoft/.pio/libdeps/blackpill_f401cc/FlashStorage_STM32/src/utility/stm32_eeprom.hpp",
"owner": "cpp",
"severity": 8,
"message": "conflicting declaration of C function 'uint8_t eeprom_read_byte(const uint32_t&)'",
"startLineNumber": 137,
"startColumn": 9,
"endLineNumber": 137,
"endColumn": 9
},{
"resource": "/d:/Dane/Grzegorz/PROGRAMOWANIE/Platformio/sterSzklarniSoft/.pio/libdeps/blackpill_f401cc/FlashStorage_STM32/src/utility/stm32_eeprom.hpp",
"owner": "cpp",
"severity": 8,
"message": "conflicting declaration of C function 'void eeprom_write_byte(const uint32_t&, const uint8_t&)'",
"startLineNumber": 138,
"startColumn": 9,
"endLineNumber": 138,
"endColumn": 9
},{
"resource": "/d:/Dane/Grzegorz/PROGRAMOWANIE/Platformio/sterSzklarniSoft/.pio/libdeps/blackpill_f401cc/FlashStorage_STM32/src/utility/stm32_eeprom.hpp",
"owner": "cpp",
"severity": 8,
"message": "conflicting declaration of C function 'uint8_t eeprom_buffered_read_byte(const uint32_t&)'",
"startLineNumber": 143,
"startColumn": 11,
"endLineNumber": 143,
"endColumn": 11
},{
"resource": "/d:/Dane/Grzegorz/PROGRAMOWANIE/Platformio/sterSzklarniSoft/.pio/libdeps/blackpill_f401cc/FlashStorage_STM32/src/utility/stm32_eeprom.hpp",
"owner": "cpp",
"severity": 8,
"message": "conflicting declaration of C function 'void eeprom_buffered_write_byte(const uint32_t&, const uint8_t&)'",
"startLineNumber": 144,
"startColumn": 11,
"endLineNumber": 144,
"endColumn": 11
}]

EEPROM.commit() results in Hardware fault

Describe the bug

Dear Khoih-prog

I've been trying to use this library to write some configuration data to my MCU.
Everytime I execute the EEPROM.commit() function my MCU goes into hard fault - very rarely it is caught in some infinite loop.
I've traced the issue with the debugger to HAL_FLASH_PROGRAM which returns a HAL_ERROR (if it doens't just go into hard fault blink mode.

Information

aditional

  • I'm using the stm32duino/STM32duino FreeRTOS@^10.2.1 library to run "classic" FreeRTOS on my MCU.

Steps to Reproduce

I have wrapped your library into a helper function which i run en setup() for testing purposes:

void use_khoih_prog() {
        for (int i = 0; i < 255; i++) {
            EEPROM.write(i, (uint8_t)i);
        }
        EEPROM.commit();
    }

Furthermore I've defined following:

// this defined is needed to use the FlashStorage_Stm32 package
#define STM32WB

// The developer allocated EEPROM page and start address
// FlashStorage_Stm32 uses 1 page for EEPROM
// ==> FLASH_END = 0x08055FFF
#define FLASH_PAGE_NUMBER 0x55
#define FLASH_BASE_ADDRESS 0x08055000

As I'm using the FULL_BLE_FW_STACK for the STM32WB55CE which starts on 0x08056000, And I want to make sure I'm not overwriting this (though that memory should be write protected).

I have also modified the linker-script MEMORY-section:

/* Specify the memory areas */
MEMORY
{
FLASH (rx)                 : ORIGIN = 0x08000000, LENGTH = 0x55000  /* =348'160B - BLE stack starts @ 0x08056000 on STM32WB55CE */
RETAIN_FLASH (rwx)         : ORIGIN = 0x08055000, LENGTH = 0x1000   /* =4096B - reserved for retained variables */
RAM1 (xrw)                 : ORIGIN = 0x20000004, LENGTH = 0x2FFFC
RAM_SHARED (xrw)           : ORIGIN = 0x20030000, LENGTH = 10K
}

Expected behavior

0-->255 should be written to addresses 0x08055000 --> 0x080550FF

Actual behavior

MCU goes into hardfault.

Hopefully your have an idea what could be the cause?

Regards
Kmeld

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.