This repository was archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEEPROM_write.ino
More file actions
88 lines (64 loc) · 3.11 KB
/
EEPROM_write.ino
File metadata and controls
88 lines (64 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/******************************************************************************************************************************************
EEPROM_write.ino
For STM32F1 using Flash emulated-EEPROM
The FlashStorage_STM32F1 library aims to provide a convenient way to store and retrieve user's data using the non-volatile flash memory
of STM32F1. It now supports writing and reading the whole object, not just byte-and-byte.
Based on and modified from Cristian Maglie's FlashStorage (https://github.com/cmaglie/FlashStorage)
Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_STM32F1
Licensed under LGPLv3 license
Orginally written by A. Christian
Copyright (c) 2015-2016 Arduino LLC. All right reserved.
Copyright (c) 2021 Khoi Hoang.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library.
If not, see (https://www.gnu.org/licenses/)
******************************************************************************************************************************************/
/*
EEPROM Write
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.
*/
// Use 0-2. Larger for more debugging messages
#define FLASH_DEBUG 2
// You can select another sector. Be careful not larger than (REGISTERED_NUMBER_FLASH_SECTORS - 1) and large enough not to overwrite your program
// Default is (REGISTERED_NUMBER_FLASH_SECTORS - 1) if you don't specify here
#define USING_FLASH_SECTOR_NUMBER (REGISTERED_NUMBER_FLASH_SECTORS - 2)
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include <FlashStorage_STM32F1.h>
// start reading from the first byte (address 0) of the EEPROM
int address = 0;
void setup()
{
Serial.begin(115200);
while (!Serial);
delay(200);
Serial.print(F("\nStart EEPROM_write on "));
Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32F1_VERSION);
Serial.print("EEPROM length: ");
Serial.println(EEPROM.length());
EEPROM.init();
}
void loop()
{
unsigned long startMillis = millis();
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);
}
***/
//Serial.print("Writing address = "); Serial.println(i);
EEPROM.write(i, (uint8_t) ( i + 1));
}
EEPROM.commit();
Serial.print("Done writing emulated EEPROM. Time spent (ms) = ");
Serial.println(millis() - startMillis);
delay(60000);
}