stm32h7xx_hal_flash.h 35 KB

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