2 ******************************************************************************
3 * @file stm32l0xx_hal_flash_ex.h
4 * @author MCD Application Team
6 * @date 06-February-2015
7 * @brief Header file of FLash HAL Extension module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
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.
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.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32L0xx_HAL_FLASH_EX_H
40 #define __STM32L0xx_HAL_FLASH_EX_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32l0xx_hal_def.h"
49 /** @addtogroup STM32L0xx_HAL_Driver
53 /** @defgroup FLASHEx FLASHEx
57 /** @defgroup FLASHEx_Exported_Types FLASH Exported Types
62 * @brief FLASH Option Bytes PROGRAM structure definition
66 uint32_t OptionType; /*!< OptionType: Option byte to be configured.
67 This parameter can be a value of @ref FLASHEx_Option_Type */
69 uint32_t WRPState; /*!< WRPState: Write protection activation or deactivation.
70 This parameter can be a value of @ref FLASHEx_WRP_State */
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 */
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 */
80 uint8_t RDPLevel; /*!< RDPLevel: Set the read protection level.
81 This parameter can be a value of @ref FLASHEx_Option_Bytes_Read_Protection */
83 uint8_t BORLevel; /*!< BORLevel: Set the BOR Level.
84 This parameter can be a value of @ref FLASHEx_Option_Bytes_BOR_Level */
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 */
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 */
93 } FLASH_OBProgramInitTypeDef;
96 * @brief FLASH Advanced Option Bytes Program structure definition
100 uint32_t OptionType; /*!< OptionType: Option byte to be configured for extension .
101 This parameter can be a value of @ref FLASHEx_OptionAdv_Type */
103 uint8_t PCROPState; /*!< PCROPState: PCROP activation or deactivation.
104 This parameter can be a value of @ref FLASHEx_PCROP_State */
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 */
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 */
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;
122 /** @defgroup FLASHEx_Exported_Constants FLASHEx Exported Constants
126 /** @defgroup FLASHEx_Type_Erase FLASHEx_Type_Erase
129 #define FLASH_TYPEERASE_PAGES ((uint32_t)0x00) /*!< Page erase only */
134 /** @defgroup FLASHEx_Option_Type FLASHEx Option Type
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*/
146 /** @defgroup FLASHEx_WRP_State FLASHEx WRP State
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 */
155 /** @defgroup FLASHEx_Option_Bytes_ReadWrite_Mask FLASHEx Option Bytes Write Mask
158 #define WRP_MASK_LOW ((uint32_t)0x0000FFFF)
159 #define WRP_MASK_HIGH ((uint32_t)0xFFFF0000)
164 #if defined (STM32L031xx) || defined (STM32L041xx)
165 /** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASHEx Option Bytes Write Protection
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 */
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
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 */
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
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 */
246 /** @defgroup FLASHEx_Option_Bytes_Write_Protection2 FLASHEx Option Bytes Write Protection
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 */
269 #endif /* STM32L071xx || STM32L072xx || (STM32L073xx) || (STM32L081xx) || (STM32L082xx) || (STM32L083xx) */
271 /** @defgroup FLASHEx_Option_Bytes_Read_Protection FLASHEx Option Bytes Read Protection
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 */
282 /** @defgroup FLASHEx_Option_Bytes_BOR_Level FLASHEx Option Bytes BOR Level
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 */
296 /** @defgroup FLASHEx_Option_Bytes_IWatchdog FLASHEx Option Bytes IWatchdog
299 #define OB_IWDG_SW ((uint8_t)0x10) /*!< Software WDG selected */
300 #define OB_IWDG_HW ((uint8_t)0x00) /*!< Hardware WDG selected */
305 /** @defgroup FLASHEx_Option_Bytes_nRST_STOP FLASHEx Option Bytes nRST_STOP
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 */
314 /** @defgroup FLASHEx_Option_Bytes_nRST_STDBY FLASHEx Option Bytes nRST_STDBY
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 */
324 /** @defgroup FLASHEx_PCROP_State
327 #define OB_PCROP_STATE_DISABLE ((uint8_t)0x00) /*!< Disable PCROP */
328 #define OB_PCROP_STATE_ENABLE ((uint8_t)0x01) /*!< Enable PCROP */
334 /** @defgroup FLASHEx_OptionAdv_Type
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 */
347 #if defined (STM32L031xx) || defined (STM32L041xx)
348 /** @defgroup FLASHEx_Option_Bytes_PC_ReadWrite_Protection FLASHEx Option Bytes PC Read/Write Protection
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 */
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
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 */
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
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 */
430 /** @defgroup FLASHEx_Option_Bytes_ReadWrite_Protection2 FLASHEx Option Bytes Read Write Protection
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 */
453 #endif /* if STM32L071xx || STM32L072xx || STM32L073xx || STM32L081xx || STM32L082xx || STM32L083xx */
455 /** @defgroup FLASHEx_Option_Bytes_BOOTBit1
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 */
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
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) */
476 #endif /* if STM32L071xx || STM32L072xx || STM32L073xx || STM32L081xx || STM32L082xx || STM32L083xx */
478 /** @defgroup FLASHEx_Type_Program_Data FLASHEx Type Program Data
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.*/
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
492 /** @defgroup FLASHEx_Address FLASHEx Address
495 #define FLASH_NBPAGES_MAX (FLASH_SIZE / FLASH_PAGE_SIZE)
504 /** @defgroup FLASHEx_Exported_Macros macros to control FLASH features
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
517 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) \
518 MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(__LATENCY__))
521 * @brief Enable/Disable the FLASH prefetch buffer.
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)
528 * @brief Enable/Disable the FLASH Buffer cache.
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)
535 * @brief Enable/Disable the FLASH preread buffer.
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)
542 * @brief Enable/Disable the FLASH power down during Sleep mode.
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)
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.
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); \
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.
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); \
572 /** @defgroup FLASHEx_Exported_Functions FLASHEx Exported functions
576 /** @defgroup FLASHEx_Exported_Functions_Group1 FLASH Memory Erasing functions
579 HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError);
580 HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit);
585 /** @defgroup FLASHEx_Exported_Functions_Group2 Option Bytes Programming functions
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);
598 /** @defgroup FLASHEx_Exported_Functions_Group3 DATA EEPROM Programming functions
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);
616 /** @addtogroup FLASH_Private_Macros FLASH Private Macros
619 #define IS_FLASH_TYPEERASE(__VALUE__) (((__VALUE__) == FLASH_TYPEERASE_PAGES))
621 #define IS_OPTIONBYTE(__VALUE__) (((__VALUE__) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | \
622 OPTIONBYTE_USER | OPTIONBYTE_BOR | OPTIONBYTE_BOOT_BIT1)))
624 #define IS_WRPSTATE(__VALUE__) (((__VALUE__) == OB_WRPSTATE_DISABLE) || \
625 ((__VALUE__) == OB_WRPSTATE_ENABLE))
627 #define IS_OB_WRP(PAGE) (((PAGE) != 0x0000000))
629 #define IS_OB_RDP(__LEVEL__) (((__LEVEL__) == OB_RDP_LEVEL0)||\
630 ((__LEVEL__) == OB_RDP_LEVEL1)||\
631 ((__LEVEL__) == OB_RDP_LEVEL2))
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))
640 #define IS_OB_IWDG_SOURCE(__SOURCE__) (((__SOURCE__) == OB_IWDG_SW) || ((__SOURCE__) == OB_IWDG_HW))
642 #define IS_OB_STOP_SOURCE(__SOURCE__) (((__SOURCE__) == OB_STOP_NORST) || ((__SOURCE__) == OB_STOP_RST))
644 #define IS_OB_STDBY_SOURCE(__SOURCE__) (((__SOURCE__) == OB_STDBY_NORST) || ((__SOURCE__) == OB_STDBY_RST))
646 #define IS_PCROPSTATE(VALUE)(((VALUE) == OB_PCROP_STATE_DISABLE) || \
647 ((VALUE) == OB_PCROP_STATE_ENABLE))
649 #define IS_OB_PCROP(__PAGE__) (((__PAGE__) != 0x0000000))
651 #define IS_OB_BOOT1(__BOOT_BIT1__) (((__BOOT_BIT1__) == OB_BOOT_BIT1_RESET) || ((__BOOT_BIT1__) == OB_BOOT_BIT1_SET))
653 #define IS_TYPEPROGRAMDATA(__VALUE__) (((__VALUE__) == FLASH_TYPEPROGRAMDATA_BYTE) || \
654 ((__VALUE__) == FLASH_TYPEPROGRAMDATA_HALFWORD) || \
655 ((__VALUE__) == FLASH_TYPEPROGRAMDATA_WORD))
657 #define IS_NBPAGES(__PAGES__) (((__PAGES__) >= 1) && ((__PAGES__) <= FLASH_NBPAGES_MAX))
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)))
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)))
689 #endif /* __STM32L0xx_HAL_FLASH_EX_H */
691 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/