Skip to content

Commit 0ede67d

Browse files
committed
library: EEPROM: use register definition instead of serie name
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent c1ac48d commit 0ede67d

File tree

2 files changed

+37
-82
lines changed

2 files changed

+37
-82
lines changed

libraries/EEPROM/src/utility/stm32_eeprom.c

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,13 @@
55
******************************************************************************
66
* @attention
77
*
8-
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
8+
* Copyright (c) 2016-2021, STMicroelectronics
9+
* All rights reserved.
910
*
10-
* Redistribution and use in source and binary forms, with or without modification,
11-
* are permitted provided that the following conditions are met:
12-
* 1. Redistributions of source code must retain the above copyright notice,
13-
* this list of conditions and the following disclaimer.
14-
* 2. Redistributions in binary form must reproduce the above copyright notice,
15-
* this list of conditions and the following disclaimer in the documentation
16-
* and/or other materials provided with the distribution.
17-
* 3. Neither the name of STMicroelectronics nor the names of its contributors
18-
* may be used to endorse or promote products derived from this software
19-
* without specific prior written permission.
20-
*
21-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11+
* This software component is licensed by ST under BSD 3-Clause license,
12+
* the "License"; You may not use this file except in compliance with the
13+
* License. You may obtain a copy of the License at:
14+
* opensource.org/licenses/BSD-3-Clause
3115
*
3216
******************************************************************************
3317
*/
@@ -40,16 +24,10 @@ extern "C" {
4024
#endif
4125

4226
/* Be able to change FLASH_BANK_NUMBER to use if relevant */
43-
#if !defined(FLASH_BANK_NUMBER) &&\
44-
(defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32G4xx) ||\
45-
defined(STM32H7xx) || defined(STM32L4xx) || defined(STM32L5xx))
46-
/* For STM32F0xx, FLASH_BANK_1 is not defined only FLASH_BANK1_END is defined */
47-
#if defined(STM32F0xx)
48-
#define FLASH_BANK_1 1U
49-
#endif
27+
#if !defined(FLASH_BANK_NUMBER) && defined(FLASH_BANK_1)
5028
#if defined(FLASH_BANK_2)
5129
#define FLASH_BANK_NUMBER FLASH_BANK_2
52-
#else
30+
#else /* FLASH_BANK_1 */
5331
#define FLASH_BANK_NUMBER FLASH_BANK_1
5432
#endif /* FLASH_BANK_2 */
5533
#ifndef FLASH_BANK_NUMBER
@@ -58,33 +36,28 @@ extern "C" {
5836
#endif /* !FLASH_BANK_NUMBER */
5937

6038
/* Be able to change FLASH_DATA_SECTOR to use if relevant */
61-
#if defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32F7xx) ||\
62-
defined(STM32H7xx)
39+
#if defined(FLASH_SECTOR_TOTAL)
6340
#if !defined(FLASH_DATA_SECTOR)
6441
#define FLASH_DATA_SECTOR ((uint32_t)(FLASH_SECTOR_TOTAL - 1))
6542
#else
6643
#ifndef FLASH_BASE_ADDRESS
6744
#error "FLASH_BASE_ADDRESS have to be defined when FLASH_DATA_SECTOR is defined"
6845
#endif
6946
#endif /* !FLASH_DATA_SECTOR */
70-
#endif /* STM32F2xx || STM32F4xx || STM32F7xx */
47+
#endif /* FLASH_SECTOR_TOTAL */
7148

7249
/* Be able to change FLASH_PAGE_NUMBER to use if relevant */
73-
#if !defined(FLASH_PAGE_NUMBER) &&\
74-
(defined (STM32G0xx) || defined(STM32G4xx) || defined (STM32L4xx) ||\
75-
defined (STM32L5xx) || defined(STM32WBxx))
50+
#if !defined(FLASH_PAGE_NUMBER) && defined (FLASH_SIZE) && defined(FLASH_PAGE_SIZE)
7651
#define FLASH_PAGE_NUMBER ((uint32_t)((FLASH_SIZE / FLASH_PAGE_SIZE) - 1))
7752
#endif /* !FLASH_PAGE_NUMBER */
7853

7954
/* Be able to change FLASH_END to use */
8055
#if !defined(FLASH_END)
81-
#if defined (STM32F0xx) || defined (STM32F1xx)
8256
#if defined (FLASH_BANK2_END) && (FLASH_BANK_NUMBER == FLASH_BANK_2)
8357
#define FLASH_END FLASH_BANK2_END
8458
#elif defined (FLASH_BANK1_END) && (FLASH_BANK_NUMBER == FLASH_BANK_1)
8559
#define FLASH_END FLASH_BANK1_END
86-
#endif
87-
#elif defined (STM32F3xx)
60+
#elif !defined (FLASH_PAGE_NUMBER)
8861
static inline uint32_t get_flash_end(void)
8962
{
9063
uint32_t size;
@@ -111,8 +84,7 @@ static inline uint32_t get_flash_end(void)
11184
return size;
11285
}
11386
#define FLASH_END get_flash_end()
114-
#elif defined(STM32G0xx) || defined(STM32G4xx) || defined (STM32L4xx) || \
115-
defined (STM32L5xx) || defined(STM32WBxx)
87+
#elif defined(FLASH_BASE) && defined(FLASH_PAGE_NUMBER) && defined (FLASH_PAGE_SIZE)
11688
/* If FLASH_PAGE_NUMBER is defined by user, this is not really end of the flash */
11789
#define FLASH_END ((uint32_t)(FLASH_BASE + (((FLASH_PAGE_NUMBER +1) * FLASH_PAGE_SIZE))-1))
11890
#elif defined(EEPROM_RETRAM_MODE)
@@ -246,20 +218,16 @@ void eeprom_buffer_flush(void)
246218
uint32_t offset = 0;
247219
uint32_t address = FLASH_BASE_ADDRESS;
248220
uint32_t address_end = FLASH_BASE_ADDRESS + E2END;
249-
#if defined (STM32F0xx) || defined (STM32F1xx) || defined (STM32F3xx) || \
250-
defined (STM32G0xx) || defined (STM32G4xx) || \
251-
defined (STM32L4xx) || defined (STM32L5xx) || defined (STM32WBxx)
221+
#if defined(FLASH_TYPEERASE_PAGES)
252222
uint32_t pageError = 0;
253223
uint64_t data = 0;
254224

255225
/* ERASING page */
256226
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
257-
#if defined (STM32F1xx) || defined (STM32G4xx) || defined (STM32L4xx) || \
258-
defined (STM32L5xx)
227+
#if defined(FLASH_BANK_NUMBER)
259228
EraseInitStruct.Banks = FLASH_BANK_NUMBER;
260-
#endif
261-
#if defined (STM32G0xx) || defined (STM32G4xx) || defined (STM32L4xx) || \
262-
defined (STM32L5xx) || defined (STM32WBxx)
229+
#endif /* FLASH_BANK_NUMBER */
230+
#if defined (FLASH_PAGE_NUMBER)
263231
EraseInitStruct.Page = FLASH_PAGE_NUMBER;
264232
#else
265233
EraseInitStruct.PageAddress = FLASH_BASE_ADDRESS;
@@ -283,17 +251,18 @@ void eeprom_buffer_flush(void)
283251
}
284252
HAL_FLASH_Lock();
285253
}
286-
#else
254+
#else /* FLASH_TYPEERASE_SECTORS */
287255
uint32_t SectorError = 0;
288-
#if defined(STM32H7xx)
256+
#if defined(FLASH_TYPEPROGRAM_FLASHWORD)
289257
uint64_t data[4] = {0x0000};
290258
#else
291259
uint32_t data = 0;
292260
#endif
293261

