stm32h7xx_hal_flash_ex.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_flash_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of FLASH HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file in
  13. * the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. ******************************************************************************
  16. */
  17. /* Define to prevent recursive inclusion -------------------------------------*/
  18. #ifndef STM32H7xx_HAL_FLASH_EX_H
  19. #define STM32H7xx_HAL_FLASH_EX_H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "stm32h7xx_hal_def.h"
  25. /** @addtogroup STM32H7xx_HAL_Driver
  26. * @{
  27. */
  28. /** @addtogroup FLASHEx
  29. * @{
  30. */
  31. /* Exported types ------------------------------------------------------------*/
  32. /** @defgroup FLASHEx_Exported_Types FLASH Exported Types
  33. * @{
  34. */
  35. /**
  36. * @brief FLASH Erase structure definition
  37. */
  38. typedef struct
  39. {
  40. uint32_t TypeErase; /*!< Mass erase or sector Erase.
  41. This parameter can be a value of @ref FLASHEx_Type_Erase */
  42. uint32_t Banks; /*!< Select banks to erase when Mass erase is enabled.
  43. This parameter must be a value of @ref FLASHEx_Banks */
  44. uint32_t Sector; /*!< Initial FLASH sector to erase when Mass erase is disabled
  45. This parameter must be a value of @ref FLASH_Sectors */
  46. uint32_t NbSectors; /*!< Number of sectors to be erased.
  47. This parameter must be a value between 1 and (max number of sectors - value of Initial sector)*/
  48. uint32_t VoltageRange;/*!< The device voltage range which defines the erase parallelism
  49. This parameter must be a value of @ref FLASHEx_Voltage_Range */
  50. } FLASH_EraseInitTypeDef;
  51. /**
  52. * @brief FLASH Option Bytes Program structure definition
  53. */
  54. typedef struct
  55. {
  56. uint32_t OptionType; /*!< Option byte to be configured.
  57. This parameter can be a value of @ref FLASHEx_Option_Type */
  58. uint32_t WRPState; /*!< Write protection activation or deactivation.
  59. This parameter can be a value of @ref FLASHEx_WRP_State */
  60. uint32_t WRPSector; /*!< Specifies the sector(s) to be write protected.
  61. The value of this parameter depend on device used within the same series */
  62. uint32_t RDPLevel; /*!< Set the read protection level.
  63. This parameter can be a value of @ref FLASHEx_Option_Bytes_Read_Protection */
  64. uint32_t BORLevel; /*!< Set the BOR Level.
  65. This parameter can be a value of @ref FLASHEx_BOR_Reset_Level */
  66. uint32_t USERType; /*!< User option byte(s) to be configured (used for OPTIONBYTE_USER).
  67. This parameter can be a combination of @ref FLASHEx_OB_USER_Type */
  68. uint32_t USERConfig; /*!< Program the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY /
  69. IWDG_FREEZE_STOP / IWDG_FREEZE_SANDBY / IO_HSLV / SWAP_BANK_OPT */
  70. uint32_t Banks; /*!< Select banks for WRP , PCROP and secure area config .
  71. This parameter must be a value of @ref FLASHEx_Banks */
  72. uint32_t PCROPConfig; /*!< specifies if the PCROP area shall be erased or not
  73. when RDP level decreased from Level 1 to Level 0 or during a mass erase.
  74. This parameter must be a value of @ref FLASHEx_OB_PCROP_RDP enumeration */
  75. uint32_t PCROPStartAddr; /*!< PCROP Start address (used for OPTIONBYTE_PCROP).
  76. This parameter must be a value between begin and end of a bank */
  77. uint32_t PCROPEndAddr; /*!< PCROP End address (used for OPTIONBYTE_PCROP).
  78. This parameter must be a value between PCROP Start address and end of a bank */
  79. uint32_t BootConfig; /*!< Specifies if the Boot Address to be configured BOOT_ADD0, BOOT_ADD1
  80. or both. This parameter must be a value of @ref FLASHEx_OB_BOOT_OPTION enumeration */
  81. uint32_t BootAddr0; /*!< Boot Address 0.
  82. This parameter must be a value between begin and end of a bank */
  83. uint32_t BootAddr1; /*!< Boot Address 1.
  84. This parameter must be a value between begin and end of a bank */
  85. #if defined(DUAL_CORE)
  86. uint32_t CM4BootConfig; /*!< specifies if the CM4 boot Address to be configured BOOT_ADD0, BOOT_ADD1
  87. or both.
  88. This parameter must be a value of @ref FLASHEx_OB_BOOT_OPTION enumeration */
  89. uint32_t CM4BootAddr0; /*!< CM4 Boot Address 0.
  90. This parameter must be a value between begin and end of a bank */
  91. uint32_t CM4BootAddr1; /*!< CM4 Boot Address 1.
  92. This parameter must be a value between begin and end of a bank */
  93. #endif /*DUAL_CORE*/
  94. uint32_t SecureAreaConfig; /*!< specifies if the bank secured area shall be erased or not
  95. when RDP level decreased from Level 1 to Level 0 or during a mass erase.
  96. This parameter must be a value of @ref FLASHEx_OB_SECURE_RDP enumeration */
  97. uint32_t SecureAreaStartAddr; /*!< Bank Secure area Start address.
  98. This parameter must be a value between begin address and end address of bank1 */
  99. uint32_t SecureAreaEndAddr; /*!< Bank Secure area End address.
  100. This parameter must be a value between Secure Area Start address and end address of a bank1 */
  101. #if defined (FLASH_OTPBL_LOCKBL)
  102. uint32_t OTPBlockLock; /*!< Specifies the OTP block(s) to be locked.
  103. This parameter must be a value of @ref FLASHEx_OTP_Blocks */
  104. #endif /* FLASH_OTPBL_LOCKBL */
  105. #if defined (FLASH_OPTSR2_TCM_AXI_SHARED)
  106. uint32_t SharedRamConfig; /*!< Specifies the configuration of TCM / AXI shared RAM.
  107. This parameter must be a value of @ref FLASHEx_OB_TCM_AXI_SHARED */
  108. #endif /* FLASH_OPTSR2_TCM_AXI_SHARED */
  109. #if defined (FLASH_OPTSR2_CPUFREQ_BOOST)
  110. uint32_t FreqBoostState; /*!< Specifies the state of CPU Frequency Boost.
  111. This parameter must be a value of @ref FLASHEx_OB_CPUFREQ_BOOST */
  112. #endif /* FLASH_OPTSR2_CPUFREQ_BOOST */
  113. } FLASH_OBProgramInitTypeDef;
  114. /**
  115. * @brief FLASH Erase structure definition
  116. */
  117. typedef struct
  118. {
  119. uint32_t TypeCRC; /*!< CRC Selection Type.
  120. This parameter can be a value of @ref FLASHEx_CRC_Selection_Type */
  121. uint32_t BurstSize; /*!< CRC Burst Size.
  122. This parameter can be a value of @ref FLASHEx_CRC_Burst_Size */
  123. uint32_t Bank; /*!< Select bank where CRC computation is enabled.
  124. This parameter must be FLASH_BANK_1 or FLASH_BANK_2 */
  125. uint32_t Sector; /*!< Initial FLASH sector from which starts the CRC computation
  126. This parameter must be a value of @ref FLASH_Sectors */
  127. uint32_t NbSectors; /*!< Number of sectors to be computed.
  128. This parameter must be a value between 1 and (max number of sectors - value of Initial sector)*/
  129. uint32_t CRCStartAddr; /*!< CRC Start address.
  130. This parameter must be a value between begin address and end address of a bank */
  131. uint32_t CRCEndAddr; /*!< CRC End address.
  132. This parameter must be a value between CRC Start address and end address of a bank */
  133. } FLASH_CRCInitTypeDef;
  134. /**
  135. * @}
  136. */
  137. /* Exported constants --------------------------------------------------------*/
  138. /** @defgroup FLASHEx_Exported_Constants FLASH Exported Constants
  139. * @{
  140. */
  141. /** @defgroup FLASHEx_Type_Erase FLASH Type Erase
  142. * @{
  143. */
  144. #define FLASH_TYPEERASE_SECTORS 0x00U /*!< Sectors erase only */
  145. #define FLASH_TYPEERASE_MASSERASE 0x01U /*!< Flash Mass erase activation */
  146. /**
  147. * @}
  148. */
  149. #if defined (FLASH_CR_PSIZE)
  150. /** @defgroup FLASHEx_Voltage_Range FLASH Voltage Range
  151. * @{
  152. */
  153. #define FLASH_VOLTAGE_RANGE_1 0x00000000U /*!< Flash program/erase by 8 bits */
  154. #define FLASH_VOLTAGE_RANGE_2 FLASH_CR_PSIZE_0 /*!< Flash program/erase by 16 bits */
  155. #define FLASH_VOLTAGE_RANGE_3 FLASH_CR_PSIZE_1 /*!< Flash program/erase by 32 bits */
  156. #define FLASH_VOLTAGE_RANGE_4 FLASH_CR_PSIZE /*!< Flash program/erase by 64 bits */
  157. /**
  158. * @}
  159. */
  160. #endif /* FLASH_CR_PSIZE */
  161. /** @defgroup FLASHEx_WRP_State FLASH WRP State
  162. * @{
  163. */
  164. #define OB_WRPSTATE_DISABLE 0x00000000U /*!< Disable the write protection of the desired bank 1 sectors */
  165. #define OB_WRPSTATE_ENABLE 0x00000001U /*!< Enable the write protection of the desired bank 1 sectors */
  166. /**
  167. * @}
  168. */
  169. /** @defgroup FLASHEx_Option_Type FLASH Option Type
  170. * @{
  171. */
  172. #define OPTIONBYTE_WRP 0x01U /*!< WRP option byte configuration */
  173. #define OPTIONBYTE_RDP 0x02U /*!< RDP option byte configuration */
  174. #define OPTIONBYTE_USER 0x04U /*!< USER option byte configuration */
  175. #define OPTIONBYTE_PCROP 0x08U /*!< PCROP option byte configuration */
  176. #define OPTIONBYTE_BOR 0x10U /*!< BOR option byte configuration */
  177. #define OPTIONBYTE_SECURE_AREA 0x20U /*!< secure area option byte configuration */
  178. #if defined (DUAL_CORE)
  179. #define OPTIONBYTE_CM7_BOOTADD 0x40U /*!< CM7 BOOT ADD option byte configuration */
  180. #define OPTIONBYTE_CM4_BOOTADD 0x80U /*!< CM4 BOOT ADD option byte configuration */
  181. #define OPTIONBYTE_BOOTADD OPTIONBYTE_CM7_BOOTADD /*!< BOOT ADD option byte configuration */
  182. #else /* Single core */
  183. #define OPTIONBYTE_BOOTADD 0x40U /*!< BOOT ADD option byte configuration */
  184. #endif /*DUAL_CORE*/
  185. #if defined (FLASH_OTPBL_LOCKBL)
  186. #define OPTIONBYTE_OTP_LOCK 0x80U /*!< OTP Lock option byte configuration */
  187. #endif /* FLASH_OTPBL_LOCKBL */
  188. #if defined (FLASH_OPTSR2_TCM_AXI_SHARED)
  189. #define OPTIONBYTE_SHARED_RAM 0x100U /*!< TCM / AXI Shared RAM option byte configuration */
  190. #endif /* FLASH_OPTSR2_TCM_AXI_SHARED */
  191. #if defined (FLASH_OPTSR2_CPUFREQ_BOOST)
  192. #define OPTIONBYTE_FREQ_BOOST 0x200U /*!< CPU Frequency Boost option byte configuration */
  193. #endif /* FLASH_OPTSR2_CPUFREQ_BOOST */
  194. #if defined (DUAL_CORE)
  195. #define OPTIONBYTE_ALL (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER |\
  196. OPTIONBYTE_PCROP | OPTIONBYTE_BOR | OPTIONBYTE_SECURE_AREA |\
  197. OPTIONBYTE_CM7_BOOTADD | OPTIONBYTE_CM4_BOOTADD) /*!< All option byte configuration */
  198. #elif defined (FLASH_OTPBL_LOCKBL)
  199. #define OPTIONBYTE_ALL (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER |\
  200. OPTIONBYTE_PCROP | OPTIONBYTE_BOR | OPTIONBYTE_SECURE_AREA |\
  201. OPTIONBYTE_BOOTADD | OPTIONBYTE_OTP_LOCK) /*!< All option byte configuration */
  202. #elif defined (FLASH_OPTSR2_TCM_AXI_SHARED)
  203. #define OPTIONBYTE_ALL (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER |\
  204. OPTIONBYTE_PCROP | OPTIONBYTE_BOR | OPTIONBYTE_SECURE_AREA |\
  205. OPTIONBYTE_BOOTADD | OPTIONBYTE_SHARED_RAM | OPTIONBYTE_FREQ_BOOST) /*!< All option byte configuration */
  206. #else
  207. #define OPTIONBYTE_ALL (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER |\
  208. OPTIONBYTE_PCROP | OPTIONBYTE_BOR | OPTIONBYTE_SECURE_AREA |\
  209. OPTIONBYTE_BOOTADD) /*!< All option byte configuration */
  210. #endif /* DUAL_CORE */
  211. /**
  212. * @}
  213. */
  214. /** @defgroup FLASHEx_Option_Bytes_Read_Protection FLASH Option Bytes Read Protection
  215. * @{
  216. */
  217. #define OB_RDP_LEVEL_0 0xAA00U
  218. #define OB_RDP_LEVEL_1 0x5500U
  219. #define OB_RDP_LEVEL_2 0xCC00U /*!< Warning: When enabling read protection level 2
  220. it s no more possible to go back to level 1 or 0 */
  221. /**
  222. * @}
  223. */
  224. /** @defgroup FLASHEx_Option_Bytes_IWatchdog FLASH Option Bytes IWatchdog
  225. * @{
  226. */
  227. #define OB_IWDG_SW OB_IWDG1_SW /*!< Software IWDG selected */
  228. #define OB_IWDG_HW OB_IWDG1_HW /*!< Hardware IWDG selected */
  229. /**
  230. * @}
  231. */
  232. /** @defgroup FLASHEx_Option_Bytes_nRST_STOP FLASH Option Bytes nRST_STOP
  233. * @{
  234. */
  235. #define OB_STOP_NO_RST 0x40U /*!< No reset generated when entering in STOP */
  236. #define OB_STOP_RST 0x00U /*!< Reset generated when entering in STOP */
  237. /**
  238. * @}
  239. */
  240. /** @defgroup FLASHEx_Option_Bytes_nRST_STDBY FLASH Option Bytes nRST_STDBY
  241. * @{
  242. */
  243. #define OB_STDBY_NO_RST 0x80U /*!< No reset generated when entering in STANDBY */
  244. #define OB_STDBY_RST 0x00U /*!< Reset generated when entering in STANDBY */
  245. /**
  246. * @}
  247. */
  248. /** @defgroup FLASHEx_Option_Bytes_IWDG_FREEZE_STOP FLASH IWDG Counter Freeze in STOP
  249. * @{
  250. */
  251. #define OB_IWDG_STOP_FREEZE 0x00000000U /*!< Freeze IWDG counter in STOP mode */
  252. #define OB_IWDG_STOP_ACTIVE FLASH_OPTSR_FZ_IWDG_STOP /*!< IWDG counter active in STOP mode */
  253. /**
  254. * @}
  255. */
  256. /** @defgroup FLASHEx_Option_Bytes_IWDG_FREEZE_SANDBY FLASH IWDG Counter Freeze in STANDBY
  257. * @{
  258. */
  259. #define OB_IWDG_STDBY_FREEZE 0x00000000U /*!< Freeze IWDG counter in STANDBY mode */
  260. #define OB_IWDG_STDBY_ACTIVE FLASH_OPTSR_FZ_IWDG_SDBY /*!< IWDG counter active in STANDBY mode */
  261. /**
  262. * @}
  263. */
  264. /** @defgroup FLASHEx_BOR_Reset_Level FLASH BOR Reset Level
  265. * @{
  266. */
  267. #define OB_BOR_LEVEL0 0x00000000U /*!< Reset level threshold is set to 1.6V */
  268. #define OB_BOR_LEVEL1 FLASH_OPTSR_BOR_LEV_0 /*!< Reset level threshold is set to 2.1V */
  269. #define OB_BOR_LEVEL2 FLASH_OPTSR_BOR_LEV_1 /*!< Reset level threshold is set to 2.4V */
  270. #define OB_BOR_LEVEL3 (FLASH_OPTSR_BOR_LEV_1 | FLASH_OPTSR_BOR_LEV_0) /*!< Reset level threshold is set to 2.7V */
  271. /**
  272. * @}
  273. */
  274. /** @defgroup FLASHEx_Boot_Address FLASH Boot Address
  275. * @{
  276. */
  277. #define OB_BOOTADDR_ITCM_RAM 0x0000U /*!< Boot from ITCM RAM (0x00000000) */
  278. #define OB_BOOTADDR_SYSTEM 0x0040U /*!< Boot from System memory bootloader (0x00100000) */
  279. #define OB_BOOTADDR_ITCM_FLASH 0x0080U /*!< Boot from Flash on ITCM interface (0x00200000) */
  280. #define OB_BOOTADDR_AXIM_FLASH 0x2000U /*!< Boot from Flash on AXIM interface (0x08000000) */
  281. #define OB_BOOTADDR_DTCM_RAM 0x8000U /*!< Boot from DTCM RAM (0x20000000) */
  282. #define OB_BOOTADDR_SRAM1 0x8004U /*!< Boot from SRAM1 (0x20010000) */
  283. #define OB_BOOTADDR_SRAM2 0x8013U /*!< Boot from SRAM2 (0x2004C000) */
  284. /**
  285. * @}
  286. */
  287. /** @defgroup FLASH_Latency FLASH Latency
  288. * @{
  289. */
  290. #define FLASH_LATENCY_0 FLASH_ACR_LATENCY_0WS /*!< FLASH Zero Latency cycle */
  291. #define FLASH_LATENCY_1 FLASH_ACR_LATENCY_1WS /*!< FLASH One Latency cycle */
  292. #define FLASH_LATENCY_2 FLASH_ACR_LATENCY_2WS /*!< FLASH Two Latency cycles */
  293. #define FLASH_LATENCY_3 FLASH_ACR_LATENCY_3WS /*!< FLASH Three Latency cycles */
  294. #define FLASH_LATENCY_4 FLASH_ACR_LATENCY_4WS /*!< FLASH Four Latency cycles */
  295. #define FLASH_LATENCY_5 FLASH_ACR_LATENCY_5WS /*!< FLASH Five Latency cycles */
  296. #define FLASH_LATENCY_6 FLASH_ACR_LATENCY_6WS /*!< FLASH Six Latency cycles */
  297. #define FLASH_LATENCY_7 FLASH_ACR_LATENCY_7WS /*!< FLASH Seven Latency cycles */
  298. /* Unused FLASH Latency defines */
  299. #define FLASH_LATENCY_8 FLASH_ACR_LATENCY_8WS /*!< FLASH Eight Latency cycle */
  300. #define FLASH_LATENCY_9 FLASH_ACR_LATENCY_9WS /*!< FLASH Nine Latency cycle */
  301. #define FLASH_LATENCY_10 FLASH_ACR_LATENCY_10WS /*!< FLASH Ten Latency cycles */
  302. #define FLASH_LATENCY_11 FLASH_ACR_LATENCY_11WS /*!< FLASH Eleven Latency cycles */
  303. #define FLASH_LATENCY_12 FLASH_ACR_LATENCY_12WS /*!< FLASH Twelve Latency cycles */
  304. #define FLASH_LATENCY_13 FLASH_ACR_LATENCY_13WS /*!< FLASH Thirteen Latency cycles */
  305. #define FLASH_LATENCY_14 FLASH_ACR_LATENCY_14WS /*!< FLASH Fourteen Latency cycles */
  306. #define FLASH_LATENCY_15 FLASH_ACR_LATENCY_15WS /*!< FLASH Fifteen Latency cycles */
  307. /**
  308. * @}
  309. */
  310. /** @defgroup FLASHEx_Banks FLASH Banks
  311. * @{
  312. */
  313. #define FLASH_BANK_1 0x01U /*!< Bank 1 */
  314. #if defined (DUAL_BANK)
  315. #define FLASH_BANK_2 0x02U /*!< Bank 2 */
  316. #define FLASH_BANK_BOTH (FLASH_BANK_1 | FLASH_BANK_2) /*!< Bank1 and Bank2 */
  317. #endif /* DUAL_BANK */
  318. /**
  319. * @}
  320. */
  321. /** @defgroup FLASHEx_OB_PCROP_RDP FLASHEx OB PCROP RDP
  322. * @{
  323. */
  324. #define OB_PCROP_RDP_NOT_ERASE 0x00000000U /*!< PCROP area is not erased when the RDP level
  325. is decreased from Level 1 to Level 0 or during a mass erase */
  326. #define OB_PCROP_RDP_ERASE FLASH_PRAR_DMEP /*!< PCROP area is erased when the RDP level is
  327. decreased from Level 1 to Level 0 (full mass erase) */
  328. /**
  329. * @}
  330. */
  331. /** @defgroup FLASHEx_Option_Bytes_Write_Protection FLASH Option Bytes Write Protection
  332. * @{
  333. */
  334. #if (FLASH_SECTOR_TOTAL == 128)
  335. #define OB_WRP_SECTOR_0TO3 0x00000001U /*!< Write protection of Sector0 to Sector3 */
  336. #define OB_WRP_SECTOR_4TO7 0x00000002U /*!< Write protection of Sector4 to Sector7 */
  337. #define OB_WRP_SECTOR_8TO11 0x00000004U /*!< Write protection of Sector8 to Sector11 */
  338. #define OB_WRP_SECTOR_12TO15 0x00000008U /*!< Write protection of Sector12 to Sector15 */
  339. #define OB_WRP_SECTOR_16TO19 0x00000010U /*!< Write protection of Sector16 to Sector19 */
  340. #define OB_WRP_SECTOR_20TO23 0x00000020U /*!< Write protection of Sector20 to Sector23 */
  341. #define OB_WRP_SECTOR_24TO27 0x00000040U /*!< Write protection of Sector24 to Sector27 */
  342. #define OB_WRP_SECTOR_28TO31 0x00000080U /*!< Write protection of Sector28 to Sector31 */
  343. #define OB_WRP_SECTOR_32TO35 0x00000100U /*!< Write protection of Sector32 to Sector35 */
  344. #define OB_WRP_SECTOR_36TO39 0x00000200U /*!< Write protection of Sector36 to Sector39 */
  345. #define OB_WRP_SECTOR_40TO43 0x00000400U /*!< Write protection of Sector40 to Sector43 */
  346. #define OB_WRP_SECTOR_44TO47 0x00000800U /*!< Write protection of Sector44 to Sector47 */
  347. #define OB_WRP_SECTOR_48TO51 0x00001000U /*!< Write protection of Sector48 to Sector51 */
  348. #define OB_WRP_SECTOR_52TO55 0x00002000U /*!< Write protection of Sector52 to Sector55 */
  349. #define OB_WRP_SECTOR_56TO59 0x00004000U /*!< Write protection of Sector56 to Sector59 */
  350. #define OB_WRP_SECTOR_60TO63 0x00008000U /*!< Write protection of Sector60 to Sector63 */
  351. #define OB_WRP_SECTOR_64TO67 0x00010000U /*!< Write protection of Sector64 to Sector67 */
  352. #define OB_WRP_SECTOR_68TO71 0x00020000U /*!< Write protection of Sector68 to Sector71 */
  353. #define OB_WRP_SECTOR_72TO75 0x00040000U /*!< Write protection of Sector72 to Sector75 */
  354. #define OB_WRP_SECTOR_76TO79 0x00080000U /*!< Write protection of Sector76 to Sector79 */
  355. #define OB_WRP_SECTOR_80TO83 0x00100000U /*!< Write protection of Sector80 to Sector83 */
  356. #define OB_WRP_SECTOR_84TO87 0x00200000U /*!< Write protection of Sector84 to Sector87 */
  357. #define OB_WRP_SECTOR_88TO91 0x00400000U /*!< Write protection of Sector88 to Sector91 */
  358. #define OB_WRP_SECTOR_92TO95 0x00800000U /*!< Write protection of Sector92 to Sector95 */
  359. #define OB_WRP_SECTOR_96TO99 0x01000000U /*!< Write protection of Sector96 to Sector99 */
  360. #define OB_WRP_SECTOR_100TO103 0x02000000U /*!< Write protection of Sector100 to Sector103 */
  361. #define OB_WRP_SECTOR_104TO107 0x04000000U /*!< Write protection of Sector104 to Sector107 */
  362. #define OB_WRP_SECTOR_108TO111 0x08000000U /*!< Write protection of Sector108 to Sector111 */
  363. #define OB_WRP_SECTOR_112TO115 0x10000000U /*!< Write protection of Sector112 to Sector115 */
  364. #define OB_WRP_SECTOR_116TO119 0x20000000U /*!< Write protection of Sector116 to Sector119 */
  365. #define OB_WRP_SECTOR_120TO123 0x40000000U /*!< Write protection of Sector120 to Sector123 */
  366. #define OB_WRP_SECTOR_124TO127 0x80000000U /*!< Write protection of Sector124 to Sector127 */
  367. #define OB_WRP_SECTOR_ALL 0xFFFFFFFFU /*!< Write protection of all Sectors */
  368. #else
  369. #define OB_WRP_SECTOR_0 0x00000001U /*!< Write protection of Sector0 */
  370. #define OB_WRP_SECTOR_1 0x00000002U /*!< Write protection of Sector1 */
  371. #define OB_WRP_SECTOR_2 0x00000004U /*!< Write protection of Sector2 */
  372. #define OB_WRP_SECTOR_3 0x00000008U /*!< Write protection of Sector3 */
  373. #define OB_WRP_SECTOR_4 0x00000010U /*!< Write protection of Sector4 */
  374. #define OB_WRP_SECTOR_5 0x00000020U /*!< Write protection of Sector5 */
  375. #define OB_WRP_SECTOR_6 0x00000040U /*!< Write protection of Sector6 */
  376. #define OB_WRP_SECTOR_7 0x00000080U /*!< Write protection of Sector7 */
  377. #define OB_WRP_SECTOR_ALL 0x000000FFU /*!< Write protection of all Sectors */
  378. #endif /* FLASH_SECTOR_TOTAL == 128 */
  379. /**
  380. * @}
  381. */
  382. /** @defgroup FLASHEx_OB_SECURITY FLASHEx OB SECURITY
  383. * @{
  384. */
  385. #define OB_SECURITY_DISABLE 0x00000000U /*!< security enabled */
  386. #define OB_SECURITY_ENABLE FLASH_OPTSR_SECURITY /*!< security disabled */
  387. /**
  388. * @}
  389. */
  390. /** @defgroup FLASHEx_OB_ST_RAM_SIZE FLASHEx OB ST RAM SIZE
  391. * @{
  392. */
  393. #define OB_ST_RAM_SIZE_2KB 0x00000000U /*!< 2 Kbytes reserved to ST code */
  394. #define OB_ST_RAM_SIZE_4KB FLASH_OPTSR_ST_RAM_SIZE_0 /*!< 4 Kbytes reserved to ST code */
  395. #define OB_ST_RAM_SIZE_8KB FLASH_OPTSR_ST_RAM_SIZE_1 /*!< 8 Kbytes reserved to ST code */
  396. #define OB_ST_RAM_SIZE_16KB FLASH_OPTSR_ST_RAM_SIZE /*!< 16 Kbytes reserved to ST code */
  397. /**
  398. * @}
  399. */
  400. #if defined(DUAL_CORE)
  401. /** @defgroup FLASHEx_OB_BCM7 FLASHEx OB BCM7
  402. * @{
  403. */
  404. #define OB_BCM7_DISABLE 0x00000000U /*!< CM7 Boot disabled */
  405. #define OB_BCM7_ENABLE FLASH_OPTSR_BCM7 /*!< CM7 Boot enabled */
  406. /**
  407. * @}
  408. */
  409. /** @defgroup FLASHEx_OB_BCM4 FLASHEx OB BCM4
  410. * @{
  411. */
  412. #define OB_BCM4_DISABLE 0x00000000U /*!< CM4 Boot disabled */
  413. #define OB_BCM4_ENABLE FLASH_OPTSR_BCM4 /*!< CM4 Boot enabled */
  414. /**
  415. * @}
  416. */
  417. #endif /* DUAL_CORE */
  418. /** @defgroup FLASHEx_OB_IWDG1_SW FLASHEx OB IWDG1 SW
  419. * @{
  420. */
  421. #define OB_IWDG1_SW FLASH_OPTSR_IWDG1_SW /*!< Hardware independent watchdog 1 */
  422. #define OB_IWDG1_HW 0x00000000U /*!< Software independent watchdog 1 */
  423. /**
  424. * @}
  425. */
  426. #if defined(DUAL_CORE)
  427. /** @defgroup FLASHEx_OB_IWDG2_SW FLASHEx OB IWDG2 SW
  428. * @{
  429. */
  430. #define OB_IWDG2_SW FLASH_OPTSR_IWDG2_SW /*!< Hardware independent watchdog 2*/
  431. #define OB_IWDG2_HW 0x00000000U /*!< Software independent watchdog 2*/
  432. /**
  433. * @}
  434. */
  435. #endif
  436. /** @defgroup FLASHEx_OB_NRST_STOP_D1 FLASHEx OB NRST STOP D1
  437. * @{
  438. */
  439. #define OB_STOP_RST_D1 0x00000000U /*!< Reset generated when entering the D1 to stop mode */
  440. #define OB_STOP_NO_RST_D1 FLASH_OPTSR_NRST_STOP_D1 /*!< No reset generated when entering the D1 to stop mode */
  441. /**
  442. * @}
  443. */
  444. /** @defgroup FLASHEx_OB_NRST_STDBY_D1 FLASHEx OB NRST STDBY D1
  445. * @{
  446. */
  447. #define OB_STDBY_RST_D1 0x00000000U /*!< Reset generated when entering the D1 to standby mode */
  448. #define OB_STDBY_NO_RST_D1 FLASH_OPTSR_NRST_STBY_D1 /*!< No reset generated when entering the D1 to standby mode */
  449. /**
  450. * @}
  451. */
  452. #if defined (FLASH_OPTSR_NRST_STOP_D2)
  453. /** @defgroup FLASHEx_OB_NRST_STOP_D2 FLASHEx OB NRST STOP D2
  454. * @{
  455. */
  456. #define OB_STOP_RST_D2 0x00000000U /*!< Reset generated when entering the D2 to stop mode */
  457. #define OB_STOP_NO_RST_D2 FLASH_OPTSR_NRST_STOP_D2 /*!< No reset generated when entering the D2 to stop mode */
  458. /**
  459. * @}
  460. */
  461. /** @defgroup FLASHEx_OB_NRST_STDBY_D2 FLASHEx OB NRST STDBY D2
  462. * @{
  463. */
  464. #define OB_STDBY_RST_D2 0x00000000U /*!< Reset generated when entering the D2 to standby mode */
  465. #define OB_STDBY_NO_RST_D2 FLASH_OPTSR_NRST_STBY_D2 /*!< No reset generated when entering the D2 to standby mode */
  466. /**
  467. * @}
  468. */
  469. #endif /* FLASH_OPTSR_NRST_STOP_D2 */
  470. #if defined (DUAL_BANK)
  471. /** @defgroup FLASHEx_OB_SWAP_BANK FLASHEx OB SWAP BANK
  472. * @{
  473. */
  474. #define OB_SWAP_BANK_DISABLE 0x00000000U /*!< Bank swap disabled */
  475. #define OB_SWAP_BANK_ENABLE FLASH_OPTSR_SWAP_BANK_OPT /*!< Bank swap enabled */
  476. /**
  477. * @}
  478. */
  479. #endif /* DUAL_BANK */
  480. /** @defgroup FLASHEx_OB_IOHSLV FLASHEx OB IOHSLV
  481. * @{
  482. */
  483. #define OB_IOHSLV_DISABLE 0x00000000U /*!< IOHSLV disabled */
  484. #define OB_IOHSLV_ENABLE FLASH_OPTSR_IO_HSLV /*!< IOHSLV enabled */
  485. /**
  486. * @}
  487. */
  488. #if defined (FLASH_OPTSR_VDDMMC_HSLV)
  489. /** @defgroup FLASHEx_OB_VDDMMC_HSLV FLASHEx OB VDDMMC HSLV
  490. * @{
  491. */
  492. #define OB_VDDMMC_HSLV_DISABLE 0x00000000U /*!< VDDMMC HSLV disabled */
  493. #define OB_VDDMMC_HSLV_ENABLE FLASH_OPTSR_VDDMMC_HSLV /*!< VDDMMC HSLV enabled */
  494. /**
  495. * @}
  496. */
  497. #endif /* FLASH_OPTSR_VDDMMC_HSLV */
  498. #if defined (FLASH_OPTSR2_CPUFREQ_BOOST)
  499. /** @defgroup FLASHEx_OB_CPUFREQ_BOOST FLASHEx OB CPUFREQ BOOST
  500. * @{
  501. */
  502. #define OB_CPUFREQ_BOOST_DISABLE 0x00000000U /*!< CPUFREQ BOOST disabled */
  503. #define OB_CPUFREQ_BOOST_ENABLE FLASH_OPTSR2_CPUFREQ_BOOST /*!< CPUFREQ BOOST enabled */
  504. /**
  505. * @}
  506. */
  507. #endif /* FLASH_OPTSR2_CPUFREQ_BOOST */
  508. #if defined (FLASH_OPTSR2_TCM_AXI_SHARED)
  509. /** @defgroup FLASHEx_OB_TCM_AXI_SHARED FLASHEx OB TCM AXI SHARED
  510. * @{
  511. */
  512. #define OB_TCM_AXI_SHARED_ITCM64KB 0x00000000U /*!< 64KB ITCM / 320KB system AXI */
  513. #define OB_TCM_AXI_SHARED_ITCM128KB FLASH_OPTSR2_TCM_AXI_SHARED_0 /*!< 128KB ITCM / 256KB system AXI */
  514. #define OB_TCM_AXI_SHARED_ITCM192KB FLASH_OPTSR2_TCM_AXI_SHARED_1 /*!< 192KB ITCM / 192KB system AXI */
  515. #define OB_TCM_AXI_SHARED_ITCM256KB FLASH_OPTSR2_TCM_AXI_SHARED /*!< 256KB ITCM / 128KB system AXI */
  516. /**
  517. * @}
  518. */
  519. #endif /* FLASH_OPTSR2_TCM_AXI_SHARED */
  520. /** @defgroup FLASHEx_OB_USER_Type FLASHEx OB USER Type
  521. * @{
  522. */
  523. #define OB_USER_IWDG1_SW 0x0001U /*!< Independent watchdog selection */
  524. #define OB_USER_NRST_STOP_D1 0x0002U /*!< Reset when entering Stop mode selection*/
  525. #define OB_USER_NRST_STDBY_D1 0x0004U /*!< Reset when entering standby mode selection*/
  526. #define OB_USER_IWDG_STOP 0x0008U /*!< Independent watchdog counter freeze in stop mode */
  527. #define OB_USER_IWDG_STDBY 0x0010U /*!< Independent watchdog counter freeze in standby mode */
  528. #define OB_USER_ST_RAM_SIZE 0x0020U /*!< dedicated DTCM Ram size selection */
  529. #define OB_USER_SECURITY 0x0040U /*!< security selection */
  530. #define OB_USER_IOHSLV 0x0080U /*!< IO HSLV selection */
  531. #if defined (DUAL_BANK)
  532. #define OB_USER_SWAP_BANK 0x0100U /*!< Bank swap selection */
  533. #endif /* DUAL_BANK */
  534. #if defined (FLASH_OPTSR_VDDMMC_HSLV)
  535. #define OB_USER_VDDMMC_HSLV 0x0200U /*!< VDDMMC HSLV selection */
  536. #endif /* FLASH_OPTSR_VDDMMC_HSLV */
  537. #if defined (DUAL_CORE)
  538. #define OB_USER_IWDG2_SW 0x0200U /*!< Window watchdog selection */
  539. #define OB_USER_BCM4 0x0400U /*!< CM4 boot selection */
  540. #define OB_USER_BCM7 0x0800U /*!< CM7 boot selection */
  541. #endif /*DUAL_CORE*/
  542. #if defined (FLASH_OPTSR_NRST_STOP_D2)
  543. #define OB_USER_NRST_STOP_D2 0x1000U /*!< Reset when entering Stop mode selection */
  544. #define OB_USER_NRST_STDBY_D2 0x2000U /*!< Reset when entering standby mode selection */
  545. #endif /* FLASH_OPTSR_NRST_STOP_D2 */
  546. #if defined (DUAL_CORE)
  547. #define OB_USER_ALL (OB_USER_IWDG1_SW | OB_USER_NRST_STOP_D1 | OB_USER_NRST_STDBY_D1 |\
  548. OB_USER_IWDG_STOP | OB_USER_IWDG_STDBY | OB_USER_ST_RAM_SIZE |\
  549. OB_USER_SECURITY | OB_USER_IOHSLV | OB_USER_SWAP_BANK |\
  550. OB_USER_IWDG2_SW | OB_USER_BCM4 | OB_USER_BCM7 |\
  551. OB_USER_NRST_STOP_D2 | OB_USER_NRST_STDBY_D2)
  552. #elif defined (FLASH_OPTSR_VDDMMC_HSLV)
  553. #if defined (DUAL_BANK)
  554. #define OB_USER_ALL (OB_USER_IWDG1_SW | OB_USER_NRST_STOP_D1 | OB_USER_NRST_STDBY_D1 |\
  555. OB_USER_IWDG_STOP | OB_USER_IWDG_STDBY | OB_USER_ST_RAM_SIZE |\
  556. OB_USER_SECURITY | OB_USER_IOHSLV | OB_USER_SWAP_BANK |\
  557. OB_USER_VDDMMC_HSLV)
  558. #else
  559. #define OB_USER_ALL (OB_USER_IWDG1_SW | OB_USER_NRST_STOP_D1 | OB_USER_NRST_STDBY_D1 |\
  560. OB_USER_IWDG_STOP | OB_USER_IWDG_STDBY | OB_USER_ST_RAM_SIZE |\
  561. OB_USER_SECURITY | OB_USER_IOHSLV |\
  562. OB_USER_VDDMMC_HSLV)
  563. #endif /* DUAL_BANK */
  564. #elif defined (FLASH_OPTSR2_TCM_AXI_SHARED)
  565. #define OB_USER_ALL (OB_USER_IWDG1_SW | OB_USER_NRST_STOP_D1 | OB_USER_NRST_STDBY_D1 |\
  566. OB_USER_IWDG_STOP | OB_USER_IWDG_STDBY | OB_USER_ST_RAM_SIZE |\
  567. OB_USER_SECURITY | OB_USER_IOHSLV |\
  568. OB_USER_NRST_STOP_D2 | OB_USER_NRST_STDBY_D2)
  569. #else /* Single core */
  570. #if defined (DUAL_BANK)
  571. #define OB_USER_ALL (OB_USER_IWDG1_SW | OB_USER_NRST_STOP_D1 | OB_USER_NRST_STDBY_D1 |\
  572. OB_USER_IWDG_STOP | OB_USER_IWDG_STDBY | OB_USER_ST_RAM_SIZE |\
  573. OB_USER_SECURITY | OB_USER_IOHSLV | OB_USER_SWAP_BANK )
  574. #else
  575. #define OB_USER_ALL (OB_USER_IWDG1_SW | OB_USER_NRST_STOP_D1 | OB_USER_NRST_STDBY_D1 |\
  576. OB_USER_IWDG_STOP | OB_USER_IWDG_STDBY | OB_USER_ST_RAM_SIZE |\
  577. OB_USER_SECURITY | OB_USER_IOHSLV )
  578. #endif /* DUAL_BANK */
  579. #endif /* DUAL_CORE */
  580. /**
  581. * @}
  582. */
  583. /** @defgroup FLASHEx_OB_BOOT_OPTION FLASHEx OB BOOT OPTION
  584. * @{
  585. */
  586. #define OB_BOOT_ADD0 0x01U /*!< Select Boot Address 0 */
  587. #define OB_BOOT_ADD1 0x02U /*!< Select Boot Address 1 */
  588. #define OB_BOOT_ADD_BOTH 0x03U /*!< Select Boot Address 0 and 1 */
  589. /**
  590. * @}
  591. */
  592. /** @defgroup FLASHEx_OB_SECURE_RDP FLASHEx OB SECURE RDP
  593. * @{
  594. */
  595. #define OB_SECURE_RDP_NOT_ERASE 0x00000000U /*!< Secure area is not erased when the RDP level
  596. is decreased from Level 1 to Level 0 or during a mass erase */
  597. #define OB_SECURE_RDP_ERASE FLASH_SCAR_DMES /*!< Secure area is erased when the RDP level is
  598. decreased from Level 1 to Level 0 (full mass erase) */
  599. /**
  600. * @}
  601. */
  602. /** @defgroup FLASHEx_CRC_Selection_Type FLASH CRC Selection Type
  603. * @{
  604. */
  605. #define FLASH_CRC_ADDR 0x00000000U /*!< CRC selection type by address */
  606. #define FLASH_CRC_SECTORS FLASH_CRCCR_CRC_BY_SECT /*!< CRC selection type by sectors */
  607. #define FLASH_CRC_BANK (FLASH_CRCCR_ALL_BANK | FLASH_CRCCR_CRC_BY_SECT) /*!< CRC selection type by bank */
  608. /**
  609. * @}
  610. */
  611. /** @defgroup FLASHEx_CRC_Burst_Size FLASH CRC Burst Size
  612. * @{
  613. */
  614. #define FLASH_CRC_BURST_SIZE_4 0x00000000U /*!< Every burst has a size of 4 Flash words (256-bit) */
  615. #define FLASH_CRC_BURST_SIZE_16 FLASH_CRCCR_CRC_BURST_0 /*!< Every burst has a size of 16 Flash words (256-bit) */
  616. #define FLASH_CRC_BURST_SIZE_64 FLASH_CRCCR_CRC_BURST_1 /*!< Every burst has a size of 64 Flash words (256-bit) */
  617. #define FLASH_CRC_BURST_SIZE_256 FLASH_CRCCR_CRC_BURST /*!< Every burst has a size of 256 Flash words (256-bit) */
  618. /**
  619. * @}
  620. */
  621. /** @defgroup FLASHEx_Programming_Delay FLASH Programming Delay
  622. * @{
  623. */
  624. #define FLASH_PROGRAMMING_DELAY_0 0x00000000U /*!< programming delay set for Flash running at 70 MHz or below */
  625. #define FLASH_PROGRAMMING_DELAY_1 FLASH_ACR_WRHIGHFREQ_0 /*!< programming delay set for Flash running between 70 MHz and 185 MHz */
  626. #define FLASH_PROGRAMMING_DELAY_2 FLASH_ACR_WRHIGHFREQ_1 /*!< programming delay set for Flash running between 185 MHz and 225 MHz */
  627. #define FLASH_PROGRAMMING_DELAY_3 FLASH_ACR_WRHIGHFREQ /*!< programming delay set for Flash at startup */
  628. /**
  629. * @}
  630. */
  631. #if defined (FLASH_OTPBL_LOCKBL)
  632. /** @defgroup FLASHEx_OTP_Blocks FLASH OTP blocks
  633. * @{
  634. */
  635. #define FLASH_OTP_BLOCK_0 0x00000001U /*!< OTP Block0 */
  636. #define FLASH_OTP_BLOCK_1 0x00000002U /*!< OTP Block1 */
  637. #define FLASH_OTP_BLOCK_2 0x00000004U /*!< OTP Block2 */
  638. #define FLASH_OTP_BLOCK_3 0x00000008U /*!< OTP Block3 */
  639. #define FLASH_OTP_BLOCK_4 0x00000010U /*!< OTP Block4 */
  640. #define FLASH_OTP_BLOCK_5 0x00000020U /*!< OTP Block5 */
  641. #define FLASH_OTP_BLOCK_6 0x00000040U /*!< OTP Block6 */
  642. #define FLASH_OTP_BLOCK_7 0x00000080U /*!< OTP Block7 */
  643. #define FLASH_OTP_BLOCK_8 0x00000100U /*!< OTP Block8 */
  644. #define FLASH_OTP_BLOCK_9 0x00000200U /*!< OTP Block9 */
  645. #define FLASH_OTP_BLOCK_10 0x00000400U /*!< OTP Block10 */
  646. #define FLASH_OTP_BLOCK_11 0x00000800U /*!< OTP Block11 */
  647. #define FLASH_OTP_BLOCK_12 0x00001000U /*!< OTP Block12 */
  648. #define FLASH_OTP_BLOCK_13 0x00002000U /*!< OTP Block13 */
  649. #define FLASH_OTP_BLOCK_14 0x00004000U /*!< OTP Block14 */
  650. #define FLASH_OTP_BLOCK_15 0x00008000U /*!< OTP Block15 */
  651. #define FLASH_OTP_BLOCK_ALL 0x0000FFFFU /*!< OTP All Blocks */
  652. /**
  653. * @}
  654. */
  655. #endif /* FLASH_OTPBL_LOCKBL */
  656. /* Exported macro ------------------------------------------------------------*/
  657. /** @defgroup FLASHEx_Exported_Macros FLASH Exported Macros
  658. * @{
  659. */
  660. /**
  661. * @brief Calculate the FLASH Boot Base Address (BOOT_ADD0 or BOOT_ADD1)
  662. * @note Returned value BOOT_ADDx[15:0] corresponds to boot address [29:14].
  663. * @param __ADDRESS__: FLASH Boot Address (in the range 0x0000 0000 to 0x2004 FFFF with a granularity of 16KB)
  664. * @retval The FLASH Boot Base Address
  665. */
  666. #define __HAL_FLASH_CALC_BOOT_BASE_ADR(__ADDRESS__) ((__ADDRESS__) >> 14U)
  667. /**
  668. * @}
  669. */
  670. #if defined (FLASH_CR_PSIZE)
  671. /**
  672. * @brief Set the FLASH Program/Erase parallelism.
  673. * @param __PSIZE__ FLASH Program/Erase parallelism
  674. * This parameter can be a value of @ref FLASH_Program_Parallelism
  675. * @param __BANK__: Flash bank (FLASH_BANK_1 or FLASH_BANK_2)
  676. * @retval none
  677. */
  678. #if defined (DUAL_BANK)
  679. #define __HAL_FLASH_SET_PSIZE(__PSIZE__, __BANK__) (((__BANK__) == FLASH_BANK_1) ? \
  680. MODIFY_REG(FLASH->CR1, FLASH_CR_PSIZE, (__PSIZE__)) : \
  681. MODIFY_REG(FLASH->CR2, FLASH_CR_PSIZE, (__PSIZE__)))
  682. #else
  683. #define __HAL_FLASH_SET_PSIZE(__PSIZE__, __BANK__) MODIFY_REG(FLASH->CR1, FLASH_CR_PSIZE, (__PSIZE__))
  684. #endif /* DUAL_BANK */
  685. /**
  686. * @brief Get the FLASH Program/Erase parallelism.
  687. * @param __BANK__ Flash bank (FLASH_BANK_1 or FLASH_BANK_2)
  688. * @retval FLASH Program/Erase parallelism
  689. * This return value can be a value of @ref FLASH_Program_Parallelism
  690. */
  691. #if defined (DUAL_BANK)
  692. #define __HAL_FLASH_GET_PSIZE(__BANK__) (((__BANK__) == FLASH_BANK_1) ? \
  693. READ_BIT((FLASH->CR1), FLASH_CR_PSIZE) : \
  694. READ_BIT((FLASH->CR2), FLASH_CR_PSIZE))
  695. #else
  696. #define __HAL_FLASH_GET_PSIZE(__BANK__) READ_BIT((FLASH->CR1), FLASH_CR_PSIZE)
  697. #endif /* DUAL_BANK */
  698. #endif /* FLASH_CR_PSIZE */
  699. /**
  700. * @brief Set the FLASH Programming Delay.
  701. * @param __DELAY__ FLASH Programming Delay
  702. * This parameter can be a value of @ref FLASHEx_Programming_Delay
  703. * @retval none
  704. */
  705. #define __HAL_FLASH_SET_PROGRAM_DELAY(__DELAY__) MODIFY_REG(FLASH->ACR, FLASH_ACR_WRHIGHFREQ, (__DELAY__))
  706. /**
  707. * @brief Get the FLASH Programming Delay.
  708. * @retval FLASH Programming Delay
  709. * This return value can be a value of @ref FLASHEx_Programming_Delay
  710. */
  711. #define __HAL_FLASH_GET_PROGRAM_DELAY() READ_BIT(FLASH->ACR, FLASH_ACR_WRHIGHFREQ)
  712. /* Exported functions --------------------------------------------------------*/
  713. /** @addtogroup FLASHEx_Exported_Functions
  714. * @{
  715. */
  716. /** @addtogroup FLASHEx_Exported_Functions_Group1
  717. * @{
  718. */
  719. /* Extension Program operation functions *************************************/
  720. HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError);
  721. HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit);
  722. HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
  723. void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit);
  724. HAL_StatusTypeDef HAL_FLASHEx_Unlock_Bank1(void);
  725. HAL_StatusTypeDef HAL_FLASHEx_Lock_Bank1(void);
  726. #if defined (DUAL_BANK)
  727. HAL_StatusTypeDef HAL_FLASHEx_Unlock_Bank2(void);
  728. HAL_StatusTypeDef HAL_FLASHEx_Lock_Bank2(void);
  729. #endif /* DUAL_BANK */
  730. HAL_StatusTypeDef HAL_FLASHEx_ComputeCRC(FLASH_CRCInitTypeDef *pCRCInit, uint32_t *CRC_Result);
  731. /**
  732. * @}
  733. */
  734. /**
  735. * @}
  736. */
  737. /* Private types -------------------------------------------------------------*/
  738. /* Private variables ---------------------------------------------------------*/
  739. /* Private constants ---------------------------------------------------------*/
  740. /* Private macros ------------------------------------------------------------*/
  741. /** @defgroup FLASHEx_Private_Macros FLASHEx Private Macros
  742. * @{
  743. */
  744. /** @defgroup FLASHEx_IS_FLASH_Definitions FLASHEx Private macros to check input parameters
  745. * @{
  746. */
  747. #define IS_FLASH_TYPEERASE(VALUE) (((VALUE) == FLASH_TYPEERASE_SECTORS) || \
  748. ((VALUE) == FLASH_TYPEERASE_MASSERASE))
  749. #if defined (FLASH_CR_PSIZE)
  750. #define IS_VOLTAGERANGE(RANGE) (((RANGE) == FLASH_VOLTAGE_RANGE_1) || \
  751. ((RANGE) == FLASH_VOLTAGE_RANGE_2) || \
  752. ((RANGE) == FLASH_VOLTAGE_RANGE_3) || \
  753. ((RANGE) == FLASH_VOLTAGE_RANGE_4))
  754. #endif /* FLASH_CR_PSIZE */
  755. #define IS_WRPSTATE(VALUE) (((VALUE) == OB_WRPSTATE_DISABLE) || \
  756. ((VALUE) == OB_WRPSTATE_ENABLE))
  757. #define IS_OPTIONBYTE(VALUE) ((((VALUE) & OPTIONBYTE_ALL) != 0U) && \
  758. (((VALUE) & ~OPTIONBYTE_ALL) == 0U))
  759. #define IS_OB_BOOT_ADDRESS(ADDRESS) ((ADDRESS) <= 0x8013U)
  760. #define IS_OB_RDP_LEVEL(LEVEL) (((LEVEL) == OB_RDP_LEVEL_0) ||\
  761. ((LEVEL) == OB_RDP_LEVEL_1) ||\
  762. ((LEVEL) == OB_RDP_LEVEL_2))
  763. #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
  764. #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NO_RST) || ((SOURCE) == OB_STOP_RST))
  765. #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NO_RST) || ((SOURCE) == OB_STDBY_RST))
  766. #define IS_OB_IWDG_STOP_FREEZE(FREEZE) (((FREEZE) == OB_IWDG_STOP_FREEZE) || ((FREEZE) == OB_IWDG_STOP_ACTIVE))
  767. #define IS_OB_IWDG_STDBY_FREEZE(FREEZE) (((FREEZE) == OB_IWDG_STDBY_FREEZE) || ((FREEZE) == OB_IWDG_STDBY_ACTIVE))
  768. #define IS_OB_BOR_LEVEL(LEVEL) (((LEVEL) == OB_BOR_LEVEL0) || ((LEVEL) == OB_BOR_LEVEL1) || \
  769. ((LEVEL) == OB_BOR_LEVEL2) || ((LEVEL) == OB_BOR_LEVEL3))
  770. #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_LATENCY_0) || \
  771. ((LATENCY) == FLASH_LATENCY_1) || \
  772. ((LATENCY) == FLASH_LATENCY_2) || \
  773. ((LATENCY) == FLASH_LATENCY_3) || \
  774. ((LATENCY) == FLASH_LATENCY_4) || \
  775. ((LATENCY) == FLASH_LATENCY_5) || \
  776. ((LATENCY) == FLASH_LATENCY_6) || \
  777. ((LATENCY) == FLASH_LATENCY_7) || \
  778. ((LATENCY) == FLASH_LATENCY_8) || \
  779. ((LATENCY) == FLASH_LATENCY_9) || \
  780. ((LATENCY) == FLASH_LATENCY_10) || \
  781. ((LATENCY) == FLASH_LATENCY_11) || \
  782. ((LATENCY) == FLASH_LATENCY_12) || \
  783. ((LATENCY) == FLASH_LATENCY_13) || \
  784. ((LATENCY) == FLASH_LATENCY_14) || \
  785. ((LATENCY) == FLASH_LATENCY_15))
  786. #define IS_FLASH_SECTOR(SECTOR) ((SECTOR) < FLASH_SECTOR_TOTAL)
  787. #if (FLASH_SECTOR_TOTAL == 8U)
  788. #define IS_OB_WRP_SECTOR(SECTOR) ((((SECTOR) & 0xFFFFFF00U) == 0x00000000U) && ((SECTOR) != 0x00000000U))
  789. #else
  790. #define IS_OB_WRP_SECTOR(SECTOR) ((SECTOR) != 0x00000000U)
  791. #endif /* FLASH_SECTOR_TOTAL == 8U */
  792. #define IS_OB_PCROP_RDP(CONFIG) (((CONFIG) == OB_PCROP_RDP_NOT_ERASE) || \
  793. ((CONFIG) == OB_PCROP_RDP_ERASE))
  794. #define IS_OB_SECURE_RDP(CONFIG) (((CONFIG) == OB_SECURE_RDP_NOT_ERASE) || \
  795. ((CONFIG) == OB_SECURE_RDP_ERASE))
  796. #if defined (DUAL_BANK)
  797. #define IS_OB_USER_SWAP_BANK(VALUE) (((VALUE) == OB_SWAP_BANK_DISABLE) || ((VALUE) == OB_SWAP_BANK_ENABLE))
  798. #endif /* DUAL_BANK */
  799. #define IS_OB_USER_IOHSLV(VALUE) (((VALUE) == OB_IOHSLV_DISABLE) || ((VALUE) == OB_IOHSLV_ENABLE))
  800. #if defined (FLASH_OPTSR_VDDMMC_HSLV)
  801. #define IS_OB_USER_VDDMMC_HSLV(VALUE) (((VALUE) == OB_VDDMMC_HSLV_DISABLE) || ((VALUE) == OB_VDDMMC_HSLV_ENABLE))
  802. #endif /* FLASH_OPTSR_VDDMMC_HSLV */
  803. #define IS_OB_IWDG1_SOURCE(SOURCE) (((SOURCE) == OB_IWDG1_SW) || ((SOURCE) == OB_IWDG1_HW))
  804. #if defined (DUAL_CORE)
  805. #define IS_OB_IWDG2_SOURCE(SOURCE) (((SOURCE) == OB_IWDG2_SW) || ((SOURCE) == OB_IWDG2_HW))
  806. #endif /* DUAL_CORE */
  807. #define IS_OB_STOP_D1_RESET(VALUE) (((VALUE) == OB_STOP_NO_RST_D1) || ((VALUE) == OB_STOP_RST_D1))
  808. #define IS_OB_STDBY_D1_RESET(VALUE) (((VALUE) == OB_STDBY_NO_RST_D1) || ((VALUE) == OB_STDBY_RST_D1))
  809. #define IS_OB_USER_IWDG_STOP(VALUE) (((VALUE) == OB_IWDG_STOP_FREEZE) || ((VALUE) == OB_IWDG_STOP_ACTIVE))
  810. #define IS_OB_USER_IWDG_STDBY(VALUE) (((VALUE) == OB_IWDG_STDBY_FREEZE) || ((VALUE) == OB_IWDG_STDBY_ACTIVE))
  811. #define IS_OB_USER_ST_RAM_SIZE(VALUE) (((VALUE) == OB_ST_RAM_SIZE_2KB) || ((VALUE) == OB_ST_RAM_SIZE_4KB) || \
  812. ((VALUE) == OB_ST_RAM_SIZE_8KB) || ((VALUE) == OB_ST_RAM_SIZE_16KB))
  813. #define IS_OB_USER_SECURITY(VALUE) (((VALUE) == OB_SECURITY_ENABLE) || ((VALUE) == OB_SECURITY_DISABLE))
  814. #if defined (DUAL_CORE)
  815. #define IS_OB_USER_BCM4(VALUE) (((VALUE) == OB_BCM4_DISABLE) || ((VALUE) == OB_BCM4_ENABLE))
  816. #define IS_OB_USER_BCM7(VALUE) (((VALUE) == OB_BCM7_DISABLE) || ((VALUE) == OB_BCM7_ENABLE))
  817. #endif /* DUAL_CORE */
  818. #if defined (FLASH_OPTSR_NRST_STOP_D2)
  819. #define IS_OB_STOP_D2_RESET(VALUE) (((VALUE) == OB_STOP_NO_RST_D2) || ((VALUE) == OB_STOP_RST_D2))
  820. #define IS_OB_STDBY_D2_RESET(VALUE) (((VALUE) == OB_STDBY_NO_RST_D2) || ((VALUE) == OB_STDBY_RST_D2))
  821. #endif /* FLASH_OPTSR_NRST_STOP_D2 */
  822. #if defined (FLASH_OPTSR2_TCM_AXI_SHARED)
  823. #define IS_OB_USER_TCM_AXI_SHARED(VALUE) (((VALUE) == OB_TCM_AXI_SHARED_ITCM64KB) || ((VALUE) == OB_TCM_AXI_SHARED_ITCM128KB) || \
  824. ((VALUE) == OB_TCM_AXI_SHARED_ITCM192KB) || ((VALUE) == OB_TCM_AXI_SHARED_ITCM256KB))
  825. #endif /* FLASH_OPTSR2_TCM_AXI_SHARED */
  826. #if defined (FLASH_OPTSR2_CPUFREQ_BOOST)
  827. #define IS_OB_USER_CPUFREQ_BOOST(VALUE) (((VALUE) == OB_CPUFREQ_BOOST_DISABLE) || ((VALUE) == OB_CPUFREQ_BOOST_ENABLE))
  828. #endif /* FLASH_OPTSR2_CPUFREQ_BOOST */
  829. #define IS_OB_USER_TYPE(TYPE) ((((TYPE) & OB_USER_ALL) != 0U) && \
  830. (((TYPE) & ~OB_USER_ALL) == 0U))
  831. #define IS_OB_BOOT_ADD_OPTION(VALUE) (((VALUE) == OB_BOOT_ADD0) || \
  832. ((VALUE) == OB_BOOT_ADD1) || \
  833. ((VALUE) == OB_BOOT_ADD_BOTH))
  834. #define IS_FLASH_TYPECRC(VALUE) (((VALUE) == FLASH_CRC_ADDR) || \
  835. ((VALUE) == FLASH_CRC_SECTORS) || \
  836. ((VALUE) == FLASH_CRC_BANK))
  837. #if defined (FLASH_OTPBL_LOCKBL)
  838. #define IS_OTP_BLOCK(VALUE) ((((VALUE) & 0xFFFF0000U) == 0x00000000U) && ((VALUE) != 0x00000000U))
  839. #endif /* FLASH_OTPBL_LOCKBL */
  840. /**
  841. * @}
  842. */
  843. /**
  844. * @}
  845. */
  846. /* Private functions ---------------------------------------------------------*/
  847. /** @defgroup FLASHEx_Private_Functions FLASHEx Private Functions
  848. * @{
  849. */
  850. void FLASH_Erase_Sector(uint32_t Sector, uint32_t Banks, uint32_t VoltageRange);
  851. /**
  852. * @}
  853. */
  854. /**
  855. * @}
  856. */
  857. /**
  858. * @}
  859. */
  860. /**
  861. * @}
  862. */
  863. #ifdef __cplusplus
  864. }
  865. #endif
  866. #endif /* STM32H7xx_HAL_FLASH_EX_H */