stm32f4xx_hal_flash_ex.h 48 KB

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