|
39 | 39 | extern "C" { |
40 | 40 | #endif |
41 | 41 |
|
42 | | -#ifndef EEPROM_RETRAM_MODE /* Buffering not needed in RETRAM mode */ |
43 | | - |
44 | | -static void eeprom_buffer_fill(); |
45 | | -static void eeprom_buffer_flush(); |
46 | | -static uint8_t eeprom_buffered_read_byte(const uint32_t pos); |
47 | | -static void eeprom_buffered_write_byte(uint32_t pos, uint8_t value); |
48 | | - |
49 | 42 | /* Be able to change FLASH_BANK_NUMBER to use if relevant */ |
50 | 43 | #if !defined(FLASH_BANK_NUMBER) &&\ |
51 | 44 | (defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32G4xx) ||\ |
@@ -137,6 +130,8 @@ static inline uint32_t get_flash_end(void) |
137 | 130 | */ |
138 | 131 | #if defined(STM32L0xx) |
139 | 132 | #define FLASH_BASE_ADDRESS ((uint32_t)(DATA_EEPROM_BASE)) |
| 133 | +#elif defined(EEPROM_RETRAM_MODE) |
| 134 | +#define FLASH_BASE_ADDRESS EEPROM_RETRAM_START_ADDRESS |
140 | 135 | #else |
141 | 136 | #define FLASH_BASE_ADDRESS ((uint32_t)((FLASH_END + 1) - FLASH_PAGE_SIZE)) |
142 | 137 | #endif |
@@ -201,6 +196,20 @@ void eeprom_buffer_fill(void) |
201 | 196 | memcpy(eeprom_buffer, (uint8_t *)(FLASH_BASE_ADDRESS), E2END + 1); |
202 | 197 | } |
203 | 198 |
|
| 199 | +#if defined(EEPROM_RETRAM_MODE) |
| 200 | + |
| 201 | +/** |
| 202 | + * @brief This function writes the buffer content into the flash |
| 203 | + * @param none |
| 204 | + * @retval none |
| 205 | + */ |
| 206 | +void eeprom_buffer_flush(void) |
| 207 | +{ |
| 208 | + memcpy((uint8_t *)(FLASH_BASE_ADDRESS), eeprom_buffer, E2END + 1); |
| 209 | +} |
| 210 | + |
| 211 | +#else /* defined(EEPROM_RETRAM_MODE) */ |
| 212 | + |
204 | 213 | /** |
205 | 214 | * @brief This function writes the buffer content into the flash |
206 | 215 | * @param none |
@@ -313,36 +322,7 @@ void eeprom_buffer_flush(void) |
313 | 322 | #endif |
314 | 323 | } |
315 | 324 |
|
316 | | -#else /* EEPROM_RETRAM_MODE */ |
317 | | -/** |
318 | | - * @brief Function reads a byte from emulated eeprom (flash) |
319 | | - * @param pos : address to read |
320 | | - * @retval byte : data read from eeprom |
321 | | - */ |
322 | | -uint8_t eeprom_read_byte(const uint32_t pos) |
323 | | -{ |
324 | | - uint8_t tmp; |
325 | | - if (pos > E2END) { |
326 | | - return 0; |
327 | | - } |
328 | | - memcpy(&tmp, (uint8_t *)(EEPROM_RETRAM_START_ADDRESS + pos), sizeof(uint8_t)); |
329 | | - return tmp; |
330 | | -} |
331 | | - |
332 | | -/** |
333 | | - * @brief Function writes a byte to emulated eeprom (flash) |
334 | | - * @param pos : address to write |
335 | | - * @param value : value to write |
336 | | - * @retval none |
337 | | - */ |
338 | | -void eeprom_write_byte(uint32_t pos, uint8_t value) |
339 | | -{ |
340 | | - if (pos > E2END) { |
341 | | - return; |
342 | | - } |
343 | | - memcpy((uint8_t *)(EEPROM_RETRAM_START_ADDRESS + pos), &value, sizeof(uint8_t)); |
344 | | -} |
345 | | -#endif /* EEPROM_RETRAM_MODE */ |
| 325 | +#endif /* defined(EEPROM_RETRAM_MODE) */ |
346 | 326 |
|
347 | 327 | #ifdef __cplusplus |
348 | 328 | } |
|
0 commit comments