]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_flash_ex.h
Merge commit '4d116a04e94cf0d19317d5b44e4fa9f34a3e5594'
[max/tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F4 / stm32f4xx_hal_flash_ex.h
1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_flash_ex.h
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    19-June-2014
7   * @brief   Header file of FLASH HAL Extension module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2014 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 __STM32F4xx_HAL_FLASH_EX_H
40 #define __STM32F4xx_HAL_FLASH_EX_H
41
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal_def.h"
48
49 /** @addtogroup STM32F4xx_HAL_Driver
50   * @{
51   */
52
53 /** @addtogroup FLASHEx
54   * @{
55   */ 
56
57 /* Exported types ------------------------------------------------------------*/ 
58
59 /**
60   * @brief  FLASH Erase structure definition
61   */
62 typedef struct
63 {
64   uint32_t TypeErase;   /*!< Mass erase or sector Erase.
65                              This parameter can be a value of @ref FLASHEx_Type_Erase */
66
67   uint32_t Banks;       /*!< Select banks to erase when Mass erase is enabled.
68                              This parameter must be a value of @ref FLASHEx_Banks */        
69
70   uint32_t Sector;      /*!< Initial FLASH sector to erase when Mass erase is disabled
71                              This parameter must be a value of @ref FLASHEx_Sectors */        
72   
73   uint32_t NbSectors;   /*!< Number of sectors to be erased.
74                              This parameter must be a value between 1 and (max number of sectors - value of Initial sector)*/           
75                                                           
76   uint32_t VoltageRange;/*!< The device voltage range which defines the erase parallelism
77                              This parameter must be a value of @ref FLASHEx_Voltage_Range */        
78   
79 } FLASH_EraseInitTypeDef;
80
81 /**
82   * @brief  FLASH Option Bytes Program structure definition
83   */
84 typedef struct
85 {
86   uint32_t OptionType;   /*!< Option byte to be configured.
87                               This parameter can be a value of @ref FLASHEx_Option_Type */
88
89   uint32_t WRPState;     /*!< Write protection activation or deactivation.
90                               This parameter can be a value of @ref FLASHEx_WRP_State */
91
92   uint32_t WRPSector;         /*!< Specifies the sector(s) to be write protected.
93                               The value of this parameter depend on device used within the same series */
94
95   uint32_t Banks;        /*!< Select banks for WRP activation/deactivation of all sectors.
96                               This parameter must be a value of @ref FLASHEx_Banks */        
97
98   uint32_t RDPLevel;     /*!< Set the read protection level.
99                               This parameter can be a value of @ref FLASHEx_Option_Bytes_Read_Protection */
100
101   uint32_t BORLevel;     /*!< Set the BOR Level.
102                               This parameter can be a value of @ref FLASHEx_BOR_Reset_Level */
103
104   uint8_t  USERConfig;   /*!< Program the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY. */
105
106 } FLASH_OBProgramInitTypeDef;
107
108 /**
109   * @brief  FLASH Advanced Option Bytes Program structure definition
110   */
111 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
112     defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
113 typedef struct
114 {
115   uint32_t OptionType;     /*!< Option byte to be configured for extension.
116                                 This parameter can be a value of @ref FLASHEx_Advanced_Option_Type */
117
118   uint32_t PCROPState;     /*!< PCROP activation or deactivation.
119                                 This parameter can be a value of @ref FLASHEx_PCROP_State */
120
121 #if defined (STM32F401xC) || defined (STM32F401xE) || defined (STM32F411xE)
122   uint16_t Sectors;        /*!< specifies the sector(s) set for PCROP.
123                                 This parameter can be a value of @ref FLASHEx_Option_Bytes_PC_ReadWrite_Protection */
124 #endif /* STM32F401xC || STM32F401xE || STM32F411xE */
125
126 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
127   uint32_t Banks;          /*!< Select banks for PCROP activation/deactivation of all sectors.
128                                 This parameter must be a value of @ref FLASHEx_Banks */
129                                 
130   uint16_t SectorsBank1;   /*!< Specifies the sector(s) set for PCROP for Bank1.
131                                 This parameter can be a value of @ref FLASHEx_Option_Bytes_PC_ReadWrite_Protection */
132
133   uint16_t SectorsBank2;   /*!< Specifies the sector(s) set for PCROP for Bank2.
134                                 This parameter can be a value of @ref FLASHEx_Option_Bytes_PC_ReadWrite_Protection */
135   
136   uint8_t BootConfig;      /*!< Specifies Option bytes for boot config.
137                                 This parameter can be a value of @ref FLASHEx_Dual_Boot */
138   
139 #endif /*STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
140 } FLASH_AdvOBProgramInitTypeDef;
141 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F401xC || STM32F401xE || STM32F411xE */
142
143 /* Exported constants --------------------------------------------------------*/
144
145 /** @defgroup FLASHEx_Exported_Constants FLASH Exported Constants
146   * @{
147   */
148
149 /** @defgroup FLASHEx_Type_Erase FLASH Type Erase
150   * @{
151   */ 
152 #define TYPEERASE_SECTORS         ((uint32_t)0x00)  /*!< Sectors erase only          */
153 #define TYPEERASE_MASSERASE       ((uint32_t)0x01)  /*!< Flash Mass erase activation */
154
155 #define IS_TYPEERASE(VALUE)(((VALUE) == TYPEERASE_SECTORS) || \
156                                ((VALUE) == TYPEERASE_MASSERASE))  
157
158 /**
159   * @}
160   */
161   
162 /** @defgroup FLASHEx_Voltage_Range FLASH Voltage Range
163   * @{
164   */ 
165 #define VOLTAGE_RANGE_1        ((uint32_t)0x00)  /*!< Device operating range: 1.8V to 2.1V                */
166 #define VOLTAGE_RANGE_2        ((uint32_t)0x01)  /*!< Device operating range: 2.1V to 2.7V                */
167 #define VOLTAGE_RANGE_3        ((uint32_t)0x02)  /*!< Device operating range: 2.7V to 3.6V                */
168 #define VOLTAGE_RANGE_4        ((uint32_t)0x03)  /*!< Device operating range: 2.7V to 3.6V + External Vpp */
169
170 #define IS_VOLTAGERANGE(RANGE)(((RANGE) == VOLTAGE_RANGE_1) || \
171                                ((RANGE) == VOLTAGE_RANGE_2) || \
172                                ((RANGE) == VOLTAGE_RANGE_3) || \
173                                ((RANGE) == VOLTAGE_RANGE_4))  
174                               
175 /**
176   * @}
177   */
178   
179 /** @defgroup FLASHEx_WRP_State FLASH WRP State
180   * @{
181   */ 
182 #define WRPSTATE_DISABLE       ((uint32_t)0x00)  /*!< Disable the write protection of the desired bank 1 sectors */
183 #define WRPSTATE_ENABLE        ((uint32_t)0x01)  /*!< Enable the write protection of the desired bank 1 sectors  */
184
185 #define IS_WRPSTATE(VALUE)(((VALUE) == WRPSTATE_DISABLE) || \
186                            ((VALUE) == WRPSTATE_ENABLE))  
187
188 /**
189   * @}
190   */
191   
192 /** @defgroup FLASHEx_Option_Type FLASH Option Type
193   * @{
194   */ 
195 #define OPTIONBYTE_WRP        ((uint32_t)0x01)  /*!< WRP option byte configuration  */
196 #define OPTIONBYTE_RDP        ((uint32_t)0x02)  /*!< RDP option byte configuration  */
197 #define OPTIONBYTE_USER       ((uint32_t)0x04)  /*!< USER option byte configuration */
198 #define OPTIONBYTE_BOR        ((uint32_t)0x08)  /*!< BOR option byte configuration  */
199
200 #define IS_OPTIONBYTE(VALUE)(((VALUE) < (OPTIONBYTE_WRP|OPTIONBYTE_RDP|OPTIONBYTE_USER|OPTIONBYTE_BOR)))
201
202 /**
203   * @}
204   */
205   
206 /** @defgroup FLASHEx_Option_Bytes_Read_Protection FLASH Option Bytes Read Protection
207   * @{
208   */
209 #define OB_RDP_LEVEL_0   ((uint8_t)0xAA)
210 #define OB_RDP_LEVEL_1   ((uint8_t)0x55)
211 /*#define OB_RDP_LEVEL_2   ((uint8_t)0xCC)*/ /*!< Warning: When enabling read protection level 2 
212                                                   it s no more possible to go back to level 1 or 0 */
213 #define IS_OB_RDP_LEVEL(LEVEL) (((LEVEL) == OB_RDP_LEVEL_0)   ||\
214                                 ((LEVEL) == OB_RDP_LEVEL_1))/*||\
215                                 ((LEVEL) == OB_RDP_LEVEL_2))*/
216 /**
217   * @}
218   */ 
219   
220 /** @defgroup FLASHEx_Option_Bytes_IWatchdog FLASH Option Bytes IWatchdog
221   * @{
222   */ 
223 #define OB_IWDG_SW                     ((uint8_t)0x20)  /*!< Software IWDG selected */
224 #define OB_IWDG_HW                     ((uint8_t)0x00)  /*!< Hardware IWDG selected */
225 #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
226 /**
227   * @}
228   */ 
229   
230 /** @defgroup FLASHEx_Option_Bytes_nRST_STOP FLASH Option Bytes nRST_STOP
231   * @{
232   */ 
233 #define OB_STOP_NO_RST                 ((uint8_t)0x40) /*!< No reset generated when entering in STOP */
234 #define OB_STOP_RST                    ((uint8_t)0x00) /*!< Reset generated when entering in STOP    */
235 #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NO_RST) || ((SOURCE) == OB_STOP_RST))
236 /**
237   * @}
238   */ 
239
240
241 /** @defgroup FLASHEx_Option_Bytes_nRST_STDBY FLASH Option Bytes nRST_STDBY
242   * @{
243   */ 
244 #define OB_STDBY_NO_RST                ((uint8_t)0x80) /*!< No reset generated when entering in STANDBY */
245 #define OB_STDBY_RST                   ((uint8_t)0x00) /*!< Reset generated when entering in STANDBY    */
246 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NO_RST) || ((SOURCE) == OB_STDBY_RST))
247 /**
248   * @}
249   */    
250
251 /** @defgroup FLASHEx_BOR_Reset_Level FLASH BOR Reset Level
252   * @{
253   */  
254 #define OB_BOR_LEVEL3          ((uint8_t)0x00)  /*!< Supply voltage ranges from 2.70 to 3.60 V */
255 #define OB_BOR_LEVEL2          ((uint8_t)0x04)  /*!< Supply voltage ranges from 2.40 to 2.70 V */
256 #define OB_BOR_LEVEL1          ((uint8_t)0x08)  /*!< Supply voltage ranges from 2.10 to 2.40 V */
257 #define OB_BOR_OFF             ((uint8_t)0x0C)  /*!< Supply voltage ranges from 1.62 to 2.10 V */
258 #define IS_OB_BOR_LEVEL(LEVEL) (((LEVEL) == OB_BOR_LEVEL1) || ((LEVEL) == OB_BOR_LEVEL2) ||\
259                                 ((LEVEL) == OB_BOR_LEVEL3) || ((LEVEL) == OB_BOR_OFF))
260 /**
261   * @}
262   */
263
264 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
265     defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
266 /** @defgroup FLASHEx_PCROP_State FLASH PCROP State
267   * @{
268   */ 
269 #define PCROPSTATE_DISABLE       ((uint32_t)0x00)  /*!< Disable PCROP */
270 #define PCROPSTATE_ENABLE        ((uint32_t)0x01)  /*!< Enable PCROP  */
271   
272 #define IS_PCROPSTATE(VALUE)(((VALUE) == PCROPSTATE_DISABLE) || \
273                              ((VALUE) == PCROPSTATE_ENABLE))  
274   
275 /**
276   * @}
277   */
278 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F401xC || STM32F401xE || STM32F411xE */
279
280 /** @defgroup FLASHEx_Advanced_Option_Type FLASH Advanced Option Type
281   * @{
282   */ 
283 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
284 #define OBEX_PCROP        ((uint32_t)0x01)  /*!< PCROP option byte configuration      */
285 #define OBEX_BOOTCONFIG   ((uint32_t)0x02)  /*!< BOOTConfig option byte configuration */
286
287 #define IS_OBEX(VALUE)(((VALUE) == OBEX_PCROP) || \
288                        ((VALUE) == OBEX_BOOTCONFIG))  
289   
290 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
291
292 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
293 #define OBEX_PCROP        ((uint32_t)0x01)  /*!<PCROP option byte configuration */
294
295 #define IS_OBEX(VALUE)(((VALUE) == OBEX_PCROP))  
296   
297 #endif /* STM32F401xC || STM32F401xE || STM32F411xE */
298 /**
299   * @}
300   */
301
302 /** @defgroup FLASH_Latency FLASH Latency
303   * @{
304   */
305 /*------------------------------------------- STM32F42xxx/STM32F43xxx------------------------------------------*/  
306 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx)
307 #define FLASH_LATENCY_0                FLASH_ACR_LATENCY_0WS   /*!< FLASH Zero Latency cycle      */
308 #define FLASH_LATENCY_1                FLASH_ACR_LATENCY_1WS   /*!< FLASH One Latency cycle       */
309 #define FLASH_LATENCY_2                FLASH_ACR_LATENCY_2WS   /*!< FLASH Two Latency cycles      */
310 #define FLASH_LATENCY_3                FLASH_ACR_LATENCY_3WS   /*!< FLASH Three Latency cycles    */
311 #define FLASH_LATENCY_4                FLASH_ACR_LATENCY_4WS   /*!< FLASH Four Latency cycles     */
312 #define FLASH_LATENCY_5                FLASH_ACR_LATENCY_5WS   /*!< FLASH Five Latency cycles     */
313 #define FLASH_LATENCY_6                FLASH_ACR_LATENCY_6WS   /*!< FLASH Six Latency cycles      */
314 #define FLASH_LATENCY_7                FLASH_ACR_LATENCY_7WS   /*!< FLASH Seven Latency cycles    */
315 #define FLASH_LATENCY_8                FLASH_ACR_LATENCY_8WS   /*!< FLASH Eight Latency cycles    */
316 #define FLASH_LATENCY_9                FLASH_ACR_LATENCY_9WS   /*!< FLASH Nine Latency cycles     */
317 #define FLASH_LATENCY_10               FLASH_ACR_LATENCY_10WS  /*!< FLASH Ten Latency cycles      */
318 #define FLASH_LATENCY_11               FLASH_ACR_LATENCY_11WS  /*!< FLASH Eleven Latency cycles   */
319 #define FLASH_LATENCY_12               FLASH_ACR_LATENCY_12WS  /*!< FLASH Twelve Latency cycles   */
320 #define FLASH_LATENCY_13               FLASH_ACR_LATENCY_13WS  /*!< FLASH Thirteen Latency cycles */
321 #define FLASH_LATENCY_14               FLASH_ACR_LATENCY_14WS  /*!< FLASH Fourteen Latency cycles */
322 #define FLASH_LATENCY_15               FLASH_ACR_LATENCY_15WS  /*!< FLASH Fifteen Latency cycles  */
323
324
325 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_LATENCY_0)  || \
326                                    ((LATENCY) == FLASH_LATENCY_1)  || \
327                                    ((LATENCY) == FLASH_LATENCY_2)  || \
328                                    ((LATENCY) == FLASH_LATENCY_3)  || \
329                                    ((LATENCY) == FLASH_LATENCY_4)  || \
330                                    ((LATENCY) == FLASH_LATENCY_5)  || \
331                                    ((LATENCY) == FLASH_LATENCY_6)  || \
332                                    ((LATENCY) == FLASH_LATENCY_7)  || \
333                                    ((LATENCY) == FLASH_LATENCY_8)  || \
334                                    ((LATENCY) == FLASH_LATENCY_9)  || \
335                                    ((LATENCY) == FLASH_LATENCY_10) || \
336                                    ((LATENCY) == FLASH_LATENCY_11) || \
337                                    ((LATENCY) == FLASH_LATENCY_12) || \
338                                    ((LATENCY) == FLASH_LATENCY_13) || \
339                                    ((LATENCY) == FLASH_LATENCY_14) || \
340                                    ((LATENCY) == FLASH_LATENCY_15))
341 #endif /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
342 /*--------------------------------------------------------------------------------------------------------------*/
343
344 /*-------------------------- STM32F40xxx/STM32F41xxx/STM32F401xx/STM32F411xx -----------------------------------*/ 
345 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || \
346     defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
347      
348 #define FLASH_LATENCY_0                FLASH_ACR_LATENCY_0WS   /*!< FLASH Zero Latency cycle      */
349 #define FLASH_LATENCY_1                FLASH_ACR_LATENCY_1WS   /*!< FLASH One Latency cycle       */
350 #define FLASH_LATENCY_2                FLASH_ACR_LATENCY_2WS   /*!< FLASH Two Latency cycles      */
351 #define FLASH_LATENCY_3                FLASH_ACR_LATENCY_3WS   /*!< FLASH Three Latency cycles    */
352 #define FLASH_LATENCY_4                FLASH_ACR_LATENCY_4WS   /*!< FLASH Four Latency cycles     */
353 #define FLASH_LATENCY_5                FLASH_ACR_LATENCY_5WS   /*!< FLASH Five Latency cycles     */
354 #define FLASH_LATENCY_6                FLASH_ACR_LATENCY_6WS   /*!< FLASH Six Latency cycles      */
355 #define FLASH_LATENCY_7                FLASH_ACR_LATENCY_7WS   /*!< FLASH Seven Latency cycles    */
356
357
358 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_LATENCY_0)  || \
359                                    ((LATENCY) == FLASH_LATENCY_1)  || \
360                                    ((LATENCY) == FLASH_LATENCY_2)  || \
361                                    ((LATENCY) == FLASH_LATENCY_3)  || \
362                                    ((LATENCY) == FLASH_LATENCY_4)  || \
363                                    ((LATENCY) == FLASH_LATENCY_5)  || \
364                                    ((LATENCY) == FLASH_LATENCY_6)  || \
365                                    ((LATENCY) == FLASH_LATENCY_7))
366 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F401xC || STM32F401xE || STM32F411xE */
367 /*--------------------------------------------------------------------------------------------------------------*/
368
369 /**
370   * @}
371   */ 
372   
373
374 /** @defgroup FLASHEx_Banks FLASH Banks
375   * @{
376   */
377 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx)
378 #define FLASH_BANK_1     ((uint32_t)1) /*!< Bank 1   */
379 #define FLASH_BANK_2     ((uint32_t)2) /*!< Bank 2   */
380 #define FLASH_BANK_BOTH  ((uint32_t)FLASH_BANK_1 | FLASH_BANK_2) /*!< Bank1 and Bank2  */
381
382 #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1)  || \
383                              ((BANK) == FLASH_BANK_2)  || \
384                              ((BANK) == FLASH_BANK_BOTH))
385 #endif /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
386
387 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
388     defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
389 #define FLASH_BANK_1     ((uint32_t)1) /*!< Bank 1   */
390
391 #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1))
392 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F401xC || STM32F401xE || STM32F411xE */
393 /**
394   * @}
395   */ 
396     
397 /** @defgroup FLASHEx_MassErase_bit FLASH Mass Erase bit
398   * @{
399   */
400 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx)
401 #define FLASH_MER_BIT     (FLASH_CR_MER1 | FLASH_CR_MER2) /*!< 2 MER bits here to clear */
402 #endif /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
403
404 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
405     defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
406 #define FLASH_MER_BIT     (FLASH_CR_MER) /*!< only 1 MER Bit */
407 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F401xC || STM32F401xE || STM32F411xE */
408 /**
409   * @}
410   */ 
411
412 /** @defgroup FLASHEx_Sectors FLASH Sectors
413   * @{
414   */
415 /*------------------------------------------ STM32F42xxx/STM32F43xxx--------------------------------------*/   
416 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx)
417 #define FLASH_SECTOR_0     ((uint32_t)0)  /*!< Sector Number 0   */
418 #define FLASH_SECTOR_1     ((uint32_t)1)  /*!< Sector Number 1   */
419 #define FLASH_SECTOR_2     ((uint32_t)2)  /*!< Sector Number 2   */
420 #define FLASH_SECTOR_3     ((uint32_t)3)  /*!< Sector Number 3   */
421 #define FLASH_SECTOR_4     ((uint32_t)4)  /*!< Sector Number 4   */
422 #define FLASH_SECTOR_5     ((uint32_t)5)  /*!< Sector Number 5   */
423 #define FLASH_SECTOR_6     ((uint32_t)6)  /*!< Sector Number 6   */
424 #define FLASH_SECTOR_7     ((uint32_t)7)  /*!< Sector Number 7   */
425 #define FLASH_SECTOR_8     ((uint32_t)8)  /*!< Sector Number 8   */
426 #define FLASH_SECTOR_9     ((uint32_t)9)  /*!< Sector Number 9   */
427 #define FLASH_SECTOR_10    ((uint32_t)10) /*!< Sector Number 10  */
428 #define FLASH_SECTOR_11    ((uint32_t)11) /*!< Sector Number 11  */
429 #define FLASH_SECTOR_12    ((uint32_t)12) /*!< Sector Number 12  */
430 #define FLASH_SECTOR_13    ((uint32_t)13) /*!< Sector Number 13  */
431 #define FLASH_SECTOR_14    ((uint32_t)14) /*!< Sector Number 14  */
432 #define FLASH_SECTOR_15    ((uint32_t)15) /*!< Sector Number 15  */
433 #define FLASH_SECTOR_16    ((uint32_t)16) /*!< Sector Number 16  */
434 #define FLASH_SECTOR_17    ((uint32_t)17) /*!< Sector Number 17  */
435 #define FLASH_SECTOR_18    ((uint32_t)18) /*!< Sector Number 18  */
436 #define FLASH_SECTOR_19    ((uint32_t)19) /*!< Sector Number 19  */
437 #define FLASH_SECTOR_20    ((uint32_t)20) /*!< Sector Number 20  */
438 #define FLASH_SECTOR_21    ((uint32_t)21) /*!< Sector Number 21  */
439 #define FLASH_SECTOR_22    ((uint32_t)22) /*!< Sector Number 22  */
440 #define FLASH_SECTOR_23    ((uint32_t)23) /*!< Sector Number 23  */
441
442 #define FLASH_SECTOR_TOTAL  24
443
444 #define IS_FLASH_SECTOR(SECTOR) ( ((SECTOR) == FLASH_SECTOR_0)   || ((SECTOR) == FLASH_SECTOR_1)   ||\
445                                   ((SECTOR) == FLASH_SECTOR_2)   || ((SECTOR) == FLASH_SECTOR_3)   ||\
446                                   ((SECTOR) == FLASH_SECTOR_4)   || ((SECTOR) == FLASH_SECTOR_5)   ||\
447                                   ((SECTOR) == FLASH_SECTOR_6)   || ((SECTOR) == FLASH_SECTOR_7)   ||\
448                                   ((SECTOR) == FLASH_SECTOR_8)   || ((SECTOR) == FLASH_SECTOR_9)   ||\
449                                   ((SECTOR) == FLASH_SECTOR_10)  || ((SECTOR) == FLASH_SECTOR_11)  ||\
450                                   ((SECTOR) == FLASH_SECTOR_12)  || ((SECTOR) == FLASH_SECTOR_13)  ||\
451                                   ((SECTOR) == FLASH_SECTOR_14)  || ((SECTOR) == FLASH_SECTOR_15)  ||\
452                                   ((SECTOR) == FLASH_SECTOR_16)  || ((SECTOR) == FLASH_SECTOR_17)  ||\
453                                   ((SECTOR) == FLASH_SECTOR_18)  || ((SECTOR) == FLASH_SECTOR_19)  ||\
454                                   ((SECTOR) == FLASH_SECTOR_20)  || ((SECTOR) == FLASH_SECTOR_21)  ||\
455                                   ((SECTOR) == FLASH_SECTOR_22)  || ((SECTOR) == FLASH_SECTOR_23))
456 #endif /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
457 /*-----------------------------------------------------------------------------------------------------*/  
458
459 /*--------------------------------------- STM32F40xxx/STM32F41xxx -------------------------------------*/ 
460 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)
461 #define FLASH_SECTOR_0     ((uint32_t)0)  /*!< Sector Number 0   */
462 #define FLASH_SECTOR_1     ((uint32_t)1)  /*!< Sector Number 1   */
463 #define FLASH_SECTOR_2     ((uint32_t)2)  /*!< Sector Number 2   */
464 #define FLASH_SECTOR_3     ((uint32_t)3)  /*!< Sector Number 3   */
465 #define FLASH_SECTOR_4     ((uint32_t)4)  /*!< Sector Number 4   */
466 #define FLASH_SECTOR_5     ((uint32_t)5)  /*!< Sector Number 5   */
467 #define FLASH_SECTOR_6     ((uint32_t)6)  /*!< Sector Number 6   */
468 #define FLASH_SECTOR_7     ((uint32_t)7)  /*!< Sector Number 7   */
469 #define FLASH_SECTOR_8     ((uint32_t)8)  /*!< Sector Number 8   */
470 #define FLASH_SECTOR_9     ((uint32_t)9)  /*!< Sector Number 9   */
471 #define FLASH_SECTOR_10    ((uint32_t)10) /*!< Sector Number 10  */
472 #define FLASH_SECTOR_11    ((uint32_t)11) /*!< Sector Number 11  */
473
474 #define FLASH_SECTOR_TOTAL  12
475
476 #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_SECTOR_0)   || ((SECTOR) == FLASH_SECTOR_1)   ||\
477                                  ((SECTOR) == FLASH_SECTOR_2)   || ((SECTOR) == FLASH_SECTOR_3)   ||\
478                                  ((SECTOR) == FLASH_SECTOR_4)   || ((SECTOR) == FLASH_SECTOR_5)   ||\
479                                  ((SECTOR) == FLASH_SECTOR_6)   || ((SECTOR) == FLASH_SECTOR_7)   ||\
480                                  ((SECTOR) == FLASH_SECTOR_8)   || ((SECTOR) == FLASH_SECTOR_9)   ||\
481                                  ((SECTOR) == FLASH_SECTOR_10)  || ((SECTOR) == FLASH_SECTOR_11))
482 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx */
483 /*-----------------------------------------------------------------------------------------------------*/
484
485 /*--------------------------------------------- STM32F401xC -------------------------------------------*/ 
486 #if defined(STM32F401xC)
487 #define FLASH_SECTOR_0     ((uint32_t)0) /*!< Sector Number 0   */
488 #define FLASH_SECTOR_1     ((uint32_t)1) /*!< Sector Number 1   */
489 #define FLASH_SECTOR_2     ((uint32_t)2) /*!< Sector Number 2   */
490 #define FLASH_SECTOR_3     ((uint32_t)3) /*!< Sector Number 3   */
491 #define FLASH_SECTOR_4     ((uint32_t)4) /*!< Sector Number 4   */
492 #define FLASH_SECTOR_5     ((uint32_t)5) /*!< Sector Number 5   */
493
494 #define FLASH_SECTOR_TOTAL  6
495
496 #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_SECTOR_0)   || ((SECTOR) == FLASH_SECTOR_1)   ||\
497                                  ((SECTOR) == FLASH_SECTOR_2)   || ((SECTOR) == FLASH_SECTOR_3)   ||\
498                                  ((SECTOR) == FLASH_SECTOR_4)   || ((SECTOR) == FLASH_SECTOR_5))
499 #endif /* STM32F401xC */
500 /*-----------------------------------------------------------------------------------------------------*/
501
502 /*--------------------------------------- STM32F401xE/STM32F411xE -------------------------------------*/
503 #if defined(STM32F401xE) || defined(STM32F411xE)
504 #define FLASH_SECTOR_0     ((uint32_t)0) /*!< Sector Number 0   */
505 #define FLASH_SECTOR_1     ((uint32_t)1) /*!< Sector Number 1   */
506 #define FLASH_SECTOR_2     ((uint32_t)2) /*!< Sector Number 2   */
507 #define FLASH_SECTOR_3     ((uint32_t)3) /*!< Sector Number 3   */
508 #define FLASH_SECTOR_4     ((uint32_t)4) /*!< Sector Number 4   */
509 #define FLASH_SECTOR_5     ((uint32_t)5) /*!< Sector Number 5   */
510 #define FLASH_SECTOR_6     ((uint32_t)6) /*!< Sector Number 6   */
511 #define FLASH_SECTOR_7     ((uint32_t)7) /*!< Sector Number 7   */
512
513 #define FLASH_SECTOR_TOTAL  8
514
515 #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_SECTOR_0)   || ((SECTOR) == FLASH_SECTOR_1)   ||\
516                                  ((SECTOR) == FLASH_SECTOR_2)   || ((SECTOR) == FLASH_SECTOR_3)   ||\
517                                  ((SECTOR) == FLASH_SECTOR_4)   || ((SECTOR) == FLASH_SECTOR_5)   ||\
518                                  ((SECTOR) == FLASH_SECTOR_6)   || ((SECTOR) == FLASH_SECTOR_7))
519 #endif /* STM32F401xE || STM32F411xE */
520 /*-----------------------------------------------------------------------------------------------------*/
521 #define IS_FLASH_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && ((ADDRESS) < FLASH_END))
522 #define IS_NBSECTORS(NBSECTORS) (((NBSECTORS) != 0) && ((NBSECTORS) <= FLASH_SECTOR_TOTAL))
523
524 /**
525   * @}
526   */ 
527
528 /** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASH Option Bytes Write Protection
529   * @{
530   */
531 /*----------------------------------------- STM32F42xxx/STM32F43xxx-------------------------------------*/  
532 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) 
533 #define OB_WRP_SECTOR_0       ((uint32_t)0x00000001) /*!< Write protection of Sector0     */
534 #define OB_WRP_SECTOR_1       ((uint32_t)0x00000002) /*!< Write protection of Sector1     */
535 #define OB_WRP_SECTOR_2       ((uint32_t)0x00000004) /*!< Write protection of Sector2     */
536 #define OB_WRP_SECTOR_3       ((uint32_t)0x00000008) /*!< Write protection of Sector3     */
537 #define OB_WRP_SECTOR_4       ((uint32_t)0x00000010) /*!< Write protection of Sector4     */
538 #define OB_WRP_SECTOR_5       ((uint32_t)0x00000020) /*!< Write protection of Sector5     */
539 #define OB_WRP_SECTOR_6       ((uint32_t)0x00000040) /*!< Write protection of Sector6     */
540 #define OB_WRP_SECTOR_7       ((uint32_t)0x00000080) /*!< Write protection of Sector7     */
541 #define OB_WRP_SECTOR_8       ((uint32_t)0x00000100) /*!< Write protection of Sector8     */
542 #define OB_WRP_SECTOR_9       ((uint32_t)0x00000200) /*!< Write protection of Sector9     */
543 #define OB_WRP_SECTOR_10      ((uint32_t)0x00000400) /*!< Write protection of Sector10    */
544 #define OB_WRP_SECTOR_11      ((uint32_t)0x00000800) /*!< Write protection of Sector11    */
545 #define OB_WRP_SECTOR_12      ((uint32_t)0x00000001 << 12) /*!< Write protection of Sector12    */
546 #define OB_WRP_SECTOR_13      ((uint32_t)0x00000002 << 12) /*!< Write protection of Sector13    */
547 #define OB_WRP_SECTOR_14      ((uint32_t)0x00000004 << 12) /*!< Write protection of Sector14    */
548 #define OB_WRP_SECTOR_15      ((uint32_t)0x00000008 << 12) /*!< Write protection of Sector15    */
549 #define OB_WRP_SECTOR_16      ((uint32_t)0x00000010 << 12) /*!< Write protection of Sector16    */
550 #define OB_WRP_SECTOR_17      ((uint32_t)0x00000020 << 12) /*!< Write protection of Sector17    */
551 #define OB_WRP_SECTOR_18      ((uint32_t)0x00000040 << 12) /*!< Write protection of Sector18    */
552 #define OB_WRP_SECTOR_19      ((uint32_t)0x00000080 << 12) /*!< Write protection of Sector19    */
553 #define OB_WRP_SECTOR_20      ((uint32_t)0x00000100 << 12) /*!< Write protection of Sector20    */
554 #define OB_WRP_SECTOR_21      ((uint32_t)0x00000200 << 12) /*!< Write protection of Sector21    */
555 #define OB_WRP_SECTOR_22      ((uint32_t)0x00000400 << 12) /*!< Write protection of Sector22    */
556 #define OB_WRP_SECTOR_23      ((uint32_t)0x00000800 << 12) /*!< Write protection of Sector23    */
557 #define OB_WRP_SECTOR_All     ((uint32_t)0x00000FFF << 12) /*!< Write protection of all Sectors */
558
559 #define IS_OB_WRP_SECTOR(SECTOR)((((SECTOR) & (uint32_t)0xFF000000) == 0x00000000) && ((SECTOR) != 0x00000000))
560 #endif /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
561 /*-----------------------------------------------------------------------------------------------------*/
562
563 /*--------------------------------------- STM32F40xxx/STM32F41xxx -------------------------------------*/ 
564 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx)
565 #define OB_WRP_SECTOR_0       ((uint32_t)0x00000001) /*!< Write protection of Sector0     */
566 #define OB_WRP_SECTOR_1       ((uint32_t)0x00000002) /*!< Write protection of Sector1     */
567 #define OB_WRP_SECTOR_2       ((uint32_t)0x00000004) /*!< Write protection of Sector2     */
568 #define OB_WRP_SECTOR_3       ((uint32_t)0x00000008) /*!< Write protection of Sector3     */
569 #define OB_WRP_SECTOR_4       ((uint32_t)0x00000010) /*!< Write protection of Sector4     */
570 #define OB_WRP_SECTOR_5       ((uint32_t)0x00000020) /*!< Write protection of Sector5     */
571 #define OB_WRP_SECTOR_6       ((uint32_t)0x00000040) /*!< Write protection of Sector6     */
572 #define OB_WRP_SECTOR_7       ((uint32_t)0x00000080) /*!< Write protection of Sector7     */
573 #define OB_WRP_SECTOR_8       ((uint32_t)0x00000100) /*!< Write protection of Sector8     */
574 #define OB_WRP_SECTOR_9       ((uint32_t)0x00000200) /*!< Write protection of Sector9     */
575 #define OB_WRP_SECTOR_10      ((uint32_t)0x00000400) /*!< Write protection of Sector10    */
576 #define OB_WRP_SECTOR_11      ((uint32_t)0x00000800) /*!< Write protection of Sector11    */
577 #define OB_WRP_SECTOR_All     ((uint32_t)0x00000FFF) /*!< Write protection of all Sectors */
578
579 #define IS_OB_WRP_SECTOR(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
580 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx */
581 /*-----------------------------------------------------------------------------------------------------*/
582
583 /*--------------------------------------------- STM32F401xC -------------------------------------------*/
584 #if defined(STM32F401xC)
585 #define OB_WRP_SECTOR_0       ((uint32_t)0x00000001) /*!< Write protection of Sector0     */
586 #define OB_WRP_SECTOR_1       ((uint32_t)0x00000002) /*!< Write protection of Sector1     */
587 #define OB_WRP_SECTOR_2       ((uint32_t)0x00000004) /*!< Write protection of Sector2     */
588 #define OB_WRP_SECTOR_3       ((uint32_t)0x00000008) /*!< Write protection of Sector3     */
589 #define OB_WRP_SECTOR_4       ((uint32_t)0x00000010) /*!< Write protection of Sector4     */
590 #define OB_WRP_SECTOR_5       ((uint32_t)0x00000020) /*!< Write protection of Sector5     */
591 #define OB_WRP_SECTOR_All     ((uint32_t)0x00000FFF) /*!< Write protection of all Sectors */
592
593 #define IS_OB_WRP_SECTOR(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
594 #endif /* STM32F401xC */
595 /*-----------------------------------------------------------------------------------------------------*/
596
597 /*--------------------------------------- STM32F401xE/STM32F411xE -------------------------------------*/
598 #if defined(STM32F401xE) || defined(STM32F411xE)
599 #define OB_WRP_SECTOR_0       ((uint32_t)0x00000001) /*!< Write protection of Sector0     */
600 #define OB_WRP_SECTOR_1       ((uint32_t)0x00000002) /*!< Write protection of Sector1     */
601 #define OB_WRP_SECTOR_2       ((uint32_t)0x00000004) /*!< Write protection of Sector2     */
602 #define OB_WRP_SECTOR_3       ((uint32_t)0x00000008) /*!< Write protection of Sector3     */
603 #define OB_WRP_SECTOR_4       ((uint32_t)0x00000010) /*!< Write protection of Sector4     */
604 #define OB_WRP_SECTOR_5       ((uint32_t)0x00000020) /*!< Write protection of Sector5     */
605 #define OB_WRP_SECTOR_6       ((uint32_t)0x00000040) /*!< Write protection of Sector6     */
606 #define OB_WRP_SECTOR_7       ((uint32_t)0x00000080) /*!< Write protection of Sector7     */
607 #define OB_WRP_SECTOR_All     ((uint32_t)0x00000FFF) /*!< Write protection of all Sectors */
608
609 #define IS_OB_WRP_SECTOR(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
610 #endif /* STM32F401xE || STM32F411xE */
611 /*-----------------------------------------------------------------------------------------------------*/
612 /**
613   * @}
614   */
615   
616 /** @defgroup FLASHEx_Option_Bytes_PC_ReadWrite_Protection FLASH Option Bytes PC ReadWrite Protection
617   * @{
618   */
619 /*----------------------------------------- STM32F42xxx/STM32F43xxx-------------------------------------*/   
620 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) 
621 #define OB_PCROP_SECTOR_0        ((uint32_t)0x00000001) /*!< PC Read/Write protection of Sector0      */
622 #define OB_PCROP_SECTOR_1        ((uint32_t)0x00000002) /*!< PC Read/Write protection of Sector1      */
623 #define OB_PCROP_SECTOR_2        ((uint32_t)0x00000004) /*!< PC Read/Write protection of Sector2      */
624 #define OB_PCROP_SECTOR_3        ((uint32_t)0x00000008) /*!< PC Read/Write protection of Sector3      */
625 #define OB_PCROP_SECTOR_4        ((uint32_t)0x00000010) /*!< PC Read/Write protection of Sector4      */
626 #define OB_PCROP_SECTOR_5        ((uint32_t)0x00000020) /*!< PC Read/Write protection of Sector5      */
627 #define OB_PCROP_SECTOR_6        ((uint32_t)0x00000040) /*!< PC Read/Write protection of Sector6      */
628 #define OB_PCROP_SECTOR_7        ((uint32_t)0x00000080) /*!< PC Read/Write protection of Sector7      */
629 #define OB_PCROP_SECTOR_8        ((uint32_t)0x00000100) /*!< PC Read/Write protection of Sector8      */
630 #define OB_PCROP_SECTOR_9        ((uint32_t)0x00000200) /*!< PC Read/Write protection of Sector9      */
631 #define OB_PCROP_SECTOR_10       ((uint32_t)0x00000400) /*!< PC Read/Write protection of Sector10     */
632 #define OB_PCROP_SECTOR_11       ((uint32_t)0x00000800) /*!< PC Read/Write protection of Sector11     */
633 #define OB_PCROP_SECTOR_12       ((uint32_t)0x00000001) /*!< PC Read/Write protection of Sector12     */
634 #define OB_PCROP_SECTOR_13       ((uint32_t)0x00000002) /*!< PC Read/Write protection of Sector13     */
635 #define OB_PCROP_SECTOR_14       ((uint32_t)0x00000004) /*!< PC Read/Write protection of Sector14     */
636 #define OB_PCROP_SECTOR_15       ((uint32_t)0x00000008) /*!< PC Read/Write protection of Sector15     */
637 #define OB_PCROP_SECTOR_16       ((uint32_t)0x00000010) /*!< PC Read/Write protection of Sector16     */
638 #define OB_PCROP_SECTOR_17       ((uint32_t)0x00000020) /*!< PC Read/Write protection of Sector17     */
639 #define OB_PCROP_SECTOR_18       ((uint32_t)0x00000040) /*!< PC Read/Write protection of Sector18     */
640 #define OB_PCROP_SECTOR_19       ((uint32_t)0x00000080) /*!< PC Read/Write protection of Sector19     */
641 #define OB_PCROP_SECTOR_20       ((uint32_t)0x00000100) /*!< PC Read/Write protection of Sector20     */
642 #define OB_PCROP_SECTOR_21       ((uint32_t)0x00000200) /*!< PC Read/Write protection of Sector21     */
643 #define OB_PCROP_SECTOR_22       ((uint32_t)0x00000400) /*!< PC Read/Write protection of Sector22     */
644 #define OB_PCROP_SECTOR_23       ((uint32_t)0x00000800) /*!< PC Read/Write protection of Sector23     */
645 #define OB_PCROP_SECTOR_All      ((uint32_t)0x00000FFF) /*!< PC Read/Write protection of all Sectors  */
646
647 #define IS_OB_PCROP(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
648 #endif /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
649 /*-----------------------------------------------------------------------------------------------------*/
650
651 /*--------------------------------------------- STM32F401xC -------------------------------------------*/
652 #if defined(STM32F401xC)
653 #define OB_PCROP_SECTOR_0        ((uint32_t)0x00000001) /*!< PC Read/Write protection of Sector0      */
654 #define OB_PCROP_SECTOR_1        ((uint32_t)0x00000002) /*!< PC Read/Write protection of Sector1      */
655 #define OB_PCROP_SECTOR_2        ((uint32_t)0x00000004) /*!< PC Read/Write protection of Sector2      */
656 #define OB_PCROP_SECTOR_3        ((uint32_t)0x00000008) /*!< PC Read/Write protection of Sector3      */
657 #define OB_PCROP_SECTOR_4        ((uint32_t)0x00000010) /*!< PC Read/Write protection of Sector4      */
658 #define OB_PCROP_SECTOR_5        ((uint32_t)0x00000020) /*!< PC Read/Write protection of Sector5      */
659 #define OB_PCROP_SECTOR_All      ((uint32_t)0x00000FFF) /*!< PC Read/Write protection of all Sectors  */
660
661 #define IS_OB_PCROP(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
662 #endif /* STM32F401xC */
663 /*-----------------------------------------------------------------------------------------------------*/
664
665 /*--------------------------------------- STM32F401xE/STM32F411xE -------------------------------------*/
666 #if defined(STM32F401xE) || defined(STM32F411xE)
667 #define OB_PCROP_SECTOR_0        ((uint32_t)0x00000001) /*!< PC Read/Write protection of Sector0      */
668 #define OB_PCROP_SECTOR_1        ((uint32_t)0x00000002) /*!< PC Read/Write protection of Sector1      */
669 #define OB_PCROP_SECTOR_2        ((uint32_t)0x00000004) /*!< PC Read/Write protection of Sector2      */
670 #define OB_PCROP_SECTOR_3        ((uint32_t)0x00000008) /*!< PC Read/Write protection of Sector3      */
671 #define OB_PCROP_SECTOR_4        ((uint32_t)0x00000010) /*!< PC Read/Write protection of Sector4      */
672 #define OB_PCROP_SECTOR_5        ((uint32_t)0x00000020) /*!< PC Read/Write protection of Sector5      */
673 #define OB_PCROP_SECTOR_6        ((uint32_t)0x00000040) /*!< PC Read/Write protection of Sector6      */
674 #define OB_PCROP_SECTOR_7        ((uint32_t)0x00000080) /*!< PC Read/Write protection of Sector7      */
675 #define OB_PCROP_SECTOR_All      ((uint32_t)0x00000FFF) /*!< PC Read/Write protection of all Sectors  */
676
677 #define IS_OB_PCROP(SECTOR)((((SECTOR) & (uint32_t)0xFFFFF000) == 0x00000000) && ((SECTOR) != 0x00000000))
678 #endif /* STM32F401xE || STM32F411xE */
679 /*-----------------------------------------------------------------------------------------------------*/
680
681 /**
682   * @}
683   */
684   
685 /** @defgroup FLASHEx_Dual_Boot FLASH Dual Boot
686   * @{
687   */
688 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) 
689 #define OB_DUAL_BOOT_ENABLE   ((uint8_t)0x10) /*!< Dual Bank Boot Enable                             */
690 #define OB_DUAL_BOOT_DISABLE  ((uint8_t)0x00) /*!< Dual Bank Boot Disable, always boot on User Flash */
691 #define IS_OB_BOOT(BOOT) (((BOOT) == OB_DUAL_BOOT_ENABLE) || ((BOOT) == OB_DUAL_BOOT_DISABLE))
692 #endif /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
693 /**
694   * @}
695   */
696
697 /** @defgroup  FLASHEx_Selection_Protection_Mode FLASH Selection Protection Mode
698   * @{
699   */
700 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
701     defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
702 #define OB_PCROP_DESELECTED     ((uint8_t)0x00) /*!< Disabled PcROP, nWPRi bits used for Write Protection on sector i */
703 #define OB_PCROP_SELECTED       ((uint8_t)0x80) /*!< Enable PcROP, nWPRi bits used for PCRoP Protection on sector i   */
704 #define IS_OB_PCROP_SELECT(PCROP) (((PCROP) == OB_PCROP_SELECTED) || ((PCROP) == OB_PCROP_DESELECTED))
705 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F401xC || STM32F401xE || STM32F411xE */
706 /**
707   * @}
708   */
709   
710 /** 
711   * @brief   OPTCR1 register byte 2 (Bits[23:16]) base address  
712   */ 
713 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx)  
714 #define OPTCR1_BYTE2_ADDRESS         ((uint32_t)0x40023C1A)
715 #endif /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
716
717 /**
718   * @}
719   */ 
720   
721 /* Exported macro ------------------------------------------------------------*/
722
723 /* Exported functions --------------------------------------------------------*/
724
725 /* Extension Program operation functions  *************************************/
726 HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError);
727 HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit);
728 HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
729 void              HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit);
730
731 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
732     defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
733 HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram (FLASH_AdvOBProgramInitTypeDef *pAdvOBInit);
734 void              HAL_FLASHEx_AdvOBGetConfig(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit);
735 HAL_StatusTypeDef HAL_FLASHEx_OB_SelectPCROP(void);
736 HAL_StatusTypeDef HAL_FLASHEx_OB_DeSelectPCROP(void);
737 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F401xC || STM32F401xE || STM32F411xE */
738
739 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx)
740 uint16_t          HAL_FLASHEx_OB_GetBank2WRP(void);
741 #endif /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
742
743 void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange);
744
745 /**
746   * @}
747   */ 
748
749 /**
750   * @}
751   */
752
753 #ifdef __cplusplus
754 }
755 #endif
756
757 #endif /* __STM32F4xx_HAL_FLASH_EX_H */
758
759 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/