stm32f1xx_hal_flash_ex.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_hal_flash_ex.h
  4. * @author MCD Application Team
  5. * @version V1.0.4
  6. * @date 29-April-2016
  7. * @brief Header file of Flash HAL Extended module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F1xx_HAL_FLASH_EX_H
  39. #define __STM32F1xx_HAL_FLASH_EX_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f1xx_hal_def.h"
  45. /** @addtogroup STM32F1xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup FLASHEx
  49. * @{
  50. */
  51. /** @addtogroup FLASHEx_Private_Constants
  52. * @{
  53. */
  54. #define FLASH_SIZE_DATA_REGISTER ((uint32_t)0x1FFFF7E0)
  55. #define OBR_REG_INDEX ((uint32_t)1)
  56. #define SR_FLAG_MASK ((uint32_t)(FLASH_SR_BSY | FLASH_SR_PGERR | FLASH_SR_WRPRTERR | FLASH_SR_EOP))
  57. /**
  58. * @}
  59. */
  60. /** @addtogroup FLASHEx_Private_Macros
  61. * @{
  62. */
  63. #define IS_FLASH_TYPEERASE(VALUE) (((VALUE) == FLASH_TYPEERASE_PAGES) || ((VALUE) == FLASH_TYPEERASE_MASSERASE))
  64. #define IS_OPTIONBYTE(VALUE) (((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_DATA)))
  65. #define IS_WRPSTATE(VALUE) (((VALUE) == OB_WRPSTATE_DISABLE) || ((VALUE) == OB_WRPSTATE_ENABLE))
  66. #define IS_OB_RDP_LEVEL(LEVEL) (((LEVEL) == OB_RDP_LEVEL_0) || ((LEVEL) == OB_RDP_LEVEL_1))
  67. #define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == OB_DATA_ADDRESS_DATA0) || ((ADDRESS) == OB_DATA_ADDRESS_DATA1))
  68. #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
  69. #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NO_RST) || ((SOURCE) == OB_STOP_RST))
  70. #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NO_RST) || ((SOURCE) == OB_STDBY_RST))
  71. #if defined(FLASH_BANK2_END)
  72. #define IS_OB_BOOT1(BOOT1) (((BOOT1) == OB_BOOT1_RESET) || ((BOOT1) == OB_BOOT1_SET))
  73. #endif /* FLASH_BANK2_END */
  74. /* Low Density */
  75. #if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6))
  76. #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x08007FFF) : \
  77. ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x08003FFF))
  78. #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
  79. /* Medium Density */
  80. #if (defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB))
  81. #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0801FFFF) : \
  82. (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x40) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0800FFFF) : \
  83. (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x08007FFF) : \
  84. ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x08003FFF))))
  85. #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB*/
  86. /* High Density */
  87. #if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE))
  88. #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x200) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0807FFFF) : \
  89. (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x180) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0805FFFF) : \
  90. ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0803FFFF)))
  91. #endif /* STM32F100xE || STM32F101xE || STM32F103xE */
  92. /* XL Density */
  93. #if defined(FLASH_BANK2_END)
  94. #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x400) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x080FFFFF) : \
  95. ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x080BFFFF))
  96. #endif /* FLASH_BANK2_END */
  97. /* Connectivity Line */
  98. #if (defined(STM32F105xC) || defined(STM32F107xC))
  99. #define IS_FLASH_NB_PAGES(ADDRESS,NBPAGES) (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x100) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0803FFFF) : \
  100. (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80) ? ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0801FFFF) : \
  101. ((ADDRESS)+((NBPAGES)*FLASH_PAGE_SIZE)-1 <= 0x0800FFFF)))
  102. #endif /* STM32F105xC || STM32F107xC */
  103. #define IS_OB_WRP(PAGE) (((PAGE) != 0x0000000))
  104. #if defined(FLASH_BANK2_END)
  105. #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1) || \
  106. ((BANK) == FLASH_BANK_2) || \
  107. ((BANK) == FLASH_BANK_BOTH))
  108. #else
  109. #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1))
  110. #endif /* FLASH_BANK2_END */
  111. /* Low Density */
  112. #if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6))
  113. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20) ? \
  114. ((ADDRESS) <= FLASH_BANK1_END) : ((ADDRESS) <= 0x08003FFF)))
  115. #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
  116. /* Medium Density */
  117. #if (defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB))
  118. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80) ? \
  119. ((ADDRESS) <= FLASH_BANK1_END) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x40) ? \
  120. ((ADDRESS) <= 0x0800FFFF) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x20) ? \
  121. ((ADDRESS) <= 0x08007FFF) : ((ADDRESS) <= 0x08003FFF)))))
  122. #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB*/
  123. /* High Density */
  124. #if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE))
  125. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x200) ? \
  126. ((ADDRESS) <= FLASH_BANK1_END) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x180) ? \
  127. ((ADDRESS) <= 0x0805FFFF) : ((ADDRESS) <= 0x0803FFFF))))
  128. #endif /* STM32F100xE || STM32F101xE || STM32F103xE */
  129. /* XL Density */
  130. #if defined(FLASH_BANK2_END)
  131. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x400) ? \
  132. ((ADDRESS) <= FLASH_BANK2_END) : ((ADDRESS) <= 0x080BFFFF)))
  133. #endif /* FLASH_BANK2_END */
  134. /* Connectivity Line */
  135. #if (defined(STM32F105xC) || defined(STM32F107xC))
  136. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x100) ? \
  137. ((ADDRESS) <= FLASH_BANK1_END) : (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x80) ? \
  138. ((ADDRESS) <= 0x0801FFFF) : ((ADDRESS) <= 0x0800FFFF))))
  139. #endif /* STM32F105xC || STM32F107xC */
  140. /**
  141. * @}
  142. */
  143. /* Exported types ------------------------------------------------------------*/
  144. /** @defgroup FLASHEx_Exported_Types FLASHEx Exported Types
  145. * @{
  146. */
  147. /**
  148. * @brief FLASH Erase structure definition
  149. */
  150. typedef struct
  151. {
  152. uint32_t TypeErase; /*!< TypeErase: Mass erase or page erase.
  153. This parameter can be a value of @ref FLASHEx_Type_Erase */
  154. uint32_t Banks; /*!< Select banks to erase when Mass erase is enabled.
  155. This parameter must be a value of @ref FLASHEx_Banks */
  156. uint32_t PageAddress; /*!< PageAdress: Initial FLASH page address to erase when mass erase is disabled
  157. This parameter must be a number between Min_Data = 0x08000000 and Max_Data = FLASH_BANKx_END
  158. (x = 1 or 2 depending on devices)*/
  159. uint32_t NbPages; /*!< NbPages: Number of pagess to be erased.
  160. This parameter must be a value between Min_Data = 1 and Max_Data = (max number of pages - value of initial page)*/
  161. } FLASH_EraseInitTypeDef;
  162. /**
  163. * @brief FLASH Options bytes program structure definition
  164. */
  165. typedef struct
  166. {
  167. uint32_t OptionType; /*!< OptionType: Option byte to be configured.
  168. This parameter can be a value of @ref FLASHEx_OB_Type */
  169. uint32_t WRPState; /*!< WRPState: Write protection activation or deactivation.
  170. This parameter can be a value of @ref FLASHEx_OB_WRP_State */
  171. uint32_t WRPPage; /*!< WRPPage: specifies the page(s) to be write protected
  172. This parameter can be a value of @ref FLASHEx_OB_Write_Protection */
  173. uint32_t Banks; /*!< Select banks for WRP activation/deactivation of all sectors.
  174. This parameter must be a value of @ref FLASHEx_Banks */
  175. uint8_t RDPLevel; /*!< RDPLevel: Set the read protection level..
  176. This parameter can be a value of @ref FLASHEx_OB_Read_Protection */
  177. #if defined(FLASH_BANK2_END)
  178. uint8_t USERConfig; /*!< USERConfig: Program the FLASH User Option Byte:
  179. IWDG / STOP / STDBY / BOOT1
  180. This parameter can be a combination of @ref FLASHEx_OB_IWatchdog, @ref FLASHEx_OB_nRST_STOP,
  181. @ref FLASHEx_OB_nRST_STDBY, @ref FLASHEx_OB_BOOT1 */
  182. #else
  183. uint8_t USERConfig; /*!< USERConfig: Program the FLASH User Option Byte:
  184. IWDG / STOP / STDBY
  185. This parameter can be a combination of @ref FLASHEx_OB_IWatchdog, @ref FLASHEx_OB_nRST_STOP,
  186. @ref FLASHEx_OB_nRST_STDBY */
  187. #endif /* FLASH_BANK2_END */
  188. uint32_t DATAAddress; /*!< DATAAddress: Address of the option byte DATA to be programmed
  189. This parameter can be a value of @ref FLASHEx_OB_Data_Address */
  190. uint8_t DATAData; /*!< DATAData: Data to be stored in the option byte DATA
  191. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */
  192. } FLASH_OBProgramInitTypeDef;
  193. /**
  194. * @}
  195. */
  196. /* Exported constants --------------------------------------------------------*/
  197. /** @defgroup FLASHEx_Exported_Constants FLASHEx Exported Constants
  198. * @{
  199. */
  200. /** @defgroup FLASHEx_Constants FLASH Constants
  201. * @{
  202. */
  203. /** @defgroup FLASHEx_Page_Size Page Size
  204. * @{
  205. */
  206. #if (defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6) || defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB))
  207. #define FLASH_PAGE_SIZE ((uint32_t)0x400)
  208. #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
  209. /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
  210. #if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) || defined(STM32F101xG) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC))
  211. #define FLASH_PAGE_SIZE ((uint32_t)0x800)
  212. #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
  213. /* STM32F101xG || STM32F103xG */
  214. /* STM32F105xC || STM32F107xC */
  215. /**
  216. * @}
  217. */
  218. /** @defgroup FLASHEx_Type_Erase Type Erase
  219. * @{
  220. */
  221. #define FLASH_TYPEERASE_PAGES ((uint32_t)0x00) /*!<Pages erase only*/
  222. #define FLASH_TYPEERASE_MASSERASE ((uint32_t)0x02) /*!<Flash mass erase activation*/
  223. /**
  224. * @}
  225. */
  226. /** @defgroup FLASHEx_Banks Banks
  227. * @{
  228. */
  229. #if defined(FLASH_BANK2_END)
  230. #define FLASH_BANK_1 ((uint32_t)1) /*!< Bank 1 */
  231. #define FLASH_BANK_2 ((uint32_t)2) /*!< Bank 2 */
  232. #define FLASH_BANK_BOTH ((uint32_t)FLASH_BANK_1 | FLASH_BANK_2) /*!< Bank1 and Bank2 */
  233. #else
  234. #define FLASH_BANK_1 ((uint32_t)1) /*!< Bank 1 */
  235. #endif
  236. /**
  237. * @}
  238. */
  239. /**
  240. * @}
  241. */
  242. /** @defgroup FLASHEx_OptionByte_Constants Option Byte Constants
  243. * @{
  244. */
  245. /** @defgroup FLASHEx_OB_Type Option Bytes Type
  246. * @{
  247. */
  248. #define OPTIONBYTE_WRP ((uint32_t)0x01) /*!<WRP option byte configuration*/
  249. #define OPTIONBYTE_RDP ((uint32_t)0x02) /*!<RDP option byte configuration*/
  250. #define OPTIONBYTE_USER ((uint32_t)0x04) /*!<USER option byte configuration*/
  251. #define OPTIONBYTE_DATA ((uint32_t)0x08) /*!<DATA option byte configuration*/
  252. /**
  253. * @}
  254. */
  255. /** @defgroup FLASHEx_OB_WRP_State Option Byte WRP State
  256. * @{
  257. */
  258. #define OB_WRPSTATE_DISABLE ((uint32_t)0x00) /*!<Disable the write protection of the desired pages*/
  259. #define OB_WRPSTATE_ENABLE ((uint32_t)0x01) /*!<Enable the write protection of the desired pagess*/
  260. /**
  261. * @}
  262. */
  263. /** @defgroup FLASHEx_OB_Write_Protection Option Bytes Write Protection
  264. * @{
  265. */
  266. /* STM32 Low and Medium density devices */
  267. #if defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6) \
  268. || defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) \
  269. || defined(STM32F103xB)
  270. #define OB_WRP_PAGES0TO3 ((uint32_t)0x00000001) /*!< Write protection of page 0 to 3 */
  271. #define OB_WRP_PAGES4TO7 ((uint32_t)0x00000002) /*!< Write protection of page 4 to 7 */
  272. #define OB_WRP_PAGES8TO11 ((uint32_t)0x00000004) /*!< Write protection of page 8 to 11 */
  273. #define OB_WRP_PAGES12TO15 ((uint32_t)0x00000008) /*!< Write protection of page 12 to 15 */
  274. #define OB_WRP_PAGES16TO19 ((uint32_t)0x00000010) /*!< Write protection of page 16 to 19 */
  275. #define OB_WRP_PAGES20TO23 ((uint32_t)0x00000020) /*!< Write protection of page 20 to 23 */
  276. #define OB_WRP_PAGES24TO27 ((uint32_t)0x00000040) /*!< Write protection of page 24 to 27 */
  277. #define OB_WRP_PAGES28TO31 ((uint32_t)0x00000080) /*!< Write protection of page 28 to 31 */
  278. #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
  279. /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
  280. /* STM32 Medium-density devices */
  281. #if defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB)
  282. #define OB_WRP_PAGES32TO35 ((uint32_t)0x00000100) /*!< Write protection of page 32 to 35 */
  283. #define OB_WRP_PAGES36TO39 ((uint32_t)0x00000200) /*!< Write protection of page 36 to 39 */
  284. #define OB_WRP_PAGES40TO43 ((uint32_t)0x00000400) /*!< Write protection of page 40 to 43 */
  285. #define OB_WRP_PAGES44TO47 ((uint32_t)0x00000800) /*!< Write protection of page 44 to 47 */
  286. #define OB_WRP_PAGES48TO51 ((uint32_t)0x00001000) /*!< Write protection of page 48 to 51 */
  287. #define OB_WRP_PAGES52TO55 ((uint32_t)0x00002000) /*!< Write protection of page 52 to 55 */
  288. #define OB_WRP_PAGES56TO59 ((uint32_t)0x00004000) /*!< Write protection of page 56 to 59 */
  289. #define OB_WRP_PAGES60TO63 ((uint32_t)0x00008000) /*!< Write protection of page 60 to 63 */
  290. #define OB_WRP_PAGES64TO67 ((uint32_t)0x00010000) /*!< Write protection of page 64 to 67 */
  291. #define OB_WRP_PAGES68TO71 ((uint32_t)0x00020000) /*!< Write protection of page 68 to 71 */
  292. #define OB_WRP_PAGES72TO75 ((uint32_t)0x00040000) /*!< Write protection of page 72 to 75 */
  293. #define OB_WRP_PAGES76TO79 ((uint32_t)0x00080000) /*!< Write protection of page 76 to 79 */
  294. #define OB_WRP_PAGES80TO83 ((uint32_t)0x00100000) /*!< Write protection of page 80 to 83 */
  295. #define OB_WRP_PAGES84TO87 ((uint32_t)0x00200000) /*!< Write protection of page 84 to 87 */
  296. #define OB_WRP_PAGES88TO91 ((uint32_t)0x00400000) /*!< Write protection of page 88 to 91 */
  297. #define OB_WRP_PAGES92TO95 ((uint32_t)0x00800000) /*!< Write protection of page 92 to 95 */
  298. #define OB_WRP_PAGES96TO99 ((uint32_t)0x01000000) /*!< Write protection of page 96 to 99 */
  299. #define OB_WRP_PAGES100TO103 ((uint32_t)0x02000000) /*!< Write protection of page 100 to 103 */
  300. #define OB_WRP_PAGES104TO107 ((uint32_t)0x04000000) /*!< Write protection of page 104 to 107 */
  301. #define OB_WRP_PAGES108TO111 ((uint32_t)0x08000000) /*!< Write protection of page 108 to 111 */
  302. #define OB_WRP_PAGES112TO115 ((uint32_t)0x10000000) /*!< Write protection of page 112 to 115 */
  303. #define OB_WRP_PAGES116TO119 ((uint32_t)0x20000000) /*!< Write protection of page 115 to 119 */
  304. #define OB_WRP_PAGES120TO123 ((uint32_t)0x40000000) /*!< Write protection of page 120 to 123 */
  305. #define OB_WRP_PAGES124TO127 ((uint32_t)0x80000000) /*!< Write protection of page 124 to 127 */
  306. #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
  307. /* STM32 High-density, XL-density and Connectivity line devices */
  308. #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE) \
  309. || defined(STM32F101xG) || defined(STM32F103xG) \
  310. || defined(STM32F105xC) || defined(STM32F107xC)
  311. #define OB_WRP_PAGES0TO1 ((uint32_t)0x00000001) /*!< Write protection of page 0 TO 1 */
  312. #define OB_WRP_PAGES2TO3 ((uint32_t)0x00000002) /*!< Write protection of page 2 TO 3 */
  313. #define OB_WRP_PAGES4TO5 ((uint32_t)0x00000004) /*!< Write protection of page 4 TO 5 */
  314. #define OB_WRP_PAGES6TO7 ((uint32_t)0x00000008) /*!< Write protection of page 6 TO 7 */
  315. #define OB_WRP_PAGES8TO9 ((uint32_t)0x00000010) /*!< Write protection of page 8 TO 9 */
  316. #define OB_WRP_PAGES10TO11 ((uint32_t)0x00000020) /*!< Write protection of page 10 TO 11 */
  317. #define OB_WRP_PAGES12TO13 ((uint32_t)0x00000040) /*!< Write protection of page 12 TO 13 */
  318. #define OB_WRP_PAGES14TO15 ((uint32_t)0x00000080) /*!< Write protection of page 14 TO 15 */
  319. #define OB_WRP_PAGES16TO17 ((uint32_t)0x00000100) /*!< Write protection of page 16 TO 17 */
  320. #define OB_WRP_PAGES18TO19 ((uint32_t)0x00000200) /*!< Write protection of page 18 TO 19 */
  321. #define OB_WRP_PAGES20TO21 ((uint32_t)0x00000400) /*!< Write protection of page 20 TO 21 */
  322. #define OB_WRP_PAGES22TO23 ((uint32_t)0x00000800) /*!< Write protection of page 22 TO 23 */
  323. #define OB_WRP_PAGES24TO25 ((uint32_t)0x00001000) /*!< Write protection of page 24 TO 25 */
  324. #define OB_WRP_PAGES26TO27 ((uint32_t)0x00002000) /*!< Write protection of page 26 TO 27 */
  325. #define OB_WRP_PAGES28TO29 ((uint32_t)0x00004000) /*!< Write protection of page 28 TO 29 */
  326. #define OB_WRP_PAGES30TO31 ((uint32_t)0x00008000) /*!< Write protection of page 30 TO 31 */
  327. #define OB_WRP_PAGES32TO33 ((uint32_t)0x00010000) /*!< Write protection of page 32 TO 33 */
  328. #define OB_WRP_PAGES34TO35 ((uint32_t)0x00020000) /*!< Write protection of page 34 TO 35 */
  329. #define OB_WRP_PAGES36TO37 ((uint32_t)0x00040000) /*!< Write protection of page 36 TO 37 */
  330. #define OB_WRP_PAGES38TO39 ((uint32_t)0x00080000) /*!< Write protection of page 38 TO 39 */
  331. #define OB_WRP_PAGES40TO41 ((uint32_t)0x00100000) /*!< Write protection of page 40 TO 41 */
  332. #define OB_WRP_PAGES42TO43 ((uint32_t)0x00200000) /*!< Write protection of page 42 TO 43 */
  333. #define OB_WRP_PAGES44TO45 ((uint32_t)0x00400000) /*!< Write protection of page 44 TO 45 */
  334. #define OB_WRP_PAGES46TO47 ((uint32_t)0x00800000) /*!< Write protection of page 46 TO 47 */
  335. #define OB_WRP_PAGES48TO49 ((uint32_t)0x01000000) /*!< Write protection of page 48 TO 49 */
  336. #define OB_WRP_PAGES50TO51 ((uint32_t)0x02000000) /*!< Write protection of page 50 TO 51 */
  337. #define OB_WRP_PAGES52TO53 ((uint32_t)0x04000000) /*!< Write protection of page 52 TO 53 */
  338. #define OB_WRP_PAGES54TO55 ((uint32_t)0x08000000) /*!< Write protection of page 54 TO 55 */
  339. #define OB_WRP_PAGES56TO57 ((uint32_t)0x10000000) /*!< Write protection of page 56 TO 57 */
  340. #define OB_WRP_PAGES58TO59 ((uint32_t)0x20000000) /*!< Write protection of page 58 TO 59 */
  341. #define OB_WRP_PAGES60TO61 ((uint32_t)0x40000000) /*!< Write protection of page 60 TO 61 */
  342. #define OB_WRP_PAGES62TO127 ((uint32_t)0x80000000) /*!< Write protection of page 62 TO 127 */
  343. #define OB_WRP_PAGES62TO255 ((uint32_t)0x80000000) /*!< Write protection of page 62 TO 255 */
  344. #define OB_WRP_PAGES62TO511 ((uint32_t)0x80000000) /*!< Write protection of page 62 TO 511 */
  345. #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB */
  346. /* STM32F101xG || STM32F103xG */
  347. /* STM32F105xC || STM32F107xC */
  348. #define OB_WRP_ALLPAGES ((uint32_t)0xFFFFFFFF) /*!< Write protection of all Pages */
  349. /* Low Density */
  350. #if defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6)
  351. #define OB_WRP_PAGES0TO31MASK ((uint32_t)0x000000FF)
  352. #endif /* STM32F101x6 || STM32F102x6 || STM32F103x6 */
  353. /* Medium Density */
  354. #if defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB)
  355. #define OB_WRP_PAGES0TO31MASK ((uint32_t)0x000000FF)
  356. #define OB_WRP_PAGES32TO63MASK ((uint32_t)0x0000FF00)
  357. #define OB_WRP_PAGES64TO95MASK ((uint32_t)0x00FF0000)
  358. #define OB_WRP_PAGES96TO127MASK ((uint32_t)0xFF000000)
  359. #endif /* STM32F100xB || STM32F101xB || STM32F102xB || STM32F103xB*/
  360. /* High Density */
  361. #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE)
  362. #define OB_WRP_PAGES0TO15MASK ((uint32_t)0x000000FF)
  363. #define OB_WRP_PAGES16TO31MASK ((uint32_t)0x0000FF00)
  364. #define OB_WRP_PAGES32TO47MASK ((uint32_t)0x00FF0000)
  365. #define OB_WRP_PAGES48TO255MASK ((uint32_t)0xFF000000)
  366. #endif /* STM32F100xE || STM32F101xE || STM32F103xE */
  367. /* XL Density */
  368. #if defined(STM32F101xG) || defined(STM32F103xG)
  369. #define OB_WRP_PAGES0TO15MASK ((uint32_t)0x000000FF)
  370. #define OB_WRP_PAGES16TO31MASK ((uint32_t)0x0000FF00)
  371. #define OB_WRP_PAGES32TO47MASK ((uint32_t)0x00FF0000)
  372. #define OB_WRP_PAGES48TO511MASK ((uint32_t)0xFF000000)
  373. #endif /* STM32F101xG || STM32F103xG */
  374. /* Connectivity line devices */
  375. #if defined(STM32F105xC) || defined(STM32F107xC)
  376. #define OB_WRP_PAGES0TO15MASK ((uint32_t)0x000000FF)
  377. #define OB_WRP_PAGES16TO31MASK ((uint32_t)0x0000FF00)
  378. #define OB_WRP_PAGES32TO47MASK ((uint32_t)0x00FF0000)
  379. #define OB_WRP_PAGES48TO127MASK ((uint32_t)0xFF000000)
  380. #endif /* STM32F105xC || STM32F107xC */
  381. /**
  382. * @}
  383. */
  384. /** @defgroup FLASHEx_OB_Read_Protection Option Byte Read Protection
  385. * @{
  386. */
  387. #define OB_RDP_LEVEL_0 ((uint8_t)0xA5)
  388. #define OB_RDP_LEVEL_1 ((uint8_t)0x00)
  389. /**
  390. * @}
  391. */
  392. /** @defgroup FLASHEx_OB_IWatchdog Option Byte IWatchdog
  393. * @{
  394. */
  395. #define OB_IWDG_SW ((uint16_t)0x0001) /*!< Software IWDG selected */
  396. #define OB_IWDG_HW ((uint16_t)0x0000) /*!< Hardware IWDG selected */
  397. /**
  398. * @}
  399. */
  400. /** @defgroup FLASHEx_OB_nRST_STOP Option Byte nRST STOP
  401. * @{
  402. */
  403. #define OB_STOP_NO_RST ((uint16_t)0x0002) /*!< No reset generated when entering in STOP */
  404. #define OB_STOP_RST ((uint16_t)0x0000) /*!< Reset generated when entering in STOP */
  405. /**
  406. * @}
  407. */
  408. /** @defgroup FLASHEx_OB_nRST_STDBY Option Byte nRST STDBY
  409. * @{
  410. */
  411. #define OB_STDBY_NO_RST ((uint16_t)0x0004) /*!< No reset generated when entering in STANDBY */
  412. #define OB_STDBY_RST ((uint16_t)0x0000) /*!< Reset generated when entering in STANDBY */
  413. /**
  414. * @}
  415. */
  416. #if defined(FLASH_BANK2_END)
  417. /** @defgroup FLASHEx_OB_BOOT1 Option Byte BOOT1
  418. * @{
  419. */
  420. #define OB_BOOT1_RESET ((uint16_t)0x0000) /*!< BOOT1 Reset */
  421. #define OB_BOOT1_SET ((uint16_t)0x0008) /*!< BOOT1 Set */
  422. /**
  423. * @}
  424. */
  425. #endif /* FLASH_BANK2_END */
  426. /** @defgroup FLASHEx_OB_Data_Address Option Byte Data Address
  427. * @{
  428. */
  429. #define OB_DATA_ADDRESS_DATA0 ((uint32_t)0x1FFFF804)
  430. #define OB_DATA_ADDRESS_DATA1 ((uint32_t)0x1FFFF806)
  431. /**
  432. * @}
  433. */
  434. /**
  435. * @}
  436. */
  437. /** @addtogroup FLASHEx_Constants
  438. * @{
  439. */
  440. /** @defgroup FLASH_Flag_definition Flag definition
  441. * @brief Flag definition
  442. * @{
  443. */
  444. #if defined(FLASH_BANK2_END)
  445. #define FLASH_FLAG_BSY FLASH_FLAG_BSY_BANK1 /*!< FLASH Bank1 Busy flag */
  446. #define FLASH_FLAG_PGERR FLASH_FLAG_PGERR_BANK1 /*!< FLASH Bank1 Programming error flag */
  447. #define FLASH_FLAG_WRPERR FLASH_FLAG_WRPERR_BANK1 /*!< FLASH Bank1 Write protected error flag */
  448. #define FLASH_FLAG_EOP FLASH_FLAG_EOP_BANK1 /*!< FLASH Bank1 End of Operation flag */
  449. #define FLASH_FLAG_BSY_BANK1 FLASH_SR_BSY /*!< FLASH Bank1 Busy flag */
  450. #define FLASH_FLAG_PGERR_BANK1 FLASH_SR_PGERR /*!< FLASH Bank1 Programming error flag */
  451. #define FLASH_FLAG_WRPERR_BANK1 FLASH_SR_WRPRTERR /*!< FLASH Bank1 Write protected error flag */
  452. #define FLASH_FLAG_EOP_BANK1 FLASH_SR_EOP /*!< FLASH Bank1 End of Operation flag */
  453. #define FLASH_FLAG_BSY_BANK2 (FLASH_SR2_BSY << 16) /*!< FLASH Bank2 Busy flag */
  454. #define FLASH_FLAG_PGERR_BANK2 (FLASH_SR2_PGERR << 16) /*!< FLASH Bank2 Programming error flag */
  455. #define FLASH_FLAG_WRPERR_BANK2 (FLASH_SR2_WRPRTERR << 16) /*!< FLASH Bank2 Write protected error flag */
  456. #define FLASH_FLAG_EOP_BANK2 (FLASH_SR2_EOP << 16) /*!< FLASH Bank2 End of Operation flag */
  457. #else
  458. #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
  459. #define FLASH_FLAG_PGERR FLASH_SR_PGERR /*!< FLASH Programming error flag */
  460. #define FLASH_FLAG_WRPERR FLASH_SR_WRPRTERR /*!< FLASH Write protected error flag */
  461. #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Operation flag */
  462. #endif
  463. #define FLASH_FLAG_OPTVERR ((OBR_REG_INDEX << 8 | FLASH_OBR_OPTERR)) /*!< Option Byte Error */
  464. /**
  465. * @}
  466. */
  467. /** @defgroup FLASH_Interrupt_definition Interrupt definition
  468. * @brief FLASH Interrupt definition
  469. * @{
  470. */
  471. #if defined(FLASH_BANK2_END)
  472. #define FLASH_IT_EOP FLASH_IT_EOP_BANK1 /*!< End of FLASH Operation Interrupt source Bank1 */
  473. #define FLASH_IT_ERR FLASH_IT_ERR_BANK1 /*!< Error Interrupt source Bank1 */
  474. #define FLASH_IT_EOP_BANK1 FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source Bank1 */
  475. #define FLASH_IT_ERR_BANK1 FLASH_CR_ERRIE /*!< Error Interrupt source Bank1 */
  476. #define FLASH_IT_EOP_BANK2 (FLASH_CR2_EOPIE << 16) /*!< End of FLASH Operation Interrupt source Bank2 */
  477. #define FLASH_IT_ERR_BANK2 (FLASH_CR2_ERRIE << 16) /*!< Error Interrupt source Bank2 */
  478. #else
  479. #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
  480. #define FLASH_IT_ERR FLASH_CR_ERRIE /*!< Error Interrupt source */
  481. #endif
  482. /**
  483. * @}
  484. */
  485. /**
  486. * @}
  487. */
  488. /**
  489. * @}
  490. */
  491. /* Exported macro ------------------------------------------------------------*/
  492. /** @defgroup FLASHEx_Exported_Macros FLASHEx Exported Macros
  493. * @{
  494. */
  495. /** @defgroup FLASH_Interrupt Interrupt
  496. * @brief macros to handle FLASH interrupts
  497. * @{
  498. */
  499. #if defined(FLASH_BANK2_END)
  500. /**
  501. * @brief Enable the specified FLASH interrupt.
  502. * @param __INTERRUPT__ FLASH interrupt
  503. * This parameter can be any combination of the following values:
  504. * @arg @ref FLASH_IT_EOP_BANK1 End of FLASH Operation Interrupt on bank1
  505. * @arg @ref FLASH_IT_ERR_BANK1 Error Interrupt on bank1
  506. * @arg @ref FLASH_IT_EOP_BANK2 End of FLASH Operation Interrupt on bank2
  507. * @arg @ref FLASH_IT_ERR_BANK2 Error Interrupt on bank2
  508. * @retval none
  509. */
  510. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) do { \
  511. /* Enable Bank1 IT */ \
  512. SET_BIT(FLASH->CR, ((__INTERRUPT__) & 0x0000FFFF)); \
  513. /* Enable Bank2 IT */ \
  514. SET_BIT(FLASH->CR2, ((__INTERRUPT__) >> 16)); \
  515. } while(0)
  516. /**
  517. * @brief Disable the specified FLASH interrupt.
  518. * @param __INTERRUPT__ FLASH interrupt
  519. * This parameter can be any combination of the following values:
  520. * @arg @ref FLASH_IT_EOP_BANK1 End of FLASH Operation Interrupt on bank1
  521. * @arg @ref FLASH_IT_ERR_BANK1 Error Interrupt on bank1
  522. * @arg @ref FLASH_IT_EOP_BANK2 End of FLASH Operation Interrupt on bank2
  523. * @arg @ref FLASH_IT_ERR_BANK2 Error Interrupt on bank2
  524. * @retval none
  525. */
  526. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) do { \
  527. /* Disable Bank1 IT */ \
  528. CLEAR_BIT(FLASH->CR, ((__INTERRUPT__) & 0x0000FFFF)); \
  529. /* Disable Bank2 IT */ \
  530. CLEAR_BIT(FLASH->CR2, ((__INTERRUPT__) >> 16)); \
  531. } while(0)
  532. /**
  533. * @brief Get the specified FLASH flag status.
  534. * @param __FLAG__ specifies the FLASH flag to check.
  535. * This parameter can be one of the following values:
  536. * @arg @ref FLASH_FLAG_EOP_BANK1 FLASH End of Operation flag on bank1
  537. * @arg @ref FLASH_FLAG_WRPERR_BANK1 FLASH Write protected error flag on bank1
  538. * @arg @ref FLASH_FLAG_PGERR_BANK1 FLASH Programming error flag on bank1
  539. * @arg @ref FLASH_FLAG_BSY_BANK1 FLASH Busy flag on bank1
  540. * @arg @ref FLASH_FLAG_EOP_BANK2 FLASH End of Operation flag on bank2
  541. * @arg @ref FLASH_FLAG_WRPERR_BANK2 FLASH Write protected error flag on bank2
  542. * @arg @ref FLASH_FLAG_PGERR_BANK2 FLASH Programming error flag on bank2
  543. * @arg @ref FLASH_FLAG_BSY_BANK2 FLASH Busy flag on bank2
  544. * @arg @ref FLASH_FLAG_OPTVERR Loaded OB and its complement do not match
  545. * @retval The new state of __FLAG__ (SET or RESET).
  546. */
  547. #define __HAL_FLASH_GET_FLAG(__FLAG__) (((__FLAG__) == FLASH_FLAG_OPTVERR) ? \
  548. (FLASH->OBR & FLASH_OBR_OPTERR) : \
  549. ((((__FLAG__) & SR_FLAG_MASK) != RESET)? \
  550. (FLASH->SR & ((__FLAG__) & SR_FLAG_MASK)) : \
  551. (FLASH->SR2 & ((__FLAG__) >> 16))))
  552. /**
  553. * @brief Clear the specified FLASH flag.
  554. * @param __FLAG__ specifies the FLASH flags to clear.
  555. * This parameter can be any combination of the following values:
  556. * @arg @ref FLASH_FLAG_EOP_BANK1 FLASH End of Operation flag on bank1
  557. * @arg @ref FLASH_FLAG_WRPERR_BANK1 FLASH Write protected error flag on bank1
  558. * @arg @ref FLASH_FLAG_PGERR_BANK1 FLASH Programming error flag on bank1
  559. * @arg @ref FLASH_FLAG_BSY_BANK1 FLASH Busy flag on bank1
  560. * @arg @ref FLASH_FLAG_EOP_BANK2 FLASH End of Operation flag on bank2
  561. * @arg @ref FLASH_FLAG_WRPERR_BANK2 FLASH Write protected error flag on bank2
  562. * @arg @ref FLASH_FLAG_PGERR_BANK2 FLASH Programming error flag on bank2
  563. * @arg @ref FLASH_FLAG_BSY_BANK2 FLASH Busy flag on bank2
  564. * @arg @ref FLASH_FLAG_OPTVERR Loaded OB and its complement do not match
  565. * @retval none
  566. */
  567. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) do { \
  568. /* Clear FLASH_FLAG_OPTVERR flag */ \
  569. if ((__FLAG__) == FLASH_FLAG_OPTVERR) \
  570. { \
  571. CLEAR_BIT(FLASH->OBR, FLASH_OBR_OPTERR); \
  572. } \
  573. else { \
  574. /* Clear Flag in Bank1 */ \
  575. if (((__FLAG__) & SR_FLAG_MASK) != RESET) \
  576. { \
  577. FLASH->SR = ((__FLAG__) & SR_FLAG_MASK); \
  578. } \
  579. /* Clear Flag in Bank2 */ \
  580. if (((__FLAG__) >> 16) != RESET) \
  581. { \
  582. FLASH->SR2 = ((__FLAG__) >> 16); \
  583. } \
  584. } \
  585. } while(0)
  586. #else
  587. /**
  588. * @brief Enable the specified FLASH interrupt.
  589. * @param __INTERRUPT__ FLASH interrupt
  590. * This parameter can be any combination of the following values:
  591. * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
  592. * @arg @ref FLASH_IT_ERR Error Interrupt
  593. * @retval none
  594. */
  595. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (FLASH->CR |= (__INTERRUPT__))
  596. /**
  597. * @brief Disable the specified FLASH interrupt.
  598. * @param __INTERRUPT__ FLASH interrupt
  599. * This parameter can be any combination of the following values:
  600. * @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
  601. * @arg @ref FLASH_IT_ERR Error Interrupt
  602. * @retval none
  603. */
  604. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (FLASH->CR &= ~(__INTERRUPT__))
  605. /**
  606. * @brief Get the specified FLASH flag status.
  607. * @param __FLAG__ specifies the FLASH flag to check.
  608. * This parameter can be one of the following values:
  609. * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
  610. * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
  611. * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag
  612. * @arg @ref FLASH_FLAG_BSY FLASH Busy flag
  613. * @arg @ref FLASH_FLAG_OPTVERR Loaded OB and its complement do not match
  614. * @retval The new state of __FLAG__ (SET or RESET).
  615. */
  616. #define __HAL_FLASH_GET_FLAG(__FLAG__) (((__FLAG__) == FLASH_FLAG_OPTVERR) ? \
  617. (FLASH->OBR & FLASH_OBR_OPTERR) : \
  618. (FLASH->SR & (__FLAG__)))
  619. /**
  620. * @brief Clear the specified FLASH flag.
  621. * @param __FLAG__ specifies the FLASH flags to clear.
  622. * This parameter can be any combination of the following values:
  623. * @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag
  624. * @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag
  625. * @arg @ref FLASH_FLAG_PGERR FLASH Programming error flag
  626. * @arg @ref FLASH_FLAG_OPTVERR Loaded OB and its complement do not match
  627. * @retval none
  628. */
  629. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) do { \
  630. /* Clear FLASH_FLAG_OPTVERR flag */ \
  631. if ((__FLAG__) == FLASH_FLAG_OPTVERR) \
  632. { \
  633. CLEAR_BIT(FLASH->OBR, FLASH_OBR_OPTERR); \
  634. } \
  635. else { \
  636. /* Clear Flag in Bank1 */ \
  637. FLASH->SR = (__FLAG__); \
  638. } \
  639. } while(0)
  640. #endif
  641. /**
  642. * @}
  643. */
  644. /**
  645. * @}
  646. */
  647. /* Exported functions --------------------------------------------------------*/
  648. /** @addtogroup FLASHEx_Exported_Functions
  649. * @{
  650. */
  651. /** @addtogroup FLASHEx_Exported_Functions_Group1
  652. * @{
  653. */
  654. /* IO operation functions *****************************************************/
  655. HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError);
  656. HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit);
  657. /**
  658. * @}
  659. */
  660. /** @addtogroup FLASHEx_Exported_Functions_Group2
  661. * @{
  662. */
  663. /* Peripheral Control functions ***********************************************/
  664. HAL_StatusTypeDef HAL_FLASHEx_OBErase(void);
  665. HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
  666. void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit);
  667. uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress);
  668. /**
  669. * @}
  670. */
  671. /**
  672. * @}
  673. */
  674. /**
  675. * @}
  676. */
  677. /**
  678. * @}
  679. */
  680. #ifdef __cplusplus
  681. }
  682. #endif
  683. #endif /* __STM32F1xx_HAL_FLASH_EX_H */
  684. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/