1 /**
2   ******************************************************************************
3   * @file    stm32l5xx_hal_flash_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of FLASH HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10   * All rights reserved.</center></h2>
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 STM32L5xx_HAL_FLASH_EX_H
22 #define STM32L5xx_HAL_FLASH_EX_H
23 
24 #ifdef __cplusplus
25  extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32l5xx_hal_def.h"
30 
31 /** @addtogroup STM32L5xx_HAL_Driver
32   * @{
33   */
34 
35 /** @addtogroup FLASHEx
36   * @{
37   */
38 
39 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
40 /* Private constants ---------------------------------------------------------*/
41 /** @defgroup FLASHEx_Private_Constants FLASH Extended Private Constants
42   * @{
43   */
44 #define FLASH_BLOCKBASED_NB_REG (4U) /*!< Number of block-based registers available */
45 /**
46   * @}
47   */
48 
49 /* Exported types ------------------------------------------------------------*/
50 /** @defgroup FLASHEx_Exported_Types FLASH Exported Types
51   * @{
52   */
53 
54 /**
55   * @brief  FLASH Block-based security structure definition
56   */
57 typedef struct
58 {
59   uint32_t Bank;                                        /*!< Configuration of the associated bank of Block-based Secure Area.
60                                                             This parameter must be a value of @ref FLASH_Banks */
61   uint32_t BBAttributesType;                            /*!< Block-Based Attributes type.
62                                                              This parameter must be a value of @ref FLASHEx_BB_Attributes */
63   uint32_t BBAttributes_array[FLASH_BLOCKBASED_NB_REG]; /*!< Each bit specifies the block-based attribute configuration of a page.
64                                                              0 means non-secure, 1 means secure */
65 } FLASH_BBAttributesTypeDef;
66 /**
67   * @}
68   */
69 #endif
70 
71 /* Exported constants --------------------------------------------------------*/
72 /** @defgroup FLASHEx_Exported_Constants FLASH Extended Exported Constants
73   * @{
74   */
75 
76 /** @defgroup FLASHEx_PRIV_MODE_CFG FLASH privilege mode configuration
77   * @{
78   */
79 #define FLASH_PRIV_GRANTED   0x00000000U          /*!< access to Flash registers is granted */
80 #define FLASH_PRIV_DENIED    FLASH_PRIVCFGR_PRIV /*!< access to Flash registers is denied to non-privilege access */
81 /**
82   * @}
83   */
84 
85 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
86 /** @defgroup FLASHEx_SEC_INVERSION_CFG FLASH security inversion configuration
87   * @{
88   */
89 #define FLASH_INV_DISABLE    0x00000000U        /*!< Security state of Flash is not inverted */
90 #define FLASH_INV_ENABLE     FLASH_SECCR_SECINV /*!< Security state of Flash is inverted */
91 /**
92   * @}
93   */
94 #endif
95 
96 /** @defgroup FLASHEx_LVE_PIN_CFG FLASH LVE pin configuration
97   * @{
98   */
99 #define FLASH_LVE_PIN_CTRL   0x00000000U       /*!< LVEA/B FLASH pin controlled by power controller */
100 #define FLASH_LVE_PIN_FORCED FLASH_ACR_LVEN    /*!< LVEA/B FLASH pin enforced to low */
101 /**
102   * @}
103   */
104 
105 /** @defgroup FLASHEx_BB_Attributes FLASH Block-Based Attributes
106   * @{
107   */
108 #define FLASH_BB_SEC         0x00000001U       /*!< Flash Block-Based Security Attributes */
109 /**
110   * @}
111   */
112 
113 /**
114   * @}
115   */
116 
117 /* Exported macro ------------------------------------------------------------*/
118 
119 /* Exported functions --------------------------------------------------------*/
120 /** @addtogroup FLASHEx_Exported_Functions
121   * @{
122   */
123 
124 /* Extended Program operation functions  *************************************/
125 /** @addtogroup FLASHEx_Exported_Functions_Group1
126   * @{
127   */
128 HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError);
129 HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit);
130 HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
131 void              HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit);
132 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
133 HAL_StatusTypeDef HAL_FLASHEx_ConfigBBAttributes(FLASH_BBAttributesTypeDef *pBBAttributes);
134 void              HAL_FLASHEx_GetConfigBBAttributes(FLASH_BBAttributesTypeDef *pBBAttributes);
135 void              HAL_FLASHEx_EnableSecHideProtection(uint32_t Banks);
136 #endif
137 /**
138   * @}
139   */
140 
141 /* Extended Peripheral Control functions  ************************************/
142 /** @addtogroup FLASHEx_Exported_Functions_Group2
143   * @{
144   */
145 void              HAL_FLASHEx_ConfigPrivMode(uint32_t PrivMode);
146 uint32_t          HAL_FLASHEx_GetPrivMode(void);
147 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
148 HAL_StatusTypeDef HAL_FLASHEx_ConfigSecInversion(uint32_t SecInvState);
149 uint32_t          HAL_FLASHEx_GetSecInversion(void);
150 #endif
151 HAL_StatusTypeDef HAL_FLASHEx_ConfigLVEPin(uint32_t ConfigLVE);
152 uint32_t          HAL_FLASHEx_GetLVEPin(void);
153 /**
154   * @}
155   */
156 
157 /**
158   * @}
159   */
160 
161 /* Private function ----------------------------------------------------------*/
162 /** @addtogroup FLASHEx_Private_Functions FLASHEx Private Functions
163  * @{
164  */
165 void FLASH_PageErase(uint32_t Page, uint32_t Banks);
166 /**
167   * @}
168   */
169 
170 /* Private macros ------------------------------------------------------------*/
171 /** @defgroup FLASHEx_Private_Macros FLASH Extended Private Macros
172  *  @{
173  */
174 #define IS_FLASH_CFGPRIVMODE(CFG)          (((CFG) == FLASH_PRIV_GRANTED) || \
175                                             ((CFG) == FLASH_PRIV_DENIED))
176 
177 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
178 #define IS_FLASH_CFGSECINV(CFG)            (((CFG) == FLASH_INV_DISABLE) || \
179                                             ((CFG) == FLASH_INV_ENABLE))
180 #endif
181 
182 #define IS_FLASH_CFGLVEPIN(CFG)            (((CFG) == FLASH_LVE_PIN_CTRL) || \
183                                             ((CFG) == FLASH_LVE_PIN_FORCED))
184 
185 /**
186   * @}
187   */
188 
189 /**
190   * @}
191   */
192 
193 /**
194   * @}
195   */
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 
201 #endif /* STM32L5xx_HAL_FLASH_EX_H */
202 
203 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
204