stm32f7xx_hal_flash_ex.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_flash_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of FLASH HAL Extension module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F7xx_HAL_FLASH_EX_H
  37. #define __STM32F7xx_HAL_FLASH_EX_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f7xx_hal_def.h"
  43. /** @addtogroup STM32F7xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup FLASHEx
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup FLASHEx_Exported_Types FLASH Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief FLASH Erase structure definition
  55. */
  56. typedef struct
  57. {
  58. uint32_t TypeErase; /*!< Mass erase or sector Erase.
  59. This parameter can be a value of @ref FLASHEx_Type_Erase */
  60. #if defined (FLASH_OPTCR_nDBANK)
  61. uint32_t Banks; /*!< Select banks to erase when Mass erase is enabled.
  62. This parameter must be a value of @ref FLASHEx_Banks */
  63. #endif /* FLASH_OPTCR_nDBANK */
  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 RDPLevel; /*!< Set the read protection level.
  83. This parameter can be a value of @ref FLASHEx_Option_Bytes_Read_Protection */
  84. uint32_t BORLevel; /*!< Set the BOR Level.
  85. This parameter can be a value of @ref FLASHEx_BOR_Reset_Level */
  86. uint32_t USERConfig; /*!< Program the FLASH User Option Byte: WWDG_SW / IWDG_SW / RST_STOP / RST_STDBY /
  87. IWDG_FREEZE_STOP / IWDG_FREEZE_SANDBY / nDBANK / nDBOOT.
  88. nDBANK / nDBOOT are only available for STM32F76xxx/STM32F77xxx devices */
  89. uint32_t BootAddr0; /*!< Boot base address when Boot pin = 0.
  90. This parameter can be a value of @ref FLASHEx_Boot_Address */
  91. uint32_t BootAddr1; /*!< Boot base address when Boot pin = 1.
  92. This parameter can be a value of @ref FLASHEx_Boot_Address */
  93. #if defined (FLASH_OPTCR2_PCROP)
  94. uint32_t PCROPSector; /*!< Set the PCROP sector.
  95. This parameter can be a value of @ref FLASHEx_Option_Bytes_PCROP_Sectors */
  96. uint32_t PCROPRdp; /*!< Set the PCROP_RDP option.
  97. This parameter can be a value of @ref FLASHEx_Option_Bytes_PCROP_RDP */
  98. #endif /* FLASH_OPTCR2_PCROP */
  99. } FLASH_OBProgramInitTypeDef;
  100. /**
  101. * @}
  102. */
  103. /* Exported constants --------------------------------------------------------*/
  104. /** @defgroup FLASHEx_Exported_Constants FLASH Exported Constants
  105. * @{
  106. */
  107. /** @defgroup FLASHEx_Type_Erase FLASH Type Erase
  108. * @{
  109. */
  110. #define FLASH_TYPEERASE_SECTORS ((uint32_t)0x00U) /*!< Sectors erase only */
  111. #define FLASH_TYPEERASE_MASSERASE ((uint32_t)0x01U) /*!< Flash Mass erase activation */
  112. /**
  113. * @}
  114. */
  115. /** @defgroup FLASHEx_Voltage_Range FLASH Voltage Range
  116. * @{
  117. */
  118. #define FLASH_VOLTAGE_RANGE_1 ((uint32_t)0x00U) /*!< Device operating range: 1.8V to 2.1V */
  119. #define FLASH_VOLTAGE_RANGE_2 ((uint32_t)0x01U) /*!< Device operating range: 2.1V to 2.7V */
  120. #define FLASH_VOLTAGE_RANGE_3 ((uint32_t)0x02U) /*!< Device operating range: 2.7V to 3.6V */
  121. #define FLASH_VOLTAGE_RANGE_4 ((uint32_t)0x03U) /*!< Device operating range: 2.7V to 3.6V + External Vpp */
  122. /**
  123. * @}
  124. */
  125. /** @defgroup FLASHEx_WRP_State FLASH WRP State
  126. * @{
  127. */
  128. #define OB_WRPSTATE_DISABLE ((uint32_t)0x00U) /*!< Disable the write protection of the desired bank 1 sectors */
  129. #define OB_WRPSTATE_ENABLE ((uint32_t)0x01U) /*!< Enable the write protection of the desired bank 1 sectors */
  130. /**
  131. * @}
  132. */
  133. /** @defgroup FLASHEx_Option_Type FLASH Option Type
  134. * @{
  135. */
  136. #define OPTIONBYTE_WRP ((uint32_t)0x01U) /*!< WRP option byte configuration */
  137. #define OPTIONBYTE_RDP ((uint32_t)0x02U) /*!< RDP option byte configuration */
  138. #define OPTIONBYTE_USER ((uint32_t)0x04U) /*!< USER option byte configuration */
  139. #define OPTIONBYTE_BOR ((uint32_t)0x08U) /*!< BOR option byte configuration */
  140. #define OPTIONBYTE_BOOTADDR_0 ((uint32_t)0x10U) /*!< Boot 0 Address configuration */
  141. #define OPTIONBYTE_BOOTADDR_1 ((uint32_t)0x20U) /*!< Boot 1 Address configuration */
  142. #if defined (FLASH_OPTCR2_PCROP)
  143. #define OPTIONBYTE_PCROP ((uint32_t)0x40U) /*!< PCROP configuration */
  144. #define OPTIONBYTE_PCROP_RDP ((uint32_t)0x80U) /*!< PCROP_RDP configuration */
  145. #endif /* FLASH_OPTCR2_PCROP */
  146. /**
  147. * @}
  148. */
  149. /** @defgroup FLASHEx_Option_Bytes_Read_Protection FLASH Option Bytes Read Protection
  150. * @{
  151. */
  152. #define OB_RDP_LEVEL_0 ((uint8_t)0xAAU)
  153. #define OB_RDP_LEVEL_1 ((uint8_t)0x55U)
  154. #define OB_RDP_LEVEL_2 ((uint8_t)0xCCU) /*!< Warning: When enabling read protection level 2
  155. it s no more possible to go back to level 1 or 0 */
  156. /**
  157. * @}
  158. */
  159. /** @defgroup FLASHEx_Option_Bytes_WWatchdog FLASH Option Bytes WWatchdog
  160. * @{
  161. */
  162. #define OB_WWDG_SW ((uint32_t)0x10U) /*!< Software WWDG selected */
  163. #define OB_WWDG_HW ((uint32_t)0x00U) /*!< Hardware WWDG selected */
  164. /**
  165. * @}
  166. */
  167. /** @defgroup FLASHEx_Option_Bytes_IWatchdog FLASH Option Bytes IWatchdog
  168. * @{
  169. */
  170. #define OB_IWDG_SW ((uint32_t)0x20U) /*!< Software IWDG selected */
  171. #define OB_IWDG_HW ((uint32_t)0x00U) /*!< Hardware IWDG selected */
  172. /**
  173. * @}
  174. */
  175. /** @defgroup FLASHEx_Option_Bytes_nRST_STOP FLASH Option Bytes nRST_STOP
  176. * @{
  177. */
  178. #define OB_STOP_NO_RST ((uint32_t)0x40U) /*!< No reset generated when entering in STOP */
  179. #define OB_STOP_RST ((uint32_t)0x00U) /*!< Reset generated when entering in STOP */
  180. /**
  181. * @}
  182. */
  183. /** @defgroup FLASHEx_Option_Bytes_nRST_STDBY FLASH Option Bytes nRST_STDBY
  184. * @{
  185. */
  186. #define OB_STDBY_NO_RST ((uint32_t)0x80U) /*!< No reset generated when entering in STANDBY */
  187. #define OB_STDBY_RST ((uint32_t)0x00U) /*!< Reset generated when entering in STANDBY */
  188. /**
  189. * @}
  190. */
  191. /** @defgroup FLASHEx_Option_Bytes_IWDG_FREEZE_STOP FLASH IWDG Counter Freeze in STOP
  192. * @{
  193. */
  194. #define OB_IWDG_STOP_FREEZE ((uint32_t)0x00000000U) /*!< Freeze IWDG counter in STOP mode */
  195. #define OB_IWDG_STOP_ACTIVE ((uint32_t)0x80000000U) /*!< IWDG counter active in STOP mode */
  196. /**
  197. * @}
  198. */
  199. /** @defgroup FLASHEx_Option_Bytes_IWDG_FREEZE_SANDBY FLASH IWDG Counter Freeze in STANDBY
  200. * @{
  201. */
  202. #define OB_IWDG_STDBY_FREEZE ((uint32_t)0x00000000U) /*!< Freeze IWDG counter in STANDBY mode */
  203. #define OB_IWDG_STDBY_ACTIVE ((uint32_t)0x40000000U) /*!< IWDG counter active in STANDBY mode */
  204. /**
  205. * @}
  206. */
  207. /** @defgroup FLASHEx_BOR_Reset_Level FLASH BOR Reset Level
  208. * @{
  209. */
  210. #define OB_BOR_LEVEL3 ((uint32_t)0x00U) /*!< Supply voltage ranges from 2.70 to 3.60 V */
  211. #define OB_BOR_LEVEL2 ((uint32_t)0x04U) /*!< Supply voltage ranges from 2.40 to 2.70 V */
  212. #define OB_BOR_LEVEL1 ((uint32_t)0x08U) /*!< Supply voltage ranges from 2.10 to 2.40 V */
  213. #define OB_BOR_OFF ((uint32_t)0x0CU) /*!< Supply voltage ranges from 1.62 to 2.10 V */
  214. /**
  215. * @}
  216. */
  217. #if defined (FLASH_OPTCR_nDBOOT)
  218. /** @defgroup FLASHEx_Option_Bytes_nDBOOT FLASH Option Bytes nDBOOT
  219. * @{
  220. */
  221. #define OB_DUAL_BOOT_DISABLE ((uint32_t)0x10000000U) /* !< Dual Boot disable. Boot according to boot address option */
  222. #define OB_DUAL_BOOT_ENABLE ((uint32_t)0x00000000U) /* !< Dual Boot enable. Boot always from system memory if boot address in flash
  223. (Dual bank Boot mode), or RAM if Boot address option in RAM */
  224. /**
  225. * @}
  226. */
  227. #endif /* FLASH_OPTCR_nDBOOT */
  228. #if defined (FLASH_OPTCR_nDBANK)
  229. /** @defgroup FLASHEx_Option_Bytes_nDBank FLASH Single Bank or Dual Bank
  230. * @{
  231. */
  232. #define OB_NDBANK_SINGLE_BANK ((uint32_t)0x20000000U) /*!< NDBANK bit is set : Single Bank mode */
  233. #define OB_NDBANK_DUAL_BANK ((uint32_t)0x00000000U) /*!< NDBANK bit is reset : Dual Bank mode */
  234. /**
  235. * @}
  236. */
  237. #endif /* FLASH_OPTCR_nDBANK */
  238. /** @defgroup FLASHEx_Boot_Address FLASH Boot Address
  239. * @{
  240. */
  241. #define OB_BOOTADDR_ITCM_RAM ((uint32_t)0x0000U) /*!< Boot from ITCM RAM (0x00000000) */
  242. #define OB_BOOTADDR_SYSTEM ((uint32_t)0x0040U) /*!< Boot from System memory bootloader (0x00100000) */
  243. #define OB_BOOTADDR_ITCM_FLASH ((uint32_t)0x0080U) /*!< Boot from Flash on ITCM interface (0x00200000) */
  244. #define OB_BOOTADDR_AXIM_FLASH ((uint32_t)0x2000U) /*!< Boot from Flash on AXIM interface (0x08000000) */
  245. #define OB_BOOTADDR_DTCM_RAM ((uint32_t)0x8000U) /*!< Boot from DTCM RAM (0x20000000) */
  246. #define OB_BOOTADDR_SRAM1 ((uint32_t)0x8004U) /*!< Boot from SRAM1 (0x20010000) */
  247. #if (SRAM2_BASE == 0x2003C000U)
  248. #define OB_BOOTADDR_SRAM2 ((uint32_t)0x800FU) /*!< Boot from SRAM2 (0x2003C000) */
  249. #else
  250. #define OB_BOOTADDR_SRAM2 ((uint32_t)0x8013U) /*!< Boot from SRAM2 (0x2004C000) */
  251. #endif /* SRAM2_BASE == 0x2003C000U */
  252. /**
  253. * @}
  254. */
  255. /** @defgroup FLASH_Latency FLASH Latency
  256. * @{
  257. */
  258. #define FLASH_LATENCY_0 FLASH_ACR_LATENCY_0WS /*!< FLASH Zero Latency cycle */
  259. #define FLASH_LATENCY_1 FLASH_ACR_LATENCY_1WS /*!< FLASH One Latency cycle */
  260. #define FLASH_LATENCY_2 FLASH_ACR_LATENCY_2WS /*!< FLASH Two Latency cycles */
  261. #define FLASH_LATENCY_3 FLASH_ACR_LATENCY_3WS /*!< FLASH Three Latency cycles */
  262. #define FLASH_LATENCY_4 FLASH_ACR_LATENCY_4WS /*!< FLASH Four Latency cycles */
  263. #define FLASH_LATENCY_5 FLASH_ACR_LATENCY_5WS /*!< FLASH Five Latency cycles */
  264. #define FLASH_LATENCY_6 FLASH_ACR_LATENCY_6WS /*!< FLASH Six Latency cycles */
  265. #define FLASH_LATENCY_7 FLASH_ACR_LATENCY_7WS /*!< FLASH Seven Latency cycles */
  266. #define FLASH_LATENCY_8 FLASH_ACR_LATENCY_8WS /*!< FLASH Eight Latency cycles */
  267. #define FLASH_LATENCY_9 FLASH_ACR_LATENCY_9WS /*!< FLASH Nine Latency cycles */
  268. #define FLASH_LATENCY_10 FLASH_ACR_LATENCY_10WS /*!< FLASH Ten Latency cycles */
  269. #define FLASH_LATENCY_11 FLASH_ACR_LATENCY_11WS /*!< FLASH Eleven Latency cycles */
  270. #define FLASH_LATENCY_12 FLASH_ACR_LATENCY_12WS /*!< FLASH Twelve Latency cycles */
  271. #define FLASH_LATENCY_13 FLASH_ACR_LATENCY_13WS /*!< FLASH Thirteen Latency cycles */
  272. #define FLASH_LATENCY_14 FLASH_ACR_LATENCY_14WS /*!< FLASH Fourteen Latency cycles */
  273. #define FLASH_LATENCY_15 FLASH_ACR_LATENCY_15WS /*!< FLASH Fifteen Latency cycles */
  274. /**
  275. * @}
  276. */
  277. #if defined (FLASH_OPTCR_nDBANK)
  278. /** @defgroup FLASHEx_Banks FLASH Banks
  279. * @{
  280. */
  281. #define FLASH_BANK_1 ((uint32_t)0x01U) /*!< Bank 1 */
  282. #define FLASH_BANK_2 ((uint32_t)0x02U) /*!< Bank 2 */
  283. #define FLASH_BANK_BOTH ((uint32_t)(FLASH_BANK_1 | FLASH_BANK_2)) /*!< Bank1 and Bank2 */
  284. /**
  285. * @}
  286. */
  287. #endif /* FLASH_OPTCR_nDBANK */
  288. /** @defgroup FLASHEx_MassErase_bit FLASH Mass Erase bit
  289. * @{
  290. */
  291. #if defined (FLASH_OPTCR_nDBANK)
  292. #define FLASH_MER_BIT (FLASH_CR_MER1 | FLASH_CR_MER2) /*!< 2 MER bits */
  293. #else
  294. #define FLASH_MER_BIT (FLASH_CR_MER) /*!< only 1 MER bit */
  295. #endif /* FLASH_OPTCR_nDBANK */
  296. /**
  297. * @}
  298. */
  299. /** @defgroup FLASHEx_Sectors FLASH Sectors
  300. * @{
  301. */
  302. #if (FLASH_SECTOR_TOTAL == 24)
  303. #define FLASH_SECTOR_8 ((uint32_t)8U) /*!< Sector Number 8 */
  304. #define FLASH_SECTOR_9 ((uint32_t)9U) /*!< Sector Number 9 */
  305. #define FLASH_SECTOR_10 ((uint32_t)10U) /*!< Sector Number 10 */
  306. #define FLASH_SECTOR_11 ((uint32_t)11U) /*!< Sector Number 11 */
  307. #define FLASH_SECTOR_12 ((uint32_t)12U) /*!< Sector Number 12 */
  308. #define FLASH_SECTOR_13 ((uint32_t)13U) /*!< Sector Number 13 */
  309. #define FLASH_SECTOR_14 ((uint32_t)14U) /*!< Sector Number 14 */
  310. #define FLASH_SECTOR_15 ((uint32_t)15U) /*!< Sector Number 15 */
  311. #define FLASH_SECTOR_16 ((uint32_t)16U) /*!< Sector Number 16 */
  312. #define FLASH_SECTOR_17 ((uint32_t)17U) /*!< Sector Number 17 */
  313. #define FLASH_SECTOR_18 ((uint32_t)18U) /*!< Sector Number 18 */
  314. #define FLASH_SECTOR_19 ((uint32_t)19U) /*!< Sector Number 19 */
  315. #define FLASH_SECTOR_20 ((uint32_t)20U) /*!< Sector Number 20 */
  316. #define FLASH_SECTOR_21 ((uint32_t)21U) /*!< Sector Number 21 */
  317. #define FLASH_SECTOR_22 ((uint32_t)22U) /*!< Sector Number 22 */
  318. #define FLASH_SECTOR_23 ((uint32_t)23U) /*!< Sector Number 23 */
  319. #endif /* FLASH_SECTOR_TOTAL == 24 */
  320. /**
  321. * @}
  322. */
  323. #if (FLASH_SECTOR_TOTAL == 24)
  324. /** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASH Option Bytes Write Protection
  325. * @note For Single Bank mode, use OB_WRP_SECTOR_x defines: In fact, in FLASH_OPTCR register,
  326. * nWRP[11:0] bits contain the value of the write-protection option bytes for sectors 0 to 11.
  327. * For Dual Bank mode, use OB_WRP_DB_SECTOR_x defines: In fact, in FLASH_OPTCR register,
  328. * nWRP[11:0] bits are divided on two groups, one group dedicated for bank 1 and
  329. * a second one dedicated for bank 2 (nWRP[i] activates Write protection on sector 2*i and 2*i+1).
  330. * This behavior is applicable only for STM32F76xxx / STM32F77xxx devices.
  331. * @{
  332. */
  333. /* Single Bank Sectors */
  334. #define OB_WRP_SECTOR_0 ((uint32_t)0x00010000U) /*!< Write protection of Single Bank Sector0 */
  335. #define OB_WRP_SECTOR_1 ((uint32_t)0x00020000U) /*!< Write protection of Single Bank Sector1 */
  336. #define OB_WRP_SECTOR_2 ((uint32_t)0x00040000U) /*!< Write protection of Single Bank Sector2 */
  337. #define OB_WRP_SECTOR_3 ((uint32_t)0x00080000U) /*!< Write protection of Single Bank Sector3 */
  338. #define OB_WRP_SECTOR_4 ((uint32_t)0x00100000U) /*!< Write protection of Single Bank Sector4 */
  339. #define OB_WRP_SECTOR_5 ((uint32_t)0x00200000U) /*!< Write protection of Single Bank Sector5 */
  340. #define OB_WRP_SECTOR_6 ((uint32_t)0x00400000U) /*!< Write protection of Single Bank Sector6 */
  341. #define OB_WRP_SECTOR_7 ((uint32_t)0x00800000U) /*!< Write protection of Single Bank Sector7 */
  342. #define OB_WRP_SECTOR_8 ((uint32_t)0x01000000U) /*!< Write protection of Single Bank Sector8 */
  343. #define OB_WRP_SECTOR_9 ((uint32_t)0x02000000U) /*!< Write protection of Single Bank Sector9 */
  344. #define OB_WRP_SECTOR_10 ((uint32_t)0x04000000U) /*!< Write protection of Single Bank Sector10 */
  345. #define OB_WRP_SECTOR_11 ((uint32_t)0x08000000U) /*!< Write protection of Single Bank Sector11 */
  346. #define OB_WRP_SECTOR_All ((uint32_t)0x0FFF0000U) /*!< Write protection of all Sectors for Single Bank Flash */
  347. /* Dual Bank Sectors */
  348. #define OB_WRP_DB_SECTOR_0 ((uint32_t)0x00010000U) /*!< Write protection of Dual Bank Sector0 */
  349. #define OB_WRP_DB_SECTOR_1 ((uint32_t)0x00010000U) /*!< Write protection of Dual Bank Sector1 */
  350. #define OB_WRP_DB_SECTOR_2 ((uint32_t)0x00020000U) /*!< Write protection of Dual Bank Sector2 */
  351. #define OB_WRP_DB_SECTOR_3 ((uint32_t)0x00020000U) /*!< Write protection of Dual Bank Sector3 */
  352. #define OB_WRP_DB_SECTOR_4 ((uint32_t)0x00040000U) /*!< Write protection of Dual Bank Sector4 */
  353. #define OB_WRP_DB_SECTOR_5 ((uint32_t)0x00040000U) /*!< Write protection of Dual Bank Sector5 */
  354. #define OB_WRP_DB_SECTOR_6 ((uint32_t)0x00080000U) /*!< Write protection of Dual Bank Sector6 */
  355. #define OB_WRP_DB_SECTOR_7 ((uint32_t)0x00080000U) /*!< Write protection of Dual Bank Sector7 */
  356. #define OB_WRP_DB_SECTOR_8 ((uint32_t)0x00100000U) /*!< Write protection of Dual Bank Sector8 */
  357. #define OB_WRP_DB_SECTOR_9 ((uint32_t)0x00100000U) /*!< Write protection of Dual Bank Sector9 */
  358. #define OB_WRP_DB_SECTOR_10 ((uint32_t)0x00200000U) /*!< Write protection of Dual Bank Sector10 */
  359. #define OB_WRP_DB_SECTOR_11 ((uint32_t)0x00200000U) /*!< Write protection of Dual Bank Sector11 */
  360. #define OB_WRP_DB_SECTOR_12 ((uint32_t)0x00400000U) /*!< Write protection of Dual Bank Sector12 */
  361. #define OB_WRP_DB_SECTOR_13 ((uint32_t)0x00400000U) /*!< Write protection of Dual Bank Sector13 */
  362. #define OB_WRP_DB_SECTOR_14 ((uint32_t)0x00800000U) /*!< Write protection of Dual Bank Sector14 */
  363. #define OB_WRP_DB_SECTOR_15 ((uint32_t)0x00800000U) /*!< Write protection of Dual Bank Sector15 */
  364. #define OB_WRP_DB_SECTOR_16 ((uint32_t)0x01000000U) /*!< Write protection of Dual Bank Sector16 */
  365. #define OB_WRP_DB_SECTOR_17 ((uint32_t)0x01000000U) /*!< Write protection of Dual Bank Sector17 */
  366. #define OB_WRP_DB_SECTOR_18 ((uint32_t)0x02000000U) /*!< Write protection of Dual Bank Sector18 */
  367. #define OB_WRP_DB_SECTOR_19 ((uint32_t)0x02000000U) /*!< Write protection of Dual Bank Sector19 */
  368. #define OB_WRP_DB_SECTOR_20 ((uint32_t)0x04000000U) /*!< Write protection of Dual Bank Sector20 */
  369. #define OB_WRP_DB_SECTOR_21 ((uint32_t)0x04000000U) /*!< Write protection of Dual Bank Sector21 */
  370. #define OB_WRP_DB_SECTOR_22 ((uint32_t)0x08000000U) /*!< Write protection of Dual Bank Sector22 */
  371. #define OB_WRP_DB_SECTOR_23 ((uint32_t)0x08000000U) /*!< Write protection of Dual Bank Sector23 */
  372. #define OB_WRP_DB_SECTOR_All ((uint32_t)0x0FFF0000U) /*!< Write protection of all Sectors for Dual Bank Flash */
  373. /**
  374. * @}
  375. */
  376. #endif /* FLASH_SECTOR_TOTAL == 24 */
  377. #if (FLASH_SECTOR_TOTAL == 8)
  378. /** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASH Option Bytes Write Protection
  379. * @{
  380. */
  381. #define OB_WRP_SECTOR_0 ((uint32_t)0x00010000U) /*!< Write protection of Sector0 */
  382. #define OB_WRP_SECTOR_1 ((uint32_t)0x00020000U) /*!< Write protection of Sector1 */
  383. #define OB_WRP_SECTOR_2 ((uint32_t)0x00040000U) /*!< Write protection of Sector2 */
  384. #define OB_WRP_SECTOR_3 ((uint32_t)0x00080000U) /*!< Write protection of Sector3 */
  385. #define OB_WRP_SECTOR_4 ((uint32_t)0x00100000U) /*!< Write protection of Sector4 */
  386. #define OB_WRP_SECTOR_5 ((uint32_t)0x00200000U) /*!< Write protection of Sector5 */
  387. #define OB_WRP_SECTOR_6 ((uint32_t)0x00400000U) /*!< Write protection of Sector6 */
  388. #define OB_WRP_SECTOR_7 ((uint32_t)0x00800000U) /*!< Write protection of Sector7 */
  389. #define OB_WRP_SECTOR_All ((uint32_t)0x00FF0000U) /*!< Write protection of all Sectors */
  390. /**
  391. * @}
  392. */
  393. #endif /* FLASH_SECTOR_TOTAL == 8 */
  394. #if (FLASH_SECTOR_TOTAL == 4)
  395. /** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASH Option Bytes Write Protection
  396. * @{
  397. */
  398. #define OB_WRP_SECTOR_0 ((uint32_t)0x00010000U) /*!< Write protection of Sector0 */
  399. #define OB_WRP_SECTOR_1 ((uint32_t)0x00020000U) /*!< Write protection of Sector1 */
  400. #define OB_WRP_SECTOR_2 ((uint32_t)0x00040000U) /*!< Write protection of Sector2 */
  401. #define OB_WRP_SECTOR_3 ((uint32_t)0x00080000U) /*!< Write protection of Sector3 */
  402. #define OB_WRP_SECTOR_All ((uint32_t)0x000F0000U) /*!< Write protection of all Sectors */
  403. /**
  404. * @}
  405. */
  406. #endif /* FLASH_SECTOR_TOTAL == 4 */
  407. #if (FLASH_SECTOR_TOTAL == 2)
  408. /** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASH Option Bytes Write Protection
  409. * @{
  410. */
  411. #define OB_WRP_SECTOR_0 ((uint32_t)0x00010000U) /*!< Write protection of Sector0 */
  412. #define OB_WRP_SECTOR_1 ((uint32_t)0x00020000U) /*!< Write protection of Sector1 */
  413. #define OB_WRP_SECTOR_All ((uint32_t)0x00030000U) /*!< Write protection of all Sectors */
  414. /**
  415. * @}
  416. */
  417. #endif /* FLASH_SECTOR_TOTAL == 2 */
  418. #if defined (FLASH_OPTCR2_PCROP)
  419. #if (FLASH_SECTOR_TOTAL == 8)
  420. /** @defgroup FLASHEx_Option_Bytes_PCROP_Sectors FLASH Option Bytes PCROP Sectors
  421. * @{
  422. */
  423. #define OB_PCROP_SECTOR_0 ((uint32_t)0x00000001U) /*!< PC Readout protection of Sector0 */
  424. #define OB_PCROP_SECTOR_1 ((uint32_t)0x00000002U) /*!< PC Readout protection of Sector1 */
  425. #define OB_PCROP_SECTOR_2 ((uint32_t)0x00000004U) /*!< PC Readout protection of Sector2 */
  426. #define OB_PCROP_SECTOR_3 ((uint32_t)0x00000008U) /*!< PC Readout protection of Sector3 */
  427. #define OB_PCROP_SECTOR_4 ((uint32_t)0x00000010U) /*!< PC Readout protection of Sector4 */
  428. #define OB_PCROP_SECTOR_5 ((uint32_t)0x00000020U) /*!< PC Readout protection of Sector5 */
  429. #define OB_PCROP_SECTOR_6 ((uint32_t)0x00000040U) /*!< PC Readout protection of Sector6 */
  430. #define OB_PCROP_SECTOR_7 ((uint32_t)0x00000080U) /*!< PC Readout protection of Sector7 */
  431. #define OB_PCROP_SECTOR_All ((uint32_t)0x000000FFU) /*!< PC Readout protection of all Sectors */
  432. /**
  433. * @}
  434. */
  435. #endif /* FLASH_SECTOR_TOTAL == 8 */
  436. #if (FLASH_SECTOR_TOTAL == 4)
  437. /** @defgroup FLASHEx_Option_Bytes_PCROP_Sectors FLASH Option Bytes PCROP Sectors
  438. * @{
  439. */
  440. #define OB_PCROP_SECTOR_0 ((uint32_t)0x00000001U) /*!< PC Readout protection of Sector0 */
  441. #define OB_PCROP_SECTOR_1 ((uint32_t)0x00000002U) /*!< PC Readout protection of Sector1 */
  442. #define OB_PCROP_SECTOR_2 ((uint32_t)0x00000004U) /*!< PC Readout protection of Sector2 */
  443. #define OB_PCROP_SECTOR_3 ((uint32_t)0x00000008U) /*!< PC Readout protection of Sector3 */
  444. #define OB_PCROP_SECTOR_All ((uint32_t)0x0000000FU) /*!< PC Readout protection of all Sectors */
  445. /**
  446. * @}
  447. */
  448. #endif /* FLASH_SECTOR_TOTAL == 4 */
  449. /** @defgroup FLASHEx_Option_Bytes_PCROP_RDP FLASH Option Bytes PCROP_RDP Bit
  450. * @{
  451. */
  452. #define OB_PCROP_RDP_ENABLE ((uint32_t)0x80000000U) /*!< PCROP_RDP Enable */
  453. #define OB_PCROP_RDP_DISABLE ((uint32_t)0x00000000U) /*!< PCROP_RDP Disable */
  454. /**
  455. * @}
  456. */
  457. #endif /* FLASH_OPTCR2_PCROP */
  458. /**
  459. * @}
  460. */
  461. /* Exported macro ------------------------------------------------------------*/
  462. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  463. * @{
  464. */
  465. /**
  466. * @brief Calculate the FLASH Boot Base Adress (BOOT_ADD0 or BOOT_ADD1)
  467. * @note Returned value BOOT_ADDx[15:0] corresponds to boot address [29:14].
  468. * @param __ADDRESS__ FLASH Boot Address (in the range 0x0000 0000 to 0x2004 FFFF with a granularity of 16KB)
  469. * @retval The FLASH Boot Base Adress
  470. */
  471. #define __HAL_FLASH_CALC_BOOT_BASE_ADR(__ADDRESS__) ((__ADDRESS__) >> 14)
  472. /**
  473. * @}
  474. */
  475. /* Exported functions --------------------------------------------------------*/
  476. /** @addtogroup FLASHEx_Exported_Functions
  477. * @{
  478. */
  479. /** @addtogroup FLASHEx_Exported_Functions_Group1
  480. * @{
  481. */
  482. /* Extension Program operation functions *************************************/
  483. HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError);
  484. HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit);
  485. HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
  486. void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit);
  487. /**
  488. * @}
  489. */
  490. /**
  491. * @}
  492. */
  493. /* Private types -------------------------------------------------------------*/
  494. /* Private variables ---------------------------------------------------------*/
  495. /* Private constants ---------------------------------------------------------*/
  496. /* Private macros ------------------------------------------------------------*/
  497. /** @defgroup FLASHEx_Private_Macros FLASH Private Macros
  498. * @{
  499. */
  500. /** @defgroup FLASHEx_IS_FLASH_Definitions FLASH Private macros to check input parameters
  501. * @{
  502. */
  503. #define IS_FLASH_TYPEERASE(VALUE)(((VALUE) == FLASH_TYPEERASE_SECTORS) || \
  504. ((VALUE) == FLASH_TYPEERASE_MASSERASE))
  505. #define IS_VOLTAGERANGE(RANGE)(((RANGE) == FLASH_VOLTAGE_RANGE_1) || \
  506. ((RANGE) == FLASH_VOLTAGE_RANGE_2) || \
  507. ((RANGE) == FLASH_VOLTAGE_RANGE_3) || \
  508. ((RANGE) == FLASH_VOLTAGE_RANGE_4))
  509. #define IS_WRPSTATE(VALUE)(((VALUE) == OB_WRPSTATE_DISABLE) || \
  510. ((VALUE) == OB_WRPSTATE_ENABLE))
  511. #if defined (FLASH_OPTCR2_PCROP)
  512. #define IS_OPTIONBYTE(VALUE)(((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER |\
  513. OPTIONBYTE_BOR | OPTIONBYTE_BOOTADDR_0 | OPTIONBYTE_BOOTADDR_1 |\
  514. OPTIONBYTE_PCROP | OPTIONBYTE_PCROP_RDP)))
  515. #else
  516. #define IS_OPTIONBYTE(VALUE)(((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER |\
  517. OPTIONBYTE_BOR | OPTIONBYTE_BOOTADDR_0 | OPTIONBYTE_BOOTADDR_1)))
  518. #endif /* FLASH_OPTCR2_PCROP */
  519. #define IS_OB_BOOT_ADDRESS(ADDRESS) ((ADDRESS) <= 0x8013)
  520. #define IS_OB_RDP_LEVEL(LEVEL) (((LEVEL) == OB_RDP_LEVEL_0) ||\
  521. ((LEVEL) == OB_RDP_LEVEL_1) ||\
  522. ((LEVEL) == OB_RDP_LEVEL_2))
  523. #define IS_OB_WWDG_SOURCE(SOURCE) (((SOURCE) == OB_WWDG_SW) || ((SOURCE) == OB_WWDG_HW))
  524. #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
  525. #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NO_RST) || ((SOURCE) == OB_STOP_RST))
  526. #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NO_RST) || ((SOURCE) == OB_STDBY_RST))
  527. #define IS_OB_IWDG_STOP_FREEZE(FREEZE) (((FREEZE) == OB_IWDG_STOP_FREEZE) || ((FREEZE) == OB_IWDG_STOP_ACTIVE))
  528. #define IS_OB_IWDG_STDBY_FREEZE(FREEZE) (((FREEZE) == OB_IWDG_STDBY_FREEZE) || ((FREEZE) == OB_IWDG_STDBY_ACTIVE))
  529. #define IS_OB_BOR_LEVEL(LEVEL) (((LEVEL) == OB_BOR_LEVEL1) || ((LEVEL) == OB_BOR_LEVEL2) ||\
  530. ((LEVEL) == OB_BOR_LEVEL3) || ((LEVEL) == OB_BOR_OFF))
  531. #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_LATENCY_0) || \
  532. ((LATENCY) == FLASH_LATENCY_1) || \
  533. ((LATENCY) == FLASH_LATENCY_2) || \
  534. ((LATENCY) == FLASH_LATENCY_3) || \
  535. ((LATENCY) == FLASH_LATENCY_4) || \
  536. ((LATENCY) == FLASH_LATENCY_5) || \
  537. ((LATENCY) == FLASH_LATENCY_6) || \
  538. ((LATENCY) == FLASH_LATENCY_7) || \
  539. ((LATENCY) == FLASH_LATENCY_8) || \
  540. ((LATENCY) == FLASH_LATENCY_9) || \
  541. ((LATENCY) == FLASH_LATENCY_10) || \
  542. ((LATENCY) == FLASH_LATENCY_11) || \
  543. ((LATENCY) == FLASH_LATENCY_12) || \
  544. ((LATENCY) == FLASH_LATENCY_13) || \
  545. ((LATENCY) == FLASH_LATENCY_14) || \
  546. ((LATENCY) == FLASH_LATENCY_15))
  547. #define IS_FLASH_ADDRESS(ADDRESS) ((((ADDRESS) >= FLASH_BASE) && ((ADDRESS) <= FLASH_END)) || \
  548. (((ADDRESS) >= FLASH_OTP_BASE) && ((ADDRESS) <= FLASH_OTP_END)))
  549. #define IS_FLASH_NBSECTORS(NBSECTORS) (((NBSECTORS) != 0U) && ((NBSECTORS) <= FLASH_SECTOR_TOTAL))
  550. #if (FLASH_SECTOR_TOTAL == 8)
  551. #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_SECTOR_0) || ((SECTOR) == FLASH_SECTOR_1) ||\
  552. ((SECTOR) == FLASH_SECTOR_2) || ((SECTOR) == FLASH_SECTOR_3) ||\
  553. ((SECTOR) == FLASH_SECTOR_4) || ((SECTOR) == FLASH_SECTOR_5) ||\
  554. ((SECTOR) == FLASH_SECTOR_6) || ((SECTOR) == FLASH_SECTOR_7))
  555. #define IS_OB_WRP_SECTOR(SECTOR) ((((SECTOR) & 0xFF00FFFFU) == 0x00000000U) && ((SECTOR) != 0x00000000U))
  556. #endif /* FLASH_SECTOR_TOTAL == 8 */
  557. #if (FLASH_SECTOR_TOTAL == 24)
  558. #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_SECTOR_0) || ((SECTOR) == FLASH_SECTOR_1) ||\
  559. ((SECTOR) == FLASH_SECTOR_2) || ((SECTOR) == FLASH_SECTOR_3) ||\
  560. ((SECTOR) == FLASH_SECTOR_4) || ((SECTOR) == FLASH_SECTOR_5) ||\
  561. ((SECTOR) == FLASH_SECTOR_6) || ((SECTOR) == FLASH_SECTOR_7) ||\
  562. ((SECTOR) == FLASH_SECTOR_8) || ((SECTOR) == FLASH_SECTOR_9) ||\
  563. ((SECTOR) == FLASH_SECTOR_10) || ((SECTOR) == FLASH_SECTOR_11) ||\
  564. ((SECTOR) == FLASH_SECTOR_12) || ((SECTOR) == FLASH_SECTOR_13) ||\
  565. ((SECTOR) == FLASH_SECTOR_14) || ((SECTOR) == FLASH_SECTOR_15) ||\
  566. ((SECTOR) == FLASH_SECTOR_16) || ((SECTOR) == FLASH_SECTOR_17) ||\
  567. ((SECTOR) == FLASH_SECTOR_18) || ((SECTOR) == FLASH_SECTOR_19) ||\
  568. ((SECTOR) == FLASH_SECTOR_20) || ((SECTOR) == FLASH_SECTOR_21) ||\
  569. ((SECTOR) == FLASH_SECTOR_22) || ((SECTOR) == FLASH_SECTOR_23))
  570. #define IS_OB_WRP_SECTOR(SECTOR) ((((SECTOR) & 0xF000FFFFU) == 0x00000000U) && ((SECTOR) != 0x00000000U))
  571. #endif /* FLASH_SECTOR_TOTAL == 24 */
  572. #if (FLASH_SECTOR_TOTAL == 4)
  573. #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_SECTOR_0) || ((SECTOR) == FLASH_SECTOR_1) ||\
  574. ((SECTOR) == FLASH_SECTOR_2) || ((SECTOR) == FLASH_SECTOR_3))
  575. #define IS_OB_WRP_SECTOR(SECTOR) ((((SECTOR) & 0xFFF0FFFFU) == 0x00000000U) && ((SECTOR) != 0x00000000U))
  576. #endif /* FLASH_SECTOR_TOTAL == 4 */
  577. #if (FLASH_SECTOR_TOTAL == 2)
  578. #define IS_FLASH_SECTOR(SECTOR) (((SECTOR) == FLASH_SECTOR_0) || ((SECTOR) == FLASH_SECTOR_1))
  579. #define IS_OB_WRP_SECTOR(SECTOR) ((((SECTOR) & 0xFFFCFFFFU) == 0x00000000U) && ((SECTOR) != 0x00000000U))
  580. #endif /* FLASH_SECTOR_TOTAL == 2 */
  581. #if defined (FLASH_OPTCR_nDBANK)
  582. #define IS_OB_NDBANK(VALUE) (((VALUE) == OB_NDBANK_SINGLE_BANK) || \
  583. ((VALUE) == OB_NDBANK_DUAL_BANK))
  584. #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1) || \
  585. ((BANK) == FLASH_BANK_2) || \
  586. ((BANK) == FLASH_BANK_BOTH))
  587. #endif /* FLASH_OPTCR_nDBANK */
  588. #if defined (FLASH_OPTCR_nDBOOT)
  589. #define IS_OB_NDBOOT(VALUE) (((VALUE) == OB_DUAL_BOOT_DISABLE) || \
  590. ((VALUE) == OB_DUAL_BOOT_ENABLE))
  591. #endif /* FLASH_OPTCR_nDBOOT */
  592. #if defined (FLASH_OPTCR2_PCROP)
  593. #define IS_OB_PCROP_SECTOR(SECTOR) (((SECTOR) & (uint32_t)0xFFFFFF00U) == 0x00000000U)
  594. #define IS_OB_PCROP_RDP_VALUE(VALUE) (((VALUE) == OB_PCROP_RDP_DISABLE) || \
  595. ((VALUE) == OB_PCROP_RDP_ENABLE))
  596. #endif /* FLASH_OPTCR2_PCROP */
  597. /**
  598. * @}
  599. */
  600. /**
  601. * @}
  602. */
  603. /* Private functions ---------------------------------------------------------*/
  604. /** @defgroup FLASHEx_Private_Functions FLASH Private Functions
  605. * @{
  606. */
  607. void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange);
  608. /**
  609. * @}
  610. */
  611. /**
  612. * @}
  613. */
  614. /**
  615. * @}
  616. */
  617. #ifdef __cplusplus
  618. }
  619. #endif
  620. #endif /* __STM32F7xx_HAL_FLASH_EX_H */
  621. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/