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) 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) 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 * @brief FLASHEx Operation structure definition 70 */ 71 typedef struct 72 { 73 uint32_t OperationType; /*!< Flash operation Type. 74 This parameter must be a value of @ref FLASHEx_Operation_Type */ 75 uint32_t FlashArea; /*!< Flash operation memory area. 76 This parameter must be a value of FLASH_Operation_Area */ 77 uint32_t Address; /*!< Flash operation Address offset. 78 This parameter is given by bank, and must be a value between 0x0 and 0xFFFF0 */ 79 } FLASH_OperationTypeDef; 80 81 /** 82 * @} 83 */ 84 85 /* Exported constants --------------------------------------------------------*/ 86 /** @defgroup FLASHEx_Exported_Constants FLASH Extended Exported Constants 87 * @{ 88 */ 89 90 #if defined(FLASH_PRIVCFGR_SPRIV) 91 /** @defgroup FLASHEx_PRIV_MODE_CFG FLASH privilege mode configuration 92 * @{ 93 */ 94 #define FLASH_NSPRIV_GRANTED 0x00000000U /*!< access to non-secure Flash registers is granted to privileged or unprivileged access */ 95 #define FLASH_NSPRIV_DENIED FLASH_PRIVCFGR_NSPRIV /*!< access to non-secure Flash registers is denied to non-privilege access */ 96 97 #define FLASH_SPRIV_GRANTED 0x00000000U /*!< access to secure Flash registers is granted to privileged or unprivileged access */ 98 #define FLASH_SPRIV_DENIED FLASH_PRIVCFGR_SPRIV /*!< access to secure Flash registers is denied to non-privilege access */ 99 /** 100 * @} 101 */ 102 #endif /* FLASH_PRIVCFGR_SPRIV */ 103 104 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 105 /** @defgroup FLASHEx_SEC_INVERSION_CFG FLASH security inversion configuration 106 * @{ 107 */ 108 #define FLASH_INV_DISABLE 0x00000000U /*!< Security state of Flash is not inverted */ 109 #define FLASH_INV_ENABLE FLASH_SECCR1_INV /*!< Security state of Flash is inverted */ 110 /** 111 * @} 112 */ 113 #endif /* __ARM_FEATURE_CMSE */ 114 115 /** @defgroup FLASHEx_LPM_CFG FLASH LPM configuration 116 * @{ 117 */ 118 #define FLASH_LPM_DISABLE 0x00000000U /*!< Flash is in normal read mode */ 119 #define FLASH_LPM_ENABLE FLASH_ACR_LPM /*!< Flash is in low-power read mode */ 120 /** 121 * @} 122 */ 123 124 #if defined(FLASH_SECBBR1_SECBB0) || defined(FLASH_PRIVBBR1_PRIVBB0) 125 /** @defgroup FLASHEx_BB_Attributes FLASH Block-Based Attributes 126 * @{ 127 */ 128 #define FLASH_BB_SEC 0x00000001U /*!< Flash Block-Based Security Attributes */ 129 #define FLASH_BB_PRIV 0x00000002U /*!< Flash Block-Based Privilege Attributes */ 130 /** 131 * @} 132 */ 133 #endif /* FLASH_SECBBR1_SECBB0 || FLASH_PRIVBBR1_PRIVBB0 */ 134 135 /** @defgroup FLASHEx_Operation_Type FLASH Operation Type 136 * @{ 137 */ 138 #define FLASH_OPERATION_TYPE_NONE 00000000U /*!< No Flash operation */ 139 #define FLASH_OPERATION_TYPE_QUADWORD FLASH_OPSR_CODE_OP_0 /*!< Single write operation */ 140 #define FLASH_OPERATION_TYPE_BURST FLASH_OPSR_CODE_OP_1 /*!< Burst write operation */ 141 #define FLASH_OPERATION_TYPE_PAGEERASE (FLASH_OPSR_CODE_OP_1 | FLASH_OPSR_CODE_OP_0) /*!< Page erase operation */ 142 #define FLASH_OPERATION_TYPE_MASSERASE (FLASH_OPSR_CODE_OP_2 | FLASH_OPSR_CODE_OP_0) /*!< Mass erase operation */ 143 #define FLASH_OPERATION_TYPE_OPTIONCHANGE (FLASH_OPSR_CODE_OP_2 | FLASH_OPSR_CODE_OP_1) /*!< Option change operation */ 144 /** 145 * @} 146 */ 147 148 /** @defgroup FLASHEx_Suspend_Request FLASH Suspend Request 149 * @{ 150 */ 151 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 152 #define FLASH_SUSPEND_PROGRAM FLASH_SECCR2_PS /*!< Suspend all program requests */ 153 #define FLASH_SUSPEND_ERASE FLASH_SECCR2_ES /*!< Suspend all erase requests */ 154 #define FLASH_SUSPEND_PROGRAM_ERASE (FLASH_SECCR2_PS | FLASH_SECCR2_ES) /*!< Suspend all requests (program and erase) */ 155 #else 156 #define FLASH_SUSPEND_PROGRAM FLASH_NSCR2_PS /*!< Suspend all program requests */ 157 #define FLASH_SUSPEND_ERASE FLASH_NSCR2_ES /*!< Suspend all erase requests */ 158 #define FLASH_SUSPEND_PROGRAM_ERASE (FLASH_NSCR2_PS | FLASH_NSCR2_ES) /*!< Suspend all requests (program and erase) */ 159 #endif /* __ARM_FEATURE_CMSE */ 160 /** 161 * @} 162 */ 163 164 /** @defgroup FLASHEx_Allow_Request FLASH Allow Request 165 * @{ 166 */ 167 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 168 #define FLASH_ALLOW_PROGRAM FLASH_SECCR2_PS /*!< Allow all program requests */ 169 #define FLASH_ALLOW_ERASE FLASH_SECCR2_ES /*!< Allow all erase requests */ 170 #define FLASH_ALLOW_PROGRAM_ERASE (FLASH_SECCR2_PS | FLASH_SECCR2_ES) /*!< Allow all requests (program and erase) */ 171 #else 172 #define FLASH_ALLOW_PROGRAM FLASH_NSCR2_PS /*!< Allow all program requests */ 173 #define FLASH_ALLOW_ERASE FLASH_NSCR2_ES /*!< Allow all erase requests */ 174 #define FLASH_ALLOW_PROGRAM_ERASE (FLASH_NSCR2_PS | FLASH_NSCR2_ES) /*!< Allow all requests (program and erase) */ 175 #endif /* __ARM_FEATURE_CMSE */ 176 /** 177 * @} 178 */ 179 180 /** 181 * @} 182 */ 183 184 /* Exported macro ------------------------------------------------------------*/ 185 186 /* Exported functions --------------------------------------------------------*/ 187 /** @addtogroup FLASHEx_Exported_Functions 188 * @{ 189 */ 190 191 /* Extended Program operation functions *************************************/ 192 /** @addtogroup FLASHEx_Exported_Functions_Group1 193 * @{ 194 */ 195 HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError); 196 HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit); 197 HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit); 198 void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit); 199 #if defined(FLASH_SECBBR1_SECBB0) || defined(FLASH_PRIVBBR1_PRIVBB0) 200 HAL_StatusTypeDef HAL_FLASHEx_ConfigBBAttributes(FLASH_BBAttributesTypeDef *pBBAttributes); 201 void HAL_FLASHEx_GetConfigBBAttributes(FLASH_BBAttributesTypeDef *pBBAttributes); 202 #endif /* FLASH_SECBBR1_SECBB0 || FLASH_PRIVBBR1_PRIVBB0 */ 203 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 204 void HAL_FLASHEx_EnableSecHideProtection(uint32_t Banks); 205 #endif /* __ARM_FEATURE_CMSE */ 206 /** 207 * @} 208 */ 209 210 /** @addtogroup FLASHEx_Exported_Functions_Group2 211 * @{ 212 */ 213 void HAL_FLASHEx_SuspendOperation(uint32_t Request); 214 void HAL_FLASHEx_AllowOperation(uint32_t Request); 215 uint32_t HAL_FLASHEx_IsOperationSuspended(void); 216 #if defined(FLASH_PRIVCFGR_SPRIV) 217 void HAL_FLASHEx_ConfigPrivMode(uint32_t PrivMode); 218 uint32_t HAL_FLASHEx_GetPrivMode(void); 219 #endif /* FLASH_PRIVCFGR_SPRIV */ 220 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 221 HAL_StatusTypeDef HAL_FLASHEx_ConfigSecInversion(uint32_t SecInvState); 222 uint32_t HAL_FLASHEx_GetSecInversion(void); 223 #endif /* __ARM_FEATURE_CMSE */ 224 HAL_StatusTypeDef HAL_FLASHEx_EnablePowerDown(void); 225 HAL_StatusTypeDef HAL_FLASHEx_ConfigLowPowerRead(uint32_t ConfigLPM); 226 uint32_t HAL_FLASHEx_GetLowPowerRead(void); 227 void HAL_FLASHEx_GetOperation(FLASH_OperationTypeDef *pFlashOperation); 228 /** 229 * @} 230 */ 231 232 /** 233 * @} 234 */ 235 236 /* Private function ----------------------------------------------------------*/ 237 /** @addtogroup FLASHEx_Private_Functions FLASHEx Private Functions 238 * @{ 239 */ 240 void FLASH_PageErase(uint32_t Page); 241 /** 242 * @} 243 */ 244 245 /* Private macros ------------------------------------------------------------*/ 246 /** @defgroup FLASHEx_Private_Macros FLASH Private Macros 247 * @{ 248 */ 249 #define IS_FLASH_BB_EXCLUSIVE(CFG) (((CFG) == FLASH_BB_SEC) || \ 250 ((CFG) == FLASH_BB_PRIV)) 251 252 #define IS_FLASH_CFGPRIVMODE(CFG) (((CFG) & 0xFFFFFFFCU) == 0U) 253 254 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 255 #define IS_FLASH_CFGSECINV(CFG) (((CFG) == FLASH_INV_DISABLE) || \ 256 ((CFG) == FLASH_INV_ENABLE)) 257 #endif /* __ARM_FEATURE_CMSE */ 258 259 #define IS_FLASH_CFGLPM(CFG) (((CFG) == FLASH_LPM_DISABLE) || \ 260 ((CFG) == FLASH_LPM_ENABLE)) 261 262 #define IS_FLASH_SUSPEND_REQ(VALUE) (((VALUE) == FLASH_SUSPEND_PROGRAM) || \ 263 ((VALUE) == FLASH_SUSPEND_ERASE) || \ 264 ((VALUE) == FLASH_SUSPEND_PROGRAM_ERASE)) 265 266 #define IS_FLASH_ALLOW_REQ(VALUE) (((VALUE) == FLASH_ALLOW_PROGRAM) || \ 267 ((VALUE) == FLASH_ALLOW_ERASE) || \ 268 ((VALUE) == FLASH_ALLOW_PROGRAM_ERASE)) 269 /** 270 * @} 271 */ 272 273 /** 274 * @} 275 */ 276 277 /** 278 * @} 279 */ 280 281 #ifdef __cplusplus 282 } 283 #endif 284 285 #endif /* STM32WBAxx_HAL_FLASH_EX_H */ 286