1 /** 2 ****************************************************************************** 3 * @file stm32wbaxx_hal_flash_ex.h 4 * @author MCD Application Team 5 * @brief Header file of FLASH HAL Extended module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2022 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 STM32WBAxx_HAL_FLASH_EX_H 21 #define STM32WBAxx_HAL_FLASH_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32wbaxx_hal_def.h" 29 30 /** @addtogroup STM32WBAxx_HAL_Driver 31 * @{ 32 */ 33 34 /** @addtogroup FLASHEx 35 * @{ 36 */ 37 38 /* Private constants ---------------------------------------------------------*/ 39 /** @defgroup FLASHEx_Private_Constants FLASH Extended Private Constants 40 * @{ 41 */ 42 #if defined(FLASH_SECBBR1_SECBB0) || defined(FLASH_PRIVBBR1_PRIVBB0) || defined(FLASH_SECBB1R1_SECBB0) || defined(FLASH_PRIVBB1R1_PRIVBB0) 43 #define FLASH_BLOCKBASED_NB_REG (4U) /*!< Number of block-based registers available */ 44 #endif /* FLASH_SECBBR1_SECBB0 || FLASH_PRIVBBR1_PRIVBB0 */ 45 /** 46 * @} 47 */ 48 49 /* Exported types ------------------------------------------------------------*/ 50 /** @defgroup FLASHEx_Exported_Types FLASH Exported Types 51 * @{ 52 */ 53 54 #if defined(FLASH_SECBBR1_SECBB0) || defined(FLASH_PRIVBBR1_PRIVBB0) || defined(FLASH_SECBB1R1_SECBB0) || defined(FLASH_PRIVBB1R1_PRIVBB0) 55 /** 56 * @brief FLASHEx Block-based attributes structure definition 57 */ 58 typedef struct 59 { 60 uint32_t BBAttributesType; /*!< Block-Based Attributes type. 61 This parameter must be a value of @ref FLASHEx_BB_Attributes */ 62 uint32_t BBAttributes_array[FLASH_BLOCKBASED_NB_REG]; /*!< Each bit specifies the block-based attribute configuration of a page: 63 0 means page non-protected, 1 means page protected. 64 Protection (secure or privilege) depends on BBAttributesType value */ 65 } FLASH_BBAttributesTypeDef; 66 #endif /* FLASH_SECBBR1_SECBB0 || FLASH_PRIVBBR1_PRIVBB0 */ 67 68 69 /** 70 * @brief FLASHEx Operation structure definition 71 */ 72 typedef struct 73 { 74 uint32_t OperationType; /*!< Flash operation Type. 75 This parameter must be a value of @ref FLASHEx_Operation_Type */ 76 uint32_t FlashArea; /*!< Flash operation memory area. 77 This parameter must be a value of FLASH_Operation_Area */ 78 uint32_t Address; /*!< Flash operation Address offset. 79 This parameter is given by bank, and must be a value between 0x0 and 0xFFFF0 */ 80 } FLASH_OperationTypeDef; 81 82 /** 83 * @brief FLASH ECC information structure definition 84 */ 85 typedef struct 86 { 87 uint32_t Area; /*!< Area from which an ECC was detected. 88 This parameter can be a value of @ref FLASHEx_ECC_Area */ 89 uint32_t Address; /*!< Flash address from which en ECC error was detected. 90 This parameter must be a value between begin address and end address of the Flash */ 91 uint32_t MasterID; /*!< Master that initiated transfer on which error was detected 92 This parameter can be a value of @ref FLASHEx_ECC_Master */ 93 } FLASH_EccInfoTypeDef; 94 95 /** 96 * @} 97 */ 98 99 /* Exported constants --------------------------------------------------------*/ 100 /** @defgroup FLASHEx_Exported_Constants FLASH Extended Exported Constants 101 * @{ 102 */ 103 104 #if defined(FLASH_PRIVCFGR_SPRIV) 105 /** @defgroup FLASHEx_PRIV_MODE_CFG FLASH privilege mode configuration 106 * @{ 107 */ 108 #define FLASH_NSPRIV_GRANTED 0x00000000U /*!< access to non-secure Flash registers is granted to privileged or unprivileged access */ 109 #define FLASH_NSPRIV_DENIED FLASH_PRIVCFGR_NSPRIV /*!< access to non-secure Flash registers is denied to non-privilege access */ 110 111 #define FLASH_SPRIV_GRANTED 0x00000000U /*!< access to secure Flash registers is granted to privileged or unprivileged access */ 112 #define FLASH_SPRIV_DENIED FLASH_PRIVCFGR_SPRIV /*!< access to secure Flash registers is denied to non-privilege access */ 113 /** 114 * @} 115 */ 116 #endif /* FLASH_PRIVCFGR_SPRIV */ 117 118 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 119 /** @defgroup FLASHEx_SEC_INVERSION_CFG FLASH security inversion configuration 120 * @{ 121 */ 122 #define FLASH_INV_DISABLE 0x00000000U /*!< Security state of Flash is not inverted */ 123 #define FLASH_INV_ENABLE FLASH_SECCR1_INV /*!< Security state of Flash is inverted */ 124 /** 125 * @} 126 */ 127 #endif /* __ARM_FEATURE_CMSE */ 128 129 /** @defgroup FLASHEx_LPM_CFG FLASH LPM configuration 130 * @{ 131 */ 132 #define FLASH_LPM_DISABLE 0x00000000U /*!< Flash is in normal read mode */ 133 #define FLASH_LPM_ENABLE FLASH_ACR_LPM /*!< Flash is in low-power read mode */ 134 /** 135 * @} 136 */ 137 138 #if defined(FLASH_SECBBR1_SECBB0) || defined(FLASH_PRIVBBR1_PRIVBB0) || defined(FLASH_SECBB1R1_SECBB0) || defined(FLASH_PRIVBB1R1_PRIVBB0) 139 /** @defgroup FLASHEx_BB_Attributes FLASH Block-Based Attributes 140 * @{ 141 */ 142 #define FLASH_BB_SEC 0x00000001U /*!< Flash Block-Based Security Attributes */ 143 #define FLASH_BB_PRIV 0x00000002U /*!< Flash Block-Based Privilege Attributes */ 144 /** 145 * @} 146 */ 147 #endif /* FLASH_SECBBR1_SECBB0 || FLASH_PRIVBBR1_PRIVBB0 */ 148 149 /** @defgroup FLASHEx_Operation_Type FLASH Operation Type 150 * @{ 151 */ 152 #define FLASH_OPERATION_TYPE_NONE 00000000U /*!< No Flash operation */ 153 #define FLASH_OPERATION_TYPE_QUADWORD FLASH_OPSR_CODE_OP_0 /*!< Single write operation */ 154 #define FLASH_OPERATION_TYPE_BURST FLASH_OPSR_CODE_OP_1 /*!< Burst write operation */ 155 #define FLASH_OPERATION_TYPE_PAGEERASE (FLASH_OPSR_CODE_OP_1 | FLASH_OPSR_CODE_OP_0) /*!< Page erase operation */ 156 #define FLASH_OPERATION_TYPE_MASSERASE (FLASH_OPSR_CODE_OP_2 | FLASH_OPSR_CODE_OP_0) /*!< Mass erase operation */ 157 #define FLASH_OPERATION_TYPE_OPTIONCHANGE (FLASH_OPSR_CODE_OP_2 | FLASH_OPSR_CODE_OP_1) /*!< Option change operation */ 158 /** 159 * @} 160 */ 161 162 163 /** @defgroup FLASHEx_ECC_Area FLASH ECC Area 164 * @{ 165 */ 166 #define FLASH_ECC_AREA_USER_BANK1 0x00000000U /*!< FLASH bank 1 area */ 167 #define FLASH_ECC_AREA_SYSTEM FLASH_ECCR_SYSF_ECC /*!< System FLASH area */ 168 /** 169 * @} 170 */ 171 172 /** @defgroup FLASHEx_ECC_Master FLASH ECC Master 173 * @{ 174 */ 175 #define FLASH_ECC_MASTER_CPU1 0x00000000U /*!< ECC error occurs on a CPU1 transaction */ 176 /** 177 * @} 178 */ 179 180 /** @defgroup FLASHEx_Suspend_Request FLASH Suspend Request 181 * @{ 182 */ 183 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 184 #define FLASH_SUSPEND_PROGRAM FLASH_SECCR2_PS /*!< Suspend all program requests */ 185 #define FLASH_SUSPEND_ERASE FLASH_SECCR2_ES /*!< Suspend all erase requests */ 186 #define FLASH_SUSPEND_PROGRAM_ERASE (FLASH_SECCR2_PS | FLASH_SECCR2_ES) /*!< Suspend all requests (program and erase) */ 187 #else 188 #define FLASH_SUSPEND_PROGRAM FLASH_NSCR2_PS /*!< Suspend all program requests */ 189 #define FLASH_SUSPEND_ERASE FLASH_NSCR2_ES /*!< Suspend all erase requests */ 190 #define FLASH_SUSPEND_PROGRAM_ERASE (FLASH_NSCR2_PS | FLASH_NSCR2_ES) /*!< Suspend all requests (program and erase) */ 191 #endif /* __ARM_FEATURE_CMSE */ 192 /** 193 * @} 194 */ 195 196 /** @defgroup FLASHEx_Allow_Request FLASH Allow Request 197 * @{ 198 */ 199 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 200 #define FLASH_ALLOW_PROGRAM FLASH_SECCR2_PS /*!< Allow all program requests */ 201 #define FLASH_ALLOW_ERASE FLASH_SECCR2_ES /*!< Allow all erase requests */ 202 #define FLASH_ALLOW_PROGRAM_ERASE (FLASH_SECCR2_PS | FLASH_SECCR2_ES) /*!< Allow all requests (program and erase) */ 203 #else 204 #define FLASH_ALLOW_PROGRAM FLASH_NSCR2_PS /*!< Allow all program requests */ 205 #define FLASH_ALLOW_ERASE FLASH_NSCR2_ES /*!< Allow all erase requests */ 206 #define FLASH_ALLOW_PROGRAM_ERASE (FLASH_NSCR2_PS | FLASH_NSCR2_ES) /*!< Allow all requests (program and erase) */ 207 #endif /* __ARM_FEATURE_CMSE */ 208 /** 209 * @} 210 */ 211 212 /** 213 * @} 214 */ 215 216 /* Exported macro ------------------------------------------------------------*/ 217 218 /* Exported functions --------------------------------------------------------*/ 219 /** @addtogroup FLASHEx_Exported_Functions 220 * @{ 221 */ 222 223 /* Extended Program operation functions *************************************/ 224 /** @addtogroup FLASHEx_Exported_Functions_Group1 225 * @{ 226 */ 227 HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError); 228 HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit); 229 HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit); 230 void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit); 231 #if defined(FLASH_SECBBR1_SECBB0) || defined(FLASH_PRIVBBR1_PRIVBB0) || defined(FLASH_SECBB1R1_SECBB0) || defined(FLASH_PRIVBB1R1_PRIVBB0) 232 HAL_StatusTypeDef HAL_FLASHEx_ConfigBBAttributes(FLASH_BBAttributesTypeDef *pBBAttributes); 233 void HAL_FLASHEx_GetConfigBBAttributes(FLASH_BBAttributesTypeDef *pBBAttributes); 234 #endif /* FLASH_SECBBR1_SECBB0 || FLASH_PRIVBBR1_PRIVBB0 */ 235 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 236 void HAL_FLASHEx_EnableSecHideProtection(uint32_t Banks); 237 #endif /* __ARM_FEATURE_CMSE */ 238 /** 239 * @} 240 */ 241 242 /** @addtogroup FLASHEx_Exported_Functions_Group2 243 * @{ 244 */ 245 void HAL_FLASHEx_SuspendOperation(uint32_t Request); 246 void HAL_FLASHEx_AllowOperation(uint32_t Request); 247 uint32_t HAL_FLASHEx_IsOperationSuspended(void); 248 #if defined(FLASH_PRIVCFGR_SPRIV) 249 void HAL_FLASHEx_ConfigPrivMode(uint32_t PrivMode); 250 uint32_t HAL_FLASHEx_GetPrivMode(void); 251 #endif /* FLASH_PRIVCFGR_SPRIV */ 252 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 253 HAL_StatusTypeDef HAL_FLASHEx_ConfigSecInversion(uint32_t SecInvState); 254 uint32_t HAL_FLASHEx_GetSecInversion(void); 255 #endif /* __ARM_FEATURE_CMSE */ 256 HAL_StatusTypeDef HAL_FLASHEx_EnablePowerDown(void); 257 HAL_StatusTypeDef HAL_FLASHEx_ConfigLowPowerRead(uint32_t ConfigLPM); 258 uint32_t HAL_FLASHEx_GetLowPowerRead(void); 259 void HAL_FLASHEx_GetOperation(FLASH_OperationTypeDef *pFlashOperation); 260 /** 261 * @} 262 */ 263 264 /** @addtogroup FLASHEx_Exported_Functions_Group3 265 * @{ 266 */ 267 void HAL_FLASHEx_EnableEccCorrectionInterrupt(void); 268 void HAL_FLASHEx_DisableEccCorrectionInterrupt(void); 269 void HAL_FLASHEx_GetEccInfo(FLASH_EccInfoTypeDef *pData); 270 void HAL_FLASHEx_ECCD_IRQHandler(void); 271 __weak void HAL_FLASHEx_EccDetectionCallback(void); 272 __weak void HAL_FLASHEx_EccCorrectionCallback(void); 273 /** 274 * @} 275 */ 276 277 /** 278 * @} 279 */ 280 281 /* Private function ----------------------------------------------------------*/ 282 /** @addtogroup FLASHEx_Private_Functions FLASHEx Private Functions 283 * @{ 284 */ 285 void FLASH_PageErase(uint32_t Page); 286 /** 287 * @} 288 */ 289 290 /* Private macros ------------------------------------------------------------*/ 291 /** @defgroup FLASHEx_Private_Macros FLASH Private Macros 292 * @{ 293 */ 294 #define IS_FLASH_BB_EXCLUSIVE(CFG) (((CFG) == FLASH_BB_SEC) || \ 295 ((CFG) == FLASH_BB_PRIV)) 296 297 #define IS_FLASH_CFGPRIVMODE(CFG) (((CFG) & 0xFFFFFFFCU) == 0U) 298 299 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 300 #define IS_FLASH_CFGSECINV(CFG) (((CFG) == FLASH_INV_DISABLE) || \ 301 ((CFG) == FLASH_INV_ENABLE)) 302 #endif /* __ARM_FEATURE_CMSE */ 303 304 #define IS_FLASH_CFGLPM(CFG) (((CFG) == FLASH_LPM_DISABLE) || \ 305 ((CFG) == FLASH_LPM_ENABLE)) 306 307 308 #define IS_FLASH_SUSPEND_REQ(VALUE) (((VALUE) == FLASH_SUSPEND_PROGRAM) || \ 309 ((VALUE) == FLASH_SUSPEND_ERASE) || \ 310 ((VALUE) == FLASH_SUSPEND_PROGRAM_ERASE)) 311 312 #define IS_FLASH_ALLOW_REQ(VALUE) (((VALUE) == FLASH_ALLOW_PROGRAM) || \ 313 ((VALUE) == FLASH_ALLOW_ERASE) || \ 314 ((VALUE) == FLASH_ALLOW_PROGRAM_ERASE)) 315 /** 316 * @} 317 */ 318 319 /** 320 * @} 321 */ 322 323 /** 324 * @} 325 */ 326 327 #ifdef __cplusplus 328 } 329 #endif 330 331 #endif /* STM32WBAxx_HAL_FLASH_EX_H */ 332