Skip to content

Commit a2e6365

Browse files
committed
remove stm32L0x and stm32L1x outside the use of EEPROM
The specific functions for stm32L0x and stm32L1x are defined with the DATA_EEPROM_BASE. So that they are no more required elsewhere. Signed-off-by: Francois Ramu <francois.ramu@st.com>
1 parent 8ad9935 commit a2e6365

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

libraries/SrcWrapper/src/stm32/stm32_eeprom.c

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ extern "C" {
4242
/* Be able to change FLASH_BANK_NUMBER to use if relevant */
4343
#if !defined(FLASH_BANK_NUMBER) &&\
4444
(defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32G4xx) ||\
45-
defined(STM32H7xx) || defined(STM32L1xx) || defined(STM32L4xx))
46-
/* Fo STM32F0xx, FLASH_BANK_1 is not defined only FLASH_BANK1_END is defined */
45+
defined(STM32H7xx) || defined(STM32L4xx))
46+
/* For STM32F0xx, FLASH_BANK_1 is not defined only FLASH_BANK1_END is defined */
4747
#if defined(STM32F0xx)
4848
#define FLASH_BANK_1 1U
4949
#endif
@@ -58,7 +58,7 @@ extern "C" {
5858
#endif /* !FLASH_BANK_NUMBER */
5959

6060
/* Be able to change FLASH_DATA_SECTOR to use if relevant */
61-
#if defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32F7xx) ||\
61+
#if defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32F7xx) ||\
6262
defined(STM32H7xx)
6363
#if !defined(FLASH_DATA_SECTOR)
6464
#define FLASH_DATA_SECTOR ((uint32_t)(FLASH_SECTOR_TOTAL - 1))
@@ -77,8 +77,8 @@ extern "C" {
7777
#endif /* !FLASH_PAGE_NUMBER */
7878

7979
/* Be able to change FLASH_END to use */
80-
#if !defined(FLASH_END) && !defined(STM32L0xx)
81-
#if defined (STM32F0xx) || defined (STM32F1xx) || defined(STM32L1xx)
80+
#if !defined(FLASH_END)
81+
#if defined (STM32F0xx) || defined (STM32F1xx)
8282
#if defined (FLASH_BANK2_END) && (FLASH_BANK_NUMBER == FLASH_BANK_2)
8383
#define FLASH_END FLASH_BANK2_END
8484
#elif defined (FLASH_BANK1_END) && (FLASH_BANK_NUMBER == FLASH_BANK_1)
@@ -117,6 +117,8 @@ static inline uint32_t get_flash_end(void)
117117
#define FLASH_END ((uint32_t)(FLASH_BASE + (((FLASH_PAGE_NUMBER +1) * FLASH_PAGE_SIZE))-1))
118118
#elif defined(EEPROM_RETRAM_MODE)
119119
#define FLASH_END ((uint32_t)(EEPROM_RETRAM_START_ADDRESS + EEPROM_RETRAM_MODE_SIZE -1))
120+
#elif defined(DATA_EEPROM_END)
121+
#define FLASH_END DATA_EEPROM_ENu
120122
#endif
121123
#ifndef FLASH_END
122124
#error "FLASH_END could not be defined"
@@ -130,7 +132,7 @@ static inline uint32_t get_flash_end(void)
130132
* in order to prevent overwritting
131133
* program data
132134
*/
133-
#if defined(STM32L0xx)
135+
#if defined(DATA_EEPROM_BASE)
134136
#define FLASH_BASE_ADDRESS ((uint32_t)(DATA_EEPROM_BASE))
135137
#elif defined(EEPROM_RETRAM_MODE)
136138
#define FLASH_BASE_ADDRESS EEPROM_RETRAM_START_ADDRESS
@@ -156,6 +158,9 @@ uint8_t eeprom_read_byte(const uint32_t pos)
156158
if (pos <= (DATA_EEPROM_END - DATA_EEPROM_BASE)) {
157159
/* with actual EEPROM, pos is a relative address */
158160
data = *(__IO uint8_t *)(DATA_EEPROM_BASE + pos);
161+
/* align content of the buffered eeprom */
162+
eeprom_buffer[pos] = (uint8_t)data;
163+
159164
return (uint8_t)data;
160165
}
161166
#else
@@ -180,6 +185,7 @@ void eeprom_write_byte(uint32_t pos, uint8_t value)
180185
HAL_FLASHEx_DATAEEPROM_Lock();
181186
}
182187
}
188+
eeprom_buffer[pos] = (uint8_t)value;
183189
#else
184190
eeprom_buffered_write_byte(pos, value);
185191
eeprom_buffer_flush();
@@ -218,7 +224,7 @@ void eeprom_buffer_fill(void)
218224
memcpy(eeprom_buffer, (uint8_t *)(DATA_EEPROM_BASE), E2END + 1);
219225
#else
220226
memcpy(eeprom_buffer, (uint8_t *)(FLASH_BASE_ADDRESS), E2END + 1);
221-
#endif /* STM32L0xx */
227+
#endif /* DATA_EEPROM_BASE */
222228
}
223229

224230
#if defined(EEPROM_RETRAM_MODE)
@@ -263,8 +269,8 @@ void eeprom_buffer_flush(void)
263269
uint32_t address = FLASH_BASE_ADDRESS;
264270
uint32_t address_end = FLASH_BASE_ADDRESS + E2END;
265271
#if defined (STM32F0xx) || defined (STM32F1xx) || defined (STM32F3xx) || \
266-
defined (STM32G0xx) || defined (STM32G4xx) || defined (STM32L0xx) || \
267-
defined (STM32L1xx) || defined (STM32L4xx) || defined (STM32WBxx)
272+
defined (STM32G0xx) || defined (STM32G4xx) || \
273+
defined (STM32L4xx) || defined (STM32WBxx)
268274
uint32_t pageError = 0;
269275
uint64_t data = 0;
270276

@@ -282,38 +288,20 @@ void eeprom_buffer_flush(void)
282288
EraseInitStruct.NbPages = 1;
283289

284290
if (HAL_FLASH_Unlock() == HAL_OK) {
285-
#if defined(STM32L0xx)
286-
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
287-
FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_RDERR | \
288-
FLASH_FLAG_FWWERR | FLASH_FLAG_NOTZEROERR);
289-
#elif defined(STM32L1xx)
290-
#if defined(FLASH_SR_RDERR)
291-
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
292-
FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_RDERR);
293-
#else
294-
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
295-
FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);
296-
#endif
297-
#elif defined (STM32G0xx) || defined (STM32G4xx) || defined (STM32L4xx) || \
291+
#if defined (STM32G0xx) || defined (STM32G4xx) || defined (STM32L4xx) || \
298292
defined (STM32WBxx)
299293
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
300294
#else
301295
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
302296
#endif
303297
if (HAL_FLASHEx_Erase(&EraseInitStruct, &pageError) == HAL_OK) {
304298
while (address <= address_end) {
305-
#if defined(STM32L0xx) || defined(STM32L1xx)
306-
memcpy(&data, eeprom_buffer + offset, sizeof(uint32_t));
307-
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data) == HAL_OK) {
308-
address += 4;
309-
offset += 4;
310-
#else
299+
311300
data = *((uint64_t *)((uint8_t *)eeprom_buffer + offset));
312301

313302
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, data) == HAL_OK) {
314303
address += 8;
315304
offset += 8;
316-
#endif
317305
} else {
318306
address = address_end + 1;
319307
}

0 commit comments

Comments
 (0)