]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_flash_ex.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32L0 / stm32l0xx_hal_flash_ex.h
1 /**
2 ******************************************************************************
3 * @file stm32l0xx_hal_flash_ex.h
4 * @author MCD Application Team
5 * @version V1.2.0
6 * @date 06-February-2015
7 * @brief Header file of FLash HAL Extension module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2015 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 __STM32L0xx_HAL_FLASH_EX_H
40 #define __STM32L0xx_HAL_FLASH_EX_H
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32l0xx_hal_def.h"
48
49 /** @addtogroup STM32L0xx_HAL_Driver
50 * @{
51 */
52
53 /** @defgroup FLASHEx FLASHEx
54 * @{
55 */
56
57 /** @defgroup FLASHEx_Exported_Types FLASH Exported Types
58 * @{
59 */
60
61 /**
62 * @brief FLASH Option Bytes PROGRAM structure definition
63 */
64 typedef struct
65 {
66 uint32_t OptionType; /*!< OptionType: Option byte to be configured.
67 This parameter can be a value of @ref FLASHEx_Option_Type */
68
69 uint32_t WRPState; /*!< WRPState: Write protection activation or deactivation.
70 This parameter can be a value of @ref FLASHEx_WRP_State */
71
72 uint32_t WRPSector; /*!< WRPSector: This bitfield specifies the sector (s) which are write protected.
73 This parameter can be a combination of @ref FLASHEx_Option_Bytes_Write_Protection */
74
75 #if defined(STM32L071xx) || defined(STM32L072xx) || defined(STM32L073xx) || defined(STM32L081xx) || defined(STM32L082xx) || defined(STM32L083xx)
76 uint32_t WRPSector2; /*!< WRPSector2 : This bitfield specifies the sector(s) upper Sector31 which are write protected.
77 This parameter can be a combination of @ref FLASHEx_Option_Bytes_Write_Protection2 */
78 #endif
79
80 uint8_t RDPLevel; /*!< RDPLevel: Set the read protection level.
81 This parameter can be a value of @ref FLASHEx_Option_Bytes_Read_Protection */
82
83 uint8_t BORLevel; /*!< BORLevel: Set the BOR Level.
84 This parameter can be a value of @ref FLASHEx_Option_Bytes_BOR_Level */
85
86 uint8_t USERConfig; /*!< USERConfig: Program the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
87 This parameter can be a combination of @ref FLASHEx_Option_Bytes_IWatchdog,
88 @ref FLASHEx_Option_Bytes_nRST_STOP and @ref FLASHEx_Option_Bytes_nRST_STDBY */
89
90 uint8_t BOOTBit1Config; /*!< BOOT1Config: Together with input pad Boot0, this bit selects the boot source, flash, ram or system memory
91 This parameter can be a value of @ref FLASHEx_Option_Bytes_BOOTBit1 */
92
93 } FLASH_OBProgramInitTypeDef;
94
95 /**
96 * @brief FLASH Advanced Option Bytes Program structure definition
97 */
98 typedef struct
99 {
100 uint32_t OptionType; /*!< OptionType: Option byte to be configured for extension .
101 This parameter can be a value of @ref FLASHEx_OptionAdv_Type */
102
103 uint8_t PCROPState; /*!< PCROPState: PCROP activation or deactivation.
104 This parameter can be a value of @ref FLASHEx_PCROP_State */
105
106 uint32_t PCROPSector; /*!< PCROPSector : This bitfield specifies the sector(s) which are read/write protected.
107 This parameter can be a combination of @ref FLASHEx_Option_Bytes_PC_ReadWrite_Protection */
108
109 #if defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
110 uint32_t PCROPSector2; /*!< PCROPSector : This bitfield specifies the sector(s) upper Sector31 which are read/write protected.
111 This parameter can be a combination of @ref FLASHEx_Option_Bytes_PC_ReadWrite_Protection2 */
112
113 uint8_t BootConfig; /*!< BootConfig: specifies Option bytes for boot config.
114 This parameter can be a value of @ref FLASHEx_Option_Bytes_BOOT_BANK */
115 #endif /* if STM32L071xx || STM32L072xx || STM32L073xx || STM32L081xx || STM32L082xx || STM32L083xx */
116 } FLASH_AdvOBProgramInitTypeDef;
117
118 /**
119 * @}
120 */
121
122 /** @defgroup FLASHEx_Exported_Constants FLASHEx Exported Constants
123 * @{
124 */
125
126 /** @defgroup FLASHEx_Type_Erase FLASHEx_Type_Erase
127 * @{
128 */
129 #define FLASH_TYPEERASE_PAGES ((uint32_t)0x00) /*!< Page erase only */
130 /**
131 * @}
132 */
133
134 /** @defgroup FLASHEx_Option_Type FLASHEx Option Type
135 * @{
136 */
137 #define OPTIONBYTE_WRP ((uint32_t)0x01) /*!< WRP option byte configuration */
138 #define OPTIONBYTE_RDP ((uint32_t)0x02) /*!< RDP option byte configuration */
139 #define OPTIONBYTE_USER ((uint32_t)0x04) /*!< USER option byte configuration */
140 #define OPTIONBYTE_BOR ((uint32_t)0x08) /*!< BOR option byte configuration */
141 #define OPTIONBYTE_BOOT_BIT1 ((uint32_t)0x10) /*!< BOOT PIN1 option byte configuration*/
142 /**
143 * @}
144 */
145
146 /** @defgroup FLASHEx_WRP_State FLASHEx WRP State
147 * @{
148 */
149 #define OB_WRPSTATE_DISABLE ((uint32_t)0x00) /*!< Disable the write protection of the desired sectors */
150 #define OB_WRPSTATE_ENABLE ((uint32_t)0x01) /*!< Enable the write protection of the desired sectors */
151 /**
152 * @}
153 */
154
155 /** @defgroup FLASHEx_Option_Bytes_ReadWrite_Mask FLASHEx Option Bytes Write Mask
156 * @{
157 */
158 #define WRP_MASK_LOW ((uint32_t)0x0000FFFF)
159 #define WRP_MASK_HIGH ((uint32_t)0xFFFF0000)
160 /**
161 * @}
162 */
163
164 #if defined (STM32L031xx) || defined (STM32L041xx)
165 /** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASHEx Option Bytes Write Protection
166 * @{
167 */
168 #define OB_WRP_Pages0to31 ((uint32_t)0x00000001) /* Write protection of Sector0 */
169 #define OB_WRP_Pages32to63 ((uint32_t)0x00000002) /* Write protection of Sector1 */
170 #define OB_WRP_Pages64to95 ((uint32_t)0x00000004) /* Write protection of Sector2 */
171 #define OB_WRP_Pages96to127 ((uint32_t)0x00000008) /* Write protection of Sector3 */
172 #define OB_WRP_Pages128to159 ((uint32_t)0x00000010) /* Write protection of Sector4 */
173 #define OB_WRP_Pages160to191 ((uint32_t)0x00000020) /* Write protection of Sector5 */
174 #define OB_WRP_Pages192to223 ((uint32_t)0x00000040) /* Write protection of Sector6 */
175 #define OB_WRP_Pages224to255 ((uint32_t)0x00000080) /* Write protection of Sector7 */
176 #define OB_WRP_AllPages ((uint32_t)0x000000FF) /*!< Write protection of all Sectors */
177 /**
178 * @}
179 */
180 #elif defined (STM32L051xx) || defined (STM32L052xx) || defined (STM32L053xx) || defined (STM32L061xx) || defined (STM32L062xx) || defined (STM32L063xx)
181 /** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASHEx Option Bytes Write Protection
182 * @{
183 */
184 #define OB_WRP_Pages0to31 ((uint32_t)0x00000001) /* Write protection of Sector0 */
185 #define OB_WRP_Pages32to63 ((uint32_t)0x00000002) /* Write protection of Sector1 */
186 #define OB_WRP_Pages64to95 ((uint32_t)0x00000004) /* Write protection of Sector2 */
187 #define OB_WRP_Pages96to127 ((uint32_t)0x00000008) /* Write protection of Sector3 */
188 #define OB_WRP_Pages128to159 ((uint32_t)0x00000010) /* Write protection of Sector4 */
189 #define OB_WRP_Pages160to191 ((uint32_t)0x00000020) /* Write protection of Sector5 */
190 #define OB_WRP_Pages192to223 ((uint32_t)0x00000040) /* Write protection of Sector6 */
191 #define OB_WRP_Pages224to255 ((uint32_t)0x00000080) /* Write protection of Sector7 */
192 #define OB_WRP_Pages256to287 ((uint32_t)0x00000100) /* Write protection of Sector8 */
193 #define OB_WRP_Pages288to319 ((uint32_t)0x00000200) /* Write protection of Sector9 */
194 #define OB_WRP_Pages320to351 ((uint32_t)0x00000400) /* Write protection of Sector10 */
195 #define OB_WRP_Pages352to383 ((uint32_t)0x00000800) /* Write protection of Sector11 */
196 #define OB_WRP_Pages384to415 ((uint32_t)0x00001000) /* Write protection of Sector12 */
197 #define OB_WRP_Pages416to447 ((uint32_t)0x00002000) /* Write protection of Sector13 */
198 #define OB_WRP_Pages448to479 ((uint32_t)0x00004000) /* Write protection of Sector14 */
199 #define OB_WRP_Pages480to511 ((uint32_t)0x00008000) /* Write protection of Sector15 */
200 #define OB_WRP_AllPages ((uint32_t)0x0000FFFF) /*!< Write protection of all Sectors */
201 /**
202 * @}
203 */
204
205 #elif defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
206 /** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASHEx Option Bytes Write ProtectionP
207 * @{
208 */
209 #define OB_WRP_Pages0to31 ((uint32_t)0x00000001) /* Write protection of Sector0 */
210 #define OB_WRP_Pages32to63 ((uint32_t)0x00000002) /* Write protection of Sector1 */
211 #define OB_WRP_Pages64to95 ((uint32_t)0x00000004) /* Write protection of Sector2 */
212 #define OB_WRP_Pages96to127 ((uint32_t)0x00000008) /* Write protection of Sector3 */
213 #define OB_WRP_Pages128to159 ((uint32_t)0x00000010) /* Write protection of Sector4 */
214 #define OB_WRP_Pages160to191 ((uint32_t)0x00000020) /* Write protection of Sector5 */
215 #define OB_WRP_Pages192to223 ((uint32_t)0x00000040) /* Write protection of Sector6 */
216 #define OB_WRP_Pages224to255 ((uint32_t)0x00000080) /* Write protection of Sector7 */
217 #define OB_WRP_Pages256to287 ((uint32_t)0x00000100) /* Write protection of Sector8 */
218 #define OB_WRP_Pages288to319 ((uint32_t)0x00000200) /* Write protection of Sector9 */
219 #define OB_WRP_Pages320to351 ((uint32_t)0x00000400) /* Write protection of Sector10 */
220 #define OB_WRP_Pages352to383 ((uint32_t)0x00000800) /* Write protection of Sector11 */
221 #define OB_WRP_Pages384to415 ((uint32_t)0x00001000) /* Write protection of Sector12 */
222 #define OB_WRP_Pages416to447 ((uint32_t)0x00002000) /* Write protection of Sector13 */
223 #define OB_WRP_Pages448to479 ((uint32_t)0x00004000) /* Write protection of Sector14 */
224 #define OB_WRP_Pages480to511 ((uint32_t)0x00008000) /* Write protection of Sector15 */
225 #define OB_WRP_Pages512to543 ((uint32_t)0x00010000) /* Write protection of Sector16 */
226 #define OB_WRP_Pages544to575 ((uint32_t)0x00020000) /* Write protection of Sector17 */
227 #define OB_WRP_Pages576to607 ((uint32_t)0x00040000) /* Write protection of Sector18 */
228 #define OB_WRP_Pages608to639 ((uint32_t)0x00080000) /* Write protection of Sector19 */
229 #define OB_WRP_Pages640to671 ((uint32_t)0x00100000) /* Write protection of Sector20 */
230 #define OB_WRP_Pages672to703 ((uint32_t)0x00200000) /* Write protection of Sector21 */
231 #define OB_WRP_Pages704to735 ((uint32_t)0x00400000) /* Write protection of Sector22 */
232 #define OB_WRP_Pages736to767 ((uint32_t)0x00800000) /* Write protection of Sector23 */
233 #define OB_WRP_Pages768to799 ((uint32_t)0x01000000) /* Write protection of Sector24 */
234 #define OB_WRP_Pages800to831 ((uint32_t)0x02000000) /* Write protection of Sector25 */
235 #define OB_WRP_Pages832to863 ((uint32_t)0x04000000) /* Write protection of Sector26 */
236 #define OB_WRP_Pages864to895 ((uint32_t)0x08000000) /* Write protection of Sector27 */
237 #define OB_WRP_Pages896to927 ((uint32_t)0x10000000) /* Write protection of Sector28 */
238 #define OB_WRP_Pages928to959 ((uint32_t)0x20000000) /* Write protection of Sector29 */
239 #define OB_WRP_Pages960to991 ((uint32_t)0x40000000) /* Write protection of Sector30 */
240 #define OB_WRP_Pages992to1023 ((uint32_t)0x80000000) /* Write protection of Sector31 */
241 #define OB_WRP_AllPages ((uint32_t)0xFFFFFFFF) /*!<Write protection of all Sectors */
242 /**
243 * @}
244 */
245
246 /** @defgroup FLASHEx_Option_Bytes_Write_Protection2 FLASHEx Option Bytes Write Protection
247 * @{
248 */
249 #define OB_WRP2_Pages1024to1055 ((uint32_t)0x00000001) /* Write protection of Sector32 */
250 #define OB_WRP2_Pages1056to1087 ((uint32_t)0x00000002) /* Write protection of Sector33 */
251 #define OB_WRP2_Pages1088to1119 ((uint32_t)0x00000004) /* Write protection of Sector34 */
252 #define OB_WRP2_Pages1120to1151 ((uint32_t)0x00000008) /* Write protection of Sector35 */
253 #define OB_WRP2_Pages1152to1183 ((uint32_t)0x00000010) /* Write protection of Sector36 */
254 #define OB_WRP2_Pages1184to1215 ((uint32_t)0x00000020) /* Write protection of Sector37 */
255 #define OB_WRP2_Pages1216to1247 ((uint32_t)0x00000040) /* Write protection of Sector38 */
256 #define OB_WRP2_Pages1248to1279 ((uint32_t)0x00000080) /* Write protection of Sector39 */
257 #define OB_WRP2_Pages1280to1311 ((uint32_t)0x00000100) /* Write protection of Sector40 */
258 #define OB_WRP2_Pages1312to1343 ((uint32_t)0x00000200) /* Write protection of Sector41 */
259 #define OB_WRP2_Pages1344to1375 ((uint32_t)0x00000400) /* Write protection of Sector42 */
260 #define OB_WRP2_Pages1376to1407 ((uint32_t)0x00000800) /* Write protection of Sector43 */
261 #define OB_WRP2_Pages1408to1439 ((uint32_t)0x00001000) /* Write protection of Sector44 */
262 #define OB_WRP2_Pages1440to1471 ((uint32_t)0x00002000) /* Write protection of Sector45 */
263 #define OB_WRP2_Pages1472to1503 ((uint32_t)0x00004000) /* Write protection of Sector46 */
264 #define OB_WRP2_Pages1504to1535 ((uint32_t)0x00008000) /* Write protection of Sector47 */
265 #define OB_WRP2_AllPages ((uint32_t)0x0000FFFF) /*!< Write protection of all Sectors WRP2 */
266 /**
267 * @}
268 */
269 #endif /* STM32L071xx || STM32L072xx || (STM32L073xx) || (STM32L081xx) || (STM32L082xx) || (STM32L083xx) */
270
271 /** @defgroup FLASHEx_Option_Bytes_Read_Protection FLASHEx Option Bytes Read Protection
272 * @{
273 */
274 #define OB_RDP_LEVEL0 ((uint8_t)0xAA)
275 #define OB_RDP_LEVEL1 ((uint8_t)0xBB)
276 #define OB_RDP_LEVEL2 ((uint8_t)0xCC) /* Warning: When enabling read protection level 2
277 it is no more possible to go back to level 1 or 0 */
278 /**
279 * @}
280 */
281
282 /** @defgroup FLASHEx_Option_Bytes_BOR_Level FLASHEx Option Bytes BOR Level
283 * @{
284 */
285 #define OB_BOR_OFF ((uint8_t)0x00) /*!< BOR is disabled at power down, the reset is asserted when the VDD
286 power supply reaches the PDR(Power Down Reset) threshold (1.5V) */
287 #define OB_BOR_LEVEL1 ((uint8_t)0x08) /*!< BOR Reset threshold levels for 1.7V - 1.8V VDD power supply */
288 #define OB_BOR_LEVEL2 ((uint8_t)0x09) /*!< BOR Reset threshold levels for 1.9V - 2.0V VDD power supply */
289 #define OB_BOR_LEVEL3 ((uint8_t)0x0A) /*!< BOR Reset threshold levels for 2.3V - 2.4V VDD power supply */
290 #define OB_BOR_LEVEL4 ((uint8_t)0x0B) /*!< BOR Reset threshold levels for 2.55V - 2.65V VDD power supply */
291 #define OB_BOR_LEVEL5 ((uint8_t)0x0C) /*!< BOR Reset threshold levels for 2.8V - 2.9V VDD power supply */
292 /**
293 * @}
294 */
295
296 /** @defgroup FLASHEx_Option_Bytes_IWatchdog FLASHEx Option Bytes IWatchdog
297 * @{
298 */
299 #define OB_IWDG_SW ((uint8_t)0x10) /*!< Software WDG selected */
300 #define OB_IWDG_HW ((uint8_t)0x00) /*!< Hardware WDG selected */
301 /**
302 * @}
303 */
304
305 /** @defgroup FLASHEx_Option_Bytes_nRST_STOP FLASHEx Option Bytes nRST_STOP
306 * @{
307 */
308 #define OB_STOP_NORST ((uint8_t)0x20) /*!< No reset generated when entering in STOP */
309 #define OB_STOP_RST ((uint8_t)0x00) /*!< Reset generated when entering in STOP */
310 /**
311 * @}
312 */
313
314 /** @defgroup FLASHEx_Option_Bytes_nRST_STDBY FLASHEx Option Bytes nRST_STDBY
315 * @{
316 */
317 #define OB_STDBY_NORST ((uint8_t)0x40) /*!< No reset generated when entering in STANDBY */
318 #define OB_STDBY_RST ((uint8_t)0x00) /*!< Reset generated when entering in STANDBY */
319 /**
320 * @}
321 */
322
323
324 /** @defgroup FLASHEx_PCROP_State
325 * @{
326 */
327 #define OB_PCROP_STATE_DISABLE ((uint8_t)0x00) /*!< Disable PCROP */
328 #define OB_PCROP_STATE_ENABLE ((uint8_t)0x01) /*!< Enable PCROP */
329 /**
330 * @}
331 */
332
333
334 /** @defgroup FLASHEx_OptionAdv_Type
335 * @{
336 */
337 #if defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
338 #define OPTIONBYTE_PCROP ((uint32_t)0x01) /*!< PCROP option byte configuration*/
339 #define OPTIONBYTE_BOOTCONFIG ((uint32_t)0x02) /*!< BOOTConfig option byte configuration, boot from bank 2*/
340 #else /* if STM32L071xx || STM32L072xx || STM32L073xx || STM32L081xx || STM32L082xx || STM32L083xx */
341 #define OPTIONBYTE_PCROP ((uint32_t)0x01) /*!< PCROP option byte configuration*/
342 #endif /* if STM32L071xx || STM32L072xx || STM32L073xx || STM32L081xx || STM32L082xx || STM32L083xx */
343 /**
344 * @}
345 */
346
347 #if defined (STM32L031xx) || defined (STM32L041xx)
348 /** @defgroup FLASHEx_Option_Bytes_PC_ReadWrite_Protection FLASHEx Option Bytes PC Read/Write Protection
349 * @{
350 */
351 #define OB_PCROP_Pages0to31 ((uint32_t)0x00000001) /* PC Read/Write protection of Sector0 */
352 #define OB_PCROP_Pages32to63 ((uint32_t)0x00000002) /* PC Read/Write protection of Sector1 */
353 #define OB_PCROP_Pages64to95 ((uint32_t)0x00000004) /* PC Read/Write protection of Sector2 */
354 #define OB_PCROP_Pages96to127 ((uint32_t)0x00000008) /* PC Read/Write protection of Sector3 */
355 #define OB_PCROP_Pages128to159 ((uint32_t)0x00000010) /* PC Read/Write protection of Sector4 */
356 #define OB_PCROP_Pages160to191 ((uint32_t)0x00000020) /* PC Read/Write protection of Sector5 */
357 #define OB_PCROP_Pages192to223 ((uint32_t)0x00000040) /* PC Read/Write protection of Sector6 */
358 #define OB_PCROP_Pages224to255 ((uint32_t)0x00000080) /* PC Read/Write protection of Sector7 */
359 #define OB_PCROP_AllPages ((uint32_t)0x000000FF) /*!< PC Read/Write protection of all Sectors */
360 /**
361 * @}
362 */
363 #elif defined (STM32L051xx) || defined (STM32L052xx) || defined (STM32L053xx) || defined (STM32L061xx) || defined (STM32L062xx) || defined (STM32L063xx)
364 /** @defgroup FLASHEx_Option_Bytes_PC_ReadWrite_Protection FLASHEx Option Bytes PC Read/Write Protection
365 * @{
366 */
367 #define OB_PCROP_Pages0to31 ((uint32_t)0x00000001) /* PC Read/Write protection of Sector0 */
368 #define OB_PCROP_Pages32to63 ((uint32_t)0x00000002) /* PC Read/Write protection of Sector1 */
369 #define OB_PCROP_Pages64to95 ((uint32_t)0x00000004) /* PC Read/Write protection of Sector2 */
370 #define OB_PCROP_Pages96to127 ((uint32_t)0x00000008) /* PC Read/Write protection of Sector3 */
371 #define OB_PCROP_Pages128to159 ((uint32_t)0x00000010) /* PC Read/Write protection of Sector4 */
372 #define OB_PCROP_Pages160to191 ((uint32_t)0x00000020) /* PC Read/Write protection of Sector5 */
373 #define OB_PCROP_Pages192to223 ((uint32_t)0x00000040) /* PC Read/Write protection of Sector6 */
374 #define OB_PCROP_Pages224to255 ((uint32_t)0x00000080) /* PC Read/Write protection of Sector7 */
375 #define OB_PCROP_Pages256to287 ((uint32_t)0x00000100) /* PC Read/Write protection of Sector8 */
376 #define OB_PCROP_Pages288to319 ((uint32_t)0x00000200) /* PC Read/Write protection of Sector9 */
377 #define OB_PCROP_Pages320to351 ((uint32_t)0x00000400) /* PC Read/Write protection of Sector10 */
378 #define OB_PCROP_Pages352to383 ((uint32_t)0x00000800) /* PC Read/Write protection of Sector11 */
379 #define OB_PCROP_Pages384to415 ((uint32_t)0x00001000) /* PC Read/Write protection of Sector12 */
380 #define OB_PCROP_Pages416to447 ((uint32_t)0x00002000) /* PC Read/Write protection of Sector13 */
381 #define OB_PCROP_Pages448to479 ((uint32_t)0x00004000) /* PC Read/Write protection of Sector14 */
382 #define OB_PCROP_Pages480to511 ((uint32_t)0x00008000) /* PC Read/Write protection of Sector15 */
383 #define OB_PCROP_AllPages ((uint32_t)0x0000FFFF) /*!< PC Read/Write protection of all Sectors */
384 /**
385 * @}
386 */
387 #endif
388
389 #if defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
390 /** @defgroup FLASHEx_Option_Bytes_PC_ReadWrite_Protection FLASHEx Option Bytes PC Read/Write Protection
391 * @{
392 */
393 #define OB_PCROP_Pages0to31 ((uint32_t)0x00000001) /* PC Read/Write protection of Sector0 */
394 #define OB_PCROP_Pages32to63 ((uint32_t)0x00000002) /* PC Read/Write protection of Sector1 */
395 #define OB_PCROP_Pages64to95 ((uint32_t)0x00000004) /* PC Read/Write protection of Sector2 */
396 #define OB_PCROP_Pages96to127 ((uint32_t)0x00000008) /* PC Read/Write protection of Sector3 */
397 #define OB_PCROP_Pages128to159 ((uint32_t)0x00000010) /* PC Read/Write protection of Sector4 */
398 #define OB_PCROP_Pages160to191 ((uint32_t)0x00000020) /* PC Read/Write protection of Sector5 */
399 #define OB_PCROP_Pages192to223 ((uint32_t)0x00000040) /* PC Read/Write protection of Sector6 */
400 #define OB_PCROP_Pages224to255 ((uint32_t)0x00000080) /* PC Read/Write protection of Sector7 */
401 #define OB_PCROP_Pages256to287 ((uint32_t)0x00000100) /* PC Read/Write protection of Sector8 */
402 #define OB_PCROP_Pages288to319 ((uint32_t)0x00000200) /* PC Read/Write protection of Sector9 */
403 #define OB_PCROP_Pages320to351 ((uint32_t)0x00000400) /* PC Read/Write protection of Sector10 */
404 #define OB_PCROP_Pages352to383 ((uint32_t)0x00000800) /* PC Read/Write protection of Sector11 */
405 #define OB_PCROP_Pages384to415 ((uint32_t)0x00001000) /* PC Read/Write protection of Sector12 */
406 #define OB_PCROP_Pages416to447 ((uint32_t)0x00002000) /* PC Read/Write protection of Sector13 */
407 #define OB_PCROP_Pages448to479 ((uint32_t)0x00004000) /* PC Read/Write protection of Sector14 */
408 #define OB_PCROP_Pages480to511 ((uint32_t)0x00008000) /* PC Read/Write protection of Sector15 */
409 #define OB_PCROP_Pages512to543 ((uint32_t)0x00010000) /* PC Read/Write protection of Sector16 */
410 #define OB_PCROP_Pages544to575 ((uint32_t)0x00020000) /* PC Read/Write protection of Sector17 */
411 #define OB_PCROP_Pages576to607 ((uint32_t)0x00040000) /* PC Read/Write protection of Sector18 */
412 #define OB_PCROP_Pages608to639 ((uint32_t)0x00080000) /* PC Read/Write protection of Sector19 */
413 #define OB_PCROP_Pages640to671 ((uint32_t)0x00100000) /* PC Read/Write protection of Sector20 */
414 #define OB_PCROP_Pages672to703 ((uint32_t)0x00200000) /* PC Read/Write protection of Sector21 */
415 #define OB_PCROP_Pages704to735 ((uint32_t)0x00400000) /* PC Read/Write protection of Sector22 */
416 #define OB_PCROP_Pages736to767 ((uint32_t)0x00800000) /* PC Read/Write protection of Sector23 */
417 #define OB_PCROP_Pages768to799 ((uint32_t)0x01000000) /* PC Read/Write protection of Sector24 */
418 #define OB_PCROP_Pages800to831 ((uint32_t)0x02000000) /* PC Read/Write protection of Sector25 */
419 #define OB_PCROP_Pages832to863 ((uint32_t)0x04000000) /* PC Read/Write protection of Sector26 */
420 #define OB_PCROP_Pages864to895 ((uint32_t)0x08000000) /* PC Read/Write protection of Sector27 */
421 #define OB_PCROP_Pages896to927 ((uint32_t)0x10000000) /* PC Read/Write protection of Sector28 */
422 #define OB_PCROP_Pages928to959 ((uint32_t)0x20000000) /* PC Read/Write protection of Sector29 */
423 #define OB_PCROP_Pages960to991 ((uint32_t)0x40000000) /* PC Read/Write protection of Sector30 */
424 #define OB_PCROP_Pages992to1023 ((uint32_t)0x80000000) /* PC Read/Write protection of Sector31 */
425 #define OB_PCROP_AllPages ((uint32_t)0xFFFFFFFF) /*!<PC Read/Write protection of all Sectors */
426 /**
427 * @}
428 */
429
430 /** @defgroup FLASHEx_Option_Bytes_ReadWrite_Protection2 FLASHEx Option Bytes Read Write Protection
431 * @{
432 */
433 #define OB_PCROP2_Pages1024to1055 ((uint32_t)0x00000001) /* PC Read/Write protection of Sector32 */
434 #define OB_PCROP2_Pages1056to1087 ((uint32_t)0x00000002) /* PC Read/Write protection of Sector33 */
435 #define OB_PCROP2_Pages1088to1119 ((uint32_t)0x00000004) /* PC Read/Write protection of Sector34 */
436 #define OB_PCROP2_Pages1120to1151 ((uint32_t)0x00000008) /* PC Read/Write protection of Sector35 */
437 #define OB_PCROP2_Pages1152to1183 ((uint32_t)0x00000010) /* PC Read/Write protection of Sector36 */
438 #define OB_PCROP2_Pages1184to1215 ((uint32_t)0x00000020) /* PC Read/Write protection of Sector37 */
439 #define OB_PCROP2_Pages1216to1247 ((uint32_t)0x00000040) /* PC Read/Write protection of Sector38 */
440 #define OB_PCROP2_Pages1248to1279 ((uint32_t)0x00000080) /* PC Read/Write protection of Sector39 */
441 #define OB_PCROP2_Pages1280to1311 ((uint32_t)0x00000100) /* PC Read/Write protection of Sector40 */
442 #define OB_PCROP2_Pages1312to1343 ((uint32_t)0x00000200) /* PC Read/Write protection of Sector41 */
443 #define OB_PCROP2_Pages1344to1375 ((uint32_t)0x00000400) /* PC Read/Write protection of Sector42 */
444 #define OB_PCROP2_Pages1376to1407 ((uint32_t)0x00000800) /* PC Read/Write protection of Sector43 */
445 #define OB_PCROP2_Pages1408to1439 ((uint32_t)0x00001000) /* PC Read/Write protection of Sector44 */
446 #define OB_PCROP2_Pages1440to1471 ((uint32_t)0x00002000) /* PC Read/Write protection of Sector45 */
447 #define OB_PCROP2_Pages1472to1503 ((uint32_t)0x00004000) /* PC Read/Write protection of Sector46 */
448 #define OB_PCROP2_Pages1504to1535 ((uint32_t)0x00008000) /* PC Read/Write protection of Sector47 */
449 #define OB_PCROP2_AllPages ((uint32_t)0x0000FFFF) /*!< PC Read/Write protection of all Sectors PCROP2 */
450 /**
451 * @}
452 */
453 #endif /* if STM32L071xx || STM32L072xx || STM32L073xx || STM32L081xx || STM32L082xx || STM32L083xx */
454
455 /** @defgroup FLASHEx_Option_Bytes_BOOTBit1
456 * @{
457 */
458 #define OB_BOOT_BIT1_RESET (uint8_t)(0x00) /*!< BOOT Bit 1 Reset */
459 #define OB_BOOT_BIT1_SET (uint8_t)(0x01) /*!< BOOT Bit 1 Set */
460 /**
461 * @}
462 */
463
464 #if defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
465 /** @defgroup FLASHEx_Option_Bytes_BOOT_BANK FLASHEx Option Bytes BOOT BANK
466 * @{
467 */
468 #define OB_BOOT_BANK1 ((uint8_t)0x00) /*!< At startup, if boot pin 0 and BOOT1 bit are set in boot from user Flash position
469 and this parameter is selected the device will boot from Bank 2
470 or Bank 1, depending on the activation of the bank */
471 #define OB_BOOT_BANK2 (uint8_t)(0x01) /*!< At startup, if boot pin 0 and BOOT1 bit are set in boot from user Flash position
472 and this parameter is selected the device will boot from Bank1(Default) */
473 /**
474 * @}
475 */
476 #endif /* if STM32L071xx || STM32L072xx || STM32L073xx || STM32L081xx || STM32L082xx || STM32L083xx */
477
478 /** @defgroup FLASHEx_Type_Program_Data FLASHEx Type Program Data
479 * @{
480 */
481 #define FLASH_TYPEPROGRAMDATA_BYTE ((uint32_t)0x00) /*!< Program byte (8-bit) at a specified address.*/
482 #define FLASH_TYPEPROGRAMDATA_HALFWORD ((uint32_t)0x01) /*!< Program a half-word (16-bit) at a specified address.*/
483 #define FLASH_TYPEPROGRAMDATA_WORD ((uint32_t)0x02) /*!< Program a word (32-bit) at a specified address.*/
484
485 /* Aliases for compatibility with the V1.0.0 package */
486 #define FLASH_TYPEPROGRAM_BYTE FLASH_TYPEPROGRAMDATA_BYTE
487 #define FLASH_TYPEPROGRAM_HALFWORD FLASH_TYPEPROGRAMDATA_HALFWORD
488 /**
489 * @}
490 */
491
492 /** @defgroup FLASHEx_Address FLASHEx Address
493 * @{
494 */
495 #define FLASH_NBPAGES_MAX (FLASH_SIZE / FLASH_PAGE_SIZE)
496 /**
497 * @}
498 */
499
500 /**
501 * @}
502 */
503
504 /** @defgroup FLASHEx_Exported_Macros macros to control FLASH features
505 * @brief
506 * @{
507 */
508
509 /**
510 * @brief Set the FLASH Latency.
511 * @param __LATENCY__: FLASH Latency
512 * This parameter can be one of the following values:
513 * @arg FLASH_LATENCY_0: FLASH Zero Latency cycle
514 * @arg FLASH_LATENCY_1: FLASH One Latency cycle
515 * @retval none
516 */
517 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) \
518 MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(__LATENCY__))
519
520 /**
521 * @brief Enable/Disable the FLASH prefetch buffer.
522 * @retval none
523 */
524 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() CLEAR_BIT((FLASH->ACR), FLASH_ACR_PRFTEN)
525 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() SET_BIT((FLASH->ACR), FLASH_ACR_PRFTEN)
526
527 /**
528 * @brief Enable/Disable the FLASH Buffer cache.
529 * @retval none
530 */
531 #define __HAL_FLASH_BUFFER_CACHE_ENABLE() SET_BIT((FLASH->ACR), FLASH_ACR_DISAB_BUF)
532 #define __HAL_FLASH_BUFFER_CACHE_DISABLE() CLEAR_BIT((FLASH->ACR), FLASH_ACR_DISAB_BUF)
533
534 /**
535 * @brief Enable/Disable the FLASH preread buffer.
536 * @retval none
537 */
538 #define __HAL_FLASH_PREREAD_BUFFER_ENABLE() SET_BIT((FLASH->ACR), FLASH_ACR_PRE_READ)
539 #define __HAL_FLASH_PREREAD_BUFFER_DISABLE() CLEAR_BIT((FLASH->ACR), FLASH_ACR_PRE_READ)
540
541 /**
542 * @brief Enable/Disable the FLASH power down during Sleep mode.
543 * @retval none
544 */
545 #define __HAL_FLASH_SLEEP_POWERDOWN_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_SLEEP_PD)
546 #define __HAL_FLASH_SLEEP_POWERDOWN_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_SLEEP_PD)
547
548 /**
549 * @brief Enable the Flash Run power down mode.
550 * @note Writing this bit to 0 this bit, automatically the keys are
551 * loss and a new unlock sequence is necessary to re-write it to 1.
552 */
553 #define __HAL_FLASH_POWER_DOWN_ENABLE() do { FLASH->PDKEYR = FLASH_PDKEY1; \
554 FLASH->PDKEYR = FLASH_PDKEY2; \
555 SET_BIT((FLASH->ACR), FLASH_ACR_RUN_PD); \
556 } while (0)
557
558 /**
559 * @brief Disable the Flash Run power down mode.
560 * @note Writing this bit to 0 this bit, automatically the keys are
561 * loss and a new unlock sequence is necessary to re-write it to 1.
562 */
563 #define __HAL_FLASH_POWER_DOWN_DISABLE() do { FLASH->PDKEYR = FLASH_PDKEY1; \
564 FLASH->PDKEYR = FLASH_PDKEY2; \
565 CLEAR_BIT((FLASH->ACR), FLASH_ACR_RUN_PD); \
566 } while (0)
567
568 /**
569 * @}
570 */
571
572 /** @defgroup FLASHEx_Exported_Functions FLASHEx Exported functions
573 * @{
574 */
575
576 /** @defgroup FLASHEx_Exported_Functions_Group1 FLASH Memory Erasing functions
577 * @{
578 */
579 HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError);
580 HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit);
581 /**
582 * @}
583 */
584
585 /** @defgroup FLASHEx_Exported_Functions_Group2 Option Bytes Programming functions
586 * @{
587 */
588 HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
589 void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit);
590 HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram (FLASH_AdvOBProgramInitTypeDef *pAdvOBInit);
591 void HAL_FLASHEx_AdvOBGetConfig(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit);
592 HAL_StatusTypeDef HAL_FLASHEx_OB_SelectPCROP(void);
593 HAL_StatusTypeDef HAL_FLASHEx_OB_DeSelectPCROP(void);
594 /**
595 * @}
596 */
597
598 /** @defgroup FLASHEx_Exported_Functions_Group3 DATA EEPROM Programming functions
599 * @{
600 */
601 HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Unlock(void);
602 HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Lock(void);
603 HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Erase(uint32_t Address);
604 HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data);
605 void HAL_FLASHEx_DATAEEPROM_EnableFixedTimeProgram(void);
606 void HAL_FLASHEx_DATAEEPROM_DisableFixedTimeProgram(void);
607
608 /**
609 * @}
610 */
611
612 /**
613 * @}
614 */
615
616 /** @addtogroup FLASH_Private_Macros FLASH Private Macros
617 * @{
618 */
619 #define IS_FLASH_TYPEERASE(__VALUE__) (((__VALUE__) == FLASH_TYPEERASE_PAGES))
620
621 #define IS_OPTIONBYTE(__VALUE__) (((__VALUE__) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | \
622 OPTIONBYTE_USER | OPTIONBYTE_BOR | OPTIONBYTE_BOOT_BIT1)))
623
624 #define IS_WRPSTATE(__VALUE__) (((__VALUE__) == OB_WRPSTATE_DISABLE) || \
625 ((__VALUE__) == OB_WRPSTATE_ENABLE))
626
627 #define IS_OB_WRP(PAGE) (((PAGE) != 0x0000000))
628
629 #define IS_OB_RDP(__LEVEL__) (((__LEVEL__) == OB_RDP_LEVEL0)||\
630 ((__LEVEL__) == OB_RDP_LEVEL1)||\
631 ((__LEVEL__) == OB_RDP_LEVEL2))
632
633 #define IS_OB_BOR_LEVEL(__LEVEL__) ( ((__LEVEL__) == OB_BOR_OFF) || \
634 ((__LEVEL__) == OB_BOR_LEVEL1) || \
635 ((__LEVEL__) == OB_BOR_LEVEL2) || \
636 ((__LEVEL__) == OB_BOR_LEVEL3) || \
637 ((__LEVEL__) == OB_BOR_LEVEL4) || \
638 ((__LEVEL__) == OB_BOR_LEVEL5))
639
640 #define IS_OB_IWDG_SOURCE(__SOURCE__) (((__SOURCE__) == OB_IWDG_SW) || ((__SOURCE__) == OB_IWDG_HW))
641
642 #define IS_OB_STOP_SOURCE(__SOURCE__) (((__SOURCE__) == OB_STOP_NORST) || ((__SOURCE__) == OB_STOP_RST))
643
644 #define IS_OB_STDBY_SOURCE(__SOURCE__) (((__SOURCE__) == OB_STDBY_NORST) || ((__SOURCE__) == OB_STDBY_RST))
645
646 #define IS_PCROPSTATE(VALUE)(((VALUE) == OB_PCROP_STATE_DISABLE) || \
647 ((VALUE) == OB_PCROP_STATE_ENABLE))
648
649 #define IS_OB_PCROP(__PAGE__) (((__PAGE__) != 0x0000000))
650
651 #define IS_OB_BOOT1(__BOOT_BIT1__) (((__BOOT_BIT1__) == OB_BOOT_BIT1_RESET) || ((__BOOT_BIT1__) == OB_BOOT_BIT1_SET))
652
653 #define IS_TYPEPROGRAMDATA(__VALUE__) (((__VALUE__) == FLASH_TYPEPROGRAMDATA_BYTE) || \
654 ((__VALUE__) == FLASH_TYPEPROGRAMDATA_HALFWORD) || \
655 ((__VALUE__) == FLASH_TYPEPROGRAMDATA_WORD))
656
657 #define IS_NBPAGES(__PAGES__) (((__PAGES__) >= 1) && ((__PAGES__) <= FLASH_NBPAGES_MAX))
658
659 #if defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
660 #define IS_OBEX(__VALUE__)(((__VALUE__) <= (OPTIONBYTE_PCROP | OPTIONBYTE_BOOTCONFIG)))
661 #define IS_OB_BOOT_BANK(__BANK__) (((__BANK__) == OB_BOOT_BANK2) || ((__BANK__) == OB_BOOT_BANK1))
662 #define IS_FLASH_DATA_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= DATA_EEPROM_BASE) && ((__ADDRESS__) <= DATA_EEPROM_BANK2_END))
663 #define IS_FLASH_DATA_BANK1_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= DATA_EEPROM_BASE) && ((__ADDRESS__) <= DATA_EEPROM_BANK1_END))
664 #define IS_FLASH_DATA_BANK2_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= DATA_EEPROM_BANK2_BASE) && ((__ADDRESS__) <= DATA_EEPROM_BANK2_END))
665 #define IS_FLASH_PROGRAM_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_BASE) && ((__ADDRESS__) < (FLASH_BASE + FLASH_SIZE)))
666 #define IS_FLASH_PROGRAM_BANK1_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_BASE) && ((__ADDRESS__) < (FLASH_BASE + (FLASH_SIZE >> 1))))
667 #define IS_FLASH_PROGRAM_BANK2_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_BANK2_BASE) && ((__ADDRESS__) < (FLASH_BASE + FLASH_SIZE)))
668 #else
669 #define IS_OBEX(VALUE)((VALUE) == OPTIONBYTE_PCROP)
670 #define IS_FLASH_DATA_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= DATA_EEPROM_BASE) && ((__ADDRESS__) <= DATA_EEPROM_END))
671 #define IS_FLASH_PROGRAM_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_BASE) && ((__ADDRESS__) < (FLASH_BASE + FLASH_SIZE)))
672 #endif
673 /**
674 * @}
675 */
676
677 /**
678 * @}
679 */
680
681 /**
682 * @}
683 */
684
685 #ifdef __cplusplus
686 }
687 #endif
688
689 #endif /* __STM32L0xx_HAL_FLASH_EX_H */
690
691 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
692
Imprint / Impressum