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