Skip to content

Commit dbf87f9

Browse files
authored
BufferedEEPROM build on MCU with EEPROM
Allows to build for CI and warn user.
1 parent f33d7a3 commit dbf87f9

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
1+
#if defined(DATA_EEPROM_BASE)
2+
#warning "STM32 devices have an integrated EEPROM. No buffered API available."
3+
4+
void setup() {
5+
}
6+
7+
void loop() {
8+
}
9+
10+
#else
111
#include <EEPROM.h>
212

313
/**
4-
* Most STM32 devices don't have an integrated EEPROM.
5-
* To emulate a EEPROM, the STM32 Arduino core emulated
6-
* the operation of an EEPROM with the help of the embedded
7-
* flash.
8-
*
9-
* Writing to a flash is very expensive operation, since a
10-
* whole flash page needs to be written, even if you only
11-
* want to access the flash byte-wise.
12-
*
13-
* The STM32 Arduino core provides a buffered access API
14-
* to the emulated EEPROM. The library has allocated the
15-
* buffer even if you don't use the buffered API, so
16-
* it's strongly suggested to use the buffered API anyhow.
17-
*/
14+
Most STM32 devices don't have an integrated EEPROM.
15+
To emulate a EEPROM, the STM32 Arduino core emulated
16+
the operation of an EEPROM with the help of the embedded
17+
flash.
1818
19-
#if defined(DATA_EEPROM_BASE)
20-
#error "STM32 devices have an integrated EEPROM. No buffered API available."
21-
#endif
19+
Writing to a flash is very expensive operation, since a
20+
whole flash page needs to be written, even if you only
21+
want to access the flash byte-wise.
22+
23+
The STM32 Arduino core provides a buffered access API
24+
to the emulated EEPROM. The library has allocated the
25+
buffer even if you don't use the buffered API, so
26+
it's strongly suggested to use the buffered API anyhow.
27+
*/
2228

2329
#define DATA_LENGTH E2END
2430

2531
void setup() {
26-
Serial.begin(115200);
32+
Serial.begin(115200);
2733
}
2834

2935
void loop() {
30-
// Fill the EEPROM buffer in memory with data
31-
for (uint16_t i = 0; i < DATA_LENGTH; i++) {
32-
eeprom_buffered_write_byte(i, i % 256);
33-
}
36+
// Fill the EEPROM buffer in memory with data
37+
for (uint16_t i = 0; i < DATA_LENGTH; i++) {
38+
eeprom_buffered_write_byte(i, i % 256);
39+
}
3440

35-
// Copy the data from the buffer to the flash
36-
eeprom_buffer_flush();
41+
// Copy the data from the buffer to the flash
42+
eeprom_buffer_flush();
3743

38-
// Clear the buffer for demonstration purpose
39-
for (uint16_t i = 0; i < DATA_LENGTH; i++) {
40-
eeprom_buffered_write_byte(i, 0);
41-
}
44+
// Clear the buffer for demonstration purpose
45+
for (uint16_t i = 0; i < DATA_LENGTH; i++) {
46+
eeprom_buffered_write_byte(i, 0);
47+
}
4248

43-
// Print the 254th byte of the current buffer (should be 0)
44-
Serial.println(eeprom_buffered_read_byte(254));
49+
// Print the 254th byte of the current buffer (should be 0)
50+
Serial.println(eeprom_buffered_read_byte(254));
4551

46-
// Copy the data from the flash to the buffer
47-
eeprom_buffer_fill();
52+
// Copy the data from the flash to the buffer
53+
eeprom_buffer_fill();
4854

49-
// Print the 254th byte of the current buffer (should be 254)
50-
Serial.println(eeprom_buffered_read_byte(254));
55+
// Print the 254th byte of the current buffer (should be 254)
56+
Serial.println(eeprom_buffered_read_byte(254));
5157
}
58+
#endif

0 commit comments

Comments
 (0)