294262
/* ERASING page */
295263
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
296-
#if defined(STM32H7xx)
264+
// #if defined(STM32H7xx)
265+
#if defined(FLASH_BANK_NUMBER)
297266
EraseInitStruct.Banks = FLASH_BANK_NUMBER;
298267
#endif
299268
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
@@ -304,7 +273,7 @@ void eeprom_buffer_flush(void)
304273

305274
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) == HAL_OK) {
306275
while (address <= address_end) {
307-
#if defined(STM32H7xx)
276+
#if defined(FLASH_TYPEPROGRAM_FLASHWORD)
308277
/* 256 bits */
309278
memcpy(&data, eeprom_buffer + offset, 8 * sizeof(uint32_t));
310279
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, address, (uint32_t)data) == HAL_OK) {

libraries/EEPROM/src/utility/stm32_eeprom.h

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,13 @@
55
******************************************************************************
66
* @attention
77
*
8-
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
8+
* Copyright (c) 2016-2021, STMicroelectronics
9+
* All rights reserved.
910
*
10-
* Redistribution and use in source and binary forms, with or without modification,
11-
* are permitted provided that the following conditions are met:
12-
* 1. Redistributions of source code must retain the above copyright notice,
13-
* this list of conditions and the following disclaimer.
14-
* 2. Redistributions in binary form must reproduce the above copyright notice,
15-
* this list of conditions and the following disclaimer in the documentation
16-
* and/or other materials provided with the distribution.
17-
* 3. Neither the name of STMicroelectronics nor the names of its contributors
18-
* may be used to endorse or promote products derived from this software
19-
* without specific prior written permission.
20-
*
21-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11+
* This software component is licensed by ST under BSD 3-Clause license,
12+
* the "License"; You may not use this file except in compliance with the
13+
* License. You may obtain a copy of the License at:
14+
* opensource.org/licenses/BSD-3-Clause
3115
*
3216
******************************************************************************
3317
*/
@@ -71,11 +55,13 @@ extern "C" {
7155
#define E2END (EEPROM_RETRAM_MODE_SIZE - 1)
7256
#else
7357
#ifndef FLASH_FLAG_ALL_ERRORS
74-
#if defined(STM32F0xx) || defined(STM32F3xx)
75-
#define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR)
76-
#elif defined(STM32F1xx)
58+
#if defined(FLASH_FLAG_PGERR)
59+
#if defined(FLASH_FLAG_OPTVERR)
7760
#define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_OPTVERR)
78-
#elif defined (STM32G0xx)
61+
#else
62+
#define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR)
63+
#endif /* FLASH_FLAG_OPTVERR */
64+
#else
7965
#if defined(FLASH_PCROP_SUPPORT)
8066
#define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_OPERR | FLASH_FLAG_PROGERR | FLASH_FLAG_WRPERR | \
8167
FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_PGSERR | \
@@ -87,8 +73,8 @@ extern "C" {
8773
FLASH_FLAG_MISERR | FLASH_FLAG_FASTERR | \
8874
FLASH_FLAG_OPTVERR | FLASH_FLAG_ECCC | FLASH_FLAG_ECCD)
8975
#endif /* FLASH_PCROP_SUPPORT */
90-
#endif
91-
#endif
76+
#endif /* FLASH_FLAG_PGERR */
77+
#endif /* FLASH_FLAG_ALL_ERRORS */
9278

9379
#ifndef FLASH_PAGE_SIZE
9480
/*
@@ -119,7 +105,7 @@ extern "C" {
119105
#define E2END (FLASH_PAGE_SIZE - 1)
120106
#endif /* _EEPROM_BASE */
121107

122-
#endif
108+
#endif /* STM32MP1xx */
123109

124110
/* Exported macro ------------------------------------------------------------*/
125111
/* Exported functions ------------------------------------------------------- */

0 commit comments

Comments
 (0)