stm32h5xx_hal_flash.h 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. /**
  2. ******************************************************************************
  3. * @file stm32h5xx_hal_flash.h
  4. * @author MCD Application Team
  5. * @brief Header file of FLASH HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2023 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32H5xx_HAL_FLASH_H
  20. #define STM32H5xx_HAL_FLASH_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32h5xx_hal_def.h"
  26. /** @addtogroup STM32H5xx_HAL_Driver
  27. * @{
  28. */
  29. /** @addtogroup FLASH
  30. * @{
  31. */
  32. /* Exported types ------------------------------------------------------------*/
  33. /** @defgroup FLASH_Exported_Types FLASH Exported Types
  34. * @{
  35. */
  36. /**
  37. * @brief FLASH handle Structure definition
  38. */
  39. typedef struct
  40. {
  41. HAL_LockTypeDef Lock; /*!< FLASH locking object */
  42. uint32_t ErrorCode; /*!< FLASH error code */
  43. uint32_t ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not
  44. in IT context */
  45. uint32_t Address; /*!< Internal variable to save address selected for program */
  46. uint32_t Bank; /*!< Internal variable to save current bank selected during erase in
  47. IT context */
  48. uint32_t Sector; /*!< Internal variable to define the current sector which is erasing */
  49. uint32_t NbSectorsToErase; /*!< Internal variable to save the remaining sectors to erase in
  50. IT context */
  51. } FLASH_ProcessTypeDef;
  52. /**
  53. * @}
  54. */
  55. /* Exported constants --------------------------------------------------------*/
  56. /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
  57. * @{
  58. */
  59. /** @defgroup FLASH_Flag_definition FLASH Flag definition
  60. * @brief Flag definition
  61. * @{
  62. */
  63. #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
  64. #define FLASH_FLAG_WBNE FLASH_SR_WBNE /*!< FLASH Write Buffer Not Empty flag */
  65. #define FLASH_FLAG_DBNE FLASH_SR_DBNE /*!< FLASH data Buffer Not Empty flag */
  66. #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End Of operation flag */
  67. #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write Protection Error flag */
  68. #define FLASH_FLAG_PGSERR FLASH_SR_PGSERR /*!< FLASH Program Sequence Error flag */
  69. #define FLASH_FLAG_STRBERR FLASH_SR_STRBERR /*!< FLASH Strobe Error flag */
  70. #define FLASH_FLAG_INCERR FLASH_SR_INCERR /*!< FLASH Inconsistency Error flag */
  71. #if defined (FLASH_SR_OBKERR)
  72. #define FLASH_FLAG_OBKERR FLASH_SR_OBKERR /*!< FLASH OBK Error flag */
  73. #define FLASH_FLAG_OBKWERR FLASH_SR_OBKWERR /*!< FLASH OBK Write Error flag */
  74. #endif /* FLASH_SR_OBKERR */
  75. #define FLASH_FLAG_OPTCHANGEERR FLASH_SR_OPTCHANGEERR /*!< FLASH Option Byte change Error flag */
  76. #define FLASH_FLAG_ECCC FLASH_ECCR_ECCC /*!< FLASH ECC Correction flag */
  77. #define FLASH_FLAG_ECCD FLASH_ECCR_ECCD /*!< FLASH ECC Detection flag */
  78. #if defined (FLASH_SR_OBKERR)
  79. #define FLASH_FLAG_SR_ERRORS (FLASH_SR_WRPERR | FLASH_SR_PGSERR | \
  80. FLASH_SR_STRBERR | FLASH_SR_INCERR | \
  81. FLASH_SR_OBKERR | FLASH_SR_OBKWERR | \
  82. FLASH_SR_OPTCHANGEERR)
  83. #else
  84. #define FLASH_FLAG_SR_ERRORS (FLASH_SR_WRPERR | FLASH_SR_PGSERR | \
  85. FLASH_SR_STRBERR | FLASH_SR_INCERR | \
  86. FLASH_SR_OPTCHANGEERR)
  87. #endif /* FLASH_SR_OBKERR */
  88. #define FLASH_FLAG_ECCR_ERRORS (FLASH_FLAG_ECCC | FLASH_FLAG_ECCD)
  89. #define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_SR_ERRORS | FLASH_FLAG_ECCR_ERRORS) /*!< All FLASH error flags */
  90. /**
  91. * @}
  92. */
  93. /** @defgroup FLASH_Interrupt_definition FLASH Interrupts definition
  94. * @brief FLASH Interrupt definition
  95. * @{
  96. */
  97. #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation interrupt enable */
  98. #define FLASH_IT_WRPERR FLASH_CR_WRPERRIE /*!< Write Protection Error interrupt enable */
  99. #define FLASH_IT_PGSERR FLASH_CR_PGSERRIE /*!< Program Sequence Error interrupt enable */
  100. #define FLASH_IT_STRBERR FLASH_CR_STRBERRIE /*!< Strobe Error interrupt enable */
  101. #define FLASH_IT_INCERR FLASH_CR_INCERRIE /*!< Inconsistency Error interrupt enable */
  102. #if defined (FLASH_SR_OBKERR)
  103. #define FLASH_IT_OBKERR FLASH_CR_OBKERRIE /*!< OBK Error interrupt enable */
  104. #define FLASH_IT_OBKWERR FLASH_CR_OBKWERRIE /*!< OBK Write Error interrupt enable */
  105. #endif /* FLASH_SR_OBKERR */
  106. #define FLASH_IT_OPTCHANGEERR FLASH_CR_OPTCHANGEERRIE /*!< Option Byte change Error interrupt enable */
  107. #define FLASH_IT_ECCC FLASH_ECCR_ECCIE /*!< Single ECC Error Correction interrupt enable */
  108. #if defined (FLASH_SR_OBKERR)
  109. #define FLASH_IT_ALL (FLASH_IT_EOP | FLASH_IT_WRPERR | \
  110. FLASH_IT_PGSERR | FLASH_IT_STRBERR | \
  111. FLASH_IT_INCERR | FLASH_IT_OBKERR | \
  112. FLASH_IT_OBKWERR | FLASH_IT_OPTCHANGEERR | \
  113. FLASH_IT_ECCC) /*!< All Flash interrupt sources */
  114. #else
  115. #define FLASH_IT_ALL (FLASH_IT_EOP | FLASH_IT_WRPERR | \
  116. FLASH_IT_PGSERR | FLASH_IT_STRBERR | \
  117. FLASH_IT_INCERR | FLASH_IT_OPTCHANGEERR | \
  118. FLASH_IT_ECCC) /*!< All Flash interrupt sources */
  119. #endif /* FLASH_SR_OBKERR */
  120. /**
  121. * @}
  122. */
  123. /** @defgroup FLASH_Error_Code FLASH Error Code
  124. * @brief FLASH Error Code
  125. * @{
  126. */
  127. #define HAL_FLASH_ERROR_NONE 0x00000000U /*!< No error */
  128. #define HAL_FLASH_ERROR_WRP FLASH_FLAG_WRPERR /*!< Write Protection Error */
  129. #define HAL_FLASH_ERROR_PGS FLASH_FLAG_PGSERR /*!< Program Sequence Error */
  130. #define HAL_FLASH_ERROR_STRB FLASH_FLAG_STRBERR /*!< Strobe Error */
  131. #define HAL_FLASH_ERROR_INC FLASH_FLAG_INCERR /*!< Inconsistency Error */
  132. #if defined (FLASH_SR_OBKERR)
  133. #define HAL_FLASH_ERROR_OBK FLASH_FLAG_OBKERR /*!< OBK Error */
  134. #define HAL_FLASH_ERROR_OBKW FLASH_FLAG_OBKWERR /*!< OBK Write Error */
  135. #endif /* FLASH_SR_OBKERR */
  136. #define HAL_FLASH_ERROR_OB_CHANGE FLASH_FLAG_OPTCHANGEERR /*!< Option Byte Change Error */
  137. #define HAL_FLASH_ERROR_ECCC FLASH_FLAG_ECCC /*!< ECC Single Correction Error */
  138. #define HAL_FLASH_ERROR_ECCD FLASH_FLAG_ECCD /*!< ECC Double Detection Error */
  139. /**
  140. * @}
  141. */
  142. /** @defgroup FLASH_Type_Program FLASH Program Type
  143. * @{
  144. */
  145. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  146. #define FLASH_TYPEPROGRAM_QUADWORD FLASH_CR_PG /*!< Program a quad-word
  147. (128-bit) at a specified secure address */
  148. #define FLASH_TYPEPROGRAM_QUADWORD_NS (FLASH_CR_PG | FLASH_NON_SECURE_MASK) /*!< Program a quad-word
  149. (128-bit) at a specified non-secure address */
  150. #if defined (FLASH_SR_OBKERR)
  151. #define FLASH_TYPEPROGRAM_QUADWORD_OBK (FLASH_CR_PG | FLASH_OBK) /*!< Program a quad-word
  152. (128-bit) of OBK to current sector */
  153. #define FLASH_TYPEPROGRAM_QUADWORD_OBK_ALT (FLASH_CR_PG | FLASH_OBK | FLASH_OBKCFGR_ALT_SECT) /*!< Program a quad-word
  154. (128-bit) of OBK to alternate sector */
  155. #endif /* FLASH_SR_OBKERR */
  156. #if defined (FLASH_EDATAR_EDATA_EN)
  157. #define FLASH_TYPEPROGRAM_HALFWORD_EDATA (FLASH_CR_PG | FLASH_EDATA_HALFWORD) /*!< Program a flash
  158. high-cycle data half-word (16-bit)at a specified secure address */
  159. #define FLASH_TYPEPROGRAM_HALFWORD_EDATA_NS (FLASH_CR_PG | FLASH_EDATA_HALFWORD | FLASH_NON_SECURE_MASK) /*!< Program a flash
  160. high-cycle data half-word (16-bit)at a specified non-secure address */
  161. #define FLASH_TYPEPROGRAM_WORD_EDATA (FLASH_CR_PG | FLASH_EDATA_WORD) /*!< Program a flash
  162. high-cycle data word (32-bit)at a specified secure address */
  163. #define FLASH_TYPEPROGRAM_WORD_EDATA_NS (FLASH_CR_PG | FLASH_EDATA_WORD | FLASH_NON_SECURE_MASK) /*!< Program a flash
  164. high-cycle data word (32-bit)at a specified non-secure address */
  165. #endif /* FLASH_EDATAR_EDATA_EN */
  166. #else
  167. #define FLASH_TYPEPROGRAM_QUADWORD FLASH_CR_PG /*!< Program a quad-word
  168. (128-bit) at a specified address */
  169. #if defined (FLASH_SR_OBKERR)
  170. #define FLASH_TYPEPROGRAM_QUADWORD_OBK (FLASH_CR_PG | FLASH_OBK) /*!< Program a quad-word
  171. (128-bit) of OBK to current sector */
  172. #define FLASH_TYPEPROGRAM_QUADWORD_OBK_ALT (FLASH_CR_PG | FLASH_OBK | FLASH_OBKCFGR_ALT_SECT) /*!< Program a quad-word
  173. (128-bit) of OBK to alternate sector */
  174. #endif /* FLASH_SR_OBKERR */
  175. #if defined (FLASH_EDATAR_EDATA_EN)
  176. #define FLASH_TYPEPROGRAM_HALFWORD_EDATA (FLASH_CR_PG | FLASH_EDATA_HALFWORD) /*!< Program a flash
  177. high-cycle data half-word (16-bit)at a specified address */
  178. #define FLASH_TYPEPROGRAM_WORD_EDATA (FLASH_CR_PG | FLASH_EDATA_WORD) /*!< Program a flash
  179. high-cycle data half-word (32-bit)at a specified address */
  180. #endif /* FLASH_EDATAR_EDATA_EN */
  181. #endif /* __ARM_FEATURE_CMSE */
  182. #define FLASH_TYPEPROGRAM_HALFWORD_OTP (FLASH_CR_PG | FLASH_OTP | FLASH_NON_SECURE_MASK) /*!< Program an OTP
  183. half-word (16-bit)at a specified address */
  184. /**
  185. * @}
  186. */
  187. /** @defgroup FLASH_Latency FLASH Latency
  188. * @{
  189. */
  190. #define FLASH_LATENCY_0 FLASH_ACR_LATENCY_0WS /*!< FLASH Zero wait cycle */
  191. #define FLASH_LATENCY_1 FLASH_ACR_LATENCY_1WS /*!< FLASH One wait cycle */
  192. #define FLASH_LATENCY_2 FLASH_ACR_LATENCY_2WS /*!< FLASH Two wait cycles */
  193. #define FLASH_LATENCY_3 FLASH_ACR_LATENCY_3WS /*!< FLASH Three wait cycles */
  194. #define FLASH_LATENCY_4 FLASH_ACR_LATENCY_4WS /*!< FLASH Four wait cycles */
  195. #define FLASH_LATENCY_5 FLASH_ACR_LATENCY_5WS /*!< FLASH Five wait cycles */
  196. #define FLASH_LATENCY_6 FLASH_ACR_LATENCY_6WS /*!< FLASH Six wait cycles */
  197. #define FLASH_LATENCY_7 FLASH_ACR_LATENCY_7WS /*!< FLASH Seven wait cycles */
  198. #define FLASH_LATENCY_8 FLASH_ACR_LATENCY_8WS /*!< FLASH Eight wait cycle */
  199. #define FLASH_LATENCY_9 FLASH_ACR_LATENCY_9WS /*!< FLASH Nine wait cycle */
  200. #define FLASH_LATENCY_10 FLASH_ACR_LATENCY_10WS /*!< FLASH Ten wait cycles */
  201. #define FLASH_LATENCY_11 FLASH_ACR_LATENCY_11WS /*!< FLASH Eleven wait cycles */
  202. #define FLASH_LATENCY_12 FLASH_ACR_LATENCY_12WS /*!< FLASH Twelve wait cycles */
  203. #define FLASH_LATENCY_13 FLASH_ACR_LATENCY_13WS /*!< FLASH Thirteen wait cycles */
  204. #define FLASH_LATENCY_14 FLASH_ACR_LATENCY_14WS /*!< FLASH Fourteen wait cycles */
  205. #define FLASH_LATENCY_15 FLASH_ACR_LATENCY_15WS /*!< FLASH Fifteen wait cycles */
  206. /**
  207. * @}
  208. */
  209. /** @defgroup FLASH_Keys FLASH Keys
  210. * @{
  211. */
  212. #define FLASH_KEY1 0x45670123U
  213. #define FLASH_KEY2 0xCDEF89ABU
  214. #define FLASH_OPT_KEY1 0x08192A3BU
  215. #define FLASH_OPT_KEY2 0x4C5D6E7FU
  216. #if defined (FLASH_SR_OBKERR)
  217. #define FLASH_OBK_KEY1 0x192A083BU
  218. #define FLASH_OBK_KEY2 0x6E7F4C5DU
  219. #endif /* FLASH_SR_OBKERR */
  220. /**
  221. * @}
  222. */
  223. /** @defgroup FLASH_Sectors FLASH Sectors
  224. * @{
  225. */
  226. #define FLASH_SECTOR_0 0U /*!< Sector Number 0 */
  227. #define FLASH_SECTOR_1 1U /*!< Sector Number 1 */
  228. #define FLASH_SECTOR_2 2U /*!< Sector Number 2 */
  229. #define FLASH_SECTOR_3 3U /*!< Sector Number 3 */
  230. #define FLASH_SECTOR_4 4U /*!< Sector Number 4 */
  231. #define FLASH_SECTOR_5 5U /*!< Sector Number 5 */
  232. #define FLASH_SECTOR_6 6U /*!< Sector Number 6 */
  233. #define FLASH_SECTOR_7 7U /*!< Sector Number 7 */
  234. #if (FLASH_SECTOR_NB >= 32)
  235. #define FLASH_SECTOR_8 8U /*!< Sector Number 8 */
  236. #define FLASH_SECTOR_9 9U /*!< Sector Number 9 */
  237. #define FLASH_SECTOR_10 10U /*!< Sector Number 10 */
  238. #define FLASH_SECTOR_11 11U /*!< Sector Number 11 */
  239. #define FLASH_SECTOR_12 12U /*!< Sector Number 12 */
  240. #define FLASH_SECTOR_13 13U /*!< Sector Number 13 */
  241. #define FLASH_SECTOR_14 14U /*!< Sector Number 14 */
  242. #define FLASH_SECTOR_15 15U /*!< Sector Number 15 */
  243. #define FLASH_SECTOR_16 16U /*!< Sector Number 16 */
  244. #define FLASH_SECTOR_17 17U /*!< Sector Number 17 */
  245. #define FLASH_SECTOR_18 18U /*!< Sector Number 18 */
  246. #define FLASH_SECTOR_19 19U /*!< Sector Number 19 */
  247. #define FLASH_SECTOR_20 20U /*!< Sector Number 20 */
  248. #define FLASH_SECTOR_21 21U /*!< Sector Number 21 */
  249. #define FLASH_SECTOR_22 22U /*!< Sector Number 22 */
  250. #define FLASH_SECTOR_23 23U /*!< Sector Number 23 */
  251. #define FLASH_SECTOR_24 24U /*!< Sector Number 24 */
  252. #define FLASH_SECTOR_25 25U /*!< Sector Number 25 */
  253. #define FLASH_SECTOR_26 26U /*!< Sector Number 26 */
  254. #define FLASH_SECTOR_27 27U /*!< Sector Number 27 */
  255. #define FLASH_SECTOR_28 28U /*!< Sector Number 28 */
  256. #define FLASH_SECTOR_29 29U /*!< Sector Number 29 */
  257. #define FLASH_SECTOR_30 30U /*!< Sector Number 30 */
  258. #define FLASH_SECTOR_31 31U /*!< Sector Number 31 */
  259. #endif /* (FLASH_SECTOR_NB >= 32) */
  260. #if (FLASH_SECTOR_NB >= 128)
  261. #define FLASH_SECTOR_32 32U /*!< Sector Number 32 */
  262. #define FLASH_SECTOR_33 33U /*!< Sector Number 33 */
  263. #define FLASH_SECTOR_34 34U /*!< Sector Number 34 */
  264. #define FLASH_SECTOR_35 35U /*!< Sector Number 35 */
  265. #define FLASH_SECTOR_36 36U /*!< Sector Number 36 */
  266. #define FLASH_SECTOR_37 37U /*!< Sector Number 37 */
  267. #define FLASH_SECTOR_38 38U /*!< Sector Number 38 */
  268. #define FLASH_SECTOR_39 39U /*!< Sector Number 39 */
  269. #define FLASH_SECTOR_40 40U /*!< Sector Number 40 */
  270. #define FLASH_SECTOR_41 41U /*!< Sector Number 41 */
  271. #define FLASH_SECTOR_42 42U /*!< Sector Number 42 */
  272. #define FLASH_SECTOR_43 43U /*!< Sector Number 43 */
  273. #define FLASH_SECTOR_44 44U /*!< Sector Number 44 */
  274. #define FLASH_SECTOR_45 45U /*!< Sector Number 45 */
  275. #define FLASH_SECTOR_46 46U /*!< Sector Number 46 */
  276. #define FLASH_SECTOR_47 47U /*!< Sector Number 47 */
  277. #define FLASH_SECTOR_48 48U /*!< Sector Number 48 */
  278. #define FLASH_SECTOR_49 49U /*!< Sector Number 49 */
  279. #define FLASH_SECTOR_50 50U /*!< Sector Number 50 */
  280. #define FLASH_SECTOR_51 51U /*!< Sector Number 51 */
  281. #define FLASH_SECTOR_52 52U /*!< Sector Number 52 */
  282. #define FLASH_SECTOR_53 53U /*!< Sector Number 53 */
  283. #define FLASH_SECTOR_54 54U /*!< Sector Number 54 */
  284. #define FLASH_SECTOR_55 55U /*!< Sector Number 55 */
  285. #define FLASH_SECTOR_56 56U /*!< Sector Number 56 */
  286. #define FLASH_SECTOR_57 57U /*!< Sector Number 57 */
  287. #define FLASH_SECTOR_58 58U /*!< Sector Number 58 */
  288. #define FLASH_SECTOR_59 59U /*!< Sector Number 59 */
  289. #define FLASH_SECTOR_60 60U /*!< Sector Number 60 */
  290. #define FLASH_SECTOR_61 61U /*!< Sector Number 61 */
  291. #define FLASH_SECTOR_62 62U /*!< Sector Number 62 */
  292. #define FLASH_SECTOR_63 63U /*!< Sector Number 63 */
  293. #define FLASH_SECTOR_64 64U /*!< Sector Number 64 */
  294. #define FLASH_SECTOR_65 65U /*!< Sector Number 65 */
  295. #define FLASH_SECTOR_66 66U /*!< Sector Number 66 */
  296. #define FLASH_SECTOR_67 67U /*!< Sector Number 67 */
  297. #define FLASH_SECTOR_68 68U /*!< Sector Number 68 */
  298. #define FLASH_SECTOR_69 69U /*!< Sector Number 69 */
  299. #define FLASH_SECTOR_70 70U /*!< Sector Number 70 */
  300. #define FLASH_SECTOR_71 71U /*!< Sector Number 71 */
  301. #define FLASH_SECTOR_72 72U /*!< Sector Number 72 */
  302. #define FLASH_SECTOR_73 73U /*!< Sector Number 73 */
  303. #define FLASH_SECTOR_74 74U /*!< Sector Number 74 */
  304. #define FLASH_SECTOR_75 75U /*!< Sector Number 75 */
  305. #define FLASH_SECTOR_76 76U /*!< Sector Number 76 */
  306. #define FLASH_SECTOR_77 77U /*!< Sector Number 77 */
  307. #define FLASH_SECTOR_78 78U /*!< Sector Number 78 */
  308. #define FLASH_SECTOR_79 79U /*!< Sector Number 79 */
  309. #define FLASH_SECTOR_80 80U /*!< Sector Number 80 */
  310. #define FLASH_SECTOR_81 81U /*!< Sector Number 81 */
  311. #define FLASH_SECTOR_82 82U /*!< Sector Number 82 */
  312. #define FLASH_SECTOR_83 83U /*!< Sector Number 83 */
  313. #define FLASH_SECTOR_84 84U /*!< Sector Number 84 */
  314. #define FLASH_SECTOR_85 85U /*!< Sector Number 85 */
  315. #define FLASH_SECTOR_86 86U /*!< Sector Number 86 */
  316. #define FLASH_SECTOR_87 87U /*!< Sector Number 87 */
  317. #define FLASH_SECTOR_88 88U /*!< Sector Number 88 */
  318. #define FLASH_SECTOR_89 89U /*!< Sector Number 89 */
  319. #define FLASH_SECTOR_90 90U /*!< Sector Number 90 */
  320. #define FLASH_SECTOR_91 91U /*!< Sector Number 91 */
  321. #define FLASH_SECTOR_92 92U /*!< Sector Number 92 */
  322. #define FLASH_SECTOR_93 93U /*!< Sector Number 93 */
  323. #define FLASH_SECTOR_94 94U /*!< Sector Number 94 */
  324. #define FLASH_SECTOR_95 95U /*!< Sector Number 95 */
  325. #define FLASH_SECTOR_96 96U /*!< Sector Number 96 */
  326. #define FLASH_SECTOR_97 97U /*!< Sector Number 97 */
  327. #define FLASH_SECTOR_98 98U /*!< Sector Number 98 */
  328. #define FLASH_SECTOR_99 99U /*!< Sector Number 99 */
  329. #define FLASH_SECTOR_100 100U /*!< Sector Number 100 */
  330. #define FLASH_SECTOR_101 101U /*!< Sector Number 101 */
  331. #define FLASH_SECTOR_102 102U /*!< Sector Number 102 */
  332. #define FLASH_SECTOR_103 103U /*!< Sector Number 103 */
  333. #define FLASH_SECTOR_104 104U /*!< Sector Number 104 */
  334. #define FLASH_SECTOR_105 105U /*!< Sector Number 105 */
  335. #define FLASH_SECTOR_106 106U /*!< Sector Number 106 */
  336. #define FLASH_SECTOR_107 107U /*!< Sector Number 107 */
  337. #define FLASH_SECTOR_108 108U /*!< Sector Number 108 */
  338. #define FLASH_SECTOR_109 109U /*!< Sector Number 109 */
  339. #define FLASH_SECTOR_110 110U /*!< Sector Number 110 */
  340. #define FLASH_SECTOR_111 111U /*!< Sector Number 111 */
  341. #define FLASH_SECTOR_112 112U /*!< Sector Number 112 */
  342. #define FLASH_SECTOR_113 113U /*!< Sector Number 113 */
  343. #define FLASH_SECTOR_114 114U /*!< Sector Number 114 */
  344. #define FLASH_SECTOR_115 115U /*!< Sector Number 115 */
  345. #define FLASH_SECTOR_116 116U /*!< Sector Number 116 */
  346. #define FLASH_SECTOR_117 117U /*!< Sector Number 117 */
  347. #define FLASH_SECTOR_118 118U /*!< Sector Number 118 */
  348. #define FLASH_SECTOR_119 119U /*!< Sector Number 119 */
  349. #define FLASH_SECTOR_120 120U /*!< Sector Number 120 */
  350. #define FLASH_SECTOR_121 121U /*!< Sector Number 121 */
  351. #define FLASH_SECTOR_122 122U /*!< Sector Number 122 */
  352. #define FLASH_SECTOR_123 123U /*!< Sector Number 123 */
  353. #define FLASH_SECTOR_124 124U /*!< Sector Number 124 */
  354. #define FLASH_SECTOR_125 125U /*!< Sector Number 125 */
  355. #define FLASH_SECTOR_126 126U /*!< Sector Number 126 */
  356. #define FLASH_SECTOR_127 127U /*!< Sector Number 127 */
  357. #endif /* (FLASH_SECTOR_NB >= 128) */
  358. /**
  359. * @}
  360. */
  361. /**
  362. * @}
  363. */
  364. /* Exported macros ------------------------------------------------------------*/
  365. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  366. * @{
  367. */
  368. /**
  369. * @brief Set the FLASH Latency.
  370. * @param __LATENCY__: FLASH Latency
  371. * This parameter can be one of the following values :
  372. * @arg FLASH_LATENCY_0: FLASH Zero wait state
  373. * @arg FLASH_LATENCY_1: FLASH One wait state
  374. * @arg FLASH_LATENCY_2: FLASH Two wait states
  375. * @arg FLASH_LATENCY_3: FLASH Three wait states
  376. * @arg FLASH_LATENCY_4: FLASH Four wait states
  377. * @arg FLASH_LATENCY_5: FLASH Five wait states
  378. * @arg FLASH_LATENCY_6: FLASH Six wait states
  379. * @arg FLASH_LATENCY_7: FLASH Seven wait states
  380. * @arg FLASH_LATENCY_8: FLASH Eight wait states
  381. * @arg FLASH_LATENCY_9: FLASH Nine wait states
  382. * @arg FLASH_LATENCY_10: FLASH Ten wait states
  383. * @arg FLASH_LATENCY_11: FLASH Eleven wait states
  384. * @arg FLASH_LATENCY_12: FLASH Twelve wait states
  385. * @arg FLASH_LATENCY_13: FLASH Thirteen wait states
  386. * @arg FLASH_LATENCY_14: FLASH Fourteen wait states
  387. * @arg FLASH_LATENCY_15: FLASH Fifteen wait states
  388. * @retval none
  389. */
  390. #define __HAL_FLASH_SET_LATENCY(__LATENCY__) MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (__LATENCY__))
  391. /**
  392. * @brief Get the FLASH Latency.
  393. * @retval FLASH Latency
  394. * This return value can be one of the following values :
  395. * @arg FLASH_LATENCY_0: FLASH Zero wait state
  396. * @arg FLASH_LATENCY_1: FLASH One wait state
  397. * @arg FLASH_LATENCY_2: FLASH Two wait states
  398. * @arg FLASH_LATENCY_3: FLASH Three wait states
  399. * @arg FLASH_LATENCY_4: FLASH Four wait states
  400. * @arg FLASH_LATENCY_5: FLASH Five wait states
  401. * @arg FLASH_LATENCY_6: FLASH Six wait states
  402. * @arg FLASH_LATENCY_7: FLASH Seven wait states
  403. * @arg FLASH_LATENCY_8: FLASH Eight wait states
  404. * @arg FLASH_LATENCY_9: FLASH Nine wait states
  405. * @arg FLASH_LATENCY_10: FLASH Ten wait states
  406. * @arg FLASH_LATENCY_11: FLASH Eleven wait states
  407. * @arg FLASH_LATENCY_12: FLASH Twelve wait states
  408. * @arg FLASH_LATENCY_13: FLASH Thirteen wait states
  409. * @arg FLASH_LATENCY_14: FLASH Fourteen wait states
  410. * @arg FLASH_LATENCY_15: FLASH Fifteen wait states
  411. */
  412. #define __HAL_FLASH_GET_LATENCY() READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)
  413. /**
  414. * @brief Enable the specified FLASH interrupt.
  415. * @param __INTERRUPT__ : FLASH interrupt
  416. * This parameter can be any combination of the following values:
  417. * @arg FLASH_IT_EOP : End of FLASH Operation Interrupt
  418. * @arg FLASH_IT_WRPERR : Write Protection Error Interrupt
  419. * @arg FLASH_IT_PGSERR : Program Sequence Error Interrupt
  420. * @arg FLASH_IT_STRBERR : Strobe Error Interrupt
  421. * @arg FLASH_IT_INCERR : Inconsistency Error Interrupt
  422. * @arg FLASH_IT_OBKERR : OBK Error Interrupt
  423. * @arg FLASH_IT_OBKWERR : OBK Write Error Interrupt
  424. * @arg FLASH_IT_OPTCHANGEERR : Option Byte Change Error Interrupt
  425. * @arg FLASH_IT_ECCC : Single ECC Error Correction Interrupt
  426. * @retval none
  427. */
  428. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  429. /* Enable secure FLASH interrupts from the secure world */
  430. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U) \
  431. { SET_BIT(FLASH->ECCCORR, FLASH_IT_ECCC); } \
  432. if(((__INTERRUPT__) & FLASH_IT_OPTCHANGEERR) != 0U) \
  433. { SET_BIT(FLASH->NSCR, FLASH_IT_OPTCHANGEERR); } \
  434. if(((__INTERRUPT__) & (~FLASH_IT_ECCC)) != 0U) \
  435. { SET_BIT(FLASH->SECCR, ((__INTERRUPT__) & (~(FLASH_IT_ECCC | \
  436. FLASH_IT_OPTCHANGEERR)))); }\
  437. } while(0)
  438. /* Enable non-secure FLASH interrupts from the secure world */
  439. #define __HAL_FLASH_ENABLE_IT_NS(__INTERRUPT__) do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U) \
  440. { SET_BIT(FLASH->ECCCORR, FLASH_IT_ECCC); } \
  441. if(((__INTERRUPT__) & (~FLASH_IT_ECCC)) != 0U) \
  442. { SET_BIT(FLASH->NSCR, ((__INTERRUPT__) & (~FLASH_IT_ECCC))); } \
  443. } while(0)
  444. #else
  445. /* Enable non-secure FLASH interrupts from the non-secure world */
  446. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U) \
  447. { SET_BIT(FLASH->ECCCORR, FLASH_IT_ECCC); } \
  448. if(((__INTERRUPT__) & (~FLASH_IT_ECCC)) != 0U) \
  449. { SET_BIT(FLASH->NSCR, ((__INTERRUPT__) & (~FLASH_IT_ECCC))); } \
  450. } while(0)
  451. #endif /* __ARM_FEATURE_CMSE */
  452. /**
  453. * @brief Disable the specified FLASH interrupt.
  454. * @param __INTERRUPT__ : FLASH interrupt
  455. * This parameter can be any combination of the following values:
  456. * @arg FLASH_IT_EOP : End of FLASH Operation Interrupt
  457. * @arg FLASH_IT_WRPERR : Write Protection Error Interrupt
  458. * @arg FLASH_IT_PGSERR : Program Sequence Error Interrupt
  459. * @arg FLASH_IT_STRBERR : Strobe Error Interrupt
  460. * @arg FLASH_IT_INCERR : Inconsistency Error Interrupt
  461. * @arg FLASH_IT_OBKERR : OBK Error Interrupt
  462. * @arg FLASH_IT_OBKWERR : OBK Write Error Interrupt
  463. * @arg FLASH_IT_OPTCHANGEERR : Option Byte Change Error Interrupt
  464. * @arg FLASH_IT_ECCC : Single ECC Error Correction Interrupt
  465. * @retval none
  466. */
  467. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  468. /* Disable secure FLASH interrupts from the secure world */
  469. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U) \
  470. { CLEAR_BIT(FLASH->ECCCORR, FLASH_IT_ECCC); } \
  471. if(((__INTERRUPT__) & FLASH_IT_OPTCHANGEERR) != 0U) \
  472. { CLEAR_BIT(FLASH->NSCR, FLASH_IT_OPTCHANGEERR); } \
  473. if(((__INTERRUPT__) & (~(FLASH_IT_ECCC | FLASH_IT_OPTCHANGEERR))) \
  474. != 0U){ CLEAR_BIT(FLASH->SECCR, ((__INTERRUPT__) & \
  475. (~(FLASH_IT_ECCC | FLASH_IT_OPTCHANGEERR)))); }\
  476. } while(0)
  477. /* Disable non-secure FLASH interrupts from the secure world */
  478. #define __HAL_FLASH_DISABLE_IT_NS(__INTERRUPT__) do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U) { CLEAR_BIT \
  479. (FLASH->ECCCORR, FLASH_IT_ECCC); } \
  480. if(((__INTERRUPT__) & (~FLASH_IT_ECCC)) != 0U) \
  481. { CLEAR_BIT(FLASH->NSCR, ((__INTERRUPT__) & (~FLASH_IT_ECCC)));\
  482. } \
  483. } while(0)
  484. #else
  485. /* Disable non-secure FLASH interrupts from the non-secure world */
  486. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U) { CLEAR_BIT \
  487. (FLASH->ECCCORR, FLASH_IT_ECCC); } \
  488. if(((__INTERRUPT__) & (~FLASH_IT_ECCC)) != 0U) { CLEAR_BIT \
  489. (FLASH->NSCR, ((__INTERRUPT__) & (~FLASH_IT_ECCC))); } \
  490. } while(0)
  491. #endif /* __ARM_FEATURE_CMSE */
  492. /**
  493. * @brief Checks whether the specified FLASH flag is set or not.
  494. * @param __FLAG__: specifies the FLASH flag to check.
  495. * This parameter can be one of the following values :
  496. * @arg FLASH_FLAG_BSY : FLASH Busy flag
  497. * @arg FLASH_FLAG_WBNE : Write Buffer Not Empty flag
  498. * @arg FLASH_FLAG_EOP : End Of Operation flag
  499. * @arg FLASH_FLAG_WRPERR : Write Protection Error flag
  500. * @arg FLASH_FLAG_PGSERR : Program Sequence Error flag
  501. * @arg FLASH_FLAG_STRBERR : Strobe Error flag
  502. * @arg FLASH_FLAG_INCERR : Inconsistency Error flag
  503. * @arg FLASH_FLAG_OBKERR : OBK Error flag
  504. * @arg FLASH_FLAG_OBKWERR : OBK Write Error flag
  505. * @arg FLASH_FLAG_OPTCHANGEERR : Option Byte Change Error flag
  506. * @arg FLASH_FLAG_ECCC : Single ECC Error Correction flag
  507. * @arg FLASH_FLAG_ECCD : Double Detection ECC Error flag
  508. * @retval The new state of FLASH_FLAG (SET or RESET).
  509. */
  510. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  511. /* Get secure FLASH flags from the secure world */
  512. #define __HAL_FLASH_GET_FLAG(__FLAG__) ((((__FLAG__) & (FLASH_FLAG_ECCC)) != 0U) ? \
  513. (READ_BIT(FLASH->ECCCORR, (__FLAG__)) == (__FLAG__)) : \
  514. (((__FLAG__) & (FLASH_FLAG_ECCD)) != 0U) ? \
  515. (READ_BIT(FLASH->ECCDETR, (__FLAG__)) == (__FLAG__)) : \
  516. ((((__FLAG__) & (FLASH_FLAG_OPTCHANGEERR)) != 0U) ? \
  517. (READ_BIT(FLASH->NSSR, (__FLAG__)) == (__FLAG__)) : \
  518. (READ_BIT(FLASH->SECSR, (__FLAG__)) == (__FLAG__))))
  519. /* Get non-secure FLASH flags from the secure world */
  520. #define __HAL_FLASH_GET_FLAG_NS(__FLAG__) ((((__FLAG__) & (FLASH_FLAG_ECCC)) != 0U) ? \
  521. (READ_BIT(FLASH->ECCCORR, (__FLAG__)) == (__FLAG__)) : \
  522. (((__FLAG__) & (FLASH_FLAG_ECCD)) != 0U) ? \
  523. (READ_BIT(FLASH->ECCDETR, (__FLAG__)) == (__FLAG__)) : \
  524. (READ_BIT(FLASH->NSSR, (__FLAG__)) == (__FLAG__))))
  525. #else
  526. /* Get non-secure FLASH flags from the non-secure world */
  527. #define __HAL_FLASH_GET_FLAG(__FLAG__) ((((__FLAG__) & (FLASH_FLAG_ECCC)) != 0U) ? \
  528. (READ_BIT(FLASH->ECCCORR, (__FLAG__)) == (__FLAG__)) : \
  529. (((__FLAG__) & (FLASH_FLAG_ECCD)) != 0U) ? \
  530. (READ_BIT(FLASH->ECCDETR, (__FLAG__)) == (__FLAG__)) : \
  531. (READ_BIT(FLASH->NSSR, (__FLAG__)) == (__FLAG__)))
  532. #endif /* __ARM_FEATURE_CMSE */
  533. /**
  534. * @brief Clear the specified FLASH flag.
  535. * @param __FLAG__: specifies the FLASH flags to clear.
  536. * This parameter can be one of the following values :
  537. * @arg FLASH_FLAG_BSY : FLASH Busy flag
  538. * @arg FLASH_FLAG_WBNE : Write Buffer Not Empty flag
  539. * @arg FLASH_FLAG_EOP : End Of Operation flag
  540. * @arg FLASH_FLAG_WRPERR : Write Protection Error flag
  541. * @arg FLASH_FLAG_PGSERR : Program Sequence Error flag
  542. * @arg FLASH_FLAG_STRBERR : Strobe Error flag
  543. * @arg FLASH_FLAG_INCERR : Inconsistency Error flag
  544. * @arg FLASH_FLAG_OBKERR : OBK Error flag
  545. * @arg FLASH_FLAG_OBKWERR : OBK Write Error flag
  546. * @arg FLASH_FLAG_OPTCHANGEERR : Option Byte Change Error flag
  547. * @arg FLASH_FLAG_ECCC : Single ECC Error Correction flag
  548. * @arg FLASH_FLAG_ECCD : Double Detection ECC Error flag
  549. * @arg FLASH_FLAG_ALL_ERRORS: All errors flags
  550. * @retval none
  551. */
  552. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  553. /* Clear secure FLASH flags from the secure world */
  554. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) do { if(((__FLAG__) & FLASH_FLAG_ECCC) != 0U) { SET_BIT(FLASH->ECCCORR,\
  555. ((__FLAG__) & FLASH_FLAG_ECCC)); } \
  556. if(((__FLAG__) & FLASH_FLAG_ECCD) != 0U) { SET_BIT(FLASH->ECCDETR,\
  557. ((__FLAG__) & FLASH_FLAG_ECCD)); } \
  558. if(((__FLAG__) & FLASH_FLAG_OPTCHANGEERR) != 0U) { SET_BIT \
  559. (FLASH->NSCCR, ((__FLAG__) & (FLASH_FLAG_OPTCHANGEERR))); } \
  560. if(((__FLAG__) & ~(FLASH_FLAG_ECCR_ERRORS | \
  561. FLASH_FLAG_OPTCHANGEERR)) != 0U) { WRITE_REG(FLASH->SECCCR, \
  562. ((__FLAG__) & ~(FLASH_FLAG_ECCR_ERRORS | \
  563. FLASH_FLAG_OPTCHANGEERR))); } \
  564. } while(0)
  565. /* Clear non-secure FLASH flags from the secure world */
  566. #define __HAL_FLASH_CLEAR_FLAG_NS(__FLAG__) do { if(((__FLAG__) & FLASH_FLAG_ECCC) != 0U) { SET_BIT(FLASH->ECCCORR,\
  567. ((__FLAG__) & FLASH_FLAG_ECCC)); } \
  568. if(((__FLAG__) & FLASH_FLAG_ECCD) != 0U) { SET_BIT(FLASH->ECCDETR,\
  569. ((__FLAG__) & FLASH_FLAG_ECCD)); } \
  570. if(((__FLAG__) & (~FLASH_FLAG_ECCR_ERRORS)) != 0U) { WRITE_REG \
  571. (FLASH->NSCCR, ((__FLAG__) & (~FLASH_FLAG_ECCR_ERRORS))); } \
  572. } while(0)
  573. #else
  574. /* Clear non-secure FLASH flags from the non-secure world */
  575. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) do { if(((__FLAG__) & FLASH_FLAG_ECCC) != 0U) { SET_BIT(FLASH->ECCCORR,\
  576. ((__FLAG__) & FLASH_FLAG_ECCC)); } \
  577. if(((__FLAG__) & FLASH_FLAG_ECCD) != 0U) { SET_BIT(FLASH->ECCDETR,\
  578. ((__FLAG__) & FLASH_FLAG_ECCD)); } \
  579. if(((__FLAG__) & (~FLASH_FLAG_ECCR_ERRORS)) != 0U) { WRITE_REG \
  580. (FLASH->NSCCR, ((__FLAG__) & (~FLASH_FLAG_ECCR_ERRORS))); } \
  581. } while(0)
  582. #endif /* __ARM_FEATURE_CMSE */
  583. /**
  584. * @}
  585. */
  586. /* Include FLASH HAL Extension module */
  587. #include "stm32h5xx_hal_flash_ex.h"
  588. /* Exported functions --------------------------------------------------------*/
  589. /** @addtogroup FLASH_Exported_Functions
  590. * @{
  591. */
  592. /** @addtogroup FLASH_Exported_Functions_Group1
  593. * @{
  594. */
  595. /* Program operation functions */
  596. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t FlashAddress, uint32_t DataAddress);
  597. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t FlashAddress, uint32_t DataAddress);
  598. /* FLASH IRQ handler method */
  599. void HAL_FLASH_IRQHandler(void);
  600. /* Callbacks in non blocking modes */
  601. void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  602. void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  603. /**
  604. * @}
  605. */
  606. /** @addtogroup FLASH_Exported_Functions_Group2
  607. * @{
  608. */
  609. /* Peripheral Control functions */
  610. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  611. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  612. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  613. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  614. /* Option bytes control */
  615. HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
  616. /**
  617. * @}
  618. */
  619. /** @addtogroup FLASH_Exported_Functions_Group3
  620. * @{
  621. */
  622. /* Peripheral State functions */
  623. uint32_t HAL_FLASH_GetError(void);
  624. /**
  625. * @}
  626. */
  627. /**
  628. * @}
  629. */
  630. /* Private types -------------------------------------------------------------*/
  631. /* Private variables ---------------------------------------------------------*/
  632. /** @defgroup FLASH_Private_Variables FLASH Private Variables
  633. * @{
  634. */
  635. extern FLASH_ProcessTypeDef pFlash;
  636. /**
  637. * @}
  638. */
  639. /* Private constants ---------------------------------------------------------*/
  640. /** @defgroup FLASH_Private_Constants FLASH Private Constants
  641. * @{
  642. */
  643. #define FLASH_TIMEOUT_VALUE 1000U /*!< 1 s */
  644. #if defined (FLASH_SR_OBKERR)
  645. #define FLASH_OBK 0x10000000U
  646. #endif /* FLASH_SR_OBKERR */
  647. #define FLASH_OTP 0x20000000U
  648. #if defined (FLASH_EDATAR_EDATA_EN)
  649. #define FLASH_EDATA_HALFWORD 0x40000000U
  650. #define FLASH_EDATA_WORD 0x60000000U
  651. #endif /* FLASH_EDATAR_EDATA_EN */
  652. #define FLASH_NON_SECURE_MASK 0x80000000U
  653. #define FLASH_EDATA_SECTOR_NB 8U /*!< Maximum number of FLASH high-cycle data sectors */
  654. /**
  655. * @}
  656. */
  657. /* Private macros ------------------------------------------------------------*/
  658. /** @defgroup FLASH_Private_Macros FLASH Private Macros
  659. * @{
  660. */
  661. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  662. #if defined (FLASH_SR_OBKERR) && defined (FLASH_EDATAR_EDATA_EN)
  663. #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_QUADWORD) || \
  664. ((VALUE) == FLASH_TYPEPROGRAM_QUADWORD_NS) || \
  665. ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_OTP) || \
  666. ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_EDATA) || \
  667. ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_EDATA_NS) || \
  668. ((VALUE) == FLASH_TYPEPROGRAM_WORD_EDATA) || \
  669. ((VALUE) == FLASH_TYPEPROGRAM_WORD_EDATA_NS) || \
  670. ((VALUE) == FLASH_TYPEPROGRAM_QUADWORD_OBK) || \
  671. ((VALUE) == FLASH_TYPEPROGRAM_QUADWORD_OBK_ALT))
  672. #else
  673. #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_QUADWORD) || \
  674. ((VALUE) == FLASH_TYPEPROGRAM_QUADWORD_NS) || \
  675. ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_OTP))
  676. #endif /* FLASH_SR_OBKERR && FLASH_EDATAR_EDATA_EN */
  677. #else
  678. #if defined (FLASH_SR_OBKERR) && defined (FLASH_EDATAR_EDATA_EN)
  679. #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_QUADWORD) || \
  680. ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_OTP) || \
  681. ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_EDATA) || \
  682. ((VALUE) == FLASH_TYPEPROGRAM_WORD_EDATA) || \
  683. ((VALUE) == FLASH_TYPEPROGRAM_QUADWORD_OBK) || \
  684. ((VALUE) == FLASH_TYPEPROGRAM_QUADWORD_OBK_ALT))
  685. #else
  686. #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_QUADWORD) || \
  687. ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_OTP))
  688. #endif /* FLASH_SR_OBKERR && FLASH_EDATAR_EDATA_EN */
  689. #endif /* __ARM_FEATURE_CMSE */
  690. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  691. #define IS_FLASH_USER_MEM_ADDRESS(ADDRESS) ((((ADDRESS) >= FLASH_BASE) && ((ADDRESS) < (FLASH_BASE+FLASH_SIZE))) || \
  692. (((ADDRESS) >= FLASH_BASE_NS) && ((ADDRESS) < (FLASH_BASE_NS+FLASH_SIZE))))
  693. #if defined (FLASH_SR_OBKERR)
  694. #define IS_FLASH_OBK_ADDRESS(ADDRESS) ((((ADDRESS) >= FLASH_OBK_BASE) && \
  695. ((ADDRESS) < (FLASH_OBK_BASE+FLASH_OBK_SIZE))) || \
  696. (((ADDRESS) >= FLASH_OBK_BASE_NS) && \
  697. ((ADDRESS) < (FLASH_OBK_BASE_NS+FLASH_OBK_SIZE))))
  698. #endif /* FLASH_SR_OBKERR */
  699. #if defined (FLASH_EDATAR_EDATA_EN)
  700. #define IS_FLASH_EDATA_ADDRESS(ADDRESS) ((((ADDRESS) >= FLASH_EDATA_BASE_S) && \
  701. ((ADDRESS) < (FLASH_EDATA_BASE_S+FLASH_EDATA_SIZE))) || \
  702. (((ADDRESS) >= FLASH_EDATA_BASE_NS) && \
  703. ((ADDRESS) < (FLASH_EDATA_BASE_NS+FLASH_EDATA_SIZE))))
  704. #endif /* FLASH_EDATAR_EDATA_EN */
  705. #else
  706. #define IS_FLASH_USER_MEM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && \
  707. ((ADDRESS) < (FLASH_BASE+FLASH_SIZE)))
  708. #if defined (FLASH_SR_OBKERR)
  709. #define IS_FLASH_OBK_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_OBK_BASE) && \
  710. ((ADDRESS) < (FLASH_OBK_BASE + FLASH_OBK_SIZE)))
  711. #endif /* FLASH_SR_OBKERR */
  712. #if defined (FLASH_EDATAR_EDATA_EN)
  713. #define IS_FLASH_EDATA_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_EDATA_BASE_NS) && \
  714. ((ADDRESS) < (FLASH_EDATA_BASE_NS + FLASH_EDATA_SIZE)))
  715. #endif /* FLASH_EDATAR_EDATA_EN */
  716. #endif /* __ARM_FEATURE_CMSE */
  717. #define IS_FLASH_OTP_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_OTP_BASE) && \
  718. ((ADDRESS) < (FLASH_OTP_BASE + FLASH_OTP_SIZE)))
  719. #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1) || \
  720. ((BANK) == FLASH_BANK_2) || \
  721. ((BANK) == FLASH_BANK_BOTH))
  722. #define IS_FLASH_BANK_EXCLUSIVE(BANK) (((BANK) == FLASH_BANK_1) || \
  723. ((BANK) == FLASH_BANK_2))
  724. #define IS_FLASH_SECTOR(SECTOR) ((SECTOR) < FLASH_SECTOR_NB)
  725. #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_LATENCY_0) || \
  726. ((LATENCY) == FLASH_LATENCY_1) || \
  727. ((LATENCY) == FLASH_LATENCY_2) || \
  728. ((LATENCY) == FLASH_LATENCY_3) || \
  729. ((LATENCY) == FLASH_LATENCY_4) || \
  730. ((LATENCY) == FLASH_LATENCY_5) || \
  731. ((LATENCY) == FLASH_LATENCY_6) || \
  732. ((LATENCY) == FLASH_LATENCY_7) || \
  733. ((LATENCY) == FLASH_LATENCY_8) || \
  734. ((LATENCY) == FLASH_LATENCY_9) || \
  735. ((LATENCY) == FLASH_LATENCY_10) || \
  736. ((LATENCY) == FLASH_LATENCY_11) || \
  737. ((LATENCY) == FLASH_LATENCY_12) || \
  738. ((LATENCY) == FLASH_LATENCY_13) || \
  739. ((LATENCY) == FLASH_LATENCY_14) || \
  740. ((LATENCY) == FLASH_LATENCY_15))
  741. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
  742. #define IS_FLASH_SECURE_OPERATION() ((pFlash.ProcedureOnGoing & FLASH_NON_SECURE_MASK) == 0U)
  743. #else
  744. #define IS_FLASH_SECURE_OPERATION() (1U == 0U)
  745. #endif /* __ARM_FEATURE_CMSE */
  746. /**
  747. * @}
  748. */
  749. /* Private functions ---------------------------------------------------------*/
  750. /** @defgroup FLASH_Private_Functions FLASH Private Functions
  751. * @{
  752. */
  753. HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
  754. /**
  755. * @}
  756. */
  757. /**
  758. * @}
  759. */
  760. /**
  761. * @}
  762. */
  763. #ifdef __cplusplus
  764. }
  765. #endif
  766. #endif /* STM32H5xx_HAL_FLASH_H */