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