You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

651 lines
35 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_flash.h
  4. * @author MCD Application Team
  5. * @brief Header file of FLASH HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32H7xx_HAL_FLASH_H
  21. #define STM32H7xx_HAL_FLASH_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32h7xx_hal_def.h"
  27. /** @addtogroup STM32H7xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup FLASH
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup FLASH_Exported_Types FLASH Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief FLASH Procedure structure definition
  39. */
  40. typedef enum
  41. {
  42. FLASH_PROC_NONE = 0U,
  43. FLASH_PROC_SECTERASE_BANK1,
  44. FLASH_PROC_MASSERASE_BANK1,
  45. FLASH_PROC_PROGRAM_BANK1,
  46. FLASH_PROC_SECTERASE_BANK2,
  47. FLASH_PROC_MASSERASE_BANK2,
  48. FLASH_PROC_PROGRAM_BANK2,
  49. FLASH_PROC_ALLBANK_MASSERASE
  50. } FLASH_ProcedureTypeDef;
  51. /**
  52. * @brief FLASH handle Structure definition
  53. */
  54. typedef struct
  55. {
  56. __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
  57. __IO uint32_t NbSectorsToErase; /*!< Internal variable to save the remaining sectors to erase in IT context */
  58. __IO uint32_t VoltageForErase; /*!< Internal variable to provide voltage range selected by user in IT context */
  59. __IO uint32_t Sector; /*!< Internal variable to define the current sector which is erasing */
  60. __IO uint32_t Address; /*!< Internal variable to save address selected for program */
  61. HAL_LockTypeDef Lock; /*!< FLASH locking object */
  62. __IO uint32_t ErrorCode; /*!< FLASH error code */
  63. }FLASH_ProcessTypeDef;
  64. /**
  65. * @}
  66. */
  67. /* Exported constants --------------------------------------------------------*/
  68. /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
  69. * @{
  70. */
  71. /** @defgroup FLASH_Error_Code FLASH Error Code
  72. * @brief FLASH Error Code
  73. * @{
  74. */
  75. #define HAL_FLASH_ERROR_NONE 0x00000000U /*!< No error */
  76. #define HAL_FLASH_ERROR_WRP FLASH_FLAG_WRPERR /*!< Write Protection Error */
  77. #define HAL_FLASH_ERROR_PGS FLASH_FLAG_PGSERR /*!< Program Sequence Error */
  78. #define HAL_FLASH_ERROR_STRB FLASH_FLAG_STRBERR /*!< Strobe Error */
  79. #define HAL_FLASH_ERROR_INC FLASH_FLAG_INCERR /*!< Inconsistency Error */
  80. #define HAL_FLASH_ERROR_OPE FLASH_FLAG_OPERR /*!< Operation Error */
  81. #define HAL_FLASH_ERROR_RDP FLASH_FLAG_RDPERR /*!< Read Protection Error */
  82. #define HAL_FLASH_ERROR_RDS FLASH_FLAG_RDSERR /*!< Read Secured Error */
  83. #define HAL_FLASH_ERROR_SNECC FLASH_FLAG_SNECCERR /*!< ECC Single Correction Error */
  84. #define HAL_FLASH_ERROR_DBECC FLASH_FLAG_DBECCERR /*!< ECC Double Detection Error */
  85. #define HAL_FLASH_ERROR_CRCRD FLASH_FLAG_CRCRDERR /*!< CRC Read Error */
  86. #define HAL_FLASH_ERROR_WRP_BANK1 FLASH_FLAG_WRPERR_BANK1 /*!< Write Protection Error on Bank 1 */
  87. #define HAL_FLASH_ERROR_PGS_BANK1 FLASH_FLAG_PGSERR_BANK1 /*!< Program Sequence Error on Bank 1 */
  88. #define HAL_FLASH_ERROR_STRB_BANK1 FLASH_FLAG_STRBERR_BANK1 /*!< Strobe Error on Bank 1 */
  89. #define HAL_FLASH_ERROR_INC_BANK1 FLASH_FLAG_INCERR_BANK1 /*!< Inconsistency Error on Bank 1 */
  90. #define HAL_FLASH_ERROR_OPE_BANK1 FLASH_FLAG_OPERR_BANK1 /*!< Operation Error on Bank 1 */
  91. #define HAL_FLASH_ERROR_RDP_BANK1 FLASH_FLAG_RDPERR_BANK1 /*!< Read Protection Error on Bank 1 */
  92. #define HAL_FLASH_ERROR_RDS_BANK1 FLASH_FLAG_RDSERR_BANK1 /*!< Read Secured Error on Bank 1 */
  93. #define HAL_FLASH_ERROR_SNECC_BANK1 FLASH_FLAG_SNECCERR_BANK1 /*!< ECC Single Correction Error on Bank 1 */
  94. #define HAL_FLASH_ERROR_DBECC_BANK1 FLASH_FLAG_DBECCERR_BANK1 /*!< ECC Double Detection Error on Bank 1 */
  95. #define HAL_FLASH_ERROR_CRCRD_BANK1 FLASH_FLAG_CRCRDERR_BANK1 /*!< CRC Read Error on Bank1 */
  96. #define HAL_FLASH_ERROR_WRP_BANK2 FLASH_FLAG_WRPERR_BANK2 /*!< Write Protection Error on Bank 2 */
  97. #define HAL_FLASH_ERROR_PGS_BANK2 FLASH_FLAG_PGSERR_BANK2 /*!< Program Sequence Error on Bank 2 */
  98. #define HAL_FLASH_ERROR_STRB_BANK2 FLASH_FLAG_STRBERR_BANK2 /*!< Strobe Error on Bank 2 */
  99. #define HAL_FLASH_ERROR_INC_BANK2 FLASH_FLAG_INCERR_BANK2 /*!< Inconsistency Error on Bank 2 */
  100. #define HAL_FLASH_ERROR_OPE_BANK2 FLASH_FLAG_OPERR_BANK2 /*!< Operation Error on Bank 2 */
  101. #define HAL_FLASH_ERROR_RDP_BANK2 FLASH_FLAG_RDPERR_BANK2 /*!< Read Protection Error on Bank 2 */
  102. #define HAL_FLASH_ERROR_RDS_BANK2 FLASH_FLAG_RDSERR_BANK2 /*!< Read Secured Error on Bank 2 */
  103. #define HAL_FLASH_ERROR_SNECC_BANK2 FLASH_FLAG_SNECCERR_BANK2 /*!< ECC Single Correction Error on Bank 2 */
  104. #define HAL_FLASH_ERROR_DBECC_BANK2 FLASH_FLAG_DBECCERR_BANK2 /*!< ECC Double Detection Error on Bank 2 */
  105. #define HAL_FLASH_ERROR_CRCRD_BANK2 FLASH_FLAG_CRCRDERR_BANK2 /*!< CRC Read Error on Bank2 */
  106. #define HAL_FLASH_ERROR_OB_CHANGE FLASH_OPTSR_OPTCHANGEERR /*!< Option Byte Change Error */
  107. /**
  108. * @}
  109. */
  110. /** @defgroup FLASH_Type_Program FLASH Type Program
  111. * @{
  112. */
  113. #define FLASH_TYPEPROGRAM_FLASHWORD 0x03U /*!< Program a flash word (256-bit) at a specified address */
  114. /**
  115. * @}
  116. */
  117. /** @defgroup FLASH_Flag_definition FLASH Flag definition
  118. * @brief Flag definition
  119. * @{
  120. */
  121. #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
  122. #define FLASH_FLAG_WDW FLASH_SR_WDW /*!< Waiting for Data to Write on flag */
  123. #define FLASH_FLAG_QW FLASH_SR_QW /*!< Write Waiting in Operation Queue on flag */
  124. #define FLASH_FLAG_CRC_BUSY FLASH_SR_CRC_BUSY /*!< CRC module is working on flag */
  125. #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< End Of Program on flag */
  126. #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< Write Protection Error on flag */
  127. #define FLASH_FLAG_PGSERR FLASH_SR_PGSERR /*!< Program Sequence Error on flag */
  128. #define FLASH_FLAG_STRBERR FLASH_SR_STRBERR /*!< strobe Error on flag */
  129. #define FLASH_FLAG_INCERR FLASH_SR_INCERR /*!< Inconsistency Error on flag */
  130. #define FLASH_FLAG_OPERR FLASH_SR_OPERR /*!< Operation Error on flag */
  131. #define FLASH_FLAG_RDPERR FLASH_SR_RDPERR /*!< Read Protection Error on flag */
  132. #define FLASH_FLAG_RDSERR FLASH_SR_RDSERR /*!< Read Secured Error on flag */
  133. #define FLASH_FLAG_SNECCERR FLASH_SR_SNECCERR /*!< Single ECC Error Correction on flag */
  134. #define FLASH_FLAG_DBECCERR FLASH_SR_DBECCERR /*!< Double Detection ECC Error on flag */
  135. #define FLASH_FLAG_CRCEND FLASH_SR_CRCEND /*!< CRC module completes on bank flag */
  136. #define FLASH_FLAG_CRCRDERR FLASH_SR_CRCRDERR /*!< CRC Read Error on bank flag */
  137. #define FLASH_FLAG_BSY_BANK1 FLASH_SR_BSY /*!< FLASH Bank 1 Busy flag */
  138. #define FLASH_FLAG_WBNE_BANK1 FLASH_SR_WBNE /*!< Waiting for Data to Write on Bank 1 flag */
  139. #define FLASH_FLAG_QW_BANK1 FLASH_SR_QW /*!< Write Waiting in Operation Queue on Bank 1 flag */
  140. #define FLASH_FLAG_CRC_BUSY_BANK1 FLASH_SR_CRC_BUSY /*!< CRC module is working on Bank 1 flag */
  141. #define FLASH_FLAG_EOP_BANK1 FLASH_SR_EOP /*!< End Of Program on Bank 1 flag */
  142. #define FLASH_FLAG_WRPERR_BANK1 FLASH_SR_WRPERR /*!< Write Protection Error on Bank 1 flag */
  143. #define FLASH_FLAG_PGSERR_BANK1 FLASH_SR_PGSERR /*!< Program Sequence Error on Bank 1 flag */
  144. #define FLASH_FLAG_STRBERR_BANK1 FLASH_SR_STRBERR /*!< strobe Error on Bank 1 flag */
  145. #define FLASH_FLAG_INCERR_BANK1 FLASH_SR_INCERR /*!< Inconsistency Error on Bank 1 flag */
  146. #define FLASH_FLAG_OPERR_BANK1 FLASH_SR_OPERR /*!< Operation Error on Bank 1 flag */
  147. #define FLASH_FLAG_RDPERR_BANK1 FLASH_SR_RDPERR /*!< Read Protection Error on Bank 1 flag */
  148. #define FLASH_FLAG_RDSERR_BANK1 FLASH_SR_RDSERR /*!< Read Secured Error on Bank 1 flag */
  149. #define FLASH_FLAG_SNECCERR_BANK1 FLASH_SR_SNECCERR /*!< Single ECC Error Correction on Bank 1 flag */
  150. #define FLASH_FLAG_DBECCERR_BANK1 FLASH_SR_DBECCERR /*!< Double Detection ECC Error on Bank 1 flag */
  151. #define FLASH_FLAG_CRCEND_BANK1 FLASH_SR_CRCEND /*!< CRC module completes on bank Bank 1 flag */
  152. #define FLASH_FLAG_CRCRDERR_BANK1 FLASH_SR_CRCRDERR /*!< CRC Read error on Bank 1 flag */
  153. #define FLASH_FLAG_ALL_ERRORS_BANK1 (FLASH_FLAG_WRPERR_BANK1 | FLASH_FLAG_PGSERR_BANK1 | \
  154. FLASH_FLAG_STRBERR_BANK1 | FLASH_FLAG_INCERR_BANK1 | \
  155. FLASH_FLAG_OPERR_BANK1 | FLASH_FLAG_RDPERR_BANK1 | \
  156. FLASH_FLAG_RDSERR_BANK1 | FLASH_FLAG_SNECCERR_BANK1 | \
  157. FLASH_FLAG_DBECCERR_BANK1 | FLASH_FLAG_CRCRDERR_BANK1)
  158. #define FLASH_FLAG_ALL_BANK1 (FLASH_FLAG_BSY_BANK1 | FLASH_FLAG_WBNE_BANK1 | \
  159. FLASH_FLAG_QW_BANK1 | FLASH_FLAG_CRC_BUSY_BANK1 | \
  160. FLASH_FLAG_EOP_BANK1 | FLASH_FLAG_CRCEND_BANK1 | \
  161. FLASH_FLAG_ALL_ERRORS_BANK1)
  162. #define FLASH_FLAG_BSY_BANK2 (FLASH_SR_BSY | 0x80000000U) /*!< FLASH Bank 2 Busy flag */
  163. #define FLASH_FLAG_WBNE_BANK2 (FLASH_SR_WBNE | 0x80000000U) /*!< Waiting for Data to Write on Bank 2 flag */
  164. #define FLASH_FLAG_QW_BANK2 (FLASH_SR_QW | 0x80000000U) /*!< Write Waiting in Operation Queue on Bank 2 flag */
  165. #define FLASH_FLAG_CRC_BUSY_BANK2 (FLASH_SR_CRC_BUSY | 0x80000000U) /*!< CRC module is working on Bank 2 flag */
  166. #define FLASH_FLAG_EOP_BANK2 (FLASH_SR_EOP | 0x80000000U) /*!< End Of Program on Bank 2 flag */
  167. #define FLASH_FLAG_WRPERR_BANK2 (FLASH_SR_WRPERR | 0x80000000U) /*!< Write Protection Error on Bank 2 flag */
  168. #define FLASH_FLAG_PGSERR_BANK2 (FLASH_SR_PGSERR | 0x80000000U) /*!< Program Sequence Error on Bank 2 flag */
  169. #define FLASH_FLAG_STRBERR_BANK2 (FLASH_SR_STRBERR | 0x80000000U) /*!< Strobe Error on Bank 2 flag */
  170. #define FLASH_FLAG_INCERR_BANK2 (FLASH_SR_INCERR | 0x80000000U) /*!< Inconsistency Error on Bank 2 flag */
  171. #define FLASH_FLAG_OPERR_BANK2 (FLASH_SR_OPERR | 0x80000000U) /*!< Operation Error on Bank 2 flag */
  172. #define FLASH_FLAG_RDPERR_BANK2 (FLASH_SR_RDPERR | 0x80000000U) /*!< Read Protection Error on Bank 2 flag */
  173. #define FLASH_FLAG_RDSERR_BANK2 (FLASH_SR_RDSERR | 0x80000000U) /*!< Read Secured Error on Bank 2 flag */
  174. #define FLASH_FLAG_SNECCERR_BANK2 (FLASH_SR_SNECCERR | 0x80000000U) /*!< Single ECC Error Correction on Bank 2 flag */
  175. #define FLASH_FLAG_DBECCERR_BANK2 (FLASH_SR_DBECCERR | 0x80000000U) /*!< Double Detection ECC Error on Bank 2 flag */
  176. #define FLASH_FLAG_CRCEND_BANK2 (FLASH_SR_CRCEND | 0x80000000U) /*!< CRC module completes on bank Bank 2 flag */
  177. #define FLASH_FLAG_CRCRDERR_BANK2 (FLASH_SR_CRCRDERR | 0x80000000U) /*!< CRC Read error on Bank 2 flag */
  178. #define FLASH_FLAG_ALL_ERRORS_BANK2 (FLASH_FLAG_WRPERR_BANK2 | FLASH_FLAG_PGSERR_BANK2 | \
  179. FLASH_FLAG_STRBERR_BANK2 | FLASH_FLAG_INCERR_BANK2 | \
  180. FLASH_FLAG_OPERR_BANK2 | FLASH_FLAG_RDPERR_BANK2 | \
  181. FLASH_FLAG_RDSERR_BANK2 | FLASH_FLAG_SNECCERR_BANK2 | \
  182. FLASH_FLAG_DBECCERR_BANK2 | FLASH_FLAG_CRCRDERR_BANK2)
  183. #define FLASH_FLAG_ALL_BANK2 (FLASH_FLAG_BSY_BANK2 | FLASH_FLAG_WBNE_BANK2 | \
  184. FLASH_FLAG_QW_BANK2 | FLASH_FLAG_CRC_BUSY_BANK2 | \
  185. FLASH_FLAG_EOP_BANK2 | FLASH_FLAG_CRCEND_BANK2 | \
  186. FLASH_FLAG_ALL_ERRORS_BANK2)
  187. /**
  188. * @}
  189. */
  190. /** @defgroup FLASH_Interrupt_definition FLASH Interrupt definition
  191. * @brief FLASH Interrupt definition
  192. * @{
  193. */
  194. #define FLASH_IT_EOP_BANK1 FLASH_CR_EOPIE /*!< End of FLASH Bank 1 Operation Interrupt source */
  195. #define FLASH_IT_WRPERR_BANK1 FLASH_CR_WRPERRIE /*!< Write Protection Error on Bank 1 Interrupt source */
  196. #define FLASH_IT_PGSERR_BANK1 FLASH_CR_PGSERRIE /*!< Program Sequence Error on Bank 1 Interrupt source */
  197. #define FLASH_IT_STRBERR_BANK1 FLASH_CR_STRBERRIE /*!< Strobe Error on Bank 1 Interrupt source */
  198. #define FLASH_IT_INCERR_BANK1 FLASH_CR_INCERRIE /*!< Inconsistency Error on Bank 1 Interrupt source */
  199. #define FLASH_IT_OPERR_BANK1 FLASH_CR_OPERRIE /*!< Operation Error on Bank 1 Interrupt source */
  200. #define FLASH_IT_RDPERR_BANK1 FLASH_CR_RDPERRIE /*!< Read protection Error on Bank 1 Interrupt source */
  201. #define FLASH_IT_RDSERR_BANK1 FLASH_CR_RDSERRIE /*!< Read Secured Error on Bank 1 Interrupt source */
  202. #define FLASH_IT_SNECCERR_BANK1 FLASH_CR_SNECCERRIE /*!< Single ECC Error Correction on Bank 1 Interrupt source */
  203. #define FLASH_IT_DBECCERR_BANK1 FLASH_CR_DBECCERRIE /*!< Double Detection ECC Error on Bank 1 Interrupt source */
  204. #define FLASH_IT_CRCEND_BANK1 FLASH_CR_CRCENDIE /*!< CRC End on Bank 1 Interrupt source */
  205. #define FLASH_IT_CRCRDERR_BANK1 FLASH_CR_CRCRDERRIE /*!< CRC Read error on Bank 1 Interrupt source */
  206. #define FLASH_IT_ALL_BANK1 (FLASH_IT_EOP_BANK1 | FLASH_IT_WRPERR_BANK1 | \
  207. FLASH_IT_PGSERR_BANK1 | FLASH_IT_STRBERR_BANK1 | \
  208. FLASH_IT_INCERR_BANK1 | FLASH_IT_OPERR_BANK1 | \
  209. FLASH_IT_RDPERR_BANK1 | FLASH_IT_RDSERR_BANK1 | \
  210. FLASH_IT_SNECCERR_BANK1 | FLASH_IT_DBECCERR_BANK1 | \
  211. FLASH_IT_CRCEND_BANK1 | FLASH_IT_CRCRDERR_BANK1)
  212. #define FLASH_IT_EOP_BANK2 (FLASH_CR_EOPIE | 0x80000000U) /*!< End of FLASH Bank 2 Operation Interrupt source */
  213. #define FLASH_IT_WRPERR_BANK2 (FLASH_CR_WRPERRIE | 0x80000000U) /*!< Write Protection Error on Bank 2 Interrupt source */
  214. #define FLASH_IT_PGSERR_BANK2 (FLASH_CR_PGSERRIE | 0x80000000U) /*!< Program Sequence Error on Bank 2 Interrupt source */
  215. #define FLASH_IT_STRBERR_BANK2 (FLASH_CR_STRBERRIE | 0x80000000U) /*!< Strobe Error on Bank 2 Interrupt source */
  216. #define FLASH_IT_INCERR_BANK2 (FLASH_CR_INCERRIE | 0x80000000U) /*!< Inconsistency Error on Bank 2 Interrupt source */
  217. #define FLASH_IT_OPERR_BANK2 (FLASH_CR_OPERRIE | 0x80000000U) /*!< Operation Error on Bank 2 Interrupt source */
  218. #define FLASH_IT_RDPERR_BANK2 (FLASH_CR_RDPERRIE | 0x80000000U) /*!< Read protection Error on Bank 2 Interrupt source */
  219. #define FLASH_IT_RDSERR_BANK2 (FLASH_CR_RDSERRIE | 0x80000000U) /*!< Read Secured Error on Bank 2 Interrupt source */
  220. #define FLASH_IT_SNECCERR_BANK2 (FLASH_CR_SNECCERRIE | 0x80000000U) /*!< Single ECC Error Correction on Bank 2 Interrupt source */
  221. #define FLASH_IT_DBECCERR_BANK2 (FLASH_CR_DBECCERRIE | 0x80000000U) /*!< Double Detection ECC Error on Bank 2 Interrupt source */
  222. #define FLASH_IT_CRCEND_BANK2 (FLASH_CR_CRCENDIE | 0x80000000U) /*!< CRC End on Bank 2 Interrupt source */
  223. #define FLASH_IT_CRCRDERR_BANK2 (FLASH_CR_CRCRDERRIE | 0x80000000U) /*!< CRC Read Error on Bank 2 Interrupt source */
  224. #define FLASH_IT_ALL_BANK2 (FLASH_IT_EOP_BANK2 | FLASH_IT_WRPERR_BANK2 | \
  225. FLASH_IT_PGSERR_BANK2 | FLASH_IT_STRBERR_BANK2 | \
  226. FLASH_IT_INCERR_BANK2 | FLASH_IT_OPERR_BANK2 | \
  227. FLASH_IT_RDPERR_BANK2 | FLASH_IT_RDSERR_BANK2 | \
  228. FLASH_IT_SNECCERR_BANK2 | FLASH_IT_DBECCERR_BANK2 | \
  229. FLASH_IT_CRCEND_BANK2 | FLASH_IT_CRCRDERR_BANK2)
  230. /**
  231. * @}
  232. */
  233. /** @defgroup FLASH_Program_Parallelism FLASH Program Parallelism
  234. * @{
  235. */
  236. #define FLASH_PSIZE_BYTE 0x00000000U /*!< Flash program/erase by 8 bits */
  237. #define FLASH_PSIZE_HALF_WORD FLASH_CR_PSIZE_0 /*!< Flash program/erase by 16 bits */
  238. #define FLASH_PSIZE_WORD FLASH_CR_PSIZE_1 /*!< Flash program/erase by 32 bits */
  239. #define FLASH_PSIZE_DOUBLE_WORD FLASH_CR_PSIZE /*!< Flash program/erase by 64 bits */
  240. /**
  241. * @}
  242. */
  243. /** @defgroup FLASH_Keys FLASH Keys
  244. * @{
  245. */
  246. #define FLASH_KEY1 0x45670123U
  247. #define FLASH_KEY2 0xCDEF89ABU
  248. #define FLASH_OPT_KEY1 0x08192A3BU
  249. #define FLASH_OPT_KEY2 0x4C5D6E7FU
  250. /**
  251. * @}
  252. */
  253. /** @defgroup FLASH_Sectors FLASH Sectors
  254. * @{
  255. */
  256. #define FLASH_SECTOR_0 0U /*!< Sector Number 0 */
  257. #define FLASH_SECTOR_1 1U /*!< Sector Number 1 */
  258. #define FLASH_SECTOR_2 2U /*!< Sector Number 2 */
  259. #define FLASH_SECTOR_3 3U /*!< Sector Number 3 */
  260. #define FLASH_SECTOR_4 4U /*!< Sector Number 4 */
  261. #define FLASH_SECTOR_5 5U /*!< Sector Number 5 */
  262. #define FLASH_SECTOR_6 6U /*!< Sector Number 6 */
  263. #define FLASH_SECTOR_7 7U /*!< Sector Number 7 */
  264. /**
  265. * @}
  266. */
  267. /**
  268. * @}
  269. */
  270. /* Exported macro ------------------------------------------------------------*/
  271. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  272. * @{
  273. */
  274. /**
  275. * @brief Set the FLASH Latency.
  276. * @param __LATENCY__: FLASH Latency
  277. * The value of this parameter depend on device used within the same series
  278. * @retval none
  279. */
  280. #define __HAL_FLASH_SET_LATENCY(__LATENCY__) \
  281. MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(__LATENCY__))
  282. /**
  283. * @brief Get the FLASH Latency.
  284. * @retval FLASH Latency
  285. * The value of this parameter depend on device used within the same series
  286. */
  287. #define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
  288. /**
  289. * @brief Enable the specified FLASH interrupt.
  290. * @param __INTERRUPT__ : FLASH interrupt
  291. * In case of Bank 1 This parameter can be any combination of the following values:
  292. * @arg FLASH_IT_EOP_BANK1 : End of FLASH Bank 1 Operation Interrupt source
  293. * @arg FLASH_IT_WRPERR_BANK1 : Write Protection Error on Bank 1 Interrupt source
  294. * @arg FLASH_IT_PGSERR_BANK1 : Program Sequence Error on Bank 1 Interrupt source
  295. * @arg FLASH_IT_STRBERR_BANK1 : Strobe Error on Bank 1 Interrupt source
  296. * @arg FLASH_IT_INCERR_BANK1 : Inconsistency Error on Bank 1 Interrupt source
  297. * @arg FLASH_IT_OPERR_BANK1 : Operation Error on Bank 1 Interrupt source
  298. * @arg FLASH_IT_RDPERR_BANK1 : Read protection Error on Bank 1 Interrupt source
  299. * @arg FLASH_IT_RDSERR_BANK1 : Read secure Error on Bank 1 Interrupt source
  300. * @arg FLASH_IT_SNECCERR_BANK1 : Single ECC Error Correction on Bank 1 Interrupt source
  301. * @arg FLASH_IT_DBECCERR_BANK1 : Double Detection ECC Error on Bank 1 Interrupt source
  302. * @arg FLASH_IT_CRCEND_BANK1 : CRC End on Bank 1 Interrupt source
  303. * @arg FLASH_IT_CRCRDERR_BANK1 : CRC Read error on Bank 1 Interrupt source
  304. * In case of Bank 2, this parameter can be any combination of the following values: *
  305. * @arg FLASH_IT_EOP_BANK2 : End of FLASH Bank 2 Operation Interrupt source
  306. * @arg FLASH_IT_WRPERR_BANK2 : Write Protection Error on Bank 2 Interrupt source
  307. * @arg FLASH_IT_PGSERR_BANK2 : Program Sequence Error on Bank 2 Interrupt source
  308. * @arg FLASH_IT_STRBERR_BANK2 : Strobe Error on Bank 2 Interrupt source
  309. * @arg FLASH_IT_INCERR_BANK2 : Inconsistency Error on Bank 2 Interrupt source
  310. * @arg FLASH_IT_OPERR_BANK2 : Operation Error on Bank 2 Interrupt source
  311. * @arg FLASH_IT_RDPERR_BANK2 : Read protection Error on Bank 2 Interrupt source
  312. * @arg FLASH_IT_RDSERR_BANK2 : Read secure Error on Bank 2 Interrupt source
  313. * @arg FLASH_IT_SNECCERR_BANK2 : Single ECC Error Correction on Bank 2 Interrupt source
  314. * @arg FLASH_IT_DBECCERR_BANK2 : Double Detection ECC Error on Bank 2 Interrupt source
  315. * @arg FLASH_IT_CRCEND_BANK2 : CRC End on Bank 2 Interrupt source
  316. * @arg FLASH_IT_CRCRDERR_BANK2 : CRC Read error on Bank 2 Interrupt source
  317. * @retval none
  318. */
  319. #define __HAL_FLASH_ENABLE_IT_BANK1(__INTERRUPT__) (FLASH->CR1 |= (__INTERRUPT__))
  320. #define __HAL_FLASH_ENABLE_IT_BANK2(__INTERRUPT__) (FLASH->CR2 |= ((__INTERRUPT__) & 0x7FFFFFFFU))
  321. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) (IS_FLASH_IT_BANK1(__INTERRUPT__) ? \
  322. __HAL_FLASH_ENABLE_IT_BANK1(__INTERRUPT__) : \
  323. __HAL_FLASH_ENABLE_IT_BANK2(__INTERRUPT__))
  324. /**
  325. * @brief Disable the specified FLASH interrupt.
  326. * @param __INTERRUPT__ : FLASH interrupt
  327. * In case of Bank 1 This parameter can be any combination of the following values:
  328. * @arg FLASH_IT_EOP_BANK1 : End of FLASH Bank 1 Operation Interrupt source
  329. * @arg FLASH_IT_WRPERR_BANK1 : Write Protection Error on Bank 1 Interrupt source
  330. * @arg FLASH_IT_PGSERR_BANK1 : Program Sequence Error on Bank 1 Interrupt source
  331. * @arg FLASH_IT_STRBERR_BANK1 : Strobe Error on Bank 1 Interrupt source
  332. * @arg FLASH_IT_INCERR_BANK1 : Inconsistency Error on Bank 1 Interrupt source
  333. * @arg FLASH_IT_OPERR_BANK1 : Operation Error on Bank 1 Interrupt source
  334. * @arg FLASH_IT_RDPERR_BANK1 : Read protection Error on Bank 1 Interrupt source
  335. * @arg FLASH_IT_RDSERR_BANK1 : Read secure Error on Bank 1 Interrupt source
  336. * @arg FLASH_IT_SNECCERR_BANK1 : Single ECC Error Correction on Bank 1 Interrupt source
  337. * @arg FLASH_IT_DBECCERR_BANK1 : Double Detection ECC Error on Bank 1 Interrupt source
  338. * @arg FLASH_IT_CRCEND_BANK1 : CRC End on Bank 1 Interrupt source
  339. * @arg FLASH_IT_CRCRDERR_BANK1 : CRC Read error on Bank 1 Interrupt source
  340. * In case of Bank 2, this parameter can be any combination of the following values: *
  341. * @arg FLASH_IT_EOP_BANK2 : End of FLASH Bank 2 Operation Interrupt source
  342. * @arg FLASH_IT_WRPERR_BANK2 : Write Protection Error on Bank 2 Interrupt source
  343. * @arg FLASH_IT_PGSERR_BANK2 : Program Sequence Error on Bank 2 Interrupt source
  344. * @arg FLASH_IT_STRBERR_BANK2 : Strobe Error on Bank 2 Interrupt source
  345. * @arg FLASH_IT_INCERR_BANK2 : Inconsistency Error on Bank 2 Interrupt source
  346. * @arg FLASH_IT_OPERR_BANK2 : Operation Error on Bank 2 Interrupt source
  347. * @arg FLASH_IT_RDPERR_BANK2 : Read protection Error on Bank 2 Interrupt source
  348. * @arg FLASH_IT_RDSERR_BANK2 : Read secure Error on Bank 2 Interrupt source
  349. * @arg FLASH_IT_SNECCERR_BANK2 : Single ECC Error Correction on Bank 2 Interrupt source
  350. * @arg FLASH_IT_DBECCERR_BANK2 : Double Detection ECC Error on Bank 2 Interrupt source
  351. * @arg FLASH_IT_CRCEND_BANK2 : CRC End on Bank 2 Interrupt source
  352. * @arg FLASH_IT_CRCRDERR_BANK2 : CRC Read error on Bank 2 Interrupt source
  353. * @retval none
  354. */
  355. #define __HAL_FLASH_DISABLE_IT_BANK1(__INTERRUPT__) (FLASH->CR1 &= ~(uint32_t)(__INTERRUPT__))
  356. #define __HAL_FLASH_DISABLE_IT_BANK2(__INTERRUPT__) (FLASH->CR2 &= ~(uint32_t)((__INTERRUPT__) & 0x7FFFFFFFU))
  357. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) (IS_FLASH_IT_BANK1(__INTERRUPT__) ? \
  358. __HAL_FLASH_DISABLE_IT_BANK1(__INTERRUPT__) : \
  359. __HAL_FLASH_DISABLE_IT_BANK2(__INTERRUPT__))
  360. /**
  361. * @brief Checks whether the specified FLASH flag is set or not.
  362. * @param __FLAG__: specifies the FLASH flag to check.
  363. * In case of Bank 1 This parameter can be any combination of the following values :
  364. * @arg FLASH_FLAG_BSY_BANK1 : FLASH Bank 1 Busy flag
  365. * @arg FLASH_FLAG_WBNE_BANK1 : Waiting for Data to Write on Bank 1 flag
  366. * @arg FLASH_FLAG_QW_BANK1 : Write Waiting in Operation Queue on Bank 1 flag
  367. * @arg FLASH_FLAG_CRC_BUSY_BANK1 : CRC module is working on Bank 1 flag
  368. * @arg FLASH_FLAG_EOP_BANK1 : End Of Program on Bank 1 flag
  369. * @arg FLASH_FLAG_WRPERR_BANK1 : Write Protection Error on Bank 1 flag
  370. * @arg FLASH_FLAG_PGSERR_BANK1 : Program Sequence Error on Bank 1 flag
  371. * @arg FLASH_FLAG_STRBER_BANK1 : Program Alignment Error on Bank 1 flag
  372. * @arg FLASH_FLAG_INCERR_BANK1 : Inconsistency Error on Bank 1 flag
  373. * @arg FLASH_FLAG_OPERR_BANK1 : Operation Error on Bank 1 flag
  374. * @arg FLASH_FLAG_RDPERR_BANK1 : Read Protection Error on Bank 1 flag
  375. * @arg FLASH_FLAG_RDSERR_BANK1 : Read secure Error on Bank 1 flag
  376. * @arg FLASH_FLAG_SNECCE_BANK1 : Single ECC Error Correction on Bank 1 flag
  377. * @arg FLASH_FLAG_DBECCE_BANK1 : Double Detection ECC Error on Bank 1 flag
  378. * @arg FLASH_FLAG_CRCEND_BANK1 : CRC End on Bank 1 flag
  379. * @arg FLASH_FLAG_CRCRDERR_BANK1 : CRC Read error on Bank 1 flag
  380. *
  381. * In case of Bank 2 This parameter can be any combination of the following values :
  382. * @arg FLASH_FLAG_BSY_BANK2 : FLASH Bank 2 Busy flag
  383. * @arg FLASH_FLAG_WBNE_BANK2 : Waiting for Data to Write on Bank 2 flag
  384. * @arg FLASH_FLAG_QW_BANK2 : Write Waiting in Operation Queue on Bank 2 flag
  385. * @arg FLASH_FLAG_CRC_BUSY_BANK2 : CRC module is working on Bank 2 flag
  386. * @arg FLASH_FLAG_EOP_BANK2 : End Of Program on Bank 2 flag
  387. * @arg FLASH_FLAG_WRPERR_BANK2 : Write Protection Error on Bank 2 flag
  388. * @arg FLASH_FLAG_PGSERR_BANK2 : Program Sequence Error on Bank 2 flag
  389. * @arg FLASH_FLAG_STRBER_BANK2 : Program Alignment Error on Bank 2 flag
  390. * @arg FLASH_FLAG_INCERR_BANK2 : Inconsistency Error on Bank 2 flag
  391. * @arg FLASH_FLAG_OPERR_BANK2 : Operation Error on Bank 2 flag
  392. * @arg FLASH_FLAG_RDPERR_BANK2 : Read Protection Error on Bank 2 flag
  393. * @arg FLASH_FLAG_RDSERR_BANK2 : Read secure Error on Bank 2 flag
  394. * @arg FLASH_FLAG_SNECCE_BANK2 : Single ECC Error Correction on Bank 2 flag
  395. * @arg FLASH_FLAG_DBECCE_BANK2 : Double Detection ECC Error on Bank 2 flag
  396. * @arg FLASH_FLAG_CRCEND_BANK2 : CRC End on Bank 2 flag
  397. * @arg FLASH_FLAG_CRCRDERR_BANK2 : CRC Read error on Bank 2 flag
  398. * @retval The new state of FLASH_FLAG (SET or RESET).
  399. */
  400. #define __HAL_FLASH_GET_FLAG_BANK1(__FLAG__) (READ_BIT(FLASH->SR1, (__FLAG__)) == (__FLAG__))
  401. #define __HAL_FLASH_GET_FLAG_BANK2(__FLAG__) (READ_BIT(FLASH->SR2, ((__FLAG__) & 0x7FFFFFFFU)) == (((__FLAG__) & 0x7FFFFFFFU)))
  402. #define __HAL_FLASH_GET_FLAG(__FLAG__) (IS_FLASH_FLAG_BANK1(__FLAG__) ? __HAL_FLASH_GET_FLAG_BANK1(__FLAG__) : \
  403. __HAL_FLASH_GET_FLAG_BANK2(__FLAG__))
  404. /**
  405. * @brief Clear the specified FLASH flag.
  406. * @param __FLAG__: specifies the FLASH flags to clear.
  407. * This parameter can be any combination of the following values:
  408. * @arg FLASH_FLAG_EOP_BANK1 : End Of Program on Bank 1 flag
  409. * @arg FLASH_FLAG_WRPERR_BANK1 : Write Protection Error on Bank 1 flag
  410. * @arg FLASH_FLAG_PGSERR_BANK1 : Program Sequence Error on Bank 1 flag
  411. * @arg FLASH_FLAG_STRBER_BANK1 : Program Alignment Error on Bank 1 flag
  412. * @arg FLASH_FLAG_INCERR_BANK1 : Inconsistency Error on Bank 1 flag
  413. * @arg FLASH_FLAG_OPERR_BANK1 : Operation Error on Bank 1 flag
  414. * @arg FLASH_FLAG_RDPERR_BANK1 : Read Protection Error on Bank 1 flag
  415. * @arg FLASH_FLAG_RDSERR_BANK1 : Read secure Error on Bank 1 flag
  416. * @arg FLASH_FLAG_SNECCE_BANK1 : Single ECC Error Correction on Bank 1 flag
  417. * @arg FLASH_FLAG_DBECCE_BANK1 : Double Detection ECC Error on Bank 1 flag
  418. * @arg FLASH_FLAG_CRCEND_BANK1 : CRC End on Bank 1 flag
  419. * @arg FLASH_FLAG_CRCRDERR_BANK1 : CRC Read error on Bank 1 flag
  420. *
  421. * In case of Bank 2 This parameter can be any combination of the following values :
  422. * @arg FLASH_FLAG_EOP_BANK2 : End Of Program on Bank 2 flag
  423. * @arg FLASH_FLAG_WRPERR_BANK2 : Write Protection Error on Bank 2 flag
  424. * @arg FLASH_FLAG_PGSERR_BANK2 : Program Sequence Error on Bank 2 flag
  425. * @arg FLASH_FLAG_STRBER_BANK2 : Program Alignment Error on Bank 2 flag
  426. * @arg FLASH_FLAG_INCERR_BANK2 : Inconsistency Error on Bank 2 flag
  427. * @arg FLASH_FLAG_OPERR_BANK2 : Operation Error on Bank 2 flag
  428. * @arg FLASH_FLAG_RDPERR_BANK2 : Read Protection Error on Bank 2 flag
  429. * @arg FLASH_FLAG_RDSERR_BANK2 : Read secure Error on Bank 2 flag
  430. * @arg FLASH_FLAG_SNECCE_BANK2 : Single ECC Error Correction on Bank 2 flag
  431. * @arg FLASH_FLAG_DBECCE_BANK2 : Double Detection ECC Error on Bank 2 flag
  432. * @arg FLASH_FLAG_CRCEND_BANK2 : CRC End on Bank 2 flag
  433. * @arg FLASH_FLAG_CRCRDERR_BANK2 : CRC Read error on Bank 2 flag
  434. * @retval none
  435. */
  436. #define __HAL_FLASH_CLEAR_FLAG_BANK1(__FLAG__) WRITE_REG(FLASH->CCR1, (__FLAG__))
  437. #define __HAL_FLASH_CLEAR_FLAG_BANK2(__FLAG__) WRITE_REG(FLASH->CCR2, ((__FLAG__) & 0x7FFFFFFFU))
  438. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (IS_FLASH_FLAG_BANK1(__FLAG__) ? __HAL_FLASH_CLEAR_FLAG_BANK1(__FLAG__) : \
  439. __HAL_FLASH_CLEAR_FLAG_BANK2(__FLAG__))
  440. /**
  441. * @}
  442. */
  443. /* Include FLASH HAL Extension module */
  444. #include "stm32h7xx_hal_flash_ex.h"
  445. /* Exported functions --------------------------------------------------------*/
  446. /** @addtogroup FLASH_Exported_Functions
  447. * @{
  448. */
  449. /** @addtogroup FLASH_Exported_Functions_Group1
  450. * @{
  451. */
  452. /* Program operation functions ***********************************************/
  453. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t FlashAddress, uint32_t DataAddress);
  454. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t FlashAddress, uint32_t DataAddress);
  455. /* FLASH IRQ handler method */
  456. void HAL_FLASH_IRQHandler(void);
  457. /* Callbacks in non blocking modes */
  458. void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  459. void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  460. /**
  461. * @}
  462. */
  463. /** @addtogroup FLASH_Exported_Functions_Group2
  464. * @{
  465. */
  466. /* Peripheral Control functions **********************************************/
  467. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  468. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  469. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  470. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  471. /* Option bytes control */
  472. HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
  473. /**
  474. * @}
  475. */
  476. /** @addtogroup FLASH_Exported_Functions_Group3
  477. * @{
  478. */
  479. /* Peripheral State functions ************************************************/
  480. uint32_t HAL_FLASH_GetError(void);
  481. /**
  482. * @}
  483. */
  484. /**
  485. * @}
  486. */
  487. /* Private types -------------------------------------------------------------*/
  488. /* Private variables ---------------------------------------------------------*/
  489. /** @defgroup FLASH_Private_Variables FLASH Private Variables
  490. * @{
  491. */
  492. extern FLASH_ProcessTypeDef pFlash;
  493. /**
  494. * @}
  495. */
  496. /* Private constants ---------------------------------------------------------*/
  497. /** @defgroup FLASH_Private_Constants FLASH Private Constants
  498. * @{
  499. */
  500. /**
  501. * @}
  502. */
  503. /* Private macros ------------------------------------------------------------*/
  504. /** @defgroup FLASH_Private_Macros FLASH Private Macros
  505. * @{
  506. */
  507. /** @defgroup FLASH_IS_FLASH_Definitions FLASH Definitions
  508. * @{
  509. */
  510. #define IS_FLASH_TYPEPROGRAM(VALUE) ((VALUE) == FLASH_TYPEPROGRAM_FLASHWORD)
  511. /**
  512. * @}
  513. */
  514. /** @defgroup FLASH_IS_BANK_IT_Definitions FLASH BANK IT Definitions
  515. * @{
  516. */
  517. #define IS_FLASH_IT_BANK1(IT) (((IT) & FLASH_IT_ALL_BANK1) == (IT))
  518. #define IS_FLASH_IT_BANK2(IT) (((IT) & FLASH_IT_ALL_BANK2) == (IT))
  519. /**
  520. * @}
  521. */
  522. #define IS_FLASH_FLAG_BANK1(FLAG) (((FLAG) & FLASH_FLAG_ALL_BANK1) == (FLAG))
  523. #define IS_FLASH_FLAG_BANK2(FLAG) (((FLAG) & FLASH_FLAG_ALL_BANK2) == (FLAG))
  524. /** @defgroup FLASH_Address FLASH Address
  525. * @{
  526. */
  527. #define IS_FLASH_PROGRAM_ADDRESS_BANK1(ADDRESS) (((ADDRESS) >= FLASH_BANK1_BASE) && ((ADDRESS) < FLASH_BANK2_BASE))
  528. #define IS_FLASH_PROGRAM_ADDRESS_BANK2(ADDRESS) (((ADDRESS) >= FLASH_BANK2_BASE ) && ((ADDRESS) <= FLASH_END))
  529. #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (IS_FLASH_PROGRAM_ADDRESS_BANK1(ADDRESS) || IS_FLASH_PROGRAM_ADDRESS_BANK2(ADDRESS))
  530. #define IS_BOOT_ADDRESS(ADDRESS) ((ADDRESS) <= (0x3FFF0000U))
  531. #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1) || \
  532. ((BANK) == FLASH_BANK_2) || \
  533. ((BANK) == FLASH_BANK_BOTH))
  534. #define IS_FLASH_BANK_EXCLUSIVE(BANK) (((BANK) == FLASH_BANK_1) || \
  535. ((BANK) == FLASH_BANK_2))
  536. /**
  537. * @}
  538. */
  539. /**
  540. * @}
  541. */
  542. /* Private functions ---------------------------------------------------------*/
  543. /** @defgroup FLASH_Private_Functions FLASH Private functions
  544. * @{
  545. */
  546. HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout, uint32_t Bank);
  547. HAL_StatusTypeDef FLASH_OB_WaitForLastOperation(uint32_t Timeout);
  548. HAL_StatusTypeDef FLASH_CRC_WaitForLastOperation(uint32_t Timeout, uint32_t Bank);
  549. /**
  550. * @}
  551. */
  552. /**
  553. * @}
  554. */
  555. /**
  556. * @}
  557. */
  558. #ifdef __cplusplus
  559. }
  560. #endif
  561. #endif /* STM32H7xx_HAL_FLASH_H */
  562. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/