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