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 ) || \
@@ -122,6 +115,8 @@ static inline uint32_t get_flash_end(void)
122
115
defined(STM32WBxx )
123
116
/* If FLASH_PAGE_NUMBER is defined by user, this is not really end of the flash */
124
117
#define FLASH_END ((uint32_t)(FLASH_BASE + (((FLASH_PAGE_NUMBER +1) * FLASH_PAGE_SIZE))-1))
118
+ #elif defined(EEPROM_RETRAM_MODE )
119
+ #define FLASH_END ((uint32_t)(EEPROM_RETRAM_START_ADDRESS + EEPROM_RETRAM_MODE_SIZE -1))
125
120
#endif
126
121
#ifndef FLASH_END
127
122
#error "FLASH_END could not be defined"
@@ -137,6 +132,8 @@ static inline uint32_t get_flash_end(void)
137
132
*/
138
133
#if defined(STM32L0xx )
139
134
#define FLASH_BASE_ADDRESS ((uint32_t)(DATA_EEPROM_BASE))
135
+ #elif defined(EEPROM_RETRAM_MODE )
136
+ #define FLASH_BASE_ADDRESS EEPROM_RETRAM_START_ADDRESS
140
137
#else
141
138
#define FLASH_BASE_ADDRESS ((uint32_t)((FLASH_END + 1) - FLASH_PAGE_SIZE))
142
139
#endif
@@ -201,6 +198,20 @@ void eeprom_buffer_fill(void)
201
198
memcpy (eeprom_buffer , (uint8_t * )(FLASH_BASE_ADDRESS ), E2END + 1 );
202
199
}
203
200
201
+ #if defined(EEPROM_RETRAM_MODE )
202
+
203
+ /**
204
+ * @brief This function writes the buffer content into the flash
205
+ * @param none
206
+ * @retval none
207
+ */
208
+ void eeprom_buffer_flush (void )
209
+ {
210
+ memcpy ((uint8_t * )(FLASH_BASE_ADDRESS ), eeprom_buffer , E2END + 1 );
211
+ }
212
+
213
+ #else /* defined(EEPROM_RETRAM_MODE) */
214
+
204
215
/**
205
216
* @brief This function writes the buffer content into the flash
206
217
* @param none
@@ -313,36 +324,7 @@ void eeprom_buffer_flush(void)
313
324
#endif
314
325
}
315
326
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 */
327
+ #endif /* defined(EEPROM_RETRAM_MODE) */
346
328
347
329
#ifdef __cplusplus
348
330
}
0 commit comments