@@ -151,8 +151,20 @@ static uint8_t eeprom_buffer[E2END + 1] __attribute__((aligned(8))) = {0};
151151 */
152152uint8_t eeprom_read_byte (const uint32_t pos )
153153{
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
154165 eeprom_buffer_fill ();
155166 return eeprom_buffered_read_byte (pos );
167+ #endif /* _EEPROM_BASE */
156168}
157169
158170/**
@@ -163,8 +175,20 @@ uint8_t eeprom_read_byte(const uint32_t pos)
163175 */
164176void eeprom_write_byte (uint32_t pos , uint8_t value )
165177{
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
166189 eeprom_buffered_write_byte (pos , value );
167190 eeprom_buffer_flush ();
191+ #endif /* _EEPROM_BASE */
168192}
169193
170194/**
@@ -195,7 +219,11 @@ void eeprom_buffered_write_byte(uint32_t pos, uint8_t value)
195219 */
196220void eeprom_buffer_fill (void )
197221{
222+ #if defined(DATA_EEPROM_BASE )
223+ memcpy (eeprom_buffer , (uint8_t * )(DATA_EEPROM_BASE ), E2END + 1 );
224+ #else
198225 memcpy (eeprom_buffer , (uint8_t * )(FLASH_BASE_ADDRESS ), E2END + 1 );
226+ #endif /* STM32L0xx */
199227}
200228
201229#if defined(EEPROM_RETRAM_MODE )
@@ -210,6 +238,22 @@ void eeprom_buffer_flush(void)
210238 memcpy ((uint8_t * )(FLASH_BASE_ADDRESS ), eeprom_buffer , E2END + 1 );
211239}
212240
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+ }
213257#else /* defined(EEPROM_RETRAM_MODE) */
214258
215259/**
0 commit comments