@@ -151,8 +151,20 @@ 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
+ /* align content of the buffered eeprom */
160
+ eeprom_buffer [pos ] = (uint8_t )data ;
161
+
162
+ return (uint8_t )data ;
163
+ }
164
+ #else
154
165
eeprom_buffer_fill ();
155
166
return eeprom_buffered_read_byte (pos );
167
+ #endif /* _EEPROM_BASE */
156
168
}
157
169
158
170
/**
@@ -163,8 +175,20 @@ uint8_t eeprom_read_byte(const uint32_t pos)
163
175
*/
164
176
void eeprom_write_byte (uint32_t pos , uint8_t value )
165
177
{
178
+ #if defined(DATA_EEPROM_BASE )
179
+ /* with actual EEPROM, pos is a relative address */
180
+ if (pos <= (DATA_EEPROM_END - DATA_EEPROM_BASE )) {
181
+ if (HAL_FLASHEx_DATAEEPROM_Unlock () == HAL_OK ) {
182
+ HAL_FLASHEx_DATAEEPROM_Program (FLASH_TYPEPROGRAMDATA_BYTE , (pos + DATA_EEPROM_BASE ), (uint32_t )value );
183
+ HAL_FLASHEx_DATAEEPROM_Lock ();
184
+ }
185
+ }
186
+ /* align content of the buffered eeprom */
187
+ eeprom_buffer [pos ] = (uint8_t )value ;
188
+ #else
166
189
eeprom_buffered_write_byte (pos , value );
167
190
eeprom_buffer_flush ();
191
+ #endif /* _EEPROM_BASE */
168
192
}
169
193
170
194
/**
@@ -195,7 +219,11 @@ void eeprom_buffered_write_byte(uint32_t pos, uint8_t value)
195
219
*/
196
220
void eeprom_buffer_fill (void )
197
221
{
222
+ #if defined(DATA_EEPROM_BASE )
223
+ memcpy (eeprom_buffer , (uint8_t * )(DATA_EEPROM_BASE ), E2END + 1 );
224
+ #else
198
225
memcpy (eeprom_buffer , (uint8_t * )(FLASH_BASE_ADDRESS ), E2END + 1 );
226
+ #endif /* STM32L0xx */
199
227
}
200
228
201
229
#if defined(EEPROM_RETRAM_MODE )
@@ -210,6 +238,22 @@ void eeprom_buffer_flush(void)
210
238
memcpy ((uint8_t * )(FLASH_BASE_ADDRESS ), eeprom_buffer , E2END + 1 );
211
239
}
212
240
241
+ #elif defined(DATA_EEPROM_BASE )
242
+ /**
243
+ * @brief This function writes the buffer content into the eeprom on L0
244
+ * @param none
245
+ * @retval none
246
+ */
247
+ void eeprom_buffer_flush (void )
248
+ {
249
+ HAL_FLASHEx_DATAEEPROM_Unlock ();
250
+
251
+ for (uint32_t i = 0 ; i < E2END ; i ++ ) {
252
+ /* Program byte (8-bit) at a specified address.*/
253
+ * (__IO uint8_t * )(i + DATA_EEPROM_BASE ) = (uint8_t ) eeprom_buffer [i ];
254
+ }
255
+ HAL_FLASHEx_DATAEEPROM_Lock ();
256
+ }
213
257
#else /* defined(EEPROM_RETRAM_MODE) */
214
258
215
259
/**
0 commit comments