1 /**
2   ******************************************************************************
3   * @file    stm32h5xx_hal_flash.h
4   * @author  MCD Application Team
5   * @brief   Header file of FLASH HAL 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 STM32H5xx_HAL_FLASH_H
21 #define STM32H5xx_HAL_FLASH_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32h5xx_hal_def.h"
29 
30 /** @addtogroup STM32H5xx_HAL_Driver
31   * @{
32   */
33 
34 /** @addtogroup FLASH
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /** @defgroup FLASH_Exported_Types FLASH Exported Types
40   * @{
41   */
42 
43 /**
44   * @brief  FLASH handle Structure definition
45   */
46 typedef struct
47 {
48   HAL_LockTypeDef        Lock;               /*!< FLASH locking object                                                */
49 
50   uint32_t               ErrorCode;          /*!< FLASH error code                                                    */
51 
52   uint32_t               ProcedureOnGoing;   /*!< Internal variable to indicate which procedure is ongoing or not
53                                                   in IT context */
54 
55   uint32_t               Address;            /*!< Internal variable to save address selected for program              */
56 
57   uint32_t               Bank;               /*!< Internal variable to save current bank selected during erase in
58                                                   IT context */
59 
60   uint32_t               Sector;             /*!< Internal variable to define the current sector which is erasing     */
61 
62   uint32_t               NbSectorsToErase;   /*!< Internal variable to save the remaining sectors to erase in
63                                                   IT context  */
64 
65 } FLASH_ProcessTypeDef;
66 
67 /**
68   * @}
69   */
70 
71 /* Exported constants --------------------------------------------------------*/
72 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
73   * @{
74   */
75 
76 /** @defgroup FLASH_Flag_definition FLASH Flag definition
77   * @brief Flag definition
78   * @{
79   */
80 #define FLASH_FLAG_BSY                     FLASH_SR_BSY             /*!< FLASH Busy flag */
81 #define FLASH_FLAG_WBNE                    FLASH_SR_WBNE            /*!< FLASH Write Buffer Not Empty flag */
82 #define FLASH_FLAG_DBNE                    FLASH_SR_DBNE            /*!< FLASH data Buffer Not Empty flag */
83 #define FLASH_FLAG_EOP                     FLASH_SR_EOP             /*!< FLASH End Of operation flag */
84 #define FLASH_FLAG_WRPERR                  FLASH_SR_WRPERR          /*!< FLASH Write Protection Error flag */
85 #define FLASH_FLAG_PGSERR                  FLASH_SR_PGSERR          /*!< FLASH Program Sequence Error flag */
86 #define FLASH_FLAG_STRBERR                 FLASH_SR_STRBERR         /*!< FLASH Strobe Error flag */
87 #define FLASH_FLAG_INCERR                  FLASH_SR_INCERR          /*!< FLASH Inconsistency Error flag */
88 #if defined (FLASH_SR_OBKERR)
89 #define FLASH_FLAG_OBKERR                  FLASH_SR_OBKERR          /*!< FLASH OBK Error flag */
90 #define FLASH_FLAG_OBKWERR                 FLASH_SR_OBKWERR         /*!< FLASH OBK Write Error flag */
91 #endif /* FLASH_SR_OBKERR */
92 #define FLASH_FLAG_OPTCHANGEERR            FLASH_SR_OPTCHANGEERR    /*!< FLASH Option Byte change Error flag */
93 #define FLASH_FLAG_ECCC                    FLASH_ECCR_ECCC          /*!< FLASH ECC Correction flag */
94 #define FLASH_FLAG_ECCD                    FLASH_ECCR_ECCD          /*!< FLASH ECC Detection flag */
95 
96 #if defined (FLASH_SR_OBKERR)
97 #define FLASH_FLAG_SR_ERRORS               (FLASH_SR_WRPERR      | FLASH_SR_PGSERR    | \
98                                             FLASH_SR_STRBERR     | FLASH_SR_INCERR    | \
99                                             FLASH_SR_OBKERR      | FLASH_SR_OBKWERR   | \
100                                             FLASH_SR_OPTCHANGEERR)
101 #else
102 #define FLASH_FLAG_SR_ERRORS               (FLASH_SR_WRPERR      | FLASH_SR_PGSERR    | \
103                                             FLASH_SR_STRBERR     | FLASH_SR_INCERR    | \
104                                             FLASH_SR_OPTCHANGEERR)
105 #endif /* FLASH_SR_OBKERR */
106 #define FLASH_FLAG_ECCR_ERRORS             (FLASH_FLAG_ECCC      | FLASH_FLAG_ECCD)
107 #define FLASH_FLAG_ALL_ERRORS              (FLASH_FLAG_SR_ERRORS | FLASH_FLAG_ECCR_ERRORS) /*!< All FLASH error flags */
108 /**
109   * @}
110   */
111 
112 /** @defgroup FLASH_Interrupt_definition FLASH Interrupts definition
113   * @brief FLASH Interrupt definition
114   * @{
115   */
116 #define FLASH_IT_EOP                  FLASH_CR_EOPIE        /*!< End of FLASH Operation interrupt enable */
117 #define FLASH_IT_WRPERR               FLASH_CR_WRPERRIE     /*!< Write Protection Error interrupt enable */
118 #define FLASH_IT_PGSERR               FLASH_CR_PGSERRIE     /*!< Program Sequence Error interrupt enable */
119 #define FLASH_IT_STRBERR              FLASH_CR_STRBERRIE    /*!< Strobe Error interrupt enable */
120 #define FLASH_IT_INCERR               FLASH_CR_INCERRIE     /*!< Inconsistency Error interrupt enable */
121 #if defined (FLASH_SR_OBKERR)
122 #define FLASH_IT_OBKERR               FLASH_CR_OBKERRIE     /*!< OBK Error interrupt enable */
123 #define FLASH_IT_OBKWERR              FLASH_CR_OBKWERRIE    /*!< OBK Write Error interrupt enable */
124 #endif /* FLASH_SR_OBKERR */
125 #define FLASH_IT_OPTCHANGEERR         FLASH_CR_OPTCHANGEERRIE /*!< Option Byte change Error interrupt enable */
126 #define FLASH_IT_ECCC                 FLASH_ECCR_ECCIE      /*!< Single ECC Error Correction interrupt enable */
127 
128 #if defined (FLASH_SR_OBKERR)
129 #define FLASH_IT_ALL                 (FLASH_IT_EOP       | FLASH_IT_WRPERR   | \
130                                       FLASH_IT_PGSERR    | FLASH_IT_STRBERR  | \
131                                       FLASH_IT_INCERR    | FLASH_IT_OBKERR   | \
132                                       FLASH_IT_OBKWERR   | FLASH_IT_OPTCHANGEERR   | \
133                                       FLASH_IT_ECCC) /*!< All Flash interrupt sources */
134 #else
135 #define FLASH_IT_ALL                 (FLASH_IT_EOP       | FLASH_IT_WRPERR       | \
136                                       FLASH_IT_PGSERR    | FLASH_IT_STRBERR      | \
137                                       FLASH_IT_INCERR    | FLASH_IT_OPTCHANGEERR | \
138                                       FLASH_IT_ECCC) /*!< All Flash interrupt sources */
139 #endif /* FLASH_SR_OBKERR */
140 
141 /**
142   * @}
143   */
144 
145 /** @defgroup FLASH_Error_Code FLASH Error Code
146   * @brief    FLASH Error Code
147   * @{
148   */
149 #define HAL_FLASH_ERROR_NONE         0x00000000U               /*!< No error                              */
150 #define HAL_FLASH_ERROR_WRP          FLASH_FLAG_WRPERR         /*!< Write Protection Error                */
151 #define HAL_FLASH_ERROR_PGS          FLASH_FLAG_PGSERR         /*!< Program Sequence Error                */
152 #define HAL_FLASH_ERROR_STRB         FLASH_FLAG_STRBERR        /*!< Strobe Error                          */
153 #define HAL_FLASH_ERROR_INC          FLASH_FLAG_INCERR         /*!< Inconsistency Error                   */
154 #if defined (FLASH_SR_OBKERR)
155 #define HAL_FLASH_ERROR_OBK          FLASH_FLAG_OBKERR         /*!< OBK Error                             */
156 #define HAL_FLASH_ERROR_OBKW         FLASH_FLAG_OBKWERR        /*!< OBK Write Error                       */
157 #endif /* FLASH_SR_OBKERR */
158 #define HAL_FLASH_ERROR_OB_CHANGE    FLASH_FLAG_OPTCHANGEERR   /*!< Option Byte Change Error              */
159 #define HAL_FLASH_ERROR_ECCC         FLASH_FLAG_ECCC           /*!< ECC Single Correction Error           */
160 #define HAL_FLASH_ERROR_ECCD         FLASH_FLAG_ECCD           /*!< ECC Double Detection Error            */
161 /**
162   * @}
163   */
164 
165 /** @defgroup FLASH_Type_Program FLASH Program Type
166   * @{
167   */
168 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
169 #define FLASH_TYPEPROGRAM_QUADWORD         FLASH_CR_PG                                        /*!< Program a quad-word
170                                                                              (128-bit) at  a specified secure address */
171 #define FLASH_TYPEPROGRAM_QUADWORD_NS       (FLASH_CR_PG | FLASH_NON_SECURE_MASK)              /*!< Program a quad-word
172                                                                           (128-bit) at a specified non-secure address */
173 #if defined (FLASH_SR_OBKERR)
174 #define FLASH_TYPEPROGRAM_QUADWORD_OBK      (FLASH_CR_PG | FLASH_OBK)                          /*!< Program a quad-word
175                                                                                    (128-bit) of OBK to current sector */
176 #define FLASH_TYPEPROGRAM_QUADWORD_OBK_ALT  (FLASH_CR_PG | FLASH_OBK | FLASH_OBKCFGR_ALT_SECT) /*!< Program a quad-word
177                                                                                  (128-bit) of OBK to alternate sector */
178 #endif /* FLASH_SR_OBKERR */
179 #if defined (FLASH_EDATAR_EDATA_EN)
180 #define FLASH_TYPEPROGRAM_HALFWORD_EDATA    (FLASH_CR_PG | FLASH_EDATA)                          /*!< Program a flash
181                                                       high-cycle data half-word (16-bit)at a specified secure address */
182 #define FLASH_TYPEPROGRAM_HALFWORD_EDATA_NS (FLASH_CR_PG | FLASH_EDATA | FLASH_NON_SECURE_MASK)  /*!< Program a flash
183                                                   high-cycle data half-word (16-bit)at a specified non-secure address */
184 #endif /* FLASH_EDATAR_EDATA_EN */
185 #else
186 #define FLASH_TYPEPROGRAM_QUADWORD           FLASH_CR_PG                                        /*!< Program a quad-word
187                                                                                      (128-bit) at a specified address */
188 #if defined (FLASH_SR_OBKERR)
189 #define FLASH_TYPEPROGRAM_QUADWORD_OBK     (FLASH_CR_PG | FLASH_OBK)                           /*!< Program a quad-word
190                                                                                    (128-bit) of OBK to current sector */
191 #define FLASH_TYPEPROGRAM_QUADWORD_OBK_ALT (FLASH_CR_PG | FLASH_OBK | FLASH_OBKCFGR_ALT_SECT)  /*!< Program a quad-word
192                                                                                  (128-bit) of OBK to alternate sector */
193 #endif /* FLASH_SR_OBKERR */
194 #if defined (FLASH_EDATAR_EDATA_EN)
195 #define FLASH_TYPEPROGRAM_HALFWORD_EDATA    (FLASH_CR_PG | FLASH_EDATA)                          /*!< Program a flash
196                                                              high-cycle data half-word (16-bit)at a specified address */
197 #endif /* FLASH_EDATAR_EDATA_EN */
198 #endif /* __ARM_FEATURE_CMSE */
199 #define FLASH_TYPEPROGRAM_HALFWORD_OTP      (FLASH_CR_PG | FLASH_OTP | FLASH_NON_SECURE_MASK)   /*!< Program an OTP
200                                                                              half-word (16-bit)at a specified address */
201 /**
202   * @}
203   */
204 
205 /** @defgroup FLASH_Latency FLASH Latency
206   * @{
207   */
208 #define FLASH_LATENCY_0          FLASH_ACR_LATENCY_0WS   /*!< FLASH Zero wait cycle      */
209 #define FLASH_LATENCY_1          FLASH_ACR_LATENCY_1WS   /*!< FLASH One wait cycle       */
210 #define FLASH_LATENCY_2          FLASH_ACR_LATENCY_2WS   /*!< FLASH Two wait cycles      */
211 #define FLASH_LATENCY_3          FLASH_ACR_LATENCY_3WS   /*!< FLASH Three wait cycles    */
212 #define FLASH_LATENCY_4          FLASH_ACR_LATENCY_4WS   /*!< FLASH Four wait cycles     */
213 #define FLASH_LATENCY_5          FLASH_ACR_LATENCY_5WS   /*!< FLASH Five wait cycles     */
214 #define FLASH_LATENCY_6          FLASH_ACR_LATENCY_6WS   /*!< FLASH Six wait cycles      */
215 #define FLASH_LATENCY_7          FLASH_ACR_LATENCY_7WS   /*!< FLASH Seven wait cycles    */
216 #define FLASH_LATENCY_8          FLASH_ACR_LATENCY_8WS   /*!< FLASH Eight wait cycle     */
217 #define FLASH_LATENCY_9          FLASH_ACR_LATENCY_9WS   /*!< FLASH Nine wait cycle      */
218 #define FLASH_LATENCY_10         FLASH_ACR_LATENCY_10WS  /*!< FLASH Ten wait cycles      */
219 #define FLASH_LATENCY_11         FLASH_ACR_LATENCY_11WS  /*!< FLASH Eleven wait cycles   */
220 #define FLASH_LATENCY_12         FLASH_ACR_LATENCY_12WS  /*!< FLASH Twelve wait cycles   */
221 #define FLASH_LATENCY_13         FLASH_ACR_LATENCY_13WS  /*!< FLASH Thirteen wait cycles */
222 #define FLASH_LATENCY_14         FLASH_ACR_LATENCY_14WS  /*!< FLASH Fourteen wait cycles */
223 #define FLASH_LATENCY_15         FLASH_ACR_LATENCY_15WS  /*!< FLASH Fifteen wait cycles  */
224 /**
225   * @}
226   */
227 
228 /** @defgroup FLASH_Keys FLASH Keys
229   * @{
230   */
231 #define FLASH_KEY1                 0x45670123U
232 #define FLASH_KEY2                 0xCDEF89ABU
233 #define FLASH_OPT_KEY1             0x08192A3BU
234 #define FLASH_OPT_KEY2             0x4C5D6E7FU
235 #if defined (FLASH_SR_OBKERR)
236 #define FLASH_OBK_KEY1             0x192A083BU
237 #define FLASH_OBK_KEY2             0x6E7F4C5DU
238 #endif /* FLASH_SR_OBKERR */
239 /**
240   * @}
241   */
242 
243 /** @defgroup FLASH_Sectors FLASH Sectors
244   * @{
245   */
246 #define FLASH_SECTOR_0             0U       /*!< Sector Number 0   */
247 #define FLASH_SECTOR_1             1U       /*!< Sector Number 1   */
248 #define FLASH_SECTOR_2             2U       /*!< Sector Number 2   */
249 #define FLASH_SECTOR_3             3U       /*!< Sector Number 3   */
250 #define FLASH_SECTOR_4             4U       /*!< Sector Number 4   */
251 #define FLASH_SECTOR_5             5U       /*!< Sector Number 5   */
252 #define FLASH_SECTOR_6             6U       /*!< Sector Number 6   */
253 #define FLASH_SECTOR_7             7U       /*!< Sector Number 7   */
254 #if (FLASH_SECTOR_NB == 128)
255 #define FLASH_SECTOR_8             8U       /*!< Sector Number 8   */
256 #define FLASH_SECTOR_9             9U       /*!< Sector Number 9   */
257 #define FLASH_SECTOR_10            10U      /*!< Sector Number 10  */
258 #define FLASH_SECTOR_11            11U      /*!< Sector Number 11  */
259 #define FLASH_SECTOR_12            12U      /*!< Sector Number 12  */
260 #define FLASH_SECTOR_13            13U      /*!< Sector Number 13  */
261 #define FLASH_SECTOR_14            14U      /*!< Sector Number 14  */
262 #define FLASH_SECTOR_15            15U      /*!< Sector Number 15  */
263 #define FLASH_SECTOR_16            16U      /*!< Sector Number 16  */
264 #define FLASH_SECTOR_17            17U      /*!< Sector Number 17  */
265 #define FLASH_SECTOR_18            18U      /*!< Sector Number 18  */
266 #define FLASH_SECTOR_19            19U      /*!< Sector Number 19  */
267 #define FLASH_SECTOR_20            20U      /*!< Sector Number 20  */
268 #define FLASH_SECTOR_21            21U      /*!< Sector Number 21  */
269 #define FLASH_SECTOR_22            22U      /*!< Sector Number 22  */
270 #define FLASH_SECTOR_23            23U      /*!< Sector Number 23  */
271 #define FLASH_SECTOR_24            24U      /*!< Sector Number 24  */
272 #define FLASH_SECTOR_25            25U      /*!< Sector Number 25  */
273 #define FLASH_SECTOR_26            26U      /*!< Sector Number 26  */
274 #define FLASH_SECTOR_27            27U      /*!< Sector Number 27  */
275 #define FLASH_SECTOR_28            28U      /*!< Sector Number 28  */
276 #define FLASH_SECTOR_29            29U      /*!< Sector Number 29  */
277 #define FLASH_SECTOR_30            30U      /*!< Sector Number 30  */
278 #define FLASH_SECTOR_31            31U      /*!< Sector Number 31  */
279 #define FLASH_SECTOR_32            32U      /*!< Sector Number 32  */
280 #define FLASH_SECTOR_33            33U      /*!< Sector Number 33  */
281 #define FLASH_SECTOR_34            34U      /*!< Sector Number 34  */
282 #define FLASH_SECTOR_35            35U      /*!< Sector Number 35  */
283 #define FLASH_SECTOR_36            36U      /*!< Sector Number 36  */
284 #define FLASH_SECTOR_37            37U      /*!< Sector Number 37  */
285 #define FLASH_SECTOR_38            38U      /*!< Sector Number 38  */
286 #define FLASH_SECTOR_39            39U      /*!< Sector Number 39  */
287 #define FLASH_SECTOR_40            40U      /*!< Sector Number 40  */
288 #define FLASH_SECTOR_41            41U      /*!< Sector Number 41  */
289 #define FLASH_SECTOR_42            42U      /*!< Sector Number 42  */
290 #define FLASH_SECTOR_43            43U      /*!< Sector Number 43  */
291 #define FLASH_SECTOR_44            44U      /*!< Sector Number 44  */
292 #define FLASH_SECTOR_45            45U      /*!< Sector Number 45  */
293 #define FLASH_SECTOR_46            46U      /*!< Sector Number 46  */
294 #define FLASH_SECTOR_47            47U      /*!< Sector Number 47  */
295 #define FLASH_SECTOR_48            48U      /*!< Sector Number 48  */
296 #define FLASH_SECTOR_49            49U      /*!< Sector Number 49  */
297 #define FLASH_SECTOR_50            50U      /*!< Sector Number 50  */
298 #define FLASH_SECTOR_51            51U      /*!< Sector Number 51  */
299 #define FLASH_SECTOR_52            52U      /*!< Sector Number 52  */
300 #define FLASH_SECTOR_53            53U      /*!< Sector Number 53  */
301 #define FLASH_SECTOR_54            54U      /*!< Sector Number 54  */
302 #define FLASH_SECTOR_55            55U      /*!< Sector Number 55  */
303 #define FLASH_SECTOR_56            56U      /*!< Sector Number 56  */
304 #define FLASH_SECTOR_57            57U      /*!< Sector Number 57  */
305 #define FLASH_SECTOR_58            58U      /*!< Sector Number 58  */
306 #define FLASH_SECTOR_59            59U      /*!< Sector Number 59  */
307 #define FLASH_SECTOR_60            60U      /*!< Sector Number 60  */
308 #define FLASH_SECTOR_61            61U      /*!< Sector Number 61  */
309 #define FLASH_SECTOR_62            62U      /*!< Sector Number 62  */
310 #define FLASH_SECTOR_63            63U      /*!< Sector Number 63  */
311 #define FLASH_SECTOR_64            64U      /*!< Sector Number 64  */
312 #define FLASH_SECTOR_65            65U      /*!< Sector Number 65  */
313 #define FLASH_SECTOR_66            66U      /*!< Sector Number 66  */
314 #define FLASH_SECTOR_67            67U      /*!< Sector Number 67  */
315 #define FLASH_SECTOR_68            68U      /*!< Sector Number 68  */
316 #define FLASH_SECTOR_69            69U      /*!< Sector Number 69  */
317 #define FLASH_SECTOR_70            70U      /*!< Sector Number 70  */
318 #define FLASH_SECTOR_71            71U      /*!< Sector Number 71  */
319 #define FLASH_SECTOR_72            72U      /*!< Sector Number 72  */
320 #define FLASH_SECTOR_73            73U      /*!< Sector Number 73  */
321 #define FLASH_SECTOR_74            74U      /*!< Sector Number 74  */
322 #define FLASH_SECTOR_75            75U      /*!< Sector Number 75  */
323 #define FLASH_SECTOR_76            76U      /*!< Sector Number 76  */
324 #define FLASH_SECTOR_77            77U      /*!< Sector Number 77  */
325 #define FLASH_SECTOR_78            78U      /*!< Sector Number 78  */
326 #define FLASH_SECTOR_79            79U      /*!< Sector Number 79  */
327 #define FLASH_SECTOR_80            80U      /*!< Sector Number 80  */
328 #define FLASH_SECTOR_81            81U      /*!< Sector Number 81  */
329 #define FLASH_SECTOR_82            82U      /*!< Sector Number 82  */
330 #define FLASH_SECTOR_83            83U      /*!< Sector Number 83  */
331 #define FLASH_SECTOR_84            84U      /*!< Sector Number 84  */
332 #define FLASH_SECTOR_85            85U      /*!< Sector Number 85  */
333 #define FLASH_SECTOR_86            86U      /*!< Sector Number 86  */
334 #define FLASH_SECTOR_87            87U      /*!< Sector Number 87  */
335 #define FLASH_SECTOR_88            88U      /*!< Sector Number 88  */
336 #define FLASH_SECTOR_89            89U      /*!< Sector Number 89  */
337 #define FLASH_SECTOR_90            90U      /*!< Sector Number 90  */
338 #define FLASH_SECTOR_91            91U      /*!< Sector Number 91  */
339 #define FLASH_SECTOR_92            92U      /*!< Sector Number 92  */
340 #define FLASH_SECTOR_93            93U      /*!< Sector Number 93  */
341 #define FLASH_SECTOR_94            94U      /*!< Sector Number 94  */
342 #define FLASH_SECTOR_95            95U      /*!< Sector Number 95  */
343 #define FLASH_SECTOR_96            96U      /*!< Sector Number 96  */
344 #define FLASH_SECTOR_97            97U      /*!< Sector Number 97  */
345 #define FLASH_SECTOR_98            98U      /*!< Sector Number 98  */
346 #define FLASH_SECTOR_99            99U      /*!< Sector Number 99  */
347 #define FLASH_SECTOR_100           100U     /*!< Sector Number 100 */
348 #define FLASH_SECTOR_101           101U     /*!< Sector Number 101 */
349 #define FLASH_SECTOR_102           102U     /*!< Sector Number 102 */
350 #define FLASH_SECTOR_103           103U     /*!< Sector Number 103 */
351 #define FLASH_SECTOR_104           104U     /*!< Sector Number 104 */
352 #define FLASH_SECTOR_105           105U     /*!< Sector Number 105 */
353 #define FLASH_SECTOR_106           106U     /*!< Sector Number 106 */
354 #define FLASH_SECTOR_107           107U     /*!< Sector Number 107 */
355 #define FLASH_SECTOR_108           108U     /*!< Sector Number 108 */
356 #define FLASH_SECTOR_109           109U     /*!< Sector Number 109 */
357 #define FLASH_SECTOR_110           110U     /*!< Sector Number 110 */
358 #define FLASH_SECTOR_111           111U     /*!< Sector Number 111 */
359 #define FLASH_SECTOR_112           112U     /*!< Sector Number 112 */
360 #define FLASH_SECTOR_113           113U     /*!< Sector Number 113 */
361 #define FLASH_SECTOR_114           114U     /*!< Sector Number 114 */
362 #define FLASH_SECTOR_115           115U     /*!< Sector Number 115 */
363 #define FLASH_SECTOR_116           116U     /*!< Sector Number 116 */
364 #define FLASH_SECTOR_117           117U     /*!< Sector Number 117 */
365 #define FLASH_SECTOR_118           118U     /*!< Sector Number 118 */
366 #define FLASH_SECTOR_119           119U     /*!< Sector Number 119 */
367 #define FLASH_SECTOR_120           120U     /*!< Sector Number 120 */
368 #define FLASH_SECTOR_121           121U     /*!< Sector Number 121 */
369 #define FLASH_SECTOR_122           122U     /*!< Sector Number 122 */
370 #define FLASH_SECTOR_123           123U     /*!< Sector Number 123 */
371 #define FLASH_SECTOR_124           124U     /*!< Sector Number 124 */
372 #define FLASH_SECTOR_125           125U     /*!< Sector Number 125 */
373 #define FLASH_SECTOR_126           126U     /*!< Sector Number 126 */
374 #define FLASH_SECTOR_127           127U     /*!< Sector Number 127 */
375 #endif /* (FLASH_SECTOR_NB == 128) */
376 /**
377   * @}
378   */
379 
380 /**
381   * @}
382   */
383 
384 /* Exported macros ------------------------------------------------------------*/
385 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
386   * @{
387   */
388 /**
389   * @brief  Set the FLASH Latency.
390   * @param  __LATENCY__: FLASH Latency
391   *         This parameter can be one of the following values :
392   *     @arg FLASH_LATENCY_0: FLASH Zero wait state
393   *     @arg FLASH_LATENCY_1: FLASH One wait state
394   *     @arg FLASH_LATENCY_2: FLASH Two wait states
395   *     @arg FLASH_LATENCY_3: FLASH Three wait states
396   *     @arg FLASH_LATENCY_4: FLASH Four wait states
397   *     @arg FLASH_LATENCY_5: FLASH Five wait states
398   *     @arg FLASH_LATENCY_6: FLASH Six wait states
399   *     @arg FLASH_LATENCY_7: FLASH Seven wait states
400   *     @arg FLASH_LATENCY_8: FLASH Eight wait states
401   *     @arg FLASH_LATENCY_9: FLASH Nine wait states
402   *     @arg FLASH_LATENCY_10: FLASH Ten wait states
403   *     @arg FLASH_LATENCY_11: FLASH Eleven wait states
404   *     @arg FLASH_LATENCY_12: FLASH Twelve wait states
405   *     @arg FLASH_LATENCY_13: FLASH Thirteen wait states
406   *     @arg FLASH_LATENCY_14: FLASH Fourteen wait states
407   *     @arg FLASH_LATENCY_15: FLASH Fifteen wait states
408   * @retval none
409   */
410 #define __HAL_FLASH_SET_LATENCY(__LATENCY__)    MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (__LATENCY__))
411 
412 /**
413   * @brief  Get the FLASH Latency.
414   * @retval FLASH Latency
415   *         This return value can be one of the following values :
416   *     @arg FLASH_LATENCY_0: FLASH Zero wait state
417   *     @arg FLASH_LATENCY_1: FLASH One wait state
418   *     @arg FLASH_LATENCY_2: FLASH Two wait states
419   *     @arg FLASH_LATENCY_3: FLASH Three wait states
420   *     @arg FLASH_LATENCY_4: FLASH Four wait states
421   *     @arg FLASH_LATENCY_5: FLASH Five wait states
422   *     @arg FLASH_LATENCY_6: FLASH Six wait states
423   *     @arg FLASH_LATENCY_7: FLASH Seven wait states
424   *     @arg FLASH_LATENCY_8: FLASH Eight wait states
425   *     @arg FLASH_LATENCY_9: FLASH Nine wait states
426   *     @arg FLASH_LATENCY_10: FLASH Ten wait states
427   *     @arg FLASH_LATENCY_11: FLASH Eleven wait states
428   *     @arg FLASH_LATENCY_12: FLASH Twelve wait states
429   *     @arg FLASH_LATENCY_13: FLASH Thirteen wait states
430   *     @arg FLASH_LATENCY_14: FLASH Fourteen wait states
431   *     @arg FLASH_LATENCY_15: FLASH Fifteen wait states
432   */
433 #define __HAL_FLASH_GET_LATENCY()               READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)
434 
435 /**
436   * @brief  Enable the specified FLASH interrupt.
437   * @param  __INTERRUPT__ : FLASH interrupt
438   *   This parameter can be any combination of the following values:
439   *     @arg FLASH_IT_EOP       : End of FLASH Operation Interrupt
440   *     @arg FLASH_IT_WRPERR    : Write Protection Error Interrupt
441   *     @arg FLASH_IT_PGSERR    : Program Sequence Error Interrupt
442   *     @arg FLASH_IT_STRBERR   : Strobe Error Interrupt
443   *     @arg FLASH_IT_INCERR    : Inconsistency Error Interrupt
444   *     @arg FLASH_IT_OBKERR    : OBK Error Interrupt
445   *     @arg FLASH_IT_OBKWERR   : OBK Write Error Interrupt
446   *     @arg FLASH_IT_OPTCHANGEERR : Option Byte Change Error Interrupt
447   *     @arg FLASH_IT_ECCC      : Single ECC Error Correction Interrupt
448   * @retval none
449   */
450 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
451 /* Enable secure FLASH interrupts from the secure world */
452 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U)                          \
453                                                     { SET_BIT(FLASH->ECCCORR, FLASH_IT_ECCC); }                        \
454                                                   if(((__INTERRUPT__) & FLASH_IT_OPTCHANGEERR) != 0U)                  \
455                                                     { SET_BIT(FLASH->NSCR, FLASH_IT_OPTCHANGEERR); }                   \
456                                                   if(((__INTERRUPT__) & (~FLASH_IT_ECCC)) != 0U)                       \
457                                                     { SET_BIT(FLASH->SECCR, ((__INTERRUPT__) & (~(FLASH_IT_ECCC |      \
458                                                       FLASH_IT_OPTCHANGEERR)))); }\
459                                                 } while(0)
460 /* Enable non-secure FLASH interrupts from the secure world */
461 #define __HAL_FLASH_ENABLE_IT_NS(__INTERRUPT__) do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U)                       \
462                                                        { SET_BIT(FLASH->ECCCORR, FLASH_IT_ECCC); }                     \
463                                                      if(((__INTERRUPT__) & (~FLASH_IT_ECCC)) != 0U)                    \
464                                                        { SET_BIT(FLASH->NSCR, ((__INTERRUPT__) & (~FLASH_IT_ECCC))); } \
465                                                    } while(0)
466 #else
467 /* Enable non-secure FLASH interrupts from the non-secure world */
468 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__)    do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U)                       \
469                                                        { SET_BIT(FLASH->ECCCORR, FLASH_IT_ECCC); }                     \
470                                                      if(((__INTERRUPT__) & (~FLASH_IT_ECCC)) != 0U)                    \
471                                                        { SET_BIT(FLASH->NSCR, ((__INTERRUPT__) & (~FLASH_IT_ECCC))); } \
472                                                    } while(0)
473 #endif /* __ARM_FEATURE_CMSE */
474 
475 /**
476   * @brief  Disable the specified FLASH interrupt.
477   * @param  __INTERRUPT__ : FLASH interrupt
478   *   This parameter can be any combination of the following values:
479   *     @arg FLASH_IT_EOP       : End of FLASH Operation Interrupt
480   *     @arg FLASH_IT_WRPERR    : Write Protection Error Interrupt
481   *     @arg FLASH_IT_PGSERR    : Program Sequence Error Interrupt
482   *     @arg FLASH_IT_STRBERR   : Strobe Error Interrupt
483   *     @arg FLASH_IT_INCERR    : Inconsistency Error Interrupt
484   *     @arg FLASH_IT_OBKERR    : OBK Error Interrupt
485   *     @arg FLASH_IT_OBKWERR   : OBK Write Error Interrupt
486   *     @arg FLASH_IT_OPTCHANGEERR : Option Byte Change Error Interrupt
487   *     @arg FLASH_IT_ECCC      : Single ECC Error Correction Interrupt
488   * @retval none
489   */
490 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
491 /* Disable secure FLASH interrupts from the secure world */
492 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U)                         \
493                                                      { CLEAR_BIT(FLASH->ECCCORR, FLASH_IT_ECCC); }                     \
494                                                    if(((__INTERRUPT__) & FLASH_IT_OPTCHANGEERR) != 0U)                 \
495                                                      { CLEAR_BIT(FLASH->NSCR, FLASH_IT_OPTCHANGEERR); }                \
496                                                    if(((__INTERRUPT__) & (~(FLASH_IT_ECCC | FLASH_IT_OPTCHANGEERR)))   \
497                                                      != 0U){ CLEAR_BIT(FLASH->SECCR, ((__INTERRUPT__) &                \
498                                                      (~(FLASH_IT_ECCC | FLASH_IT_OPTCHANGEERR)))); }\
499                                                  } while(0)
500 /* Disable non-secure FLASH interrupts from the secure world */
501 #define __HAL_FLASH_DISABLE_IT_NS(__INTERRUPT__) do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U) { CLEAR_BIT          \
502                                                         (FLASH->ECCCORR, FLASH_IT_ECCC); }                             \
503                                                       if(((__INTERRUPT__) & (~FLASH_IT_ECCC)) != 0U)                   \
504                                                         { CLEAR_BIT(FLASH->NSCR, ((__INTERRUPT__) & (~FLASH_IT_ECCC)));\
505                                                         }                                                              \
506                                                     } while(0)
507 #else
508 /* Disable non-secure FLASH interrupts from the non-secure world */
509 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__)   do { if(((__INTERRUPT__) & FLASH_IT_ECCC) != 0U) { CLEAR_BIT           \
510                                                        (FLASH->ECCCORR, FLASH_IT_ECCC); }                              \
511                                                      if(((__INTERRUPT__) & (~FLASH_IT_ECCC)) != 0U) { CLEAR_BIT        \
512                                                        (FLASH->NSCR, ((__INTERRUPT__) & (~FLASH_IT_ECCC))); }          \
513                                                     } while(0)
514 #endif /* __ARM_FEATURE_CMSE */
515 
516 /**
517   * @brief  Checks whether the specified FLASH flag is set or not.
518   * @param  __FLAG__: specifies the FLASH flag to check.
519   *   This parameter can be one of the following values :
520   *     @arg FLASH_FLAG_BSY      : FLASH Busy flag
521   *     @arg FLASH_FLAG_WBNE     : Write Buffer Not Empty flag
522   *     @arg FLASH_FLAG_EOP      : End Of Operation flag
523   *     @arg FLASH_FLAG_WRPERR   : Write Protection Error flag
524   *     @arg FLASH_FLAG_PGSERR   : Program Sequence Error flag
525   *     @arg FLASH_FLAG_STRBERR  : Strobe Error flag
526   *     @arg FLASH_FLAG_INCERR   : Inconsistency Error flag
527   *     @arg FLASH_FLAG_OBKERR   : OBK Error flag
528   *     @arg FLASH_FLAG_OBKWERR  : OBK Write Error flag
529   *     @arg FLASH_FLAG_OPTCHANGEERR : Option Byte Change Error flag
530   *     @arg FLASH_FLAG_ECCC     : Single ECC Error Correction flag
531   *     @arg FLASH_FLAG_ECCD     : Double Detection ECC Error flag
532   * @retval The new state of FLASH_FLAG (SET or RESET).
533   */
534 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
535 /* Get secure FLASH flags from the secure world */
536 #define __HAL_FLASH_GET_FLAG(__FLAG__)          ((((__FLAG__) & (FLASH_FLAG_ECCC)) != 0U) ?                            \
537                                                  (READ_BIT(FLASH->ECCCORR, (__FLAG__)) == (__FLAG__))  :               \
538                                                  (((__FLAG__) & (FLASH_FLAG_ECCD)) != 0U) ?                            \
539                                                  (READ_BIT(FLASH->ECCDETR, (__FLAG__)) == (__FLAG__))  :               \
540                                                  ((((__FLAG__) & (FLASH_FLAG_OPTCHANGEERR)) != 0U) ?                   \
541                                                   (READ_BIT(FLASH->NSSR, (__FLAG__)) == (__FLAG__)) :                  \
542                                                   (READ_BIT(FLASH->SECSR, (__FLAG__)) == (__FLAG__))))
543 /* Get non-secure FLASH flags from the secure world */
544 #define __HAL_FLASH_GET_FLAG_NS(__FLAG__)       ((((__FLAG__) & (FLASH_FLAG_ECCC)) != 0U) ?                            \
545                                                  (READ_BIT(FLASH->ECCCORR, (__FLAG__)) == (__FLAG__))  :               \
546                                                  (((__FLAG__) & (FLASH_FLAG_ECCD)) != 0U) ?                            \
547                                                  (READ_BIT(FLASH->ECCDETR, (__FLAG__)) == (__FLAG__))  :               \
548                                                  (READ_BIT(FLASH->NSSR, (__FLAG__)) == (__FLAG__))))
549 #else
550 /* Get non-secure FLASH flags from the non-secure world */
551 #define __HAL_FLASH_GET_FLAG(__FLAG__)          ((((__FLAG__) & (FLASH_FLAG_ECCC)) != 0U) ?                            \
552                                                  (READ_BIT(FLASH->ECCCORR, (__FLAG__)) == (__FLAG__))  :               \
553                                                  (((__FLAG__) & (FLASH_FLAG_ECCD)) != 0U) ?                            \
554                                                  (READ_BIT(FLASH->ECCDETR, (__FLAG__)) == (__FLAG__))  :               \
555                                                  (READ_BIT(FLASH->NSSR, (__FLAG__)) == (__FLAG__)))
556 #endif /* __ARM_FEATURE_CMSE */
557 
558 /**
559   * @brief  Clear the specified FLASH flag.
560   * @param  __FLAG__: specifies the FLASH flags to clear.
561   *   This parameter can be one of the following values :
562   *     @arg FLASH_FLAG_BSY       : FLASH Busy flag
563   *     @arg FLASH_FLAG_WBNE      : Write Buffer Not Empty flag
564   *     @arg FLASH_FLAG_EOP       : End Of Operation flag
565   *     @arg FLASH_FLAG_WRPERR    : Write Protection Error flag
566   *     @arg FLASH_FLAG_PGSERR    : Program Sequence Error flag
567   *     @arg FLASH_FLAG_STRBERR   : Strobe Error flag
568   *     @arg FLASH_FLAG_INCERR    : Inconsistency Error flag
569   *     @arg FLASH_FLAG_OBKERR    : OBK Error flag
570   *     @arg FLASH_FLAG_OBKWERR   : OBK Write Error flag
571   *     @arg FLASH_FLAG_OPTCHANGEERR : Option Byte Change Error flag
572   *     @arg FLASH_FLAG_ECCC      : Single ECC Error Correction flag
573   *     @arg FLASH_FLAG_ECCD      : Double Detection ECC Error flag
574   *     @arg FLASH_FLAG_ALL_ERRORS: All errors flags
575   * @retval none
576   */
577 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
578 /* Clear secure FLASH flags from the secure world */
579 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__)        do { if(((__FLAG__) & FLASH_FLAG_ECCC) != 0U) { SET_BIT(FLASH->ECCCORR,\
580                                                         ((__FLAG__) & FLASH_FLAG_ECCC)); }                             \
581                                                      if(((__FLAG__) & FLASH_FLAG_ECCD) != 0U) { SET_BIT(FLASH->ECCDETR,\
582                                                         ((__FLAG__) & FLASH_FLAG_ECCD)); }                             \
583                                                      if(((__FLAG__) & FLASH_FLAG_OPTCHANGEERR) != 0U) { SET_BIT        \
584                                                          (FLASH->NSCCR, ((__FLAG__) & (FLASH_FLAG_OPTCHANGEERR))); }   \
585                                                      if(((__FLAG__) & ~(FLASH_FLAG_ECCR_ERRORS |                       \
586                                                           FLASH_FLAG_OPTCHANGEERR)) != 0U) { WRITE_REG(FLASH->SECCCR,  \
587                                                         ((__FLAG__) & ~(FLASH_FLAG_ECCR_ERRORS |                       \
588                                                           FLASH_FLAG_OPTCHANGEERR))); }                                \
589                                                    } while(0)
590 /* Clear non-secure FLASH flags from the secure world */
591 #define __HAL_FLASH_CLEAR_FLAG_NS(__FLAG__)     do { if(((__FLAG__) & FLASH_FLAG_ECCC) != 0U) { SET_BIT(FLASH->ECCCORR,\
592                                                         ((__FLAG__) & FLASH_FLAG_ECCC)); }                             \
593                                                      if(((__FLAG__) & FLASH_FLAG_ECCD) != 0U) { SET_BIT(FLASH->ECCDETR,\
594                                                         ((__FLAG__) & FLASH_FLAG_ECCD)); }                             \
595                                                      if(((__FLAG__) & (~FLASH_FLAG_ECCR_ERRORS)) != 0U) { WRITE_REG    \
596                                                          (FLASH->NSCCR, ((__FLAG__) & (~FLASH_FLAG_ECCR_ERRORS))); }   \
597                                                    } while(0)
598 #else
599 /* Clear non-secure FLASH flags from the non-secure world */
600 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__)        do { if(((__FLAG__) & FLASH_FLAG_ECCC) != 0U) { SET_BIT(FLASH->ECCCORR,\
601                                                         ((__FLAG__) & FLASH_FLAG_ECCC)); }                             \
602                                                      if(((__FLAG__) & FLASH_FLAG_ECCD) != 0U) { SET_BIT(FLASH->ECCDETR,\
603                                                         ((__FLAG__) & FLASH_FLAG_ECCD)); }                             \
604                                                      if(((__FLAG__) & (~FLASH_FLAG_ECCR_ERRORS)) != 0U) { WRITE_REG    \
605                                                          (FLASH->NSCCR, ((__FLAG__) & (~FLASH_FLAG_ECCR_ERRORS))); }   \
606                                                    } while(0)
607 #endif /* __ARM_FEATURE_CMSE */
608 
609 /**
610   * @}
611   */
612 
613 /* Include FLASH HAL Extension module */
614 #include "stm32h5xx_hal_flash_ex.h"
615 
616 /* Exported functions --------------------------------------------------------*/
617 /** @addtogroup FLASH_Exported_Functions
618   * @{
619   */
620 /** @addtogroup FLASH_Exported_Functions_Group1
621   * @{
622   */
623 /* Program operation functions */
624 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t FlashAddress, uint32_t DataAddress);
625 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t FlashAddress, uint32_t DataAddress);
626 /* FLASH IRQ handler method */
627 void HAL_FLASH_IRQHandler(void);
628 /* Callbacks in non blocking modes */
629 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
630 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
631 /**
632   * @}
633   */
634 
635 /** @addtogroup FLASH_Exported_Functions_Group2
636   * @{
637   */
638 /* Peripheral Control functions */
639 HAL_StatusTypeDef HAL_FLASH_Unlock(void);
640 HAL_StatusTypeDef HAL_FLASH_Lock(void);
641 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
642 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
643 /* Option bytes control */
644 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
645 /**
646   * @}
647   */
648 
649 /** @addtogroup FLASH_Exported_Functions_Group3
650   * @{
651   */
652 /* Peripheral State functions */
653 uint32_t HAL_FLASH_GetError(void);
654 /**
655   * @}
656   */
657 
658 /**
659   * @}
660   */
661 /* Private types -------------------------------------------------------------*/
662 /* Private variables ---------------------------------------------------------*/
663 /** @defgroup FLASH_Private_Variables FLASH Private Variables
664   * @{
665   */
666 extern FLASH_ProcessTypeDef pFlash;
667 /**
668   * @}
669   */
670 /* Private constants ---------------------------------------------------------*/
671 /** @defgroup FLASH_Private_Constants FLASH Private Constants
672   * @{
673   */
674 #define FLASH_TIMEOUT_VALUE             1000U   /*!< 1 s */
675 
676 #if defined (FLASH_SR_OBKERR)
677 #define FLASH_OBK                       0x10000000U
678 #endif /* FLASH_SR_OBKERR */
679 
680 #define FLASH_OTP                       0x20000000U
681 
682 #if defined (FLASH_EDATAR_EDATA_EN)
683 #define FLASH_EDATA                     0x40000000U
684 #endif /* FLASH_EDATAR_EDATA_EN */
685 
686 #define FLASH_NON_SECURE_MASK           0x80000000U
687 
688 #define FLASH_EDATA_SECTOR_NB           8U       /*!< Maximum number of FLASH high-cycle data sectors */
689 /**
690   * @}
691   */
692 
693 /* Private macros ------------------------------------------------------------*/
694 /** @defgroup FLASH_Private_Macros FLASH Private Macros
695   * @{
696   */
697 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
698 #if defined (FLASH_SR_OBKERR) && defined (FLASH_EDATAR_EDATA_EN)
699 #define IS_FLASH_TYPEPROGRAM(VALUE)      (((VALUE) == FLASH_TYPEPROGRAM_QUADWORD)                                   || \
700                                           ((VALUE) == FLASH_TYPEPROGRAM_QUADWORD_NS)                                || \
701                                           ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_OTP)                               || \
702                                           ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_EDATA)                             || \
703                                           ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_EDATA_NS)                          || \
704                                           ((VALUE) == FLASH_TYPEPROGRAM_QUADWORD_OBK)                               || \
705                                           ((VALUE) == FLASH_TYPEPROGRAM_QUADWORD_OBK_ALT))
706 #else
707 #define IS_FLASH_TYPEPROGRAM(VALUE)      (((VALUE) == FLASH_TYPEPROGRAM_QUADWORD)                                   || \
708                                           ((VALUE) == FLASH_TYPEPROGRAM_QUADWORD_NS)                                || \
709                                           ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_OTP))
710 #endif /* FLASH_SR_OBKERR && FLASH_EDATAR_EDATA_EN */
711 #else
712 #if defined (FLASH_SR_OBKERR) && defined (FLASH_EDATAR_EDATA_EN)
713 #define IS_FLASH_TYPEPROGRAM(VALUE)      (((VALUE) == FLASH_TYPEPROGRAM_QUADWORD)                                   || \
714                                           ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_OTP)                               || \
715                                           ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_EDATA)                             || \
716                                           ((VALUE) == FLASH_TYPEPROGRAM_QUADWORD_OBK)                               || \
717                                           ((VALUE) == FLASH_TYPEPROGRAM_QUADWORD_OBK_ALT))
718 #else
719 #define IS_FLASH_TYPEPROGRAM(VALUE)      (((VALUE) == FLASH_TYPEPROGRAM_QUADWORD)                                   || \
720                                           ((VALUE) == FLASH_TYPEPROGRAM_HALFWORD_OTP))
721 #endif /* FLASH_SR_OBKERR && FLASH_EDATAR_EDATA_EN */
722 #endif /* __ARM_FEATURE_CMSE */
723 
724 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
725 #define IS_FLASH_USER_MEM_ADDRESS(ADDRESS) ((((ADDRESS) >= FLASH_BASE) && ((ADDRESS) < (FLASH_BASE+FLASH_SIZE)))    || \
726                                             (((ADDRESS) >= FLASH_BASE_NS) && ((ADDRESS) < (FLASH_BASE_NS+FLASH_SIZE))))
727 #if defined (FLASH_SR_OBKERR)
728 #define IS_FLASH_OBK_ADDRESS(ADDRESS)      ((((ADDRESS) >= FLASH_OBK_BASE)                                          && \
729                                              ((ADDRESS)  < (FLASH_OBK_BASE+FLASH_OBK_SIZE)))                        || \
730                                             (((ADDRESS) >= FLASH_OBK_BASE_NS)                                       && \
731                                              ((ADDRESS)  < (FLASH_OBK_BASE_NS+FLASH_OBK_SIZE))))
732 #endif /* FLASH_SR_OBKERR */
733 #if defined (FLASH_EDATAR_EDATA_EN)
734 #define IS_FLASH_EDATA_ADDRESS(ADDRESS)    ((((ADDRESS) >= FLASH_EDATA_BASE_S)                                      && \
735                                              ((ADDRESS)  < (FLASH_EDATA_BASE_S+FLASH_EDATA_SIZE)))                  || \
736                                             (((ADDRESS) >= FLASH_EDATA_BASE_NS)                                     && \
737                                              ((ADDRESS)  < (FLASH_EDATA_BASE_NS+FLASH_EDATA_SIZE))))
738 #endif /* FLASH_EDATAR_EDATA_EN */
739 #else
740 #define IS_FLASH_USER_MEM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE)                                               && \
741                                             ((ADDRESS) < (FLASH_BASE+FLASH_SIZE)))
742 #if defined (FLASH_SR_OBKERR)
743 #define IS_FLASH_OBK_ADDRESS(ADDRESS)      (((ADDRESS) >= FLASH_OBK_BASE)                                           && \
744                                             ((ADDRESS) < (FLASH_OBK_BASE + FLASH_OBK_SIZE)))
745 #endif /* FLASH_SR_OBKERR */
746 #if defined (FLASH_EDATAR_EDATA_EN)
747 #define IS_FLASH_EDATA_ADDRESS(ADDRESS)    (((ADDRESS) >= FLASH_EDATA_BASE_NS)                                      && \
748                                             ((ADDRESS) < (FLASH_EDATA_BASE_NS + FLASH_EDATA_SIZE)))
749 #endif /* FLASH_EDATAR_EDATA_EN */
750 #endif /* __ARM_FEATURE_CMSE */
751 
752 #define IS_FLASH_OTP_ADDRESS(ADDRESS)      (((ADDRESS) >= FLASH_OTP_BASE)                                           && \
753                                             ((ADDRESS) < (FLASH_OTP_BASE + FLASH_OTP_SIZE)))
754 
755 #define IS_FLASH_BANK(BANK)              (((BANK) == FLASH_BANK_1)                                                  || \
756                                           ((BANK) == FLASH_BANK_2)                                                  || \
757                                           ((BANK) == FLASH_BANK_BOTH))
758 
759 #define IS_FLASH_BANK_EXCLUSIVE(BANK)    (((BANK) == FLASH_BANK_1)                                                  || \
760                                           ((BANK) == FLASH_BANK_2))
761 
762 #define IS_FLASH_SECTOR(SECTOR)          ((SECTOR) < FLASH_SECTOR_NB)
763 
764 #define IS_FLASH_LATENCY(LATENCY)        (((LATENCY) == FLASH_LATENCY_0)                                            || \
765                                           ((LATENCY) == FLASH_LATENCY_1)                                            || \
766                                           ((LATENCY) == FLASH_LATENCY_2)                                            || \
767                                           ((LATENCY) == FLASH_LATENCY_3)                                            || \
768                                           ((LATENCY) == FLASH_LATENCY_4)                                            || \
769                                           ((LATENCY) == FLASH_LATENCY_5)                                            || \
770                                           ((LATENCY) == FLASH_LATENCY_6)                                            || \
771                                           ((LATENCY) == FLASH_LATENCY_7)                                            || \
772                                           ((LATENCY) == FLASH_LATENCY_8)                                            || \
773                                           ((LATENCY) == FLASH_LATENCY_9)                                            || \
774                                           ((LATENCY) == FLASH_LATENCY_10)                                           || \
775                                           ((LATENCY) == FLASH_LATENCY_11)                                           || \
776                                           ((LATENCY) == FLASH_LATENCY_12)                                           || \
777                                           ((LATENCY) == FLASH_LATENCY_13)                                           || \
778                                           ((LATENCY) == FLASH_LATENCY_14)                                           || \
779                                           ((LATENCY) == FLASH_LATENCY_15))
780 
781 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
782 #define IS_FLASH_SECURE_OPERATION()        ((pFlash.ProcedureOnGoing & FLASH_NON_SECURE_MASK) == 0U)
783 #else
784 #define IS_FLASH_SECURE_OPERATION()        (1U == 0U)
785 #endif /* __ARM_FEATURE_CMSE */
786 /**
787   * @}
788   */
789 /* Private functions ---------------------------------------------------------*/
790 /** @defgroup FLASH_Private_Functions FLASH Private Functions
791   * @{
792   */
793 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
794 /**
795   * @}
796   */
797 
798 /**
799   * @}
800   */
801 
802 /**
803   * @}
804   */
805 
806 #ifdef __cplusplus
807 }
808 #endif
809 
810 #endif /* STM32H5xx_HAL_FLASH_H */
811