My Project
Loading...
Searching...
No Matches
stm32f3xx_hal_flash_ex.h
Go to the documentation of this file.
1
18/* Define to prevent recursive inclusion -------------------------------------*/
19#ifndef __STM32F3xx_HAL_FLASH_EX_H
20#define __STM32F3xx_HAL_FLASH_EX_H
21
22#ifdef __cplusplus
23 extern "C" {
24#endif
25
26/* Includes ------------------------------------------------------------------*/
27#include "stm32f3xx_hal_def.h"
28
41#define FLASH_SIZE_DATA_REGISTER (0x1FFFF7CCU)
42
50#define IS_FLASH_TYPEERASE(VALUE) (((VALUE) == FLASH_TYPEERASE_PAGES) || \
51 ((VALUE) == FLASH_TYPEERASE_MASSERASE))
52
53#define IS_OPTIONBYTE(VALUE) ((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_DATA))
54
55#define IS_WRPSTATE(VALUE) (((VALUE) == OB_WRPSTATE_DISABLE) || \
56 ((VALUE) == OB_WRPSTATE_ENABLE))
57
58#define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == OB_DATA_ADDRESS_DATA0) || ((ADDRESS) == OB_DATA_ADDRESS_DATA1))
59
60#define IS_OB_RDP_LEVEL(LEVEL) (((LEVEL) == OB_RDP_LEVEL_0) ||\
61 ((LEVEL) == OB_RDP_LEVEL_1))/*||\
62 ((LEVEL) == OB_RDP_LEVEL_2))*/
64#define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
66#define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NO_RST) || ((SOURCE) == OB_STOP_RST))
68#define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NO_RST) || ((SOURCE) == OB_STDBY_RST))
70#define IS_OB_BOOT1(BOOT1) (((BOOT1) == OB_BOOT1_RESET) || ((BOOT1) == OB_BOOT1_SET))
72#define IS_OB_VDDA_ANALOG(ANALOG) (((ANALOG) == OB_VDDA_ANALOG_ON) || ((ANALOG) == OB_VDDA_ANALOG_OFF))
74#define IS_OB_SRAM_PARITY(PARITY) (((PARITY) == OB_SRAM_PARITY_SET) || ((PARITY) == OB_SRAM_PARITY_RESET))
75
76
77#if defined(FLASH_OBR_SDADC12_VDD_MONITOR)
78#define IS_OB_SDACD_VDD_MONITOR(VDD_MONITOR) (((VDD_MONITOR) == OB_SDACD_VDD_MONITOR_SET) || \
79 ((VDD_MONITOR) == OB_SDACD_VDD_MONITOR_RESET))
80#endif /* FLASH_OBR_SDADC12_VDD_MONITOR */
82#define IS_OB_WRP(PAGE) (((PAGE) != 0x0000000U))
83
84#if defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) \
85 || defined(STM32F373xC) || defined(STM32F378xx)
86#define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x100U) ? \
87 ((ADDRESS) <= 0x0803FFFFU) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? \
88 ((ADDRESS) <= 0x0801FFFFU) : ((ADDRESS) <= 0x0800FFFFU))))
89#endif /* STM32F302xC || STM32F303xC || STM32F358xx || */
90 /* STM32F373xC || STM32F378xx */
91
92#if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx)
93#define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && ((ADDRESS) <= 0x0807FFFFU))
94#endif /* STM32F302xE || STM32F303xE || STM32F398xx */
95
96#if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) \
97 || defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx)
98#define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x40U) ? \
99 ((ADDRESS) <= 0x0800FFFFU) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? \
100 ((ADDRESS) <= 0x08007FFFU) : ((ADDRESS) <= 0x08003FFFU))))
101#endif /* STM32F301x8 || STM32F302x8 || STM32F318xx || */
102 /* STM32F303x8 || STM32F334x8 || STM32F328xx */
103
104#if defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) \
105 || defined(STM32F373xC) || defined(STM32F378xx)
106#define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x100U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1U <= 0x0803FFFFU) : \
107 (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1U <= 0x0801FFFFU) : \
108 ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1U <= 0x0800FFFFU)))
109#endif /* STM32F302xC || STM32F303xC || STM32F358xx || */
110 /* STM32F373xC || STM32F378xx */
111
112#if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx)
113#define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1U <= 0x0807FFFFU)
114#endif /* STM32F302xE || STM32F303xE || STM32F398xx */
115
116#if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) \
117 || defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx)
118#define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x40U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1U <= 0x0800FFFFU) : \
119 (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1U <= 0x08007FFFU) : \
120 ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1U <= 0x08003FFFU)))
121#endif /* STM32F301x8 || STM32F302x8 || STM32F318xx || */
122 /* STM32F303x8 || STM32F334x8 || STM32F328xx */
123
128/* Exported types ------------------------------------------------------------*/
135typedef struct
137 uint32_t TypeErase;
140 uint32_t PageAddress;
143 uint32_t NbPages;
147
151typedef struct
153 uint32_t OptionType;
156 uint32_t WRPState;
159 uint32_t WRPPage;
162 uint8_t RDPLevel;
165 uint8_t USERConfig;
178 uint32_t DATAAddress;
181 uint8_t DATAData;
188/* Exported constants --------------------------------------------------------*/
196#define FLASH_PAGE_SIZE 0x800
204#define FLASH_TYPEERASE_PAGES (0x00U)
205#define FLASH_TYPEERASE_MASSERASE (0x01U)
218#define OPTIONBYTE_WRP (0x01U)
219#define OPTIONBYTE_RDP (0x02U)
220#define OPTIONBYTE_USER (0x04U)
221#define OPTIONBYTE_DATA (0x08U)
230#define OB_WRPSTATE_DISABLE (0x00U)
231#define OB_WRPSTATE_ENABLE (0x01U)
240#define OB_WRP_PAGES0TO1 (0x00000001U) /* Write protection of page 0 to 1 */
241#define OB_WRP_PAGES2TO3 (0x00000002U) /* Write protection of page 2 to 3 */
242#define OB_WRP_PAGES4TO5 (0x00000004U) /* Write protection of page 4 to 5 */
243#define OB_WRP_PAGES6TO7 (0x00000008U) /* Write protection of page 6 to 7 */
244#define OB_WRP_PAGES8TO9 (0x00000010U) /* Write protection of page 8 to 9 */
245#define OB_WRP_PAGES10TO11 (0x00000020U) /* Write protection of page 10 to 11 */
246#define OB_WRP_PAGES12TO13 (0x00000040U) /* Write protection of page 12 to 13 */
247#define OB_WRP_PAGES14TO15 (0x00000080U) /* Write protection of page 14 to 15 */
248#define OB_WRP_PAGES16TO17 (0x00000100U) /* Write protection of page 16 to 17 */
249#define OB_WRP_PAGES18TO19 (0x00000200U) /* Write protection of page 18 to 19 */
250#define OB_WRP_PAGES20TO21 (0x00000400U) /* Write protection of page 20 to 21 */
251#define OB_WRP_PAGES22TO23 (0x00000800U) /* Write protection of page 22 to 23 */
252#define OB_WRP_PAGES24TO25 (0x00001000U) /* Write protection of page 24 to 25 */
253#define OB_WRP_PAGES26TO27 (0x00002000U) /* Write protection of page 26 to 27 */
254#define OB_WRP_PAGES28TO29 (0x00004000U) /* Write protection of page 28 to 29 */
255#define OB_WRP_PAGES30TO31 (0x00008000U) /* Write protection of page 30 to 31 */
256
257#if defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) \
258 || defined(STM32F373xC) || defined(STM32F378xx)
259#define OB_WRP_PAGES32TO33 (0x00010000U) /* Write protection of page 32 to 33 */
260#define OB_WRP_PAGES34TO35 (0x00020000U) /* Write protection of page 34 to 35 */
261#define OB_WRP_PAGES36TO37 (0x00040000U) /* Write protection of page 36 to 37 */
262#define OB_WRP_PAGES38TO39 (0x00080000U) /* Write protection of page 38 to 39 */
263#define OB_WRP_PAGES40TO41 (0x00100000U) /* Write protection of page 40 to 41 */
264#define OB_WRP_PAGES42TO43 (0x00200000U) /* Write protection of page 42 to 43 */
265#define OB_WRP_PAGES44TO45 (0x00400000U) /* Write protection of page 44 to 45 */
266#define OB_WRP_PAGES46TO47 (0x00800000U) /* Write protection of page 46 to 47 */
267#define OB_WRP_PAGES48TO49 (0x01000000U) /* Write protection of page 48 to 49 */
268#define OB_WRP_PAGES50TO51 (0x02000000U) /* Write protection of page 50 to 51 */
269#define OB_WRP_PAGES52TO53 (0x04000000U) /* Write protection of page 52 to 53 */
270#define OB_WRP_PAGES54TO55 (0x08000000U) /* Write protection of page 54 to 55 */
271#define OB_WRP_PAGES56TO57 (0x10000000U) /* Write protection of page 56 to 57 */
272#define OB_WRP_PAGES58TO59 (0x20000000U) /* Write protection of page 58 to 59 */
273#define OB_WRP_PAGES60TO61 (0x40000000U) /* Write protection of page 60 to 61 */
274#define OB_WRP_PAGES62TO127 (0x80000000U) /* Write protection of page 62 to 127 */
275#endif /* STM32F302xC || STM32F303xC || STM32F358xx || */
276 /* STM32F373xC || STM32F378xx */
277
278#if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx)
279#define OB_WRP_PAGES32TO33 (0x00010000U) /* Write protection of page 32 to 33 */
280#define OB_WRP_PAGES34TO35 (0x00020000U) /* Write protection of page 34 to 35 */
281#define OB_WRP_PAGES36TO37 (0x00040000U) /* Write protection of page 36 to 37 */
282#define OB_WRP_PAGES38TO39 (0x00080000U) /* Write protection of page 38 to 39 */
283#define OB_WRP_PAGES40TO41 (0x00100000U) /* Write protection of page 40 to 41 */
284#define OB_WRP_PAGES42TO43 (0x00200000U) /* Write protection of page 42 to 43 */
285#define OB_WRP_PAGES44TO45 (0x00400000U) /* Write protection of page 44 to 45 */
286#define OB_WRP_PAGES46TO47 (0x00800000U) /* Write protection of page 46 to 47 */
287#define OB_WRP_PAGES48TO49 (0x01000000U) /* Write protection of page 48 to 49 */
288#define OB_WRP_PAGES50TO51 (0x02000000U) /* Write protection of page 50 to 51 */
289#define OB_WRP_PAGES52TO53 (0x04000000U) /* Write protection of page 52 to 53 */
290#define OB_WRP_PAGES54TO55 (0x08000000U) /* Write protection of page 54 to 55 */
291#define OB_WRP_PAGES56TO57 (0x10000000U) /* Write protection of page 56 to 57 */
292#define OB_WRP_PAGES58TO59 (0x20000000U) /* Write protection of page 58 to 59 */
293#define OB_WRP_PAGES60TO61 (0x40000000U) /* Write protection of page 60 to 61 */
294#define OB_WRP_PAGES62TO255 (0x80000000U) /* Write protection of page 62 to 255 */
295#endif /* STM32F302xE || STM32F303xE || STM32F398xx */
297#define OB_WRP_PAGES0TO15MASK (0x000000FFU)
298#define OB_WRP_PAGES16TO31MASK (0x0000FF00U)
299
300#if defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) \
301 || defined(STM32F373xC) || defined(STM32F378xx)
302#define OB_WRP_PAGES32TO47MASK (0x00FF0000U)
303#define OB_WRP_PAGES48TO127MASK (0xFF000000U)
304#endif /* STM32F302xC || STM32F303xC || STM32F358xx || */
305 /* STM32F373xC || STM32F378xx */
306
307#if defined(STM32F302xE) || defined(STM32F303xE)
308#define OB_WRP_PAGES32TO47MASK (0x00FF0000U)
309#define OB_WRP_PAGES48TO255MASK (0xFF000000U)
310#endif /* STM32F302xE || STM32F303xE */
311
312#if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) \
313 || defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) \
314 || defined(STM32F373xC) || defined(STM32F378xx)
315#define OB_WRP_ALLPAGES (0xFFFFFFFFU)
316#endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
317 /* STM32F302xC || STM32F303xC || STM32F358xx || */
318 /* STM32F373xC || STM32F378xx */
319
320#if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) \
321 || defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx)
322#define OB_WRP_ALLPAGES (0x0000FFFFU)
323#endif /* STM32F301x8 || STM32F302x8 || STM32F318xx || */
324 /* STM32F303x8 || STM32F334x8 || STM32F328xx */
325
333#define OB_RDP_LEVEL_0 ((uint8_t)0xAAU)
334#define OB_RDP_LEVEL_1 ((uint8_t)0xBBU)
335#define OB_RDP_LEVEL_2 ((uint8_t)0xCCU)
344#define OB_IWDG_SW ((uint8_t)0x01U)
345#define OB_IWDG_HW ((uint8_t)0x00U)
353#define OB_STOP_NO_RST ((uint8_t)0x02U)
354#define OB_STOP_RST ((uint8_t)0x00U)
362#define OB_STDBY_NO_RST ((uint8_t)0x04U)
363#define OB_STDBY_RST ((uint8_t)0x00U)
371#define OB_BOOT1_RESET ((uint8_t)0x00U)
372#define OB_BOOT1_SET ((uint8_t)0x10U)
380#define OB_VDDA_ANALOG_ON ((uint8_t)0x20U)
381#define OB_VDDA_ANALOG_OFF ((uint8_t)0x00U)
389#define OB_SRAM_PARITY_SET ((uint8_t)0x00U)
390#define OB_SRAM_PARITY_RESET ((uint8_t)0x40U)
396#if defined(FLASH_OBR_SDADC12_VDD_MONITOR)
400#define OB_SDACD_VDD_MONITOR_RESET ((uint8_t)0x00U)
401#define OB_SDACD_VDD_MONITOR_SET ((uint8_t)0x80U)
406#endif /* FLASH_OBR_SDADC12_VDD_MONITOR */
407
411#define OB_DATA_ADDRESS_DATA0 (0x1FFFF804U)
412#define OB_DATA_ADDRESS_DATA1 (0x1FFFF806U)
425/* Exported functions --------------------------------------------------------*/
433/* IO operation functions *****************************************************/
436
444/* Peripheral Control functions ***********************************************/
448uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress);
449
466#ifdef __cplusplus
467}
468#endif
469
470#endif /* __STM32F3xx_HAL_FLASH_EX_H */
471
472
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError)
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress)
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
This file contains HAL common defines, enumeration, macros and structures definitions.
HAL_StatusTypeDef
HAL Status structures definition
Definition: stm32f3xx_hal_def.h:39
FLASH Erase structure definition.
Definition: stm32f3xx_hal_flash_ex.h:135
FLASH Options bytes program structure definition.
Definition: stm32f3xx_hal_flash_ex.h:151