From bb0dd71e4274283edc399a6ade83ae0fb9fdf1f1 Mon Sep 17 00:00:00 2001
From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com>
Date: Thu, 24 Nov 2022 19:38:01 -0500
Subject: [PATCH] Update `README.md` and use `allman` astyle
---
CONTRIBUTING.md | 28 +-
changelog.md | 7 +
examples/EEPROM_CRC/EEPROM_CRC.ino | 8 +-
examples/EEPROM_Clear/EEPROM_Clear.ino | 24 +-
examples/EEPROM_get/EEPROM_get.ino | 4 +-
.../EEPROM_iteration/EEPROM_iteration.ino | 10 +-
examples/EEPROM_put/EEPROM_put.ino | 4 +-
examples/EEPROM_read/EEPROM_read.ino | 10 +-
examples/EEPROM_update/EEPROM_update.ino | 7 +-
examples/EEPROM_write/EEPROM_write.ino | 17 +-
examples/EmulateEEPROM/EmulateEEPROM.ino | 7 +-
.../FlashStoreAndRetrieve.ino | 7 +-
.../StoreNameAndSurname.ino | 15 +-
.../multiFileProject/multiFileProject.cpp | 13 +-
examples/multiFileProject/multiFileProject.h | 2 +-
.../multiFileProject/multiFileProject.ino | 13 +-
platformio/platformio.ini | 2 +
src/FlashStorage_STM32.h | 2 +-
src/utility/stm32_eeprom_Impl.h | 530 +++++++++---------
utils/astyle_library.conf | 70 +++
utils/restyle.sh | 6 +
21 files changed, 470 insertions(+), 316 deletions(-)
create mode 100644 utils/astyle_library.conf
create mode 100644 utils/restyle.sh
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 94df11d..d3bf66f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
Please ensure to specify the following:
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
-* Board Core Version (e.g. Arduino STM32 core v2.2.0, etc.)
+* Board Core Version (e.g. Arduino STM32 core v2.3.0, etc.)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
* Anything that might be relevant in your opinion, such as:
@@ -27,12 +27,12 @@ Please ensure to specify the following:
```
Arduino IDE version: 1.8.19
-Arduino STM32 core v2.2.0
+Arduino STM32 core v2.3.0
OS: Ubuntu 20.04 LTS
-Linux Inspiron-3593 5.4.0-96-generic #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
+Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
-The board couldn't autoreconnect to Local Blynk Server after router power recycling.
+I encountered a crash while using this library
Steps to reproduce:
1. ...
@@ -41,6 +41,7 @@ Steps to reproduce:
4. ...
```
+---
### Sending Feature Requests
@@ -48,6 +49,25 @@ Feel free to post feature requests. It's helpful if you can explain exactly why
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/FlashStorage_STM32/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
+---
+
### Sending Pull Requests
Pull Requests with changes and fixes are also welcome!
+
+Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
+
+1. Change directory to the library GitHub
+
+```
+xy@xy-Inspiron-3593:~$ cd Arduino/xy/FlashStorage_STM32_GitHub/
+xy@xy-Inspiron-3593:~/Arduino/xy/FlashStorage_STM32_GitHub$
+```
+
+2. Issue astyle command
+
+```
+xy@xy-Inspiron-3593:~/Arduino/xy/FlashStorage_STM32_GitHub$ bash utils/restyle.sh
+```
+
+
diff --git a/changelog.md b/changelog.md
index 616ac25..1d3028d 100644
--- a/changelog.md
+++ b/changelog.md
@@ -6,6 +6,13 @@
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/FlashStorage_STM32.svg)](http://github.com/khoih-prog/FlashStorage_STM32/issues)
+
+
+
+
+
+
+
---
---
diff --git a/examples/EEPROM_CRC/EEPROM_CRC.ino b/examples/EEPROM_CRC/EEPROM_CRC.ino
index 63a92e1..5d99512 100644
--- a/examples/EEPROM_CRC/EEPROM_CRC.ino
+++ b/examples/EEPROM_CRC/EEPROM_CRC.ino
@@ -23,7 +23,7 @@
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include
-unsigned long eeprom_crc()
+unsigned long eeprom_crc()
{
const unsigned long crc_table[16] =
{
@@ -48,11 +48,13 @@ unsigned long eeprom_crc()
void setup()
{
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print(F("\nStart EEPROM_CRC on ")); Serial.println(BOARD_NAME);
+ Serial.print(F("\nStart EEPROM_CRC on "));
+ Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
//Print length of data to run CRC on.
@@ -65,7 +67,7 @@ void setup()
Serial.print("Done!");
}
-void loop()
+void loop()
{
/* Empty loop */
}
diff --git a/examples/EEPROM_Clear/EEPROM_Clear.ino b/examples/EEPROM_Clear/EEPROM_Clear.ino
index 2af426c..bc90f9d 100644
--- a/examples/EEPROM_Clear/EEPROM_Clear.ino
+++ b/examples/EEPROM_Clear/EEPROM_Clear.ino
@@ -2,8 +2,8 @@
EEPROM_Clear.ino
For STM32 using Flash emulated-EEPROM
- 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.
+ 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.
Inspired by Cristian Maglie's FlashStorage (https://github.com/cmaglie/FlashStorage)
@@ -15,25 +15,28 @@
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include
-void setup()
+void setup()
{
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print(F("\nStart EEPROM_Clear on ")); Serial.println(BOARD_NAME);
+ Serial.print(F("\nStart EEPROM_Clear on "));
+ Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
-
+
// initialize the LED pin as an output.
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
- Serial.print("Emulated EEPROM length (bytes) = "); Serial.println(EEPROM.length());
+ Serial.print("Emulated EEPROM length (bytes) = ");
+ Serial.println(EEPROM.length());
unsigned long startMillis = millis();
-
- for (int i = 0 ; i < EEPROM.length() ; i++)
+
+ for (int i = 0 ; i < EEPROM.length() ; i++)
{
EEPROM.write(i, 0);
}
@@ -42,13 +45,14 @@ void setup()
// The time spent can be very short (4-5ms) if the EEPROM is not dirty.
// For F767ZI, the time is around 1.1s for 16384 bytes of emulated-EEPROM
- Serial.print("Done clearing emulated EEPROM. Time spent (ms) = "); Serial.println(millis() - startMillis);
+ Serial.print("Done clearing emulated EEPROM. Time spent (ms) = ");
+ Serial.println(millis() - startMillis);
// turn the LED on when we're done
digitalWrite(LED_BUILTIN, HIGH);
}
-void loop()
+void loop()
{
/** Empty loop. **/
}
diff --git a/examples/EEPROM_get/EEPROM_get.ino b/examples/EEPROM_get/EEPROM_get.ino
index de5e12a..2109a48 100644
--- a/examples/EEPROM_get/EEPROM_get.ino
+++ b/examples/EEPROM_get/EEPROM_get.ino
@@ -52,11 +52,13 @@ void secondTest()
void setup()
{
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print(F("\nStart EEPROM_get on ")); Serial.println(BOARD_NAME);
+ Serial.print(F("\nStart EEPROM_get on "));
+ Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
Serial.print("EEPROM length: ");
diff --git a/examples/EEPROM_iteration/EEPROM_iteration.ino b/examples/EEPROM_iteration/EEPROM_iteration.ino
index f1800ed..88c48d5 100644
--- a/examples/EEPROM_iteration/EEPROM_iteration.ino
+++ b/examples/EEPROM_iteration/EEPROM_iteration.ino
@@ -28,11 +28,13 @@
void setup()
{
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print(F("\nStart EEPROM_iteration on ")); Serial.println(BOARD_NAME);
+ Serial.print(F("\nStart EEPROM_iteration on "));
+ Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
Serial.print("EEPROM length: ");
@@ -42,7 +44,7 @@ void setup()
Iterate the EEPROM using a for loop.
***/
- for (int index = 0 ; index < EEPROM.length() ; index++)
+ for (int index = 0 ; index < EEPROM.length() ; index++)
{
// Add one to each cell in the EEPROM
EEPROM.write(index, EEPROM.read(index) + 1);
@@ -58,7 +60,7 @@ void setup()
int index = 0;
- while (index < EEPROM.length())
+ while (index < EEPROM.length())
{
//Add one to each cell in the EEPROM
// Add one to each cell in the EEPROM
@@ -86,7 +88,7 @@ void setup()
EEPROM.commit();
Serial.println("Done do-while loop");
-
+
} //End of setup function.
void loop() {}
diff --git a/examples/EEPROM_put/EEPROM_put.ino b/examples/EEPROM_put/EEPROM_put.ino
index 58d150a..eaf3384 100644
--- a/examples/EEPROM_put/EEPROM_put.ino
+++ b/examples/EEPROM_put/EEPROM_put.ino
@@ -37,11 +37,13 @@ struct MyObject
void setup()
{
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print(F("\nStart EEPROM_put on ")); Serial.println(BOARD_NAME);
+ Serial.print(F("\nStart EEPROM_put on "));
+ Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
Serial.print("EEPROM length: ");
diff --git a/examples/EEPROM_read/EEPROM_read.ino b/examples/EEPROM_read/EEPROM_read.ino
index 2d9a2a8..b7f1b0c 100644
--- a/examples/EEPROM_read/EEPROM_read.ino
+++ b/examples/EEPROM_read/EEPROM_read.ino
@@ -28,18 +28,20 @@ byte value;
void setup()
{
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print(F("\nStart EEPROM_read on ")); Serial.println(BOARD_NAME);
+ Serial.print(F("\nStart EEPROM_read on "));
+ Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
Serial.print("EEPROM length: ");
Serial.println(EEPROM.length());
}
-void loop()
+void loop()
{
// read a byte from the current address of the EEPROM
value = EEPROM.read(address);
@@ -48,8 +50,8 @@ void loop()
Serial.print("\t");
Serial.print(value, DEC);
Serial.println();
-
- if (++address == EEPROM.length())
+
+ if (++address == EEPROM.length())
{
address = 0;
}
diff --git a/examples/EEPROM_update/EEPROM_update.ino b/examples/EEPROM_update/EEPROM_update.ino
index 167d565..bf4e03b 100644
--- a/examples/EEPROM_update/EEPROM_update.ino
+++ b/examples/EEPROM_update/EEPROM_update.ino
@@ -33,11 +33,13 @@ int address = 0;
void setup()
{
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print(F("\nStart EEPROM_update on ")); Serial.println(BOARD_NAME);
+ Serial.print(F("\nStart EEPROM_update on "));
+ Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
Serial.print("EEPROM length: ");
@@ -63,7 +65,8 @@ void loop()
EEPROM.commit();
- Serial.print("Done updating emulated EEPROM. Time spent (ms) = "); Serial.println(millis() - startMillis);
+ Serial.print("Done updating emulated EEPROM. Time spent (ms) = ");
+ Serial.println(millis() - startMillis);
delay(60000);
}
diff --git a/examples/EEPROM_write/EEPROM_write.ino b/examples/EEPROM_write/EEPROM_write.ino
index 73feff9..10c8a42 100644
--- a/examples/EEPROM_write/EEPROM_write.ino
+++ b/examples/EEPROM_write/EEPROM_write.ino
@@ -14,7 +14,7 @@
/*
EEPROM Write
- Stores values read from analog input 0 into the EEPROM. These values will stay in the EEPROM
+ Stores values read from analog input 0 into the EEPROM. These values will stay in the EEPROM
when the board is turned off and may be retrieved later by another sketch.
*/
@@ -27,11 +27,13 @@ int address = 0;
void setup()
{
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print(F("\nStart EEPROM_write on ")); Serial.println(BOARD_NAME);
+ Serial.print(F("\nStart EEPROM_write on "));
+ Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
Serial.print("EEPROM length: ");
@@ -41,12 +43,12 @@ void setup()
void loop()
{
unsigned long startMillis = millis();
-
- for (int i = 0 ; i < EEPROM.length() ; i++)
+
+ for (int i = 0 ; i < EEPROM.length() ; i++)
{
/***
The function EEPROM.update(address, val) is equivalent to the following:
-
+
if( EEPROM.read(address) != val )
{
EEPROM.write(address, val);
@@ -54,10 +56,11 @@ void loop()
***/
EEPROM.write(i, (uint8_t) analogRead(0));
}
-
+
EEPROM.commit();
- Serial.print("Done writing emulated EEPROM. Time spent (ms) = "); Serial.println(millis() - startMillis);
+ Serial.print("Done writing emulated EEPROM. Time spent (ms) = ");
+ Serial.println(millis() - startMillis);
delay(60000);
}
diff --git a/examples/EmulateEEPROM/EmulateEEPROM.ino b/examples/EmulateEEPROM/EmulateEEPROM.ino
index b98e9f3..d2176cc 100644
--- a/examples/EmulateEEPROM/EmulateEEPROM.ino
+++ b/examples/EmulateEEPROM/EmulateEEPROM.ino
@@ -22,11 +22,13 @@ const int WRITTEN_SIGNATURE = 0xBEEFDEED;
void setup()
{
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print(F("\nStart EmulatedEEPROM on ")); Serial.println(BOARD_NAME);
+ Serial.print(F("\nStart EmulatedEEPROM on "));
+ Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
Serial.print("EEPROM length: ");
@@ -67,7 +69,8 @@ void setup()
{
EEPROM.get(0, signature);
- Serial.print("EEPROM has been written.Signature = 0x"); Serial.println(signature, HEX);
+ Serial.print("EEPROM has been written.Signature = 0x");
+ Serial.println(signature, HEX);
Serial.println("Here is the content of the next 16 bytes:");
diff --git a/examples/FlashStoreAndRetrieve/FlashStoreAndRetrieve.ino b/examples/FlashStoreAndRetrieve/FlashStoreAndRetrieve.ino
index 9b85889..947f438 100644
--- a/examples/FlashStoreAndRetrieve/FlashStoreAndRetrieve.ino
+++ b/examples/FlashStoreAndRetrieve/FlashStoreAndRetrieve.ino
@@ -18,11 +18,13 @@
void setup()
{
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print(F("\nStart FlashStoreAndRetrieve on ")); Serial.println(BOARD_NAME);
+ Serial.print(F("\nStart FlashStoreAndRetrieve on "));
+ Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
Serial.print("EEPROM length: ");
@@ -35,7 +37,8 @@ void setup()
EEPROM.get(address, number);
// Print the current number on the serial monitor
- Serial.print("Number = 0x"); Serial.println(number, HEX);
+ Serial.print("Number = 0x");
+ Serial.println(number, HEX);
// Save into emulated-EEPROM the number increased by 1 for the next run of the sketch
EEPROM.put(address, (int) (number + 1));
diff --git a/examples/StoreNameAndSurname/StoreNameAndSurname.ino b/examples/StoreNameAndSurname/StoreNameAndSurname.ino
index b7594ac..4cc0441 100644
--- a/examples/StoreNameAndSurname/StoreNameAndSurname.ino
+++ b/examples/StoreNameAndSurname/StoreNameAndSurname.ino
@@ -31,11 +31,13 @@ typedef struct
void setup()
{
Serial.begin(115200);
+
while (!Serial);
delay(200);
- Serial.print(F("\nStart StoreNameAndSurname on ")); Serial.println(BOARD_NAME);
+ Serial.print(F("\nStart StoreNameAndSurname on "));
+ Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
Serial.print("EEPROM length: ");
@@ -56,7 +58,10 @@ void setup()
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.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");
@@ -87,8 +92,10 @@ void setup()
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.print("<< Your name: ");
+ Serial.print(owner.name);
+ Serial.print(". Your surname: ");
+ Serial.print(owner.surname);
Serial.println(" >> have been saved. Thank you!");
}
}
diff --git a/examples/multiFileProject/multiFileProject.cpp b/examples/multiFileProject/multiFileProject.cpp
index 0dc4549..1e613b1 100644
--- a/examples/multiFileProject/multiFileProject.cpp
+++ b/examples/multiFileProject/multiFileProject.cpp
@@ -1,6 +1,6 @@
/****************************************************************************************************************************
multiFileProject.cpp
-
+
For STM32 using Flash emulated-EEPROM
The FlashStorage_STM32 library aims to provide a convenient way to store and retrieve user's data using the non-volatile flash memory
@@ -36,7 +36,10 @@ void testEEPROM()
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.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");
@@ -73,8 +76,10 @@ void testEEPROM()
}
// Print a confirmation of the data inserted.
- Serial.print("<< Your name: "); Serial.print(owner.name);
- Serial.print(". Your surname: "); Serial.print(owner.surname);
+ Serial.print("<< Your name: ");
+ Serial.print(owner.name);
+ Serial.print(". Your surname: ");
+ Serial.print(owner.surname);
Serial.println(" >> have been saved. Thank you!");
Serial.println("You can reset to check emulated-EEPROM data retention.");
}
diff --git a/examples/multiFileProject/multiFileProject.h b/examples/multiFileProject/multiFileProject.h
index 53c9f35..43ab003 100644
--- a/examples/multiFileProject/multiFileProject.h
+++ b/examples/multiFileProject/multiFileProject.h
@@ -1,6 +1,6 @@
/****************************************************************************************************************************
multiFileProject.h
-
+
For STM32 using Flash emulated-EEPROM
The FlashStorage_STM32 library aims to provide a convenient way to store and retrieve user's data using the non-volatile flash memory
diff --git a/examples/multiFileProject/multiFileProject.ino b/examples/multiFileProject/multiFileProject.ino
index 9221789..98ac23c 100644
--- a/examples/multiFileProject/multiFileProject.ino
+++ b/examples/multiFileProject/multiFileProject.ino
@@ -1,6 +1,6 @@
/****************************************************************************************************************************
multiFileProject.ino
-
+
For STM32 using Flash emulated-EEPROM
The FlashStorage_STM32 library aims to provide a convenient way to store and retrieve user's data using the non-volatile flash memory
@@ -20,7 +20,7 @@
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) || defined(STM32L5) )
- #error This code is intended to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
+#error This code is intended to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
#endif
#define FLASH_STORAGE_STM32_VERSION_MIN_TARGET "FlashStorage_STM32 v1.2.0"
@@ -31,26 +31,29 @@
#include "multiFileProject.h"
-void setup()
+void setup()
{
Serial.begin(115200);
+
while (!Serial);
-
+
Serial.println("\nStart multiFileProject");
Serial.println(FLASH_STORAGE_STM32_VERSION);
#if defined(FLASH_STORAGE_STM32_VERSION_MIN)
+
if (FLASH_STORAGE_STM32_VERSION_INT < FLASH_STORAGE_STM32_VERSION_MIN)
{
Serial.print("Warning. Must use this example on Version equal or later than : ");
Serial.println(FLASH_STORAGE_STM32_VERSION_MIN_TARGET);
}
+
#endif
testEEPROM();
}
-void loop()
+void loop()
{
// put your main code here, to run repeatedly:
}
diff --git a/platformio/platformio.ini b/platformio/platformio.ini
index dc71973..ed4e7c7 100644
--- a/platformio/platformio.ini
+++ b/platformio/platformio.ini
@@ -28,6 +28,8 @@ upload_speed = 921600
; Checks for the compatibility with frameworks and dev/platforms
lib_compat_mode = strict
+lib_ldf_mode = chain+
+;lib_ldf_mode = deep+
lib_deps =
; PlatformIO 4.x
diff --git a/src/FlashStorage_STM32.h b/src/FlashStorage_STM32.h
index 206cda9..b9b0482 100644
--- a/src/FlashStorage_STM32.h
+++ b/src/FlashStorage_STM32.h
@@ -31,7 +31,7 @@
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) || defined(STM32L5) )
- #error This code is intended to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
+#error This code is intended to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
#endif
#include "FlashStorage_STM32.hpp"
diff --git a/src/utility/stm32_eeprom_Impl.h b/src/utility/stm32_eeprom_Impl.h
index c9ab63f..abf3ffb 100644
--- a/src/utility/stm32_eeprom_Impl.h
+++ b/src/utility/stm32_eeprom_Impl.h
@@ -21,37 +21,37 @@
******************************************************************************************************************************************/
/**
******************************************************************************
- * @file stm32_eeprom.c
- * @brief Provides emulated eeprom from flash
+ @file stm32_eeprom.c
+ @brief Provides emulated eeprom from flash
******************************************************************************
- * @attention
- *
- * © COPYRIGHT(c) 2016 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
+ @attention
+
+ © COPYRIGHT(c) 2016 STMicroelectronics
+
+ Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of STMicroelectronics nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
******************************************************************************
- */
+*/
// The .hpp contains only definitions, and can be included as many times as necessary, without `Multiple Definitions` Linker Error
// The .h contains implementations, and can be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
@@ -69,130 +69,137 @@ extern "C" {
/* Be able to change FLASH_BANK_NUMBER to use if relevant */
#if !defined(FLASH_BANK_NUMBER) && \
(defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32G4xx) || defined(STM32H7xx) || defined(STM32L4xx) || defined(STM32L5xx))
-
- /* For STM32F0xx, FLASH_BANK_1 is not defined only FLASH_BANK1_END is defined */
- #if defined(STM32F0xx)
- #define FLASH_BANK_1 1U
- #endif
-
- #if defined(FLASH_BANK_2)
- #define FLASH_BANK_NUMBER FLASH_BANK_2
- #else
- #define FLASH_BANK_NUMBER FLASH_BANK_1
- #endif /* FLASH_BANK_2 */
-
- #ifndef FLASH_BANK_NUMBER
- #error "FLASH_BANK_NUMBER could not be defined"
- #endif
+
+/* For STM32F0xx, FLASH_BANK_1 is not defined only FLASH_BANK1_END is defined */
+#if defined(STM32F0xx)
+#define FLASH_BANK_1 1U
+#endif
+
+#if defined(FLASH_BANK_2)
+#define FLASH_BANK_NUMBER FLASH_BANK_2
+#else
+#define FLASH_BANK_NUMBER FLASH_BANK_1
+#endif /* FLASH_BANK_2 */
+
+#ifndef FLASH_BANK_NUMBER
+#error "FLASH_BANK_NUMBER could not be defined"
+#endif
#endif /* !FLASH_BANK_NUMBER */
/* Be able to change FLASH_DATA_SECTOR to use if relevant */
#if ( defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32F7xx) || defined(STM32H7xx) )
- #if !defined(FLASH_DATA_SECTOR)
- #define FLASH_DATA_SECTOR ((uint32_t)(FLASH_SECTOR_TOTAL - 1))
- #else
- #ifndef FLASH_BASE_ADDRESS
- #error "FLASH_BASE_ADDRESS have to be defined when FLASH_DATA_SECTOR is defined"
- #endif
- #endif /* !FLASH_DATA_SECTOR */
+#if !defined(FLASH_DATA_SECTOR)
+#define FLASH_DATA_SECTOR ((uint32_t)(FLASH_SECTOR_TOTAL - 1))
+#else
+#ifndef FLASH_BASE_ADDRESS
+#error "FLASH_BASE_ADDRESS have to be defined when FLASH_DATA_SECTOR is defined"
+#endif
+#endif /* !FLASH_DATA_SECTOR */
#endif /* STM32F2xx || STM32F4xx || STM32F7xx */
/* Be able to change FLASH_PAGE_NUMBER to use if relevant */
#if !defined(FLASH_PAGE_NUMBER) &&\
(defined (STM32G0xx) || defined(STM32G4xx) || defined (STM32L4xx) || defined (STM32L5xx) || defined(STM32WBxx))
- #define FLASH_PAGE_NUMBER ((uint32_t)((FLASH_SIZE / FLASH_PAGE_SIZE) - 1))
+#define FLASH_PAGE_NUMBER ((uint32_t)((FLASH_SIZE / FLASH_PAGE_SIZE) - 1))
#endif /* !FLASH_PAGE_NUMBER */
/* Be able to change FLASH_END to use */
#if !defined(FLASH_END)
- #if defined (STM32F0xx) || defined (STM32F1xx)
- #if defined (FLASH_BANK2_END) && (FLASH_BANK_NUMBER == FLASH_BANK_2)
- #define FLASH_END FLASH_BANK2_END
- #elif defined (FLASH_BANK1_END) && (FLASH_BANK_NUMBER == FLASH_BANK_1)
- #define FLASH_END FLASH_BANK1_END
- #endif
- #elif defined (STM32F3xx)
- static inline uint32_t get_flash_end()
- {
- uint32_t size;
- switch ((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)))
- {
- case 0x200U:
- size = 0x0807FFFFU;
- break;
- case 0x100U:
- size = 0x0803FFFFU;
- break;
- case 0x80U:
- size = 0x0801FFFFU;
- break;
- case 0x40U:
- size = 0x0800FFFFU;
- break;
- case 0x20U:
- size = 0x08007FFFU;
- break;
- default:
- size = 0x08003FFFU;
- break;
- }
- return size;
- }
-
- #define FLASH_END get_flash_end()
-
- #elif defined(STM32G0xx) || defined(STM32G4xx) || defined (STM32L4xx) || defined (STM32L5xx) || defined(STM32WBxx)
- /* If FLASH_PAGE_NUMBER is defined by user, this is not really end of the flash */
- #define FLASH_END ((uint32_t)(FLASH_BASE + (((FLASH_PAGE_NUMBER +1) * FLASH_PAGE_SIZE))-1))
- #elif defined(EEPROM_RETRAM_MODE)
- #define FLASH_END ((uint32_t)(EEPROM_RETRAM_START_ADDRESS + EEPROM_RETRAM_MODE_SIZE -1))
- #elif defined(DATA_EEPROM_END)
- #define FLASH_END DATA_EEPROM_END
- #endif
-
- #ifndef FLASH_END
- #error "FLASH_END could not be defined"
- #endif
+#if defined (STM32F0xx) || defined (STM32F1xx)
+#if defined (FLASH_BANK2_END) && (FLASH_BANK_NUMBER == FLASH_BANK_2)
+#define FLASH_END FLASH_BANK2_END
+#elif defined (FLASH_BANK1_END) && (FLASH_BANK_NUMBER == FLASH_BANK_1)
+#define FLASH_END FLASH_BANK1_END
+#endif
+#elif defined (STM32F3xx)
+static inline uint32_t get_flash_end()
+{
+ uint32_t size;
+
+ switch ((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)))
+ {
+ case 0x200U:
+ size = 0x0807FFFFU;
+ break;
+
+ case 0x100U:
+ size = 0x0803FFFFU;
+ break;
+
+ case 0x80U:
+ size = 0x0801FFFFU;
+ break;
+
+ case 0x40U:
+ size = 0x0800FFFFU;
+ break;
+
+ case 0x20U:
+ size = 0x08007FFFU;
+ break;
+
+ default:
+ size = 0x08003FFFU;
+ break;
+ }
+
+ return size;
+}
+
+#define FLASH_END get_flash_end()
+
+#elif defined(STM32G0xx) || defined(STM32G4xx) || defined (STM32L4xx) || defined (STM32L5xx) || defined(STM32WBxx)
+/* If FLASH_PAGE_NUMBER is defined by user, this is not really end of the flash */
+#define FLASH_END ((uint32_t)(FLASH_BASE + (((FLASH_PAGE_NUMBER +1) * FLASH_PAGE_SIZE))-1))
+#elif defined(EEPROM_RETRAM_MODE)
+#define FLASH_END ((uint32_t)(EEPROM_RETRAM_START_ADDRESS + EEPROM_RETRAM_MODE_SIZE -1))
+#elif defined(DATA_EEPROM_END)
+#define FLASH_END DATA_EEPROM_END
+#endif
+
+#ifndef FLASH_END
+#error "FLASH_END could not be defined"
+#endif
#endif /* FLASH_END */
/* Be able to change FLASH_BASE_ADDRESS to use */
#ifndef FLASH_BASE_ADDRESS
- /*
- * By default, Use the last page of the flash to store data
- * in order to prevent overwritting
- * program data
- */
- #if defined(EEPROM_RETRAM_MODE)
- #define FLASH_BASE_ADDRESS EEPROM_RETRAM_START_ADDRESS
- #else
- #define FLASH_BASE_ADDRESS ((uint32_t)((FLASH_END + 1) - FLASH_PAGE_SIZE))
- #endif
-
- #ifndef FLASH_BASE_ADDRESS
- #error "FLASH_BASE_ADDRESS could not be defined"
- #endif
+/*
+ By default, Use the last page of the flash to store data
+ in order to prevent overwritting
+ program data
+*/
+#if defined(EEPROM_RETRAM_MODE)
+#define FLASH_BASE_ADDRESS EEPROM_RETRAM_START_ADDRESS
+#else
+#define FLASH_BASE_ADDRESS ((uint32_t)((FLASH_END + 1) - FLASH_PAGE_SIZE))
+#endif
+
+#ifndef FLASH_BASE_ADDRESS
+#error "FLASH_BASE_ADDRESS could not be defined"
+#endif
#endif /* FLASH_BASE_ADDRESS */
#if !defined(DATA_EEPROM_BASE)
- static uint8_t eeprom_buffer[E2END + 1] __attribute__((aligned(8))) = {0};
+static uint8_t eeprom_buffer[E2END + 1] __attribute__((aligned(8))) = {0};
#endif
/**
- * @brief Function reads a byte from emulated eeprom (flash)
- * @param pos : address to read
- * @retval byte : data read from eeprom
- */
+ @brief Function reads a byte from emulated eeprom (flash)
+ @param pos : address to read
+ @retval byte : data read from eeprom
+*/
uint8_t eeprom_read_byte(const uint32_t& pos)
{
#if defined(DATA_EEPROM_BASE)
__IO uint8_t data = 0;
-
- if (pos <= (DATA_EEPROM_END - DATA_EEPROM_BASE))
+
+ if (pos <= (DATA_EEPROM_END - DATA_EEPROM_BASE))
{
/* with actual EEPROM, pos is a relative address */
data = *(__IO uint8_t *)(DATA_EEPROM_BASE + pos);
}
-
+
return (uint8_t)data;
#else
eeprom_buffer_fill();
@@ -201,61 +208,61 @@ uint8_t eeprom_read_byte(const uint32_t& pos)
}
/**
- * @brief Function writes a byte to emulated eeprom (flash)
- * @param pos : address to write
- * @param value : value to write
- * @retval none
- */
+ @brief Function writes a byte to emulated eeprom (flash)
+ @param pos : address to write
+ @param value : value to write
+ @retval none
+*/
void eeprom_write_byte(const uint32_t& pos, const uint8_t& value)
{
#if defined(DATA_EEPROM_BASE)
/* with actual EEPROM, pos is a relative address */
- if (pos <= (DATA_EEPROM_END - DATA_EEPROM_BASE))
+ if (pos <= (DATA_EEPROM_END - DATA_EEPROM_BASE))
{
- if (HAL_FLASHEx_DATAEEPROM_Unlock() == HAL_OK)
+ if (HAL_FLASHEx_DATAEEPROM_Unlock() == HAL_OK)
{
HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE, (pos + DATA_EEPROM_BASE), (uint32_t)value);
HAL_FLASHEx_DATAEEPROM_Lock();
}
}
-
+
#else
eeprom_buffered_write_byte(pos, value);
eeprom_buffer_flush();
-
+
#endif /* _EEPROM_BASE */
}
#if !defined(DATA_EEPROM_BASE)
/**
- * @brief Function reads a byte from the eeprom buffer
- * @param pos : address to read
- * @retval byte : data read from eeprom
- */
+ @brief Function reads a byte from the eeprom buffer
+ @param pos : address to read
+ @retval byte : data read from eeprom
+*/
uint8_t eeprom_buffered_read_byte(const uint32_t& pos)
{
return eeprom_buffer[pos];
}
/**
- * @brief Function writes a byte to the eeprom buffer
- * @param pos : address to write
- * @param value : value to write
- * @retval none
- */
+ @brief Function writes a byte to the eeprom buffer
+ @param pos : address to write
+ @param value : value to write
+ @retval none
+*/
void eeprom_buffered_write_byte(const uint32_t& pos, const uint8_t& value)
{
eeprom_buffer[pos] = value;
}
/**
- * @brief This function copies the data from flash into the buffer
- * @param none
- * @retval none
- */
+ @brief This function copies the data from flash into the buffer
+ @param none
+ @retval none
+*/
void eeprom_buffer_fill()
{
memcpy(eeprom_buffer, (uint8_t *)(FLASH_BASE_ADDRESS), E2END + 1);
@@ -263,139 +270,140 @@ void eeprom_buffer_fill()
#if defined(EEPROM_RETRAM_MODE)
- /**
- * @brief This function writes the buffer content into the flash
- * @param none
- * @retval none
- */
- void eeprom_buffer_flush()
- {
- memcpy((uint8_t *)(FLASH_BASE_ADDRESS), eeprom_buffer, E2END + 1);
- }
+/**
+ @brief This function writes the buffer content into the flash
+ @param none
+ @retval none
+*/
+void eeprom_buffer_flush()
+{
+ memcpy((uint8_t *)(FLASH_BASE_ADDRESS), eeprom_buffer, E2END + 1);
+}
#else /* defined(EEPROM_RETRAM_MODE) */
- /**
- * @brief This function writes the buffer content into the flash
- * @param none
- * @retval none
- */
- void eeprom_buffer_flush()
- {
- FLASH_EraseInitTypeDef EraseInitStruct;
- uint32_t offset = 0;
- uint32_t address = FLASH_BASE_ADDRESS;
- uint32_t address_end = FLASH_BASE_ADDRESS + E2END;
-
- #if defined (STM32F0xx) || defined (STM32F1xx) || defined (STM32F3xx) || defined (STM32G0xx) || \
+/**
+ @brief This function writes the buffer content into the flash
+ @param none
+ @retval none
+*/
+void eeprom_buffer_flush()
+{
+ FLASH_EraseInitTypeDef EraseInitStruct;
+ uint32_t offset = 0;
+ uint32_t address = FLASH_BASE_ADDRESS;
+ uint32_t address_end = FLASH_BASE_ADDRESS + E2END;
+
+#if defined (STM32F0xx) || defined (STM32F1xx) || defined (STM32F3xx) || defined (STM32G0xx) || \
defined (STM32G4xx) || defined (STM32L4xx) || defined (STM32L5xx) || defined (STM32WBxx)
-
- uint32_t pageError = 0;
- uint64_t data = 0;
-
- /* ERASING page */
- EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
-
- #if defined (STM32F1xx) || defined (STM32G4xx) || defined (STM32L4xx) || defined (STM32L5xx)
- EraseInitStruct.Banks = FLASH_BANK_NUMBER;
- #endif
-
- #if defined (STM32G0xx) || defined (STM32G4xx) || defined (STM32L4xx) || defined (STM32L5xx) || defined (STM32WBxx)
-
- EraseInitStruct.Page = FLASH_PAGE_NUMBER;
-
- #else
-
- EraseInitStruct.PageAddress = FLASH_BASE_ADDRESS;
-
- #endif
-
- EraseInitStruct.NbPages = 1;
-
- if (HAL_FLASH_Unlock() == HAL_OK)
+
+ uint32_t pageError = 0;
+ uint64_t data = 0;
+
+ /* ERASING page */
+ EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
+
+#if defined (STM32F1xx) || defined (STM32G4xx) || defined (STM32L4xx) || defined (STM32L5xx)
+ EraseInitStruct.Banks = FLASH_BANK_NUMBER;
+#endif
+
+#if defined (STM32G0xx) || defined (STM32G4xx) || defined (STM32L4xx) || defined (STM32L5xx) || defined (STM32WBxx)
+
+ EraseInitStruct.Page = FLASH_PAGE_NUMBER;
+
+#else
+
+ EraseInitStruct.PageAddress = FLASH_BASE_ADDRESS;
+
+#endif
+
+ EraseInitStruct.NbPages = 1;
+
+ if (HAL_FLASH_Unlock() == HAL_OK)
+ {
+#if defined (STM32G0xx) || defined (STM32G4xx) || defined (STM32L4xx) || defined (STM32L5xx) || defined (STM32WBxx)
+ __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
+#else
+ __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
+#endif
+
+ if (HAL_FLASHEx_Erase(&EraseInitStruct, &pageError) == HAL_OK)
{
- #if defined (STM32G0xx) || defined (STM32G4xx) || defined (STM32L4xx) || defined (STM32L5xx) || defined (STM32WBxx)
- __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
- #else
- __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
- #endif
-
- if (HAL_FLASHEx_Erase(&EraseInitStruct, &pageError) == HAL_OK)
+ while (address <= address_end)
{
- while (address <= address_end)
+ data = *((uint64_t *)((uint8_t *)eeprom_buffer + offset));
+
+ if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, data) == HAL_OK)
{
- data = *((uint64_t *)((uint8_t *)eeprom_buffer + offset));
-
- if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, data) == HAL_OK)
- {
- address += 8;
- offset += 8;
- }
- else
- {
- address = address_end + 1;
- }
+ address += 8;
+ offset += 8;
}
- }
-
- HAL_FLASH_Lock();
- }
- #else
-
- uint32_t SectorError = 0;
-
- #if defined(STM32H7xx)
- uint64_t data[4] = {0x0000};
- #else
- uint32_t data = 0;
- #endif
-
- /* ERASING page */
- EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
-
- #if defined(STM32H7xx)
- EraseInitStruct.Banks = FLASH_BANK_NUMBER;
- #endif
-
- EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
- EraseInitStruct.Sector = FLASH_DATA_SECTOR;
- EraseInitStruct.NbSectors = 1;
-
- HAL_FLASH_Unlock();
-
- if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) == HAL_OK)
- {
- while (address <= address_end)
- {
- #if defined(STM32H7xx)
- /* 256 bits */
- memcpy(&data, eeprom_buffer + offset, 8 * sizeof(uint32_t));
-
- if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, address, (uint32_t)data) == HAL_OK)
- {
- address += 32;
- offset += 32;
- #else
- memcpy(&data, eeprom_buffer + offset, sizeof(uint32_t));
-
- if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data) == HAL_OK)
- {
- address += 4;
- offset += 4;
- #endif
- }
- else
+ else
{
address = address_end + 1;
}
}
}
-
+
HAL_FLASH_Lock();
-
- #endif
}
+#else
+
+ uint32_t SectorError = 0;
+
+#if defined(STM32H7xx)
+ uint64_t data[4] = {0x0000};
+#else
+ uint32_t data = 0;
+#endif
+
+ /* ERASING page */
+ EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
+
+#if defined(STM32H7xx)
+ EraseInitStruct.Banks = FLASH_BANK_NUMBER;
+#endif
+
+ EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
+ EraseInitStruct.Sector = FLASH_DATA_SECTOR;
+ EraseInitStruct.NbSectors = 1;
+
+ HAL_FLASH_Unlock();
+
+ if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) == HAL_OK)
+ {
+ while (address <= address_end)
+ {
+#if defined(STM32H7xx)
+ /* 256 bits */
+ memcpy(&data, eeprom_buffer + offset, 8 * sizeof(uint32_t));
+
+ if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, address, (uint32_t)data) == HAL_OK)
+ {
+ address += 32;
+ offset += 32;
+#else
+ memcpy(&data, eeprom_buffer + offset, sizeof(uint32_t));
+
+ if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data) == HAL_OK)
+ {
+ address += 4;
+ offset += 4;
+#endif
+ }
+ else
+ {
+ address = address_end + 1;
+ }
+ }
+ }
+
+ HAL_FLASH_Lock();
+
+#endif
+}
+
#endif /* defined(EEPROM_RETRAM_MODE) */
#endif /* ! DATA_EEPROM_BASE */
diff --git a/utils/astyle_library.conf b/utils/astyle_library.conf
new file mode 100644
index 0000000..8a73bc2
--- /dev/null
+++ b/utils/astyle_library.conf
@@ -0,0 +1,70 @@
+# Code formatting rules for Arduino libraries, modified from for KH libraries:
+#
+# https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf
+#
+
+# astyle --style=allman -s2 -t2 -C -S -xW -Y -M120 -f -p -xg -H -xb -c --xC120 -xL *.h *.cpp *.ino
+
+--mode=c
+--lineend=linux
+--style=allman
+
+# -r or -R
+#--recursive
+
+# -c => Converts tabs into spaces
+convert-tabs
+
+# -s2 => 2 spaces indentation
+--indent=spaces=2
+
+# -t2 => tab =2 spaces
+#--indent=tab=2
+
+# -C
+--indent-classes
+
+# -S
+--indent-switches
+
+# -xW
+--indent-preproc-block
+
+# -Y => indent classes, switches (and cases), comments starting at column 1
+--indent-col1-comments
+
+# -M120 => maximum of 120 spaces to indent a continuation line
+--max-continuation-indent=120
+
+# -xC120 => max‑code‑length will break a line if the code exceeds # characters
+--max-code-length=120
+
+# -f =>
+--break-blocks
+
+# -p => put a space around operators
+--pad-oper
+
+# -xg => Insert space padding after commas
+--pad-comma
+
+# -H => put a space after if/for/while
+pad-header
+
+# -xb => Break one line headers (e.g. if/for/while)
+--break-one-line-headers
+
+# -c => Converts tabs into spaces
+#--convert-tabs
+
+# if you like one-liners, keep them
+#keep-one-line-statements
+
+# -xV
+--attach-closing-while
+
+#unpad-paren
+
+# -xp
+remove-comment-prefix
+
diff --git a/utils/restyle.sh b/utils/restyle.sh
new file mode 100644
index 0000000..bcd846f
--- /dev/null
+++ b/utils/restyle.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+for dir in . ; do
+ find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.ino" \) -exec astyle --suffix=none --options=./utils/astyle_library.conf \{\} \;
+done
+