|
| 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 |
1 | 11 | #include <EEPROM.h> |
2 | 12 |
|
3 | 13 | /** |
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. |
18 | 18 |
|
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 | +*/ |
22 | 28 |
|
23 | 29 | #define DATA_LENGTH E2END |
24 | 30 |
|
25 | 31 | void setup() { |
26 | | - Serial.begin(115200); |
| 32 | + Serial.begin(115200); |
27 | 33 | } |
28 | 34 |
|
29 | 35 | 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 | + } |
34 | 40 |
|
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(); |
37 | 43 |
|
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 | + } |
42 | 48 |
|
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)); |
45 | 51 |
|
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(); |
48 | 54 |
|
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)); |
51 | 57 | } |
| 58 | +#endif |
0 commit comments