@@ -151,8 +151,17 @@ static uint8_t eeprom_buffer[E2END + 1] __attribute__((aligned(8))) = {0};
151
151
*/
152
152
uint8_t eeprom_read_byte (const uint32_t pos )
153
153
{
154
+ #if defined(DATA_EEPROM_BASE )
155
+ __IO uint8_t data = 0 ;
156
+ if (pos <= (DATA_EEPROM_END - DATA_EEPROM_BASE )) {
157
+ /* with actual EEPROM, pos is a relative address */
158
+ data = * (__IO uint8_t * )(DATA_EEPROM_BASE + pos );
159
+ return (uint8_t )data ;
160
+ }
161
+ #else
154
162
eeprom_buffer_fill ();
155
163
return eeprom_buffered_read_byte (pos );
164
+ #endif /* _EEPROM_BASE */
156
165
}
157
166
158
167
/**
@@ -163,8 +172,18 @@ uint8_t eeprom_read_byte(const uint32_t pos)
163
172
*/
164
173
void eeprom_write_byte (uint32_t pos , uint8_t value )
165
174
{
175
+ #if defined(DATA_EEPROM_BASE )
176
+ /* with actual EEPROM, pos is a relative address */
177
+ if (pos <= (DATA_EEPROM_END - DATA_EEPROM_BASE )) {
178
+ if (HAL_FLASHEx_DATAEEPROM_Unlock () == HAL_OK ) {
179
+ HAL_FLASHEx_DATAEEPROM_Program (FLASH_TYPEPROGRAMDATA_BYTE , (pos + DATA_EEPROM_BASE ), (uint32_t )value );
180
+ HAL_FLASHEx_DATAEEPROM_Lock ();
181
+ }
182
+ }
183
+ #else
166
184
eeprom_buffered_write_byte (pos , value );
167
185
eeprom_buffer_flush ();
186
+ #endif /* _EEPROM_BASE */
168
187
}
169
188
170
189
/**
@@ -195,7 +214,11 @@ void eeprom_buffered_write_byte(uint32_t pos, uint8_t value)
195
214
*/
196
215
void eeprom_buffer_fill (void )
197
216
{
217
+ #if defined(DATA_EEPROM_BASE )
218
+ memcpy (eeprom_buffer , (uint8_t * )(DATA_EEPROM_BASE ), E2END + 1 );
219
+ #else
198
220
memcpy (eeprom_buffer , (uint8_t * )(FLASH_BASE_ADDRESS ), E2END + 1 );
221
+ #endif /* STM32L0xx */
199
222
}
200
223
201
224
#if defined(EEPROM_RETRAM_MODE )
@@ -210,6 +233,22 @@ void eeprom_buffer_flush(void)
210
233
memcpy ((uint8_t * )(FLASH_BASE_ADDRESS ), eeprom_buffer , E2END + 1 );
211
234
}
212
235
236
+ #elif defined(DATA_EEPROM_BASE )
237
+ /**
238
+ * @brief This function writes the buffer content into the eeprom on L0
239
+ * @param none
240
+ * @retval none
241
+ */
242
+ void eeprom_buffer_flush (void )
243
+ {
244
+ HAL_FLASHEx_DATAEEPROM_Unlock ();
245
+
246
+ for (uint32_t i = 0 ; i < E2END ; i ++ ) {
247
+ /* Program byte (8-bit) at a specified address.*/
248
+ * (__IO uint8_t * )(i + DATA_EEPROM_BASE ) = (uint8_t ) eeprom_buffer [i ];
249
+ }
250
+ HAL_FLASHEx_DATAEEPROM_Lock ();
251
+ }
213
252
#else /* defined(EEPROM_RETRAM_MODE) */
214
253
215
254
/**
0 commit comments