1 /** 2 ****************************************************************************** 3 * @file stm32u5xx_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) 2021 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software component is licensed by ST under BSD 3-Clause license, 13 * the "License"; You may not use this file except in compliance with the 14 * License. You may obtain a copy of the License at: 15 * opensource.org/licenses/BSD-3-Clause 16 * 17 ****************************************************************************** 18 */ 19 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef STM32U5xx_HAL_FLASH_EX_H 22 #define STM32U5xx_HAL_FLASH_EX_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Includes ------------------------------------------------------------------*/ 29 #include "stm32u5xx_hal_def.h" 30 31 /** @addtogroup STM32U5xx_HAL_Driver 32 * @{ 33 */ 34 35 /** @addtogroup FLASHEx 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 /** @addtogroup FLASHEx_Exported_Types FLASHEx Exported Types 41 * @{ 42 */ 43 44 /** 45 * @brief FLASHEx Block-based attributes structure definition 46 */ 47 48 typedef struct 49 { 50 uint32_t Bank; /*!< Selection of the associated bank of Block-based Area. 51 This parameter must be a value of @ref FLASH_Banks */ 52 uint32_t BBAttributesType; /*!< Block-Based Attributes type. This parameter must 53 be a value of @ref FLASH_BB_Attributes */ 54 uint32_t BBAttributes_array[FLASH_BLOCKBASED_NB_REG]; /*!< Each bit specifies the block-based attribute configuration 55 of a page: 0 means page non-protected, 1 means page 56 protected. Protection (secure or privilege) depends 57 on BBAttributesType value */ 58 } FLASH_BBAttributesTypeDef; 59 60 61 /** 62 * @brief FLASHEx Operation structure definition 63 */ 64 typedef struct 65 { 66 uint32_t OperationType; /*!< Flash operation Type. 67 This parameter must be a value of @ref FLASH_Operation_Type */ 68 uint32_t FlashArea; /*!< Flash operation memory area. 69 This parameter must be a value of @ref FLASH_Operation_Area */ 70 uint32_t Address; /*!< Flash operation Address offset. 71 This parameter is given by bank, and must be a value between 0x0 and 0xFFFF0 */ 72 } FLASH_OperationTypeDef; 73 74 /** 75 * @} 76 */ 77 78 /* Exported constants --------------------------------------------------------*/ 79 /** @addtogroup FLASHEx_Exported_Constants 80 * @{ 81 */ 82 /** @defgroup PRIV_MODE_CFG FLASH privilege mode configuration 83 * @{ 84 */ 85 #define FLASH_NSPRIV_GRANTED 0x00000000U /*!< access to non-secure Flash registers is granted 86 to privileged or unprivileged access */ 87 #define FLASH_NSPRIV_DENIED FLASH_PRIVCFGR_NSPRIV /*!< access to non-secure Flash registers is denied 88 to non-privilege access */ 89 #define FLASH_SPRIV_GRANTED 0x00000000U /*!< access to secure Flash registers is granted to privileged 90 or unprivileged access */ 91 #define FLASH_SPRIV_DENIED FLASH_PRIVCFGR_SPRIV /*!< access to secure Flash registers is denied 92 to non-privilege access */ 93 /** 94 * @} 95 */ 96 97 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 98 /** @defgroup SEC_INVERSION_CFG FLASH security inversion configuration 99 * @{ 100 */ 101 #define FLASH_INV_DISABLE 0x00000000U /*!< Security state of Flash is not inverted */ 102 #define FLASH_INV_ENABLE FLASH_SECCR_INV /*!< Security state of Flash is inverted */ 103 /** 104 * @} 105 */ 106 #endif /* __ARM_FEATURE_CMSE */ 107 108 /** @defgroup FLASH_LPM_CFG FLASH LPM configuration 109 * @{ 110 */ 111 #define FLASH_LPM_DISABLE 0x00000000U /*!< Flash is in normal read mode */ 112 #define FLASH_LPM_ENABLE FLASH_ACR_LPM /*!< Flash is in low-power read mode */ 113 /** 114 * @} 115 */ 116 117 /** @defgroup FLASH_BB_Attributes FLASH Block-Base Attributes 118 * @{ 119 */ 120 #define FLASH_BB_SEC 0x01U /*!< Flash Block-Based Security Attributes */ 121 #define FLASH_BB_PRIV 0x02U /*!< Flash Block-Based Privilege Attributes */ 122 /** 123 * @} 124 */ 125 126 /** @defgroup FLASH_Operation_Type FLASH Operation Type 127 * @{ 128 */ 129 #define FLASH_OPERATION_TYPE_NONE 00000000U /*!< No Flash operation */ 130 #define FLASH_OPERATION_TYPE_QUADWORD FLASH_OPSR_CODE_OP_0 /*!< Single write operation */ 131 #define FLASH_OPERATION_TYPE_BURST FLASH_OPSR_CODE_OP_1 /*!< Burst write operation */ 132 #define FLASH_OPERATION_TYPE_PAGEERASE (FLASH_OPSR_CODE_OP_1 | FLASH_OPSR_CODE_OP_0) /*!< Page erase operation */ 133 #define FLASH_OPERATION_TYPE_BANKERASE FLASH_OPSR_CODE_OP_2 /*!< Bank erase operation */ 134 #define FLASH_OPERATION_TYPE_MASSERASE (FLASH_OPSR_CODE_OP_2 | FLASH_OPSR_CODE_OP_0) /*!< Mass erase operation */ 135 #define FLASH_OPERATION_TYPE_OPTIONCHANGE (FLASH_OPSR_CODE_OP_2 | FLASH_OPSR_CODE_OP_1) /*!< Option change operation */ 136 /** 137 * @} 138 */ 139 140 /** @defgroup FLASH_Operation_Area FLASH Operation Area 141 * @{ 142 */ 143 #define FLASH_OPERATION_AREA_BANK_1 00000000U /*!< Operation in Bank 1 */ 144 #define FLASH_OPERATION_AREA_BANK_2 FLASH_OPSR_BK_OP /*!< Operation in Bank 2 */ 145 #define FLASH_OPERATION_AREA_SYSF FLASH_OPSR_SYSF_OP /*!< Operation in System Flash memory */ 146 /** 147 * @} 148 */ 149 150 /** 151 * @} 152 */ 153 154 /* Exported macro ------------------------------------------------------------*/ 155 156 /* Exported functions --------------------------------------------------------*/ 157 /** @addtogroup FLASHEx_Exported_Functions 158 * @{ 159 */ 160 161 /* Extended Program operation functions *************************************/ 162 /** @addtogroup FLASHEx_Exported_Functions_Group1 163 * @{ 164 */ 165 HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError); 166 HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit); 167 HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit); 168 void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit); 169 HAL_StatusTypeDef HAL_FLASHEx_ConfigBBAttributes(FLASH_BBAttributesTypeDef *pBBAttributes); 170 void HAL_FLASHEx_GetConfigBBAttributes(FLASH_BBAttributesTypeDef *pBBAttributes); 171 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 172 void HAL_FLASHEx_EnableSecHideProtection(uint32_t Banks); 173 #endif /* __ARM_FEATURE_CMSE */ 174 /** 175 * @} 176 */ 177 178 /** @addtogroup FLASHEx_Exported_Functions_Group2 179 * @{ 180 */ 181 void HAL_FLASHEx_ConfigPrivMode(uint32_t PrivMode); 182 uint32_t HAL_FLASHEx_GetPrivMode(void); 183 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 184 HAL_StatusTypeDef HAL_FLASHEx_ConfigSecInversion(uint32_t SecInvState); 185 uint32_t HAL_FLASHEx_GetSecInversion(void); 186 #endif /* __ARM_FEATURE_CMSE */ 187 HAL_StatusTypeDef HAL_FLASHEx_EnablePowerDown(uint32_t Banks); 188 HAL_StatusTypeDef HAL_FLASHEx_ConfigLowPowerRead(uint32_t ConfigLPM); 189 uint32_t HAL_FLASHEx_GetLowPowerRead(void); 190 void HAL_FLASHEx_GetOperation(FLASH_OperationTypeDef *pFlashOperation); 191 /** 192 * @} 193 */ 194 195 /** 196 * @} 197 */ 198 199 /* Private function ----------------------------------------------------------*/ 200 /** @addtogroup FLASHEx_Private_Functions FLASHEx Private Functions 201 * @{ 202 */ 203 void FLASH_PageErase(uint32_t Page, uint32_t Banks); 204 /** 205 * @} 206 */ 207 208 /* Private macros ------------------------------------------------------------*/ 209 /** @defgroup FLASHEx_Private_Macros FLASH Private Macros 210 * @{ 211 */ 212 #define IS_FLASH_BB_EXCLUSIVE(CFG) (((CFG) == FLASH_BB_SEC) || \ 213 ((CFG) == FLASH_BB_PRIV)) 214 215 #define IS_FLASH_CFGPRIVMODE(CFG) (((CFG) & 0xFFFFFFFCU) == 0U) 216 217 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 218 #define IS_FLASH_CFGSECINV(CFG) (((CFG) == FLASH_INV_DISABLE) || \ 219 ((CFG) == FLASH_INV_ENABLE)) 220 #endif /* __ARM_FEATURE_CMSE */ 221 222 #define IS_FLASH_CFGLPM(CFG) (((CFG) == FLASH_LPM_DISABLE) || \ 223 ((CFG) == FLASH_LPM_ENABLE)) 224 /** 225 * @} 226 */ 227 228 /** 229 * @} 230 */ 231 232 /** 233 * @} 234 */ 235 236 #ifdef __cplusplus 237 } 238 #endif 239 240 #endif /* STM32U5xx_HAL_FLASH_EX_H */ 241 242