STM32F103xB HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f1xx_hal_flash_ex.h 00004 * @author MCD Application Team 00005 * @brief Header file of Flash HAL Extended module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 00010 * All rights reserved.</center></h2> 00011 * 00012 * This software component is licensed by ST under BSD 3-Clause license, 00013 * the "License"; You may not use this file except in compliance with the 00014 * License. You may obtain a copy of the License at: 00015 * opensource.org/licenses/BSD-3-Clause 00016 * 00017 ****************************************************************************** 00018 */ 00019 00020 /* Define to prevent recursive inclusion -------------------------------------*/ 00021 #ifndef __STM32F1xx_HAL_FLASH_EX_H 00022 #define __STM32F1xx_HAL_FLASH_EX_H 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 /* Includes ------------------------------------------------------------------*/ 00029 #include "stm32f1xx_hal_def.h" 00030 00031 /** @addtogroup STM32F1xx_HAL_Driver 00032 * @{ 00033 */ 00034 00035 /** @addtogroup FLASHEx 00036 * @{ 00037 */ 00038 00039 /** @addtogroup FLASHEx_Private_Constants 00040 * @{ 00041 */ 00042 00043 #define FLASH_SIZE_DATA_REGISTER 0x1FFFF7E0U 00044 #define OBR_REG_INDEX 1U 00045 #define SR_FLAG_MASK ((uint32_t)(FLASH_SR_BSY | FLASH_SR_PGERR | FLASH_SR_WRPRTERR | FLASH_SR_EOP)) 00046 00047 /** 00048 * @} 00049 */ 00050 00051 /** @addtogroup FLASHEx_Private_Macros 00052 * @{ 00053 */ 00054 00055 #define IS_FLASH_TYPEERASE(VALUE) (((VALUE) == FLASH_TYPEERASE_PAGES) || ((VALUE) == FLASH_TYPEERASE_MASSERASE)) 00056 00057 #define IS_OPTIONBYTE(VALUE) (((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_DATA))) 00058 00059 #define IS_WRPSTATE(VALUE) (((VALUE) == OB_WRPSTATE_DISABLE) || ((VALUE) == OB_WRPSTATE_ENABLE)) 00060 00061 #define IS_OB_RDP_LEVEL(LEVEL) (((LEVEL) == OB_RDP_LEVEL_0) || ((LEVEL) == OB_RDP_LEVEL_1)) 00062 00063 #define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == OB_DATA_ADDRESS_DATA0) || ((ADDRESS) == OB_DATA_ADDRESS_DATA1)) 00064 00065 #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW)) 00066 00067 #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NO_RST) || ((SOURCE) == OB_STOP_RST)) 00068 00069 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NO_RST) || ((SOURCE) == OB_STDBY_RST)) 00070 00071 #if defined(FLASH_BANK2_END) 00072 #define IS_OB_BOOT1(BOOT1) (((BOOT1) == OB_BOOT1_RESET) || ((BOOT1) == OB_BOOT1_SET)) 00073 #endif /* FLASH_BANK2_END */ 00074 00075 /* Low Density */ 00076 #if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6)) 00077 #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)- 1 <= 0x08007FFFU) : \ 00078 ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)- 1 <= 0x08003FFFU)) 00079 #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */ 00080 00081 /* Medium Density */ 00082 #if (defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB)) 00083 #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0801FFFFU) : \ 00084 (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x40U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0800FFFFU) : \ 00085 (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x08007FFFU) : \ 00086 ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x08003FFFU)))) 00087 #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB*/ 00088 00089 /* High Density */ 00090 #if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE)) 00091 #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x200U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0807FFFFU) : \ 00092 (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x180U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0805FFFFU) : \ 00093 ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0803FFFFU))) 00094 #endif /* STM32F100xE || STM32F101xE || STM32F103xE */ 00095 00096 /* XL Density */ 00097 #if defined(FLASH_BANK2_END) 00098 #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x400U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x080FFFFFU) : \ 00099 ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x080BFFFFU)) 00100 #endif /* FLASH_BANK2_END */ 00101 00102 /* Connectivity Line */ 00103 #if (defined(STM32F105xC) || defined(STM32F107xC)) 00104 #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x100U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0803FFFFU) : \ 00105 (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0801FFFFU) : \ 00106 ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0800FFFFU))) 00107 #endif /* STM32F105xC || STM32F107xC */ 00108 00109 #define IS_OB_WRP(PAGE) (((PAGE) != 0x0000000U)) 00110 00111 #if defined(FLASH_BANK2_END) 00112 #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1) || \ 00113 ((BANK) == FLASH_BANK_2) || \ 00114 ((BANK) == FLASH_BANK_BOTH)) 00115 #else 00116 #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1)) 00117 #endif /* FLASH_BANK2_END */ 00118 00119 /* Low Density */ 00120 #if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6)) 00121 #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? \ 00122 ((ADDRESS) <= FLASH_BANK1_END) : ((ADDRESS) <= 0x08003FFFU))) 00123 00124 #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */ 00125 00126 /* Medium Density */ 00127 #if (defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB)) 00128 #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? \ 00129 ((ADDRESS) <= FLASH_BANK1_END) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x40U) ? \ 00130 ((ADDRESS) <= 0x0800FFFF) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20U) ? \ 00131 ((ADDRESS) <= 0x08007FFF) : ((ADDRESS) <= 0x08003FFFU))))) 00132 00133 #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB*/ 00134 00135 /* High Density */ 00136 #if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE)) 00137 #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x200U) ? \ 00138 ((ADDRESS) <= FLASH_BANK1_END) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x180U) ? \ 00139 ((ADDRESS) <= 0x0805FFFFU) : ((ADDRESS) <= 0x0803FFFFU)))) 00140 00141 #endif /* STM32F100xE || STM32F101xE || STM32F103xE */ 00142 00143 /* XL Density */ 00144 #if defined(FLASH_BANK2_END) 00145 #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x400U) ? \ 00146 ((ADDRESS) <= FLASH_BANK2_END) : ((ADDRESS) <= 0x080BFFFFU))) 00147 00148 #endif /* FLASH_BANK2_END */ 00149 00150 /* Connectivity Line */ 00151 #if (defined(STM32F105xC) || defined(STM32F107xC)) 00152 #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x100U) ? \ 00153 ((ADDRESS) <= FLASH_BANK1_END) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80U) ? \ 00154 ((ADDRESS) <= 0x0801FFFFU) : ((ADDRESS) <= 0x0800FFFFU)))) 00155 00156 #endif /* STM32F105xC || STM32F107xC */ 00157 00158 /** 00159 * @} 00160 */ 00161 00162 /* Exported types ------------------------------------------------------------*/ 00163 /** @defgroup FLASHEx_Exported_Types FLASHEx Exported Types 00164 * @{ 00165 */ 00166 00167 /** 00168 * @brief FLASH Erase structure definition 00169 */ 00170 typedef struct 00171 { 00172 uint32_t TypeErase; /*!< TypeErase: Mass erase or page erase. 00173 This parameter can be a value of @ref FLASHEx_Type_Erase */ 00174 00175 uint32_t Banks; /*!< Select banks to erase when Mass erase is enabled. 00176 This parameter must be a value of @ref FLASHEx_Banks */ 00177 00178 uint32_t PageAddress; /*!< PageAdress: Initial FLASH page address to erase when mass erase is disabled 00179 This parameter must be a number between Min_Data = 0x08000000 and Max_Data = FLASH_BANKx_END 00180 (x = 1 or 2 depending on devices)*/ 00181 00182 uint32_t NbPages; /*!< NbPages: Number of pagess to be erased. 00183 This parameter must be a value between Min_Data = 1 and Max_Data = (max number of pages - value of initial page)*/ 00184 00185 } FLASH_EraseInitTypeDef; 00186 00187 /** 00188 * @brief FLASH Options bytes program structure definition 00189 */ 00190 typedef struct 00191 { 00192 uint32_t OptionType; /*!< OptionType: Option byte to be configured. 00193 This parameter can be a value of @ref FLASHEx_OB_Type */ 00194 00195 uint32_t WRPState; /*!< WRPState: Write protection activation or deactivation. 00196 This parameter can be a value of @ref FLASHEx_OB_WRP_State */ 00197 00198 uint32_t WRPPage; /*!< WRPPage: specifies the page(s) to be write protected 00199 This parameter can be a value of @ref FLASHEx_OB_Write_Protection */ 00200 00201 uint32_t Banks; /*!< Select banks for WRP activation/deactivation of all sectors. 00202 This parameter must be a value of @ref FLASHEx_Banks */ 00203 00204 uint8_t RDPLevel; /*!< RDPLevel: Set the read protection level.. 00205 This parameter can be a value of @ref FLASHEx_OB_Read_Protection */ 00206 00207 #if defined(FLASH_BANK2_END) 00208 uint8_t USERConfig; /*!< USERConfig: Program the FLASH User Option Byte: 00209 IWDG / STOP / STDBY / BOOT1 00210 This parameter can be a combination of @ref FLASHEx_OB_IWatchdog, @ref FLASHEx_OB_nRST_STOP, 00211 @ref FLASHEx_OB_nRST_STDBY, @ref FLASHEx_OB_BOOT1 */ 00212 #else 00213 uint8_t USERConfig; /*!< USERConfig: Program the FLASH User Option Byte: 00214 IWDG / STOP / STDBY 00215 This parameter can be a combination of @ref FLASHEx_OB_IWatchdog, @ref FLASHEx_OB_nRST_STOP, 00216 @ref FLASHEx_OB_nRST_STDBY */ 00217 #endif /* FLASH_BANK2_END */ 00218 00219 uint32_t DATAAddress; /*!< DATAAddress: Address of the option byte DATA to be programmed 00220 This parameter can be a value of @ref FLASHEx_OB_Data_Address */ 00221 00222 uint8_t DATAData; /*!< DATAData: Data to be stored in the option byte DATA 00223 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */ 00224 } FLASH_OBProgramInitTypeDef; 00225 00226 /** 00227 * @} 00228 */ 00229 00230 /* Exported constants --------------------------------------------------------*/ 00231 /** @defgroup FLASHEx_Exported_Constants FLASHEx Exported Constants 00232 * @{ 00233 */ 00234 00235 /** @defgroup FLASHEx_Constants FLASH Constants 00236 * @{ 00237 */ 00238 00239 /** @defgroup FLASHEx_Page_Size Page Size 00240 * @{ 00241 */ 00242 #if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6) || defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB)) 00243 #define FLASH_PAGE_SIZE 0x400U 00244 #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */ 00245 /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */ 00246 00247 #if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) || defined(STM32F101xG) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)) 00248 #define FLASH_PAGE_SIZE 0x800U 00249 #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */ 00250 /* STM32F101xG || STM32F103xG */ 00251 /* STM32F105xC || STM32F107xC */ 00252 00253 /** 00254 * @} 00255 */ 00256 00257 /** @defgroup FLASHEx_Type_Erase Type Erase 00258 * @{ 00259 */ 00260 #define FLASH_TYPEERASE_PAGES 0x00U /*!<Pages erase only*/ 00261 #define FLASH_TYPEERASE_MASSERASE 0x02U /*!<Flash mass erase activation*/ 00262 00263 /** 00264 * @} 00265 */ 00266 00267 /** @defgroup FLASHEx_Banks Banks 00268 * @{ 00269 */ 00270 #if defined(FLASH_BANK2_END) 00271 #define FLASH_BANK_1 1U /*!< Bank 1 */ 00272 #define FLASH_BANK_2 2U /*!< Bank 2 */ 00273 #define FLASH_BANK_BOTH ((uint32_t)FLASH_BANK_1 | FLASH_BANK_2) /*!< Bank1 and Bank2 */ 00274 00275 #else 00276 #define FLASH_BANK_1 1U /*!< Bank 1 */ 00277 #endif 00278 /** 00279 * @} 00280 */ 00281 00282 /** 00283 * @} 00284 */ 00285 00286 /** @defgroup FLASHEx_OptionByte_Constants Option Byte Constants 00287 * @{ 00288 */ 00289 00290 /** @defgroup FLASHEx_OB_Type Option Bytes Type 00291 * @{ 00292 */ 00293 #define OPTIONBYTE_WRP 0x01U /*!<WRP option byte configuration*/ 00294 #define OPTIONBYTE_RDP 0x02U /*!<RDP option byte configuration*/ 00295 #define OPTIONBYTE_USER 0x04U /*!<USER option byte configuration*/ 00296 #define OPTIONBYTE_DATA 0x08U /*!<DATA option byte configuration*/ 00297 00298 /** 00299 * @} 00300 */ 00301 00302 /** @defgroup FLASHEx_OB_WRP_State Option Byte WRP State 00303 * @{ 00304 */ 00305 #define OB_WRPSTATE_DISABLE 0x00U /*!<Disable the write protection of the desired pages*/ 00306 #define OB_WRPSTATE_ENABLE 0x01U /*!<Enable the write protection of the desired pagess*/ 00307 00308 /** 00309 * @} 00310 */ 00311 00312 /** @defgroup FLASHEx_OB_Write_Protection Option Bytes Write Protection 00313 * @{ 00314 */ 00315 /* STM32 Low and Medium density devices */ 00316 #if defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6) \ 00317 || defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) \ 00318 || defined(STM32F103xB) 00319 #define OB_WRP_PAGES0TO3 0x00000001U /*!< Write protection of page 0 to 3 */ 00320 #define OB_WRP_PAGES4TO7 0x00000002U /*!< Write protection of page 4 to 7 */ 00321 #define OB_WRP_PAGES8TO11 0x00000004U /*!< Write protection of page 8 to 11 */ 00322 #define OB_WRP_PAGES12TO15 0x00000008U /*!< Write protection of page 12 to 15 */ 00323 #define OB_WRP_PAGES16TO19 0x00000010U /*!< Write protection of page 16 to 19 */ 00324 #define OB_WRP_PAGES20TO23 0x00000020U /*!< Write protection of page 20 to 23 */ 00325 #define OB_WRP_PAGES24TO27 0x00000040U /*!< Write protection of page 24 to 27 */ 00326 #define OB_WRP_PAGES28TO31 0x00000080U /*!< Write protection of page 28 to 31 */ 00327 #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */ 00328 /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */ 00329 00330 /* STM32 Medium-density devices */ 00331 #if defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB) 00332 #define OB_WRP_PAGES32TO35 0x00000100U /*!< Write protection of page 32 to 35 */ 00333 #define OB_WRP_PAGES36TO39 0x00000200U /*!< Write protection of page 36 to 39 */ 00334 #define OB_WRP_PAGES40TO43 0x00000400U /*!< Write protection of page 40 to 43 */ 00335 #define OB_WRP_PAGES44TO47 0x00000800U /*!< Write protection of page 44 to 47 */ 00336 #define OB_WRP_PAGES48TO51 0x00001000U /*!< Write protection of page 48 to 51 */ 00337 #define OB_WRP_PAGES52TO55 0x00002000U /*!< Write protection of page 52 to 55 */ 00338 #define OB_WRP_PAGES56TO59 0x00004000U /*!< Write protection of page 56 to 59 */ 00339 #define OB_WRP_PAGES60TO63 0x00008000U /*!< Write protection of page 60 to 63 */ 00340 #define OB_WRP_PAGES64TO67 0x00010000U /*!< Write protection of page 64 to 67 */ 00341 #define OB_WRP_PAGES68TO71 0x00020000U /*!< Write protection of page 68 to 71 */ 00342 #define OB_WRP_PAGES72TO75 0x00040000U /*!< Write protection of page 72 to 75 */ 00343 #define OB_WRP_PAGES76TO79 0x00080000U /*!< Write protection of page 76 to 79 */ 00344 #define OB_WRP_PAGES80TO83 0x00100000U /*!< Write protection of page 80 to 83 */ 00345 #define OB_WRP_PAGES84TO87 0x00200000U /*!< Write protection of page 84 to 87 */ 00346 #define OB_WRP_PAGES88TO91 0x00400000U /*!< Write protection of page 88 to 91 */ 00347 #define OB_WRP_PAGES92TO95 0x00800000U /*!< Write protection of page 92 to 95 */ 00348 #define OB_WRP_PAGES96TO99 0x01000000U /*!< Write protection of page 96 to 99 */ 00349 #define OB_WRP_PAGES100TO103 0x02000000U /*!< Write protection of page 100 to 103 */ 00350 #define OB_WRP_PAGES104TO107 0x04000000U /*!< Write protection of page 104 to 107 */ 00351 #define OB_WRP_PAGES108TO111 0x08000000U /*!< Write protection of page 108 to 111 */ 00352 #define OB_WRP_PAGES112TO115 0x10000000U /*!< Write protection of page 112 to 115 */ 00353 #define OB_WRP_PAGES116TO119 0x20000000U /*!< Write protection of page 115 to 119 */ 00354 #define OB_WRP_PAGES120TO123 0x40000000U /*!< Write protection of page 120 to 123 */ 00355 #define OB_WRP_PAGES124TO127 0x80000000U /*!< Write protection of page 124 to 127 */ 00356 #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */ 00357 00358 00359 /* STM32 High-density, XL-density and Connectivity line devices */ 00360 #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) \ 00361 || defined(STM32F101xG) || defined(STM32F103xG) \ 00362 || defined(STM32F105xC) || defined(STM32F107xC) 00363 #define OB_WRP_PAGES0TO1 0x00000001U /*!< Write protection of page 0 TO 1 */ 00364 #define OB_WRP_PAGES2TO3 0x00000002U /*!< Write protection of page 2 TO 3 */ 00365 #define OB_WRP_PAGES4TO5 0x00000004U /*!< Write protection of page 4 TO 5 */ 00366 #define OB_WRP_PAGES6TO7 0x00000008U /*!< Write protection of page 6 TO 7 */ 00367 #define OB_WRP_PAGES8TO9 0x00000010U /*!< Write protection of page 8 TO 9 */ 00368 #define OB_WRP_PAGES10TO11 0x00000020U /*!< Write protection of page 10 TO 11 */ 00369 #define OB_WRP_PAGES12TO13 0x00000040U /*!< Write protection of page 12 TO 13 */ 00370 #define OB_WRP_PAGES14TO15 0x00000080U /*!< Write protection of page 14 TO 15 */ 00371 #define OB_WRP_PAGES16TO17 0x00000100U /*!< Write protection of page 16 TO 17 */ 00372 #define OB_WRP_PAGES18TO19 0x00000200U /*!< Write protection of page 18 TO 19 */ 00373 #define OB_WRP_PAGES20TO21 0x00000400U /*!< Write protection of page 20 TO 21 */ 00374 #define OB_WRP_PAGES22TO23 0x00000800U /*!< Write protection of page 22 TO 23 */ 00375 #define OB_WRP_PAGES24TO25 0x00001000U /*!< Write protection of page 24 TO 25 */ 00376 #define OB_WRP_PAGES26TO27 0x00002000U /*!< Write protection of page 26 TO 27 */ 00377 #define OB_WRP_PAGES28TO29 0x00004000U /*!< Write protection of page 28 TO 29 */ 00378 #define OB_WRP_PAGES30TO31 0x00008000U /*!< Write protection of page 30 TO 31 */ 00379 #define OB_WRP_PAGES32TO33 0x00010000U /*!< Write protection of page 32 TO 33 */ 00380 #define OB_WRP_PAGES34TO35 0x00020000U /*!< Write protection of page 34 TO 35 */ 00381 #define OB_WRP_PAGES36TO37 0x00040000U /*!< Write protection of page 36 TO 37 */ 00382 #define OB_WRP_PAGES38TO39 0x00080000U /*!< Write protection of page 38 TO 39 */ 00383 #define OB_WRP_PAGES40TO41 0x00100000U /*!< Write protection of page 40 TO 41 */ 00384 #define OB_WRP_PAGES42TO43 0x00200000U /*!< Write protection of page 42 TO 43 */ 00385 #define OB_WRP_PAGES44TO45 0x00400000U /*!< Write protection of page 44 TO 45 */ 00386 #define OB_WRP_PAGES46TO47 0x00800000U /*!< Write protection of page 46 TO 47 */ 00387 #define OB_WRP_PAGES48TO49 0x01000000U /*!< Write protection of page 48 TO 49 */ 00388 #define OB_WRP_PAGES50TO51 0x02000000U /*!< Write protection of page 50 TO 51 */ 00389 #define OB_WRP_PAGES52TO53 0x04000000U /*!< Write protection of page 52 TO 53 */ 00390 #define OB_WRP_PAGES54TO55 0x08000000U /*!< Write protection of page 54 TO 55 */ 00391 #define OB_WRP_PAGES56TO57 0x10000000U /*!< Write protection of page 56 TO 57 */ 00392 #define OB_WRP_PAGES58TO59 0x20000000U /*!< Write protection of page 58 TO 59 */ 00393 #define OB_WRP_PAGES60TO61 0x40000000U /*!< Write protection of page 60 TO 61 */ 00394 #define OB_WRP_PAGES62TO127 0x80000000U /*!< Write protection of page 62 TO 127 */ 00395 #define OB_WRP_PAGES62TO255 0x80000000U /*!< Write protection of page 62 TO 255 */ 00396 #define OB_WRP_PAGES62TO511 0x80000000U /*!< Write protection of page 62 TO 511 */ 00397 #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */ 00398 /* STM32F101xG || STM32F103xG */ 00399 /* STM32F105xC || STM32F107xC */ 00400 00401 #define OB_WRP_ALLPAGES 0xFFFFFFFFU /*!< Write protection of all Pages */ 00402 00403 /* Low Density */ 00404 #if defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6) 00405 #define OB_WRP_PAGES0TO31MASK 0x000000FFU 00406 #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */ 00407 00408 /* Medium Density */ 00409 #if defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB) 00410 #define OB_WRP_PAGES0TO31MASK 0x000000FFU 00411 #define OB_WRP_PAGES32TO63MASK 0x0000FF00U 00412 #define OB_WRP_PAGES64TO95MASK 0x00FF0000U 00413 #define OB_WRP_PAGES96TO127MASK 0xFF000000U 00414 #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB*/ 00415 00416 /* High Density */ 00417 #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) 00418 #define OB_WRP_PAGES0TO15MASK 0x000000FFU 00419 #define OB_WRP_PAGES16TO31MASK 0x0000FF00U 00420 #define OB_WRP_PAGES32TO47MASK 0x00FF0000U 00421 #define OB_WRP_PAGES48TO255MASK 0xFF000000U 00422 #endif /* STM32F100xE || STM32F101xE || STM32F103xE */ 00423 00424 /* XL Density */ 00425 #if defined(STM32F101xG) || defined(STM32F103xG) 00426 #define OB_WRP_PAGES0TO15MASK 0x000000FFU 00427 #define OB_WRP_PAGES16TO31MASK 0x0000FF00U 00428 #define OB_WRP_PAGES32TO47MASK 0x00FF0000U 00429 #define OB_WRP_PAGES48TO511MASK 0xFF000000U 00430 #endif /* STM32F101xG || STM32F103xG */ 00431 00432 /* Connectivity line devices */ 00433 #if defined(STM32F105xC) || defined(STM32F107xC) 00434 #define OB_WRP_PAGES0TO15MASK 0x000000FFU 00435 #define OB_WRP_PAGES16TO31MASK 0x0000FF00U 00436 #define OB_WRP_PAGES32TO47MASK 0x00FF0000U 00437 #define OB_WRP_PAGES48TO127MASK 0xFF000000U 00438 #endif /* STM32F105xC || STM32F107xC */ 00439 00440 /** 00441 * @} 00442 */ 00443 00444 /** @defgroup FLASHEx_OB_Read_Protection Option Byte Read Protection 00445 * @{ 00446 */ 00447 #define OB_RDP_LEVEL_0 ((uint8_t)0xA5) 00448 #define OB_RDP_LEVEL_1 ((uint8_t)0x00) 00449 /** 00450 * @} 00451 */ 00452 00453 /** @defgroup FLASHEx_OB_IWatchdog Option Byte IWatchdog 00454 * @{ 00455 */ 00456 #define OB_IWDG_SW ((uint16_t)0x0001) /*!< Software IWDG selected */ 00457 #define OB_IWDG_HW ((uint16_t)0x0000) /*!< Hardware IWDG selected */ 00458 /** 00459 * @} 00460 */ 00461 00462 /** @defgroup FLASHEx_OB_nRST_STOP Option Byte nRST STOP 00463 * @{ 00464 */ 00465 #define OB_STOP_NO_RST ((uint16_t)0x0002) /*!< No reset generated when entering in STOP */ 00466 #define OB_STOP_RST ((uint16_t)0x0000) /*!< Reset generated when entering in STOP */ 00467 /** 00468 * @} 00469 */ 00470 00471 /** @defgroup FLASHEx_OB_nRST_STDBY Option Byte nRST STDBY 00472 * @{ 00473 */ 00474 #define OB_STDBY_NO_RST ((uint16_t)0x0004) /*!< No reset generated when entering in STANDBY */ 00475 #define OB_STDBY_RST ((uint16_t)0x0000) /*!< Reset generated when entering in STANDBY */ 00476 /** 00477 * @} 00478 */ 00479 00480 #if defined(FLASH_BANK2_END) 00481 /** @defgroup FLASHEx_OB_BOOT1 Option Byte BOOT1 00482 * @{ 00483 */ 00484 #define OB_BOOT1_RESET ((uint16_t)0x0000) /*!< BOOT1 Reset */ 00485 #define OB_BOOT1_SET ((uint16_t)0x0008) /*!< BOOT1 Set */ 00486 /** 00487 * @} 00488 */ 00489 #endif /* FLASH_BANK2_END */ 00490 00491 /** @defgroup FLASHEx_OB_Data_Address Option Byte Data Address 00492 * @{ 00493 */ 00494 #define OB_DATA_ADDRESS_DATA0 0x1FFFF804U 00495 #define OB_DATA_ADDRESS_DATA1 0x1FFFF806U 00496 /** 00497 * @} 00498 */ 00499 00500 /** 00501 * @} 00502 */ 00503 00504 /** @addtogroup FLASHEx_Constants 00505 * @{ 00506 */ 00507 00508 /** @defgroup FLASH_Flag_definition Flag definition 00509 * @brief Flag definition 00510 * @{ 00511 */ 00512 #if defined(FLASH_BANK2_END) 00513 #define FLASH_FLAG_BSY FLASH_FLAG_BSY_BANK1 /*!< FLASH Bank1 Busy flag */ 00514 #define FLASH_FLAG_PGERR FLASH_FLAG_PGERR_BANK1 /*!< FLASH Bank1 Programming error flag */ 00515 #define FLASH_FLAG_WRPERR FLASH_FLAG_WRPERR_BANK1 /*!< FLASH Bank1 Write protected error flag */ 00516 #define FLASH_FLAG_EOP FLASH_FLAG_EOP_BANK1 /*!< FLASH Bank1 End of Operation flag */ 00517 00518 #define FLASH_FLAG_BSY_BANK1 FLASH_SR_BSY /*!< FLASH Bank1 Busy flag */ 00519 #define FLASH_FLAG_PGERR_BANK1 FLASH_SR_PGERR /*!< FLASH Bank1 Programming error flag */ 00520 #define FLASH_FLAG_WRPERR_BANK1 FLASH_SR_WRPRTERR /*!< FLASH Bank1 Write protected error flag */ 00521 #define FLASH_FLAG_EOP_BANK1 FLASH_SR_EOP /*!< FLASH Bank1 End of Operation flag */ 00522 00523 #define FLASH_FLAG_BSY_BANK2 (FLASH_SR2_BSY << 16U) /*!< FLASH Bank2 Busy flag */ 00524 #define FLASH_FLAG_PGERR_BANK2 (FLASH_SR2_PGERR << 16U) /*!< FLASH Bank2 Programming error flag */ 00525 #define FLASH_FLAG_WRPERR_BANK2 (FLASH_SR2_WRPRTERR << 16U) /*!< FLASH Bank2 Write protected error flag */ 00526 #define FLASH_FLAG_EOP_BANK2 (FLASH_SR2_EOP << 16U) /*!< FLASH Bank2 End of Operation flag */ 00527 00528 #else 00529 00530 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */ 00531 #define FLASH_FLAG_PGERR FLASH_SR_PGERR /*!< FLASH Programming error flag */ 00532 #define FLASH_FLAG_WRPERR FLASH_SR_WRPRTERR /*!< FLASH Write protected error flag */ 00533 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */ 00534 00535 #endif 00536 #define FLASH_FLAG_OPTVERR ((OBR_REG_INDEX << 8U | FLASH_OBR_OPTERR)) /*!< Option Byte Error */ 00537 /** 00538 * @} 00539 */ 00540 00541 /** @defgroup FLASH_Interrupt_definition Interrupt definition 00542 * @brief FLASH Interrupt definition 00543 * @{ 00544 */ 00545 #if defined(FLASH_BANK2_END) 00546 #define FLASH_IT_EOP FLASH_IT_EOP_BANK1 /*!< End of FLASH Operation Interrupt source Bank1 */ 00547 #define FLASH_IT_ERR FLASH_IT_ERR_BANK1 /*!< Error Interrupt source Bank1 */ 00548 00549 #define FLASH_IT_EOP_BANK1 FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source Bank1 */ 00550 #define FLASH_IT_ERR_BANK1 FLASH_CR_ERRIE /*!< Error Interrupt source Bank1 */ 00551 00552 #define FLASH_IT_EOP_BANK2 (FLASH_CR2_EOPIE << 16U) /*!< End of FLASH Operation Interrupt source Bank2 */ 00553 #define FLASH_IT_ERR_BANK2 (FLASH_CR2_ERRIE << 16U) /*!< Error Interrupt source Bank2 */ 00554 00555 #else 00556 00557 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */ 00558 #define FLASH_IT_ERR FLASH_CR_ERRIE /*!< Error Interrupt source */ 00559 00560 #endif 00561 /** 00562 * @} 00563 */ 00564 00565 /** 00566 * @} 00567 */ 00568 00569 00570 /** 00571 * @} 00572 */ 00573 00574 /* Exported macro ------------------------------------------------------------*/ 00575 /** @defgroup FLASHEx_Exported_Macros FLASHEx Exported Macros 00576 * @{ 00577 */ 00578 00579 /** @defgroup FLASH_Interrupt Interrupt 00580 * @brief macros to handle FLASH interrupts 00581 * @{ 00582 */ 00583 00584 #if defined(FLASH_BANK2_END) 00585 /** 00586 * @brief Enable the specified FLASH interrupt. 00587 * @param __INTERRUPT__ FLASH interrupt 00588 * This parameter can be any combination of the following values: 00589 * @arg @ref FLASH_IT_EOP_BANK1 End of FLASH Operation Interrupt on bank1 00590 * @arg @ref FLASH_IT_ERR_BANK1 Error Interrupt on bank1 00591 * @arg @ref FLASH_IT_EOP_BANK2 End of FLASH Operation Interrupt on bank2 00592 * @arg @ref FLASH_IT_ERR_BANK2 Error Interrupt on bank2 00593 * @retval none 00594 */ 00595 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) do { \ 00596 /* Enable Bank1 IT */ \ 00597 SET_BIT(FLASH->CR, ((__INTERRUPT__) & 0x0000FFFFU)); \ 00598 /* Enable Bank2 IT */ \ 00599 SET_BIT(FLASH->CR2, ((__INTERRUPT__) >> 16U)); \ 00600 } while(0U) 00601 00602 /** 00603 * @brief Disable the specified FLASH interrupt. 00604 * @param __INTERRUPT__ FLASH interrupt 00605 * This parameter can be any combination of the following values: 00606 * @arg @ref FLASH_IT_EOP_BANK1 End of FLASH Operation Interrupt on bank1 00607 * @arg @ref FLASH_IT_ERR_BANK1 Error Interrupt on bank1 00608 * @arg @ref FLASH_IT_EOP_BANK2 End of FLASH Operation Interrupt on bank2 00609 * @arg @ref FLASH_IT_ERR_BANK2 Error Interrupt on bank2 00610 * @retval none 00611 */ 00612 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) do { \ 00613 /* Disable Bank1 IT */ \ 00614 CLEAR_BIT(FLASH->CR, ((__INTERRUPT__) & 0x0000FFFFU)); \ 00615 /* Disable Bank2 IT */ \ 00616 CLEAR_BIT(FLASH->CR2, ((__INTERRUPT__) >> 16U)); \ 00617 } while(0U) 00618 00619 /** 00620 * @brief Get the specified FLASH flag status. 00621 * @param __FLAG__ specifies the FLASH flag to check. 00622 * This parameter can be one of the following values: 00623 * @arg @ref FLASH_FLAG_EOP_BANK1 FLASH End of Operation flag on bank1 00624 * @arg @ref FLASH_FLAG_WRPERR_BANK1 FLASH Write protected error flag on bank1 00625 * @arg @ref FLASH_FLAG_PGERR_BANK1 FLASH Programming error flag on bank1 00626 * @arg @ref FLASH_FLAG_BSY_BANK1 FLASH Busy flag on bank1 00627 * @arg @ref FLASH_FLAG_EOP_BANK2 FLASH End of Operation flag on bank2 00628 * @arg @ref FLASH_FLAG_WRPERR_BANK2 FLASH Write protected error flag on bank2 00629 * @arg @ref FLASH_FLAG_PGERR_BANK2 FLASH Programming error flag on bank2 00630 * @arg @ref FLASH_FLAG_BSY_BANK2 FLASH Busy flag on bank2 00631 * @arg @ref FLASH_FLAG_OPTVERR Loaded OB and its complement do not match 00632 * @retval The new state of __FLAG__ (SET or RESET). 00633 */ 00634 #define __HAL_FLASH_GET_FLAG(__FLAG__) (((__FLAG__) == FLASH_FLAG_OPTVERR) ? \ 00635 (FLASH->OBR & FLASH_OBR_OPTERR) : \ 00636 ((((__FLAG__) & SR_FLAG_MASK) != RESET)? \ 00637 (FLASH->SR & ((__FLAG__) & SR_FLAG_MASK)) : \ 00638 (FLASH->SR2 & ((__FLAG__) >> 16U)))) 00639 00640 /** 00641 * @brief Clear the specified FLASH flag. 00642 * @param __FLAG__ specifies the FLASH flags to clear. 00643 * This parameter can be any combination of the following values: 00644 * @arg @ref FLASH_FLAG_EOP_BANK1 FLASH End of Operation flag on bank1 00645 * @arg @ref FLASH_FLAG_WRPERR_BANK1 FLASH Write protected error flag on bank1 00646 * @arg @ref FLASH_FLAG_PGERR_BANK1 FLASH Programming error flag on bank1 00647 * @arg @ref FLASH_FLAG_BSY_BANK1 FLASH Busy flag on bank1 00648 * @arg @ref FLASH_FLAG_EOP_BANK2 FLASH End of Operation flag on bank2 00649 * @arg @ref FLASH_FLAG_WRPERR_BANK2 FLASH Write protected error flag on bank2 00650 * @arg @ref FLASH_FLAG_PGERR_BANK2 FLASH Programming error flag on bank2 00651 * @arg @ref FLASH_FLAG_BSY_BANK2 FLASH Busy flag on bank2 00652 * @arg @ref FLASH_FLAG_OPTVERR Loaded OB and its complement do not match 00653 * @retval none 00654 */ 00655 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) do { \ 00656 /* Clear FLASH_FLAG_OPTVERR flag */ \ 00657 if ((__FLAG__) == FLASH_FLAG_OPTVERR) \ 00658 { \ 00659 CLEAR_BIT(FLASH->OBR, FLASH_OBR_OPTERR); \ 00660 } \ 00661 else { \ 00662 /* Clear Flag in Bank1 */ \ 00663 if (((__FLAG__) & SR_FLAG_MASK) != RESET) \ 00664 { \ 00665 FLASH->SR = ((__FLAG__) & SR_FLAG_MASK); \ 00666 } \ 00667 /* Clear Flag in Bank2 */ \ 00668 if (((__FLAG__) >> 16U) != RESET) \ 00669 { \ 00670 FLASH->SR2 = ((__FLAG__) >> 16U); \ 00671 } \ 00672 } \ 00673 } while(0U) 00674 #else 00675 /** 00676 * @brief Enable the specified FLASH interrupt. 00677 * @param __INTERRUPT__ FLASH interrupt 00678 * This parameter can be any combination of the following values: 00679 * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt 00680 * @arg @ref FLASH_IT_ERR Error Interrupt 00681 * @retval none 00682 */ 00683 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__)) 00684 00685 /** 00686 * @brief Disable the specified FLASH interrupt. 00687 * @param __INTERRUPT__ FLASH interrupt 00688 * This parameter can be any combination of the following values: 00689 * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt 00690 * @arg @ref FLASH_IT_ERR Error Interrupt 00691 * @retval none 00692 */ 00693 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(__INTERRUPT__)) 00694 00695 /** 00696 * @brief Get the specified FLASH flag status. 00697 * @param __FLAG__ specifies the FLASH flag to check. 00698 * This parameter can be one of the following values: 00699 * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag 00700 * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag 00701 * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag 00702 * @arg @ref FLASH_FLAG_BSY FLASH Busy flag 00703 * @arg @ref FLASH_FLAG_OPTVERR Loaded OB and its complement do not match 00704 * @retval The new state of __FLAG__ (SET or RESET). 00705 */ 00706 #define __HAL_FLASH_GET_FLAG(__FLAG__) (((__FLAG__) == FLASH_FLAG_OPTVERR) ? \ 00707 (FLASH->OBR & FLASH_OBR_OPTERR) : \ 00708 (FLASH->SR & (__FLAG__))) 00709 /** 00710 * @brief Clear the specified FLASH flag. 00711 * @param __FLAG__ specifies the FLASH flags to clear. 00712 * This parameter can be any combination of the following values: 00713 * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag 00714 * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag 00715 * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag 00716 * @arg @ref FLASH_FLAG_OPTVERR Loaded OB and its complement do not match 00717 * @retval none 00718 */ 00719 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) do { \ 00720 /* Clear FLASH_FLAG_OPTVERR flag */ \ 00721 if ((__FLAG__) == FLASH_FLAG_OPTVERR) \ 00722 { \ 00723 CLEAR_BIT(FLASH->OBR, FLASH_OBR_OPTERR); \ 00724 } \ 00725 else { \ 00726 /* Clear Flag in Bank1 */ \ 00727 FLASH->SR = (__FLAG__); \ 00728 } \ 00729 } while(0U) 00730 00731 #endif 00732 00733 /** 00734 * @} 00735 */ 00736 00737 /** 00738 * @} 00739 */ 00740 00741 /* Exported functions --------------------------------------------------------*/ 00742 /** @addtogroup FLASHEx_Exported_Functions 00743 * @{ 00744 */ 00745 00746 /** @addtogroup FLASHEx_Exported_Functions_Group1 00747 * @{ 00748 */ 00749 /* IO operation functions *****************************************************/ 00750 HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError); 00751 HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit); 00752 00753 /** 00754 * @} 00755 */ 00756 00757 /** @addtogroup FLASHEx_Exported_Functions_Group2 00758 * @{ 00759 */ 00760 /* Peripheral Control functions ***********************************************/ 00761 HAL_StatusTypeDef HAL_FLASHEx_OBErase(void); 00762 HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit); 00763 void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit); 00764 uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress); 00765 /** 00766 * @} 00767 */ 00768 00769 /** 00770 * @} 00771 */ 00772 00773 /** 00774 * @} 00775 */ 00776 00777 /** 00778 * @} 00779 */ 00780 #ifdef __cplusplus 00781 } 00782 #endif 00783 00784 #endif /* __STM32F1xx_HAL_FLASH_EX_H */ 00785 00786 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/