rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
stm32f7xx_hal_flash_ex.h
Go to the documentation of this file.
1/**
2 ******************************************************************************
3 * @file stm32f7xx_hal_flash_ex.h
4 * @author MCD Application Team
5 * @version V1.2.0
6 * @date 30-December-2016
7 * @brief Header file of FLASH HAL Extension module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
12 *
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************
36 */
37
38/* Define to prevent recursive inclusion -------------------------------------*/
39#ifndef __STM32F7xx_HAL_FLASH_EX_H
40#define __STM32F7xx_HAL_FLASH_EX_H
41
42#ifdef __cplusplus
43 extern "C" {
44#endif
45
46/* Includes ------------------------------------------------------------------*/
47#include "stm32f7xx_hal_def.h"
48
49/** @addtogroup STM32F7xx_HAL_Driver
50 * @{
51 */
52
53/** @addtogroup FLASHEx
54 * @{
55 */
56
57/* Exported types ------------------------------------------------------------*/
58/** @defgroup FLASHEx_Exported_Types FLASH Exported Types
59 * @{
60 */
61
62/**
63 * @brief FLASH Erase structure definition
64 */
65typedef struct
66{
67 uint32_t TypeErase; /*!< Mass erase or sector Erase.
68 This parameter can be a value of @ref FLASHEx_Type_Erase */
69
70#if defined (FLASH_OPTCR_nDBANK)
71 uint32_t Banks; /*!< Select banks to erase when Mass erase is enabled.
72 This parameter must be a value of @ref FLASHEx_Banks */
73#endif /* FLASH_OPTCR_nDBANK */
74
75 uint32_t Sector; /*!< Initial FLASH sector to erase when Mass erase is disabled
76 This parameter must be a value of @ref FLASHEx_Sectors */
77
78 uint32_t NbSectors; /*!< Number of sectors to be erased.
79 This parameter must be a value between 1 and (max number of sectors - value of Initial sector)*/
80
81 uint32_t VoltageRange;/*!< The device voltage range which defines the erase parallelism
82 This parameter must be a value of @ref FLASHEx_Voltage_Range */
83
84} FLASH_EraseInitTypeDef;
85
86/**
87 * @brief FLASH Option Bytes Program structure definition
88 */
89typedef struct
90{
91 uint32_t OptionType; /*!< Option byte to be configured.
92 This parameter can be a value of @ref FLASHEx_Option_Type */
93
94 uint32_t WRPState; /*!< Write protection activation or deactivation.
95 This parameter can be a value of @ref FLASHEx_WRP_State */
96
97 uint32_t WRPSector; /*!< Specifies the sector(s) to be write protected.
98 The value of this parameter depend on device used within the same series */
99
100 uint32_t RDPLevel; /*!< Set the read protection level.
101 This parameter can be a value of @ref FLASHEx_Option_Bytes_Read_Protection */
102
103 uint32_t BORLevel; /*!< Set the BOR Level.
104 This parameter can be a value of @ref FLASHEx_BOR_Reset_Level */
105
106 uint32_t USERConfig; /*!< Program the FLASH User Option Byte: WWDG_SW / IWDG_SW / RST_STOP / RST_STDBY /
107 IWDG_FREEZE_STOP / IWDG_FREEZE_SANDBY / nDBANK / nDBOOT.
108 nDBANK / nDBOOT are only available for STM32F76xxx/STM32F77xxx devices */
109
110 uint32_t BootAddr0; /*!< Boot base address when Boot pin = 0.
111 This parameter can be a value of @ref FLASHEx_Boot_Address */
112
113 uint32_t BootAddr1; /*!< Boot base address when Boot pin = 1.
114 This parameter can be a value of @ref FLASHEx_Boot_Address */
115
116#if defined (FLASH_OPTCR2_PCROP)
117 uint32_t PCROPSector; /*!< Set the PCROP sector.
118 This parameter can be a value of @ref FLASHEx_Option_Bytes_PCROP_Sectors */
119
120 uint32_t PCROPRdp; /*!< Set the PCROP_RDP option.
121 This parameter can be a value of @ref FLASHEx_Option_Bytes_PCROP_RDP */
122#endif /* FLASH_OPTCR2_PCROP */
123
125
126/**
127 * @}
128 */
129/* Exported constants --------------------------------------------------------*/
130
131/** @defgroup FLASHEx_Exported_Constants FLASH Exported Constants
132 * @{
133 */
134
135/** @defgroup FLASHEx_Type_Erase FLASH Type Erase
136 * @{
137 */
138#define FLASH_TYPEERASE_SECTORS ((uint32_t)0x00U) /*!< Sectors erase only */
139#define FLASH_TYPEERASE_MASSERASE ((uint32_t)0x01U) /*!< Flash Mass erase activation */
140/**
141 * @}
142 */
143
144/** @defgroup FLASHEx_Voltage_Range FLASH Voltage Range
145 * @{
146 */
147#define FLASH_VOLTAGE_RANGE_1 ((uint32_t)0x00U) /*!< Device operating range: 1.8V to 2.1V */
148#define FLASH_VOLTAGE_RANGE_2 ((uint32_t)0x01U) /*!< Device operating range: 2.1V to 2.7V */
149#define FLASH_VOLTAGE_RANGE_3 ((uint32_t)0x02U) /*!< Device operating range: 2.7V to 3.6V */
150#define FLASH_VOLTAGE_RANGE_4 ((uint32_t)0x03U) /*!< Device operating range: 2.7V to 3.6V + External Vpp */
151/**
152 * @}
153 */
154
155/** @defgroup FLASHEx_WRP_State FLASH WRP State
156 * @{
157 */
158#define OB_WRPSTATE_DISABLE ((uint32_t)0x00U) /*!< Disable the write protection of the desired bank 1 sectors */
159#define OB_WRPSTATE_ENABLE ((uint32_t)0x01U) /*!< Enable the write protection of the desired bank 1 sectors */
160/**
161 * @}
162 */
163
164/** @defgroup FLASHEx_Option_Type FLASH Option Type
165 * @{
166 */
167#define OPTIONBYTE_WRP ((uint32_t)0x01U) /*!< WRP option byte configuration */
168#define OPTIONBYTE_RDP ((uint32_t)0x02U) /*!< RDP option byte configuration */
169#define OPTIONBYTE_USER ((uint32_t)0x04U) /*!< USER option byte configuration */
170#define OPTIONBYTE_BOR ((uint32_t)0x08U) /*!< BOR option byte configuration */
171#define OPTIONBYTE_BOOTADDR_0 ((uint32_t)0x10U) /*!< Boot 0 Address configuration */
172#define OPTIONBYTE_BOOTADDR_1 ((uint32_t)0x20U) /*!< Boot 1 Address configuration */
173#if defined (FLASH_OPTCR2_PCROP)
174#define OPTIONBYTE_PCROP ((uint32_t)0x40U) /*!< PCROP configuration */
175#define OPTIONBYTE_PCROP_RDP ((uint32_t)0x80U) /*!< PCROP_RDP configuration */
176#endif /* FLASH_OPTCR2_PCROP */
177/**
178 * @}
179 */
180
181/** @defgroup FLASHEx_Option_Bytes_Read_Protection FLASH Option Bytes Read Protection
182 * @{
183 */
184#define OB_RDP_LEVEL_0 ((uint8_t)0xAAU)
185#define OB_RDP_LEVEL_1 ((uint8_t)0x55U)
186#define OB_RDP_LEVEL_2 ((uint8_t)0xCCU) /*!< Warning: When enabling read protection level 2
187 it s no more possible to go back to level 1 or 0 */
188/**
189 * @}
190 */
191
192/** @defgroup FLASHEx_Option_Bytes_WWatchdog FLASH Option Bytes WWatchdog
193 * @{
194 */
195#define OB_WWDG_SW ((uint32_t)0x10U) /*!< Software WWDG selected */
196#define OB_WWDG_HW ((uint32_t)0x00U) /*!< Hardware WWDG selected */
197/**
198 * @}
199 */
200
201
202/** @defgroup FLASHEx_Option_Bytes_IWatchdog FLASH Option Bytes IWatchdog
203 * @{
204 */
205#define OB_IWDG_SW ((uint32_t)0x20U) /*!< Software IWDG selected */
206#define OB_IWDG_HW ((uint32_t)0x00U) /*!< Hardware IWDG selected */
207/**
208 * @}
209 */
210
211/** @defgroup FLASHEx_Option_Bytes_nRST_STOP FLASH Option Bytes nRST_STOP
212 * @{
213 */
214#define OB_STOP_NO_RST ((uint32_t)0x40U) /*!< No reset generated when entering in STOP */
215#define OB_STOP_RST ((uint32_t)0x00U) /*!< Reset generated when entering in STOP */
216/**
217 * @}
218 */
219
220/** @defgroup FLASHEx_Option_Bytes_nRST_STDBY FLASH Option Bytes nRST_STDBY
221 * @{
222 */
223#define OB_STDBY_NO_RST ((uint32_t)0x80U) /*!< No reset generated when entering in STANDBY */
224#define OB_STDBY_RST ((uint32_t)0x00U) /*!< Reset generated when entering in STANDBY */
225/**
226 * @}
227 */
228
229/** @defgroup FLASHEx_Option_Bytes_IWDG_FREEZE_STOP FLASH IWDG Counter Freeze in STOP
230 * @{
231 */
232#define OB_IWDG_STOP_FREEZE ((uint32_t)0x00000000U) /*!< Freeze IWDG counter in STOP mode */
233#define OB_IWDG_STOP_ACTIVE ((uint32_t)0x80000000U) /*!< IWDG counter active in STOP mode */
234/**
235 * @}
236 */
237
238/** @defgroup FLASHEx_Option_Bytes_IWDG_FREEZE_SANDBY FLASH IWDG Counter Freeze in STANDBY
239 * @{
240 */
241#define OB_IWDG_STDBY_FREEZE ((uint32_t)0x00000000U) /*!< Freeze IWDG counter in STANDBY mode */
242#define OB_IWDG_STDBY_ACTIVE ((uint32_t)0x40000000U) /*!< IWDG counter active in STANDBY mode */
243/**
244 * @}
245 */
246
247/** @defgroup FLASHEx_BOR_Reset_Level FLASH BOR Reset Level
248 * @{
249 */
250#define OB_BOR_LEVEL3 ((uint32_t)0x00U) /*!< Supply voltage ranges from 2.70 to 3.60 V */
251#define OB_BOR_LEVEL2 ((uint32_t)0x04U) /*!< Supply voltage ranges from 2.40 to 2.70 V */
252#define OB_BOR_LEVEL1 ((uint32_t)0x08U) /*!< Supply voltage ranges from 2.10 to 2.40 V */
253#define OB_BOR_OFF ((uint32_t)0x0CU) /*!< Supply voltage ranges from 1.62 to 2.10 V */
254/**
255 * @}
256 */
257
258#if defined (FLASH_OPTCR_nDBOOT)
259/** @defgroup FLASHEx_Option_Bytes_nDBOOT FLASH Option Bytes nDBOOT
260 * @{
261 */
262#define OB_DUAL_BOOT_DISABLE ((uint32_t)0x10000000U) /* !< Dual Boot disable. Boot according to boot address option */
263#define OB_DUAL_BOOT_ENABLE ((uint32_t)0x00000000U) /* !< Dual Boot enable. Boot always from system memory if boot address in flash
264 (Dual bank Boot mode), or RAM if Boot address option in RAM */
265/**
266 * @}
267 */
268#endif /* FLASH_OPTCR_nDBOOT */
269
270#if defined (FLASH_OPTCR_nDBANK)
271/** @defgroup FLASHEx_Option_Bytes_nDBank FLASH Single Bank or Dual Bank
272 * @{
273 */
274#define OB_NDBANK_SINGLE_BANK ((uint32_t)0x20000000U) /*!< NDBANK bit is set : Single Bank mode */
275#define OB_NDBANK_DUAL_BANK ((uint32_t)0x00000000U) /*!< NDBANK bit is reset : Dual Bank mode */
276/**
277 * @}
278 */
279#endif /* FLASH_OPTCR_nDBANK */
280
281/** @defgroup FLASHEx_Boot_Address FLASH Boot Address
282 * @{
283 */
284#define OB_BOOTADDR_ITCM_RAM ((uint32_t)0x0000U) /*!< Boot from ITCM RAM (0x00000000) */
285#define OB_BOOTADDR_SYSTEM ((uint32_t)0x0040U) /*!< Boot from System memory bootloader (0x00100000) */
286#define OB_BOOTADDR_ITCM_FLASH ((uint32_t)0x0080U) /*!< Boot from Flash on ITCM interface (0x00200000) */
287#define OB_BOOTADDR_AXIM_FLASH ((uint32_t)0x2000U) /*!< Boot from Flash on AXIM interface (0x08000000) */
288#define OB_BOOTADDR_DTCM_RAM ((uint32_t)0x8000U) /*!< Boot from DTCM RAM (0x20000000) */
289#define OB_BOOTADDR_SRAM1 ((uint32_t)0x8004U) /*!< Boot from SRAM1 (0x20010000) */
290#if (SRAM2_BASE == 0x2003C000U)
291#define OB_BOOTADDR_SRAM2 ((uint32_t)0x800FU) /*!< Boot from SRAM2 (0x2003C000) */
292#else
293#define OB_BOOTADDR_SRAM2 ((uint32_t)0x8013U) /*!< Boot from SRAM2 (0x2004C000) */
294#endif /* SRAM2_BASE == 0x2003C000U */
295/**
296 * @}
297 */
298
299/** @defgroup FLASH_Latency FLASH Latency
300 * @{
301 */
302#define FLASH_LATENCY_0 FLASH_ACR_LATENCY_0WS /*!< FLASH Zero Latency cycle */
303#define FLASH_LATENCY_1 FLASH_ACR_LATENCY_1WS /*!< FLASH One Latency cycle */
304#define FLASH_LATENCY_2 FLASH_ACR_LATENCY_2WS /*!< FLASH Two Latency cycles */
305#define FLASH_LATENCY_3 FLASH_ACR_LATENCY_3WS /*!< FLASH Three Latency cycles */
306#define FLASH_LATENCY_4 FLASH_ACR_LATENCY_4WS /*!< FLASH Four Latency cycles */
307#define FLASH_LATENCY_5 FLASH_ACR_LATENCY_5WS /*!< FLASH Five Latency cycles */
308#define FLASH_LATENCY_6 FLASH_ACR_LATENCY_6WS /*!< FLASH Six Latency cycles */
309#define FLASH_LATENCY_7 FLASH_ACR_LATENCY_7WS /*!< FLASH Seven Latency cycles */
310#define FLASH_LATENCY_8 FLASH_ACR_LATENCY_8WS /*!< FLASH Eight Latency cycles */
311#define FLASH_LATENCY_9 FLASH_ACR_LATENCY_9WS /*!< FLASH Nine Latency cycles */
312#define FLASH_LATENCY_10 FLASH_ACR_LATENCY_10WS /*!< FLASH Ten Latency cycles */
313#define FLASH_LATENCY_11 FLASH_ACR_LATENCY_11WS /*!< FLASH Eleven Latency cycles */
314#define FLASH_LATENCY_12 FLASH_ACR_LATENCY_12WS /*!< FLASH Twelve Latency cycles */
315#define FLASH_LATENCY_13 FLASH_ACR_LATENCY_13WS /*!< FLASH Thirteen Latency cycles */
316#define FLASH_LATENCY_14 FLASH_ACR_LATENCY_14WS /*!< FLASH Fourteen Latency cycles */
317#define FLASH_LATENCY_15 FLASH_ACR_LATENCY_15WS /*!< FLASH Fifteen Latency cycles */
318/**
319 * @}
320 */
321
322#if defined (FLASH_OPTCR_nDBANK)
323/** @defgroup FLASHEx_Banks FLASH Banks
324 * @{
325 */
326#define FLASH_BANK_1 ((uint32_t)0x01U) /*!< Bank 1 */
327#define FLASH_BANK_2 ((uint32_t)0x02U) /*!< Bank 2 */
328#define FLASH_BANK_BOTH ((uint32_t)(FLASH_BANK_1 | FLASH_BANK_2)) /*!< Bank1 and Bank2 */
329/**
330 * @}
331 */
332#endif /* FLASH_OPTCR_nDBANK */
333
334/** @defgroup FLASHEx_MassErase_bit FLASH Mass Erase bit
335 * @{
336 */
337#if defined (FLASH_OPTCR_nDBANK)
338#define FLASH_MER_BIT (FLASH_CR_MER1 | FLASH_CR_MER2) /*!< 2 MER bits */
339#else
340#define FLASH_MER_BIT (FLASH_CR_MER) /*!< only 1 MER bit */
341#endif /* FLASH_OPTCR_nDBANK */
342/**
343 * @}
344 */
345
346/** @defgroup FLASHEx_Sectors FLASH Sectors
347 * @{
348 */
349#if (FLASH_SECTOR_TOTAL == 24)
350#define FLASH_SECTOR_8 ((uint32_t)8U) /*!< Sector Number 8 */
351#define FLASH_SECTOR_9 ((uint32_t)9U) /*!< Sector Number 9 */
352#define FLASH_SECTOR_10 ((uint32_t)10U) /*!< Sector Number 10 */
353#define FLASH_SECTOR_11 ((uint32_t)11U) /*!< Sector Number 11 */
354#define FLASH_SECTOR_12 ((uint32_t)12U) /*!< Sector Number 12 */
355#define FLASH_SECTOR_13 ((uint32_t)13U) /*!< Sector Number 13 */
356#define FLASH_SECTOR_14 ((uint32_t)14U) /*!< Sector Number 14 */
357#define FLASH_SECTOR_15 ((uint32_t)15U) /*!< Sector Number 15 */
358#define FLASH_SECTOR_16 ((uint32_t)16U) /*!< Sector Number 16 */
359#define FLASH_SECTOR_17 ((uint32_t)17U) /*!< Sector Number 17 */
360#define FLASH_SECTOR_18 ((uint32_t)18U) /*!< Sector Number 18 */
361#define FLASH_SECTOR_19 ((uint32_t)19U) /*!< Sector Number 19 */
362#define FLASH_SECTOR_20 ((uint32_t)20U) /*!< Sector Number 20 */
363#define FLASH_SECTOR_21 ((uint32_t)21U) /*!< Sector Number 21 */
364#define FLASH_SECTOR_22 ((uint32_t)22U) /*!< Sector Number 22 */
365#define FLASH_SECTOR_23 ((uint32_t)23U) /*!< Sector Number 23 */
366#endif /* FLASH_SECTOR_TOTAL == 24 */
367/**
368 * @}
369 */
370
371#if (FLASH_SECTOR_TOTAL == 24)
372/** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASH Option Bytes Write Protection
373 * @note For Single Bank mode, use OB_WRP_SECTOR_x defines: In fact, in FLASH_OPTCR register,
374 * nWRP[11:0] bits contain the value of the write-protection option bytes for sectors 0 to 11.
375 * For Dual Bank mode, use OB_WRP_DB_SECTOR_x defines: In fact, in FLASH_OPTCR register,
376 * nWRP[11:0] bits are divided on two groups, one group dedicated for bank 1 and
377 * a second one dedicated for bank 2 (nWRP[i] activates Write protection on sector 2*i and 2*i+1).
378 * This behavior is applicable only for STM32F76xxx / STM32F77xxx devices.
379 * @{
380 */
381/* Single Bank Sectors */
382#define OB_WRP_SECTOR_0 ((uint32_t)0x00010000U) /*!< Write protection of Single Bank Sector0 */
383#define OB_WRP_SECTOR_1 ((uint32_t)0x00020000U) /*!< Write protection of Single Bank Sector1 */
384#define OB_WRP_SECTOR_2 ((uint32_t)0x00040000U) /*!< Write protection of Single Bank Sector2 */
385#define OB_WRP_SECTOR_3 ((uint32_t)0x00080000U) /*!< Write protection of Single Bank Sector3 */
386#define OB_WRP_SECTOR_4 ((uint32_t)0x00100000U) /*!< Write protection of Single Bank Sector4 */
387#define OB_WRP_SECTOR_5 ((uint32_t)0x00200000U) /*!< Write protection of Single Bank Sector5 */
388#define OB_WRP_SECTOR_6 ((uint32_t)0x00400000U) /*!< Write protection of Single Bank Sector6 */
389#define OB_WRP_SECTOR_7 ((uint32_t)0x00800000U) /*!< Write protection of Single Bank Sector7 */
390#define OB_WRP_SECTOR_8 ((uint32_t)0x01000000U) /*!< Write protection of Single Bank Sector8 */
391#define OB_WRP_SECTOR_9 ((uint32_t)0x02000000U) /*!< Write protection of Single Bank Sector9 */
392#define OB_WRP_SECTOR_10 ((uint32_t)0x04000000U) /*!< Write protection of Single Bank Sector10 */
393#define OB_WRP_SECTOR_11 ((uint32_t)0x08000000U) /*!< Write protection of Single Bank Sector11 */
394#define OB_WRP_SECTOR_All ((uint32_t)0x0FFF0000U) /*!< Write protection of all Sectors for Single Bank Flash */
395
396/* Dual Bank Sectors */
397#define OB_WRP_DB_SECTOR_0 ((uint32_t)0x00010000U) /*!< Write protection of Dual Bank Sector0 */
398#define OB_WRP_DB_SECTOR_1 ((uint32_t)0x00010000U) /*!< Write protection of Dual Bank Sector1 */
399#define OB_WRP_DB_SECTOR_2 ((uint32_t)0x00020000U) /*!< Write protection of Dual Bank Sector2 */
400#define OB_WRP_DB_SECTOR_3 ((uint32_t)0x00020000U) /*!< Write protection of Dual Bank Sector3 */
401#define OB_WRP_DB_SECTOR_4 ((uint32_t)0x00040000U) /*!< Write protection of Dual Bank Sector4 */
402#define OB_WRP_DB_SECTOR_5 ((uint32_t)0x00040000U) /*!< Write protection of Dual Bank Sector5 */
403#define OB_WRP_DB_SECTOR_6 ((uint32_t)0x00080000U) /*!< Write protection of Dual Bank Sector6 */
404#define OB_WRP_DB_SECTOR_7 ((uint32_t)0x00080000U) /*!< Write protection of Dual Bank Sector7 */
405#define OB_WRP_DB_SECTOR_8 ((uint32_t)0x00100000U) /*!< Write protection of Dual Bank Sector8 */
406#define OB_WRP_DB_SECTOR_9 ((uint32_t)0x00100000U) /*!< Write protection of Dual Bank Sector9 */
407#define OB_WRP_DB_SECTOR_10 ((uint32_t)0x00200000U) /*!< Write protection of Dual Bank Sector10 */
408#define OB_WRP_DB_SECTOR_11 ((uint32_t)0x00200000U) /*!< Write protection of Dual Bank Sector11 */
409#define OB_WRP_DB_SECTOR_12 ((uint32_t)0x00400000U) /*!< Write protection of Dual Bank Sector12 */
410#define OB_WRP_DB_SECTOR_13 ((uint32_t)0x00400000U) /*!< Write protection of Dual Bank Sector13 */
411#define OB_WRP_DB_SECTOR_14 ((uint32_t)0x00800000U) /*!< Write protection of Dual Bank Sector14 */
412#define OB_WRP_DB_SECTOR_15 ((uint32_t)0x00800000U) /*!< Write protection of Dual Bank Sector15 */
413#define OB_WRP_DB_SECTOR_16 ((uint32_t)0x01000000U) /*!< Write protection of Dual Bank Sector16 */
414#define OB_WRP_DB_SECTOR_17 ((uint32_t)0x01000000U) /*!< Write protection of Dual Bank Sector17 */
415#define OB_WRP_DB_SECTOR_18 ((uint32_t)0x02000000U) /*!< Write protection of Dual Bank Sector18 */
416#define OB_WRP_DB_SECTOR_19 ((uint32_t)0x02000000U) /*!< Write protection of Dual Bank Sector19 */
417#define OB_WRP_DB_SECTOR_20 ((uint32_t)0x04000000U) /*!< Write protection of Dual Bank Sector20 */
418#define OB_WRP_DB_SECTOR_21 ((uint32_t)0x04000000U) /*!< Write protection of Dual Bank Sector21 */
419#define OB_WRP_DB_SECTOR_22 ((uint32_t)0x08000000U) /*!< Write protection of Dual Bank Sector22 */
420#define OB_WRP_DB_SECTOR_23 ((uint32_t)0x08000000U) /*!< Write protection of Dual Bank Sector23 */
421#define OB_WRP_DB_SECTOR_All ((uint32_t)0x0FFF0000U) /*!< Write protection of all Sectors for Dual Bank Flash */
422/**
423 * @}
424 */
425#endif /* FLASH_SECTOR_TOTAL == 24 */
426
427#if (FLASH_SECTOR_TOTAL == 8)
428/** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASH Option Bytes Write Protection
429 * @{
430 */
431#define OB_WRP_SECTOR_0 ((uint32_t)0x00010000U) /*!< Write protection of Sector0 */
432#define OB_WRP_SECTOR_1 ((uint32_t)0x00020000U) /*!< Write protection of Sector1 */
433#define OB_WRP_SECTOR_2 ((uint32_t)0x00040000U) /*!< Write protection of Sector2 */
434#define OB_WRP_SECTOR_3 ((uint32_t)0x00080000U) /*!< Write protection of Sector3 */
435#define OB_WRP_SECTOR_4 ((uint32_t)0x00100000U) /*!< Write protection of Sector4 */
436#define OB_WRP_SECTOR_5 ((uint32_t)0x00200000U) /*!< Write protection of Sector5 */
437#define OB_WRP_SECTOR_6 ((uint32_t)0x00400000U) /*!< Write protection of Sector6 */
438#define OB_WRP_SECTOR_7 ((uint32_t)0x00800000U) /*!< Write protection of Sector7 */
439#define OB_WRP_SECTOR_All ((uint32_t)0x00FF0000U) /*!< Write protection of all Sectors */
440/**
441 * @}
442 */
443#endif /* FLASH_SECTOR_TOTAL == 8 */
444
445#if defined (FLASH_OPTCR2_PCROP)
446/** @defgroup FLASHEx_Option_Bytes_PCROP_Sectors FLASH Option Bytes PCROP Sectors
447 * @{
448 */
449#define OB_PCROP_SECTOR_0 ((uint32_t)0x00000001U) /*!< PC Readout protection of Sector0 */
450#define OB_PCROP_SECTOR_1 ((uint32_t)0x00000002U) /*!< PC Readout protection of Sector1 */
451#define OB_PCROP_SECTOR_2 ((uint32_t)0x00000004U) /*!< PC Readout protection of Sector2 */
452#define OB_PCROP_SECTOR_3 ((uint32_t)0x00000008U) /*!< PC Readout protection of Sector3 */
453#define OB_PCROP_SECTOR_4 ((uint32_t)0x00000010U) /*!< PC Readout protection of Sector4 */
454#define OB_PCROP_SECTOR_5 ((uint32_t)0x00000020U) /*!< PC Readout protection of Sector5 */
455#define OB_PCROP_SECTOR_6 ((uint32_t)0x00000040U) /*!< PC Readout protection of Sector6 */
456#define OB_PCROP_SECTOR_7 ((uint32_t)0x00000080U) /*!< PC Readout protection of Sector7 */
457#define OB_PCROP_SECTOR_All ((uint32_t)0x000000FFU) /*!< PC Readout protection of all Sectors */
458/**
459 * @}
460 */
461
462/** @defgroup FLASHEx_Option_Bytes_PCROP_RDP FLASH Option Bytes PCROP_RDP Bit
463 * @{
464 */
465#define OB_PCROP_RDP_ENABLE ((uint32_t)0x80000000U) /*!< PCROP_RDP Enable */
466#define OB_PCROP_RDP_DISABLE ((uint32_t)0x00000000U) /*!< PCROP_RDP Disable */
467/**
468 * @}
469 */
470#endif /* FLASH_OPTCR2_PCROP */
471
472/**
473 * @}
474 */
475
476/* Exported macro ------------------------------------------------------------*/
477/** @defgroup FLASH_Exported_Macros FLASH Exported Macros
478 * @{
479 */
480/**
481 * @brief Calculate the FLASH Boot Base Adress (BOOT_ADD0 or BOOT_ADD1)
482 * @note Returned value BOOT_ADDx[15:0] corresponds to boot address [29:14].
483 * @param __ADDRESS__: FLASH Boot Address (in the range 0x0000 0000 to 0x2004 FFFF with a granularity of 16KB)
484 * @retval The FLASH Boot Base Adress
485 */
486#define __HAL_FLASH_CALC_BOOT_BASE_ADR(__ADDRESS__) ((__ADDRESS__) >> 14)
487 /**
488 * @}
489 */
490
491/* Exported functions --------------------------------------------------------*/
492/** @addtogroup FLASHEx_Exported_Functions
493 * @{
494 */
495
496/** @addtogroup FLASHEx_Exported_Functions_Group1
497 * @{
498 */
499/* Extension Program operation functions *************************************/
500HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError);
501HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit);
502HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
504
505/**
506 * @}
507 */
508
509/**
510 * @}
511 */
512/* Private types -------------------------------------------------------------*/
513/* Private variables ---------------------------------------------------------*/
514/* Private constants ---------------------------------------------------------*/
515/* Private macros ------------------------------------------------------------*/
516/** @defgroup FLASHEx_Private_Macros FLASH Private Macros
517 * @{
518 */
519
520/** @defgroup FLASHEx_IS_FLASH_Definitions FLASH Private macros to check input parameters
521 * @{
522 */
523
524#define IS_FLASH_TYPEERASE(VALUE)(((VALUE) == FLASH_TYPEERASE_SECTORS) || \
525 ((VALUE) == FLASH_TYPEERASE_MASSERASE))
526
527#define IS_VOLTAGERANGE(RANGE)(((RANGE) == FLASH_VOLTAGE_RANGE_1) || \
528 ((RANGE) == FLASH_VOLTAGE_RANGE_2) || \
529 ((RANGE) == FLASH_VOLTAGE_RANGE_3) || \
530 ((RANGE) == FLASH_VOLTAGE_RANGE_4))
531
532#define IS_WRPSTATE(VALUE)(((VALUE) == OB_WRPSTATE_DISABLE) || \
533 ((VALUE) == OB_WRPSTATE_ENABLE))
534
535#if defined (FLASH_OPTCR2_PCROP)
536#define IS_OPTIONBYTE(VALUE)(((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER |\
537 OPTIONBYTE_BOR | OPTIONBYTE_BOOTADDR_0 | OPTIONBYTE_BOOTADDR_1 |\
538 OPTIONBYTE_PCROP | OPTIONBYTE_PCROP_RDP)))
539#else
540#define IS_OPTIONBYTE(VALUE)(((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER |\
541 OPTIONBYTE_BOR | OPTIONBYTE_BOOTADDR_0 | OPTIONBYTE_BOOTADDR_1)))
542#endif /* FLASH_OPTCR2_PCROP */
543
544#define IS_OB_BOOT_ADDRESS(ADDRESS) ((ADDRESS) <= 0x8013)
545
546#define IS_OB_RDP_LEVEL(LEVEL) (((LEVEL) == OB_RDP_LEVEL_0) ||\
547 ((LEVEL) == OB_RDP_LEVEL_1) ||\
548 ((LEVEL) == OB_RDP_LEVEL_2))
549
550#define IS_OB_WWDG_SOURCE(SOURCE) (((SOURCE) == OB_WWDG_SW) || ((SOURCE) == OB_WWDG_HW))
551
552#define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
553
554#define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NO_RST) || ((SOURCE) == OB_STOP_RST))
555
556#define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NO_RST) || ((SOURCE) == OB_STDBY_RST))
557
558#define IS_OB_IWDG_STOP_FREEZE(FREEZE) (((FREEZE) == OB_IWDG_STOP_FREEZE) || ((FREEZE) == OB_IWDG_STOP_ACTIVE))
559
560#define IS_OB_IWDG_STDBY_FREEZE(FREEZE) (((FREEZE) == OB_IWDG_STDBY_FREEZE) || ((FREEZE) == OB_IWDG_STDBY_ACTIVE))
561
562#define IS_OB_BOR_LEVEL(LEVEL) (((LEVEL) == OB_BOR_LEVEL1) || ((LEVEL) == OB_BOR_LEVEL2) ||\
563 ((LEVEL) == OB_BOR_LEVEL3) || ((LEVEL) == OB_BOR_OFF))
564
565#define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_LATENCY_0) || \
566 ((LATENCY) == FLASH_LATENCY_1) || \
567 ((LATENCY) == FLASH_LATENCY_2) || \
568 ((LATENCY) == FLASH_LATENCY_3) || \
569 ((LATENCY) == FLASH_LATENCY_4) || \
570 ((LATENCY) == FLASH_LATENCY_5) || \
571 ((LATENCY) == FLASH_LATENCY_6) || \
572 ((LATENCY) == FLASH_LATENCY_7) || \
573 ((LATENCY) == FLASH_LATENCY_8) || \
574 ((LATENCY) == FLASH_LATENCY_9) || \
575 ((LATENCY) == FLASH_LATENCY_10) || \
576 ((LATENCY) == FLASH_LATENCY_11) || \
577 ((LATENCY) == FLASH_LATENCY_12) || \
578 ((LATENCY) == FLASH_LATENCY_13) || \
579 ((LATENCY) == FLASH_LATENCY_14) || \
580 ((LATENCY) == FLASH_LATENCY_15))
581
582#define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= FLASH_BASE) && ((ADDRESS) <= FLASH_END)) || \
583 (((ADDRESS) >= FLASH_OTP_BASE) && ((ADDRESS) <= FLASH_OTP_END)))
584#define IS_FLASH_NBSECTORS(NBSECTORS) (((NBSECTORS) != 0U) && ((NBSECTORS) <= FLASH_SECTOR_TOTAL))
585
586#if (FLASH_SECTOR_TOTAL == 8)
587#define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_SECTOR_0) || ((SECTOR) == FLASH_SECTOR_1) ||\
588 ((SECTOR) == FLASH_SECTOR_2) || ((SECTOR) == FLASH_SECTOR_3) ||\
589 ((SECTOR) == FLASH_SECTOR_4) || ((SECTOR) == FLASH_SECTOR_5) ||\
590 ((SECTOR) == FLASH_SECTOR_6) || ((SECTOR) == FLASH_SECTOR_7))
591
592#define IS_OB_WRP_SECTOR(SECTOR) ((((SECTOR) & 0xFF00FFFFU) == 0x00000000U) && ((SECTOR) != 0x00000000U))
593#endif /* FLASH_SECTOR_TOTAL == 8 */
594
595#if (FLASH_SECTOR_TOTAL == 24)
596#define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_SECTOR_0) || ((SECTOR) == FLASH_SECTOR_1) ||\
597 ((SECTOR) == FLASH_SECTOR_2) || ((SECTOR) == FLASH_SECTOR_3) ||\
598 ((SECTOR) == FLASH_SECTOR_4) || ((SECTOR) == FLASH_SECTOR_5) ||\
599 ((SECTOR) == FLASH_SECTOR_6) || ((SECTOR) == FLASH_SECTOR_7) ||\
600 ((SECTOR) == FLASH_SECTOR_8) || ((SECTOR) == FLASH_SECTOR_9) ||\
601 ((SECTOR) == FLASH_SECTOR_10) || ((SECTOR) == FLASH_SECTOR_11) ||\
602 ((SECTOR) == FLASH_SECTOR_12) || ((SECTOR) == FLASH_SECTOR_13) ||\
603 ((SECTOR) == FLASH_SECTOR_14) || ((SECTOR) == FLASH_SECTOR_15) ||\
604 ((SECTOR) == FLASH_SECTOR_16) || ((SECTOR) == FLASH_SECTOR_17) ||\
605 ((SECTOR) == FLASH_SECTOR_18) || ((SECTOR) == FLASH_SECTOR_19) ||\
606 ((SECTOR) == FLASH_SECTOR_20) || ((SECTOR) == FLASH_SECTOR_21) ||\
607 ((SECTOR) == FLASH_SECTOR_22) || ((SECTOR) == FLASH_SECTOR_23))
608
609#define IS_OB_WRP_SECTOR(SECTOR) ((((SECTOR) & 0xF000FFFFU) == 0x00000000U) && ((SECTOR) != 0x00000000U))
610#endif /* FLASH_SECTOR_TOTAL == 24 */
611
612#if defined (FLASH_OPTCR_nDBANK)
613#define IS_OB_NDBANK(VALUE) (((VALUE) == OB_NDBANK_SINGLE_BANK) || \
614 ((VALUE) == OB_NDBANK_DUAL_BANK))
615
616#define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1) || \
617 ((BANK) == FLASH_BANK_2) || \
618 ((BANK) == FLASH_BANK_BOTH))
619#endif /* FLASH_OPTCR_nDBANK */
620
621#if defined (FLASH_OPTCR_nDBOOT)
622#define IS_OB_NDBOOT(VALUE) (((VALUE) == OB_DUAL_BOOT_DISABLE) || \
623 ((VALUE) == OB_DUAL_BOOT_ENABLE))
624#endif /* FLASH_OPTCR_nDBOOT */
625
626#if defined (FLASH_OPTCR2_PCROP)
627#define IS_OB_PCROP_SECTOR(SECTOR) (((SECTOR) & (uint32_t)0xFFFFFF00U) == 0x00000000U)
628#define IS_OB_PCROP_RDP_VALUE(VALUE) (((VALUE) == OB_PCROP_RDP_DISABLE) || \
629 ((VALUE) == OB_PCROP_RDP_ENABLE))
630#endif /* FLASH_OPTCR2_PCROP */
631
632/**
633 * @}
634 */
635
636/**
637 * @}
638 */
639
640/* Private functions ---------------------------------------------------------*/
641/** @defgroup FLASHEx_Private_Functions FLASH Private Functions
642 * @{
643 */
644void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange);
645/**
646 * @}
647 */
648
649/**
650 * @}
651 */
652
653/**
654 * @}
655 */
656
657#ifdef __cplusplus
658}
659#endif
660
661#endif /* __STM32F7xx_HAL_FLASH_EX_H */
662
663/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
Program option bytes.
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError)
Perform a mass erase or erase the specified FLASH memory sectors.
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
Get the Option byte configuration.
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled.
void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange)
Erase the specified FLASH memory sector.
This file contains HAL common defines, enumeration, macros and structures definitions.
FLASH Option Bytes Program structure definition.