1 /**
2   ******************************************************************************
3   * @file    stm32wb0x_hal_flash.h
4   * @author  MCD Application Team
5   * @brief   Header file of FLASH HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2024 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 STM32WB0x_HAL_FLASH_H
21 #define STM32WB0x_HAL_FLASH_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32wb0x_hal_def.h"
29 
30 /** @addtogroup STM32WB0x_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 Erase structure definition
45   */
46 typedef struct
47 {
48   uint32_t TypeErase;   /*!< Mass erase or page erase.
49                             This parameter can be a value of @ref FLASH_TYPE_ERASE */
50   uint32_t Page;        /*!< Initial Flash page to erase when page erase is enabled
51                             This parameter must be a value between 0 and (max number of pages - 1) */
52   uint32_t NbPages;     /*!< Number of pages to be erased.
53                             This parameter must be a value between 1 and (max number of pages - value of initial page)*/
54 } FLASH_EraseInitTypeDef;
55 
56 /**
57   * @brief  FLASH handle Structure definition
58   */
59 typedef struct
60 {
61   HAL_LockTypeDef   Lock;              /*!< FLASH locking object */
62   uint32_t          ErrorCode;         /*!< FLASH error code */
63   uint32_t          ProcedureOnGoing;  /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
64   uint32_t          Address;           /*!< Internal variable to save address selected for program in IT context */
65   uint32_t          Page;              /*!< Internal variable to define the current page which is erasing in IT context */
66   uint32_t          NbPagesToErase;    /*!< Internal variable to save the remaining pages to erase in IT context */
67 } FLASH_ProcessTypeDef;
68 
69 /**
70   * @}
71   */
72 
73 /* Exported constants --------------------------------------------------------*/
74 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
75   * @{
76   */
77 
78 /** @defgroup FLASH_WAIT_STATES FLASH Wait States
79   * @{
80   */
81 #define FLASH_WAIT_STATES_0                 0x00000000U                 /*!< FLASH Zero wait state   */
82 #define FLASH_WAIT_STATES_1                 FLASH_CONFIG_WAIT_STATES_0  /*!< FLASH One wait state    */
83 /**
84   * @}
85   */
86 
87 /** @defgroup FLASH_CONFIG_IRQ_VECT_TABLE FLASH Configuration Interrupt Vector Table
88   * @{
89   */
90 #define FLASH_CONFIG_IRQ_VECT_TABLE_FLASH    0x00000000U          /*!< Vector Table located in FLASH */
91 #define FLASH_CONFIG_IRQ_VECT_TABLE_RAM      FLASH_CONFIG_REMAP   /*!< Vector Table located in RAM   */
92 /**
93   * @}
94   */
95 
96 /** @defgroup FLASH_FLAGS FLASH Flags Definition
97   * @{
98   */
99 #define FLASH_FLAG_CMDDONE             FLASH_IRQRAW_CMDDONE_RIS     /*!< FLASH command done flag      */
100 #define FLASH_FLAG_CMDSTART            FLASH_IRQRAW_CMDSTART_RIS    /*!< FLASH command started flag   */
101 #define FLASH_FLAG_CMDERR              FLASH_IRQRAW_CMDERR_RIS      /*!< FLASH command error flag     */
102 #define FLASH_FLAG_ILLCMD              FLASH_IRQRAW_ILLCMD_RIS      /*!< FLASH illegal command flag   */
103 #define FLASH_FLAG_READOK              FLASH_IRQRAW_READOK_RIS      /*!< FLASH mass read command flag */
104 
105 #define FLASH_FLAG_ALL_ERRORS          (FLASH_IRQRAW_CMDERR_RIS | FLASH_IRQRAW_ILLCMD_RIS)
106 
107 /**
108   * @}
109   */
110 
111 /** @defgroup FLASH_INTERRUPT_DEFINITION FLASH Interrupts Definition
112   * @brief FLASH Interrupt definition
113   * @{
114   */
115 #define FLASH_IT_CMDDONE               FLASH_IRQMASK_CMDDONEM     /*!< FLASH command done Interrupt source      */
116 #define FLASH_IT_CMDSTART              FLASH_IRQMASK_CMDSTARTM    /*!< FLASH command started Interrupt source   */
117 #define FLASH_IT_CMDERR                FLASH_IRQMASK_CMDERRM      /*!< FLASH command error Interrupt source     */
118 #define FLASH_IT_ILLCMD                FLASH_IRQMASK_ILLCMDM      /*!< FLASH illegal command Interrupt source   */
119 #define FLASH_IT_READOK                FLASH_IRQMASK_READOKM      /*!< FLASH mass read command Interrupt source */
120 
121 /**
122   * @}
123   */
124 
125 /** @defgroup FLASH_ERROR FLASH Error
126   * @{
127   */
128 #define HAL_FLASH_ERROR_NONE            0x00000000U
129 #define HAL_FLASH_ERROR_OP              FLASH_FLAG_CMDERR
130 #define HAL_FLASH_ERROR_ILLCMD          FLASH_FLAG_ILLCMD
131 
132 /**
133   * @}
134   */
135 
136 /** @defgroup FLASH_COMMAND FLASH Command
137   * @{
138   */
139 #define FLASH_CMD_ERASE_PAGES           0x11  /*!< Flash pages erase command   */
140 #define FLASH_CMD_MASSERASE             0x22  /*!< Flash mass erase command    */
141 #define FLASH_CMD_WRITE                 0x33  /*!< Flash write command         */
142 #define FLASH_CMD_MASSREAD              0x55  /*!< Flash mass read command     */
143 #define FLASH_CMD_SLEEP                 0xAA  /*!< Flash in sleep mode command */
144 #define FLASH_CMD_WAKEUP                0xBB  /*!< Flash wakeup command        */
145 #define FLASH_CMD_BURSTWRITE            0xCC  /*!< Flash burst write command   */
146 #define FLASH_CMD_OTPWRITE              0xEE  /*!< Flash OTP write command     */
147 #define FLASH_CMD_KEYWRITE              0xFF  /*!< Flash keywrite command      */
148 
149 /**
150   * @}
151   */
152 
153 /** @defgroup FLASH_TYPE_ERASE FLASH Erase Type
154   * @{
155   */
156 #define FLASH_TYPEERASE_PAGES            0x00  /*!< Pages erase      */
157 #define FLASH_TYPEERASE_MASSERASE        0xFF  /*!< Flash mass erase */
158 /**
159   * @}
160   */
161 
162 /** @defgroup FLASH_TYPE_PROGRAM FLASH Program Type
163   * @{
164   */
165 #define FLASH_TYPEPROGRAM_WORD          0x00000000U
166 #define FLASH_TYPEPROGRAM_BURST         0x00000001U
167 /**
168   * @}
169   */
170 
171 /** @defgroup FLASH_PAGEPROT_GROUP FLASH write/page erase protection for group
172   * @{
173   */
174 #define FLASH_PAGEPROT_GROUP_15           (0x8000UL)    /*!< write/page erase protection for group 15 containing Flash pages 120 to 127 */
175 #define FLASH_PAGEPROT_GROUP_14           (0x4000UL)    /*!< write/page erase protection for group 14 containing Flash pages 112 to 119 */
176 #define FLASH_PAGEPROT_GROUP_13           (0x2000UL)    /*!< write/page erase protection for group 13 containing Flash pages 104 to 111 */
177 #define FLASH_PAGEPROT_GROUP_12           (0x1000UL)    /*!< write/page erase protection for group 12 containing Flash pages 96 to 103  */
178 #define FLASH_PAGEPROT_GROUP_11           (0x0800UL)    /*!< write/page erase protection for group 11 containing Flash pages 88 to 95   */
179 #define FLASH_PAGEPROT_GROUP_10           (0x0400UL)    /*!< write/page erase protection for group 10 containing Flash pages 80 to 87   */
180 #define FLASH_PAGEPROT_GROUP_9            (0x0200UL)    /*!< write/page erase protection for group 9  containing Flash pages 72 to 79   */
181 #define FLASH_PAGEPROT_GROUP_8            (0x0100UL)    /*!< write/page erase protection for group 8  containing Flash pages 64 to 71   */
182 #define FLASH_PAGEPROT_GROUP_7            (0x0080UL)    /*!< write/page erase protection for group 7  containing Flash pages 56 to 63   */
183 #define FLASH_PAGEPROT_GROUP_6            (0x0040UL)    /*!< write/page erase protection for group 6  containing Flash pages 48 to 55   */
184 #define FLASH_PAGEPROT_GROUP_5            (0x0020UL)    /*!< write/page erase protection for group 5  containing Flash pages 40 to 47   */
185 #define FLASH_PAGEPROT_GROUP_4            (0x0010UL)    /*!< write/page erase protection for group 4  containing Flash pages 32 to 39   */
186 #define FLASH_PAGEPROT_GROUP_3            (0x0008UL)    /*!< write/page erase protection for group 3  containing Flash pages 24 to 31   */
187 #define FLASH_PAGEPROT_GROUP_2            (0x0004UL)    /*!< write/page erase protection for group 2  containing Flash pages 16 to 23   */
188 #define FLASH_PAGEPROT_GROUP_1            (0x0002UL)    /*!< write/page erase protection for group 1  containing Flash pages 8 to 15    */
189 #define FLASH_PAGEPROT_GROUP_0            (0x0001UL)    /*!< write/page erase protection for group 0  containing Flash pages 0 to 7     */
190 /**
191   * @}
192   */
193 
194 
195 /**
196   * @brief  Page Protection function configuration structure definition
197   */
198 typedef struct
199 {
200   uint32_t pageProt_0;       /*!< For cut 1.0 indicate the group to configure.
201                                   - This parameter can be a value of @ref FLASH_PAGEPROT_GROUP
202                                   For cut 2.0 it is a bitfield built as follows:
203                                   - bit[6:0]   = SIZE: number of 2kB pages to protect including the starting page
204                                                        @ref pageProt_0 param (provided in the offset bits)
205                                   - bit[7]     = reserved
206                                   - bit[14:8]  = OFFSET: page number to start the write protection
207                                                         (value between 0 and 0x7F)
208                                   - bit[15]    = reserved
209                                   - bit[22:16] = SIZE: same meaning of bit[6:0]
210                                   - bit[23]    = reserved
211                                   - bit[30:24] = OFFSET: same meaning of bit[22:16]
212                                   - bit[31]    = reserved                                                           */
213   uint32_t pageProt_1;       /*!< Valid only for cut 2.0 same meaning of @ref pageProt_0 parameter                  */
214   FunctionalState state;     /*!< The new state of the group.
215                                       This parameter can be a value of FunctionalState enumeration                  */
216 } FLASH_PageProtectionTypeDef;
217 
218 /** @defgroup FLASH_ PROTECTION_level FLASH Protection level
219   * @{
220   */
221 
222 #define PROT_LEVEL_NONE               0x00000000U
223 #define PROT_LEVEL_1                  0x00000001U
224 #define PROT_LEVEL_2                  0x00000002U
225 #define PROT_LEVEL_3                  0x00000003U
226 
227 /**
228   * @}
229   */
230 
231 /** @defgroup FLASH_KEYS FLASH Keys
232   * @{
233   */
234 #define FLASH_KEY0                    0xFFFFFFFFU      /*!< Flash key0 */
235 #define FLASH_KEY1                    0xAAAAAAAAU      /*!< Flash key1 */
236 #define FLASH_KEY2                    0xABACABADU      /*!< Flash key2 */
237 #define FLASH_DATAKEY2                0xC7EF584DU
238 #define FLASH_DATAKEY3                0xB3A21096U
239 /**
240   * @}
241   */
242 
243 
244 /**
245   * @}
246   */
247 
248 /* Exported macros -----------------------------------------------------------*/
249 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
250   * @brief macros to control FLASH features
251   * @{
252   */
253 
254 /** @defgroup FLASH_Configuration_Macros FLASH Configuration Macros
255   * @brief macros to configure the FLASH
256   * @{
257   */
258 
259 /**
260   * @brief  Set the FLASH Wait States.
261   * @param __WAIT_STATES__ FLASH WAIT States
262   *         This parameter can be one of the following values :
263   *     @arg @ref FLASH_WAIT_STATES_0 FLASH Zero wait state
264   *     @arg @ref FLASH_WAIT_STATES_1 FLASH One wait state
265   * @retval None
266   */
267 #define __HAL_FLASH_SET_WAIT_STATES(__WAIT_STATES__)    MODIFY_REG(FLASH->CONFIG, FLASH_CONFIG_WAIT_STATES, (__WAIT_STATES__))
268 
269 /**
270   * @brief  Get the FLASH Wait States.
271   * @retval FLASH Wait States
272   *         Returned value can be one of the following values :
273   *     @arg @ref FLASH_WAIT_STATES_0 FLASH Zero wait state
274   *     @arg @ref FLASH_WAIT_STATES_1 FLASH One wait state
275   */
276 #define __HAL_FLASH_GET_WAIT_STATES()               READ_BIT(FLASH->CONFIG, FLASH_CONFIG_WAIT_STATES)
277 
278 /**
279   * @brief  Enable the FLASH burst write operations.
280   * @retval None
281   */
282 #define __HAL_FLASH_BURSTWRITE_ENABLE()    CLEAR_BIT(FLASH->CONFIG, FLASH_CONFIG_DIS_GROUP_WRITE)
283 
284 /**
285   * @brief  Disable the FLASH burst write operations.
286   * @retval None
287   */
288 #define __HAL_FLASH_BURSTWRITE_DISABLE()    SET_BIT(FLASH->CONFIG, FLASH_CONFIG_DIS_GROUP_WRITE)
289 
290 /**
291   * @brief  Set the FLASH Interrupt Vector Table location.
292   * @param __VECT_TABLE__ Vector Table Configuration
293   *         This parameter can be one of the following values :
294   *     @arg @ref FLASH_CONFIG_IRQ_VECT_TABLE_FLASH Vector Table located in FLASH
295   *     @arg @ref FLASH_CONFIG_IRQ_VECT_TABLE_RAM   Vector Table located in RAM
296   * @retval None
297   */
298 #define __HAL_FLASH_SET_VECT_TABLE(__VECT_TABLE__)    MODIFY_REG(FLASH->CONFIG, FLASH_CONFIG_REMAP, (__VECT_TABLE__))
299 
300 /**
301   * @brief  Get the FLASH Interrupt Vector Table location.
302   * @retval Vector Table Configuration
303   *         Returned value can be one of the following values :
304   *     @arg @ref FLASH_CONFIG_IRQ_VECT_TABLE_FLASH Vector Table located in FLASH
305   *     @arg @ref FLASH_CONFIG_IRQ_VECT_TABLE_RAM   Vector Table located in RAM
306   */
307 #define __HAL_FLASH_GET_VECT_TABLE()               READ_BIT(FLASH->CONFIG, FLASH_CONFIG_REMAP)
308 
309 /**
310   * @}
311   */
312 
313 /** @defgroup FLASH_Interrupt FLASH Interrupts Macros
314   *  @brief macros to handle FLASH interrupts
315   * @{
316   */
317 
318 /**
319   * @brief  Enable the specified FLASH interrupt.
320   * @param __INTERRUPT__ FLASH interrupt
321   *         This parameter can be any combination of the following values:
322   *     @arg @ref FLASH_IT_CMDDONE  Command Done Interrupt
323   *     @arg @ref FLASH_IT_CMDSTART Command Started Interrupt
324   *     @arg @ref FLASH_IT_CMDERR   Command Error Interrupt
325   *     @arg @ref FLASH_IT_ILLCMD   Illegal Command Interrupt
326   *     @arg @ref FLASH_IT_READOK   Mass read Command Interrupt
327   * @retval none
328   */
329 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__)    CLEAR_BIT(FLASH->IRQMASK, (__INTERRUPT__))
330 
331 /**
332   * @brief  Disable the specified FLASH interrupt.
333   * @param __INTERRUPT__ FLASH interrupt
334   *         This parameter can be any combination of the following values:
335   *     @arg @ref FLASH_IT_CMDDONE  Command Done Interrupt
336   *     @arg @ref FLASH_IT_CMDSTART Command Started Interrupt
337   *     @arg @ref FLASH_IT_CMDERR   Command Error Interrupt
338   *     @arg @ref FLASH_IT_ILLCMD   Illegal Command Interrupt
339   *     @arg @ref FLASH_IT_READOK   Mass read Command Interrupt
340   * @retval none
341   */
342 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__)   SET_BIT(FLASH->IRQMASK, (__INTERRUPT__))
343 
344 /**
345   * @brief  Check whether the specified FLASH interrupt has occurred or not.
346   * @param __INTERRUPT__ FLASH interrupt
347   *         This parameter can be any combination of the following values:
348   *     @arg @ref FLASH_IT_CMDDONE  Command Done Interrupt
349   *     @arg @ref FLASH_IT_CMDSTART Command Started Interrupt
350   *     @arg @ref FLASH_IT_CMDERR   Command Error Interrupt
351   *     @arg @ref FLASH_IT_ILLCMD   Illegal Command Interrupt
352   *     @arg @ref FLASH_IT_READOK   Mass read Command Interrupt
353   * @retval The new state of __INTERRUPT__ (SET or RESET).
354   */
355 #define __HAL_FLASH_GET_IT(__INTERRUPT__)   ((READ_BIT(FLASH->IRQSTAT, (__INTERRUPT__)) != RESET) ? SET : RESET)
356 
357 /**
358   * @brief Clear the specified FLASH interrupt flag.
359   * @param __INTERRUPT__ FLASH interrupt
360   *         This parameter can be any combination of the following values:
361   *     @arg @ref FLASH_IT_CMDDONE  Command Done Interrupt
362   *     @arg @ref FLASH_IT_CMDSTART Command Started Interrupt
363   *     @arg @ref FLASH_IT_CMDERR   Command Error Interrupt
364   *     @arg @ref FLASH_IT_ILLCMD   Illegal Command Interrupt
365   *     @arg @ref FLASH_IT_READOK   Mass read Command Interrupt
366   * @retval None
367   */
368 #define __HAL_FLASH_CLEAR_IT(__INTERRUPT__)   SET_BIT(FLASH->IRQSTAT, (__INTERRUPT__))
369 
370 /**
371   * @}
372   */
373 
374 /** @defgroup FLASH_FLAG FLASH Flags Macros
375   *  @brief macros to handle FLASH
376   * @{
377   */
378 
379 /**
380   * @brief  Check whether the specified FLASH flag is set or not.
381   * @param __FLAG__ specifies the FLASH flag to check.
382   *   This parameter can be one of the following values:
383   *     @arg @ref FLASH_FLAG_CMDDONE     FLASH command done flag
384   *     @arg @ref FLASH_FLAG_CMDSTART    FLASH command started flag
385   *     @arg @ref FLASH_FLAG_CMDERR      FLASH command error flag
386   *     @arg @ref FLASH_FLAG_ILLCMD      FLASH illegal command flag
387   *     @arg @ref FLASH_FLAG_READOK      FLASH mass read flag
388   * @retval The new state of FLASH_FLAG (SET or RESET).
389   */
390 #define __HAL_FLASH_GET_FLAG(__FLAG__)  ((READ_BIT(FLASH->IRQRAW, (__FLAG__)) == (__FLAG__)) ? 1UL : 0UL)
391 
392 /**
393   * @brief  Clear the FLASH's pending flags.
394   * @param __FLAG__ specifies the FLASH flags to clear.
395   *   This parameter can be any combination of the following values:
396   *     @arg @ref FLASH_FLAG_CMDDONE     FLASH command done flag
397   *     @arg @ref FLASH_FLAG_CMDSTART    FLASH command started flag
398   *     @arg @ref FLASH_FLAG_CMDERR      FLASH command error flag
399   *     @arg @ref FLASH_FLAG_ILLCMD      FLASH illegal command flag
400   *     @arg @ref FLASH_FLAG_READOK      FLASH mass read flag
401   * @retval None
402   */
403 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) (SET_BIT(FLASH->IRQRAW, (__FLAG__)))
404 
405 /**
406   * @}
407   */
408 
409 /**
410   * @}
411   */
412 
413 /* Include FLASH HAL Extended module */
414 #include "stm32wb0x_hal_flash_ex.h"
415 
416 /* Exported variables --------------------------------------------------------*/
417 /** @defgroup FLASH_Exported_Variables FLASH Exported Variables
418   * @{
419   */
420 extern FLASH_ProcessTypeDef pFlash;
421 /**
422   * @}
423   */
424 
425 /* Exported functions --------------------------------------------------------*/
426 /** @addtogroup FLASH_Exported_Functions
427   * @{
428   */
429 
430 /* Program operation functions  ***********************************************/
431 /** @addtogroup FLASH_Exported_Functions_Group1
432   * @{
433   */
434 HAL_StatusTypeDef  HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data);
435 HAL_StatusTypeDef  HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint32_t Data);
436 /* FLASH IRQ handler method */
437 void               HAL_FLASH_IRQHandler(void);
438 /* Callbacks in non blocking modes */
439 void               HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
440 void               HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
441 /**
442   * @}
443   */
444 
445 /* Peripheral State functions  ************************************************/
446 /** @addtogroup FLASH_Exported_Functions_Group2
447   * @{
448   */
449 uint32_t HAL_FLASH_GetError(void);
450 /**
451   * @}
452   */
453 
454 /**
455   * @}
456   */
457 
458 /* Private types --------------------------------------------------------*/
459 /** @defgroup FLASH_Private_types FLASH Private Types
460   * @{
461   */
462 HAL_StatusTypeDef  FLASH_WaitForLastOperation(uint32_t Timeout);
463 /**
464   * @}
465   */
466 
467 /* Private constants --------------------------------------------------------*/
468 /** @defgroup FLASH_Private_Constants FLASH Private Constants
469   * @{
470   */
471 #define FLASH_SIZE_MASK                 FLASH_FLASH_SIZE_FLASH_SIZE
472 #define FLASH_SIZE                      (((*(uint32_t *)FLASHSIZE_BASE & FLASH_SIZE_MASK) + 1) << 2U)
473 #define FLASH_START_ADDR                NVM_BASE
474 #define FLASH_END_ADDR                  (FLASH_START_ADDR + FLASH_SIZE - 1U)
475 
476 #define FLASH_PAGE_SIZE                 0x00000800U  /*!< FLASH Page Size, 2KBytes */
477 #define FLASH_PAGE_NUMBER               (FLASH_SIZE/FLASH_PAGE_SIZE )
478 #define FLASH_TIMEOUT_VALUE             1000U        /*!< FLASH Execution Timeout, 1 s */
479 
480 #define FLASH_WRERP_GRANULARITY         0x00004000U  /*!< FLASH Write/Erase Protection Granularity, 16KBytes */
481 #define FLASH_PCROP_GRANULARITY         FLASH_SIZE   /*!< FLASH Code Readout Protection Granularity, all the MAIN FLASH */
482 
483 #define FLASH_TYPENONE                  0x00000000U  /*!< No Programming Procedure On Going */
484 
485 /**
486   * @}
487   */
488 
489 /* Private macros ------------------------------------------------------------*/
490 /** @defgroup FLASH_Private_Macros FLASH Private Macros
491   *  @{
492   */
493 
494 #define IS_FLASH_MAIN_MEM_ADDRESS(__VALUE__)        (((__VALUE__) >= FLASH_START_ADDR) &&\
495                                                      ((__VALUE__) <= FLASH_END_ADDR))
496 
497 #define IS_FLASH_PROGRAM_MAIN_MEM_ADDRESS(__VALUE__)   (((__VALUE__) >= FLASH_START_ADDR) &&\
498                                                         ((__VALUE__) <= (FLASH_START_ADDR + FLASH_SIZE - 4UL)) && (((__VALUE__) % 4UL) == 0UL))
499 
500 #define IS_FLASH_PROGRAM_OTP_ADDRESS(__VALUE__)     (((__VALUE__) >= OTP_AREA_BASE) &&\
501                                                      ((__VALUE__) <= (OTP_AREA_END_ADDR + 1UL - 4UL)) && (((__VALUE__) % 4UL) == 0UL))
502 
503 #define IS_FLASH_PROGRAM_ADDRESS(__VALUE__)         ((IS_FLASH_PROGRAM_MAIN_MEM_ADDRESS(__VALUE__)) ||\
504                                                      (IS_FLASH_PROGRAM_OTP_ADDRESS(__VALUE__)))
505 
506 #define IS_FLASH_PAGE(__VALUE__)                    ((__VALUE__) <= FLASH_PAGE_NUMBER)
507 
508 #define IS_ADDR_ALIGNED_32BITS(__VALUE__)           (((__VALUE__) & ~0x3U) == (__VALUE__))
509 
510 #define IS_FLASH_WAIT_STATES(__VALUE__)             (((__VALUE__) == FLASH_WAIT_STATES_0) || \
511                                                      ((__VALUE__) == FLASH_WAIT_STATES_1))
512 
513 #define IS_FLASH_TYPE_ERASE(__VALUE__)              (((__VALUE__) == FLASH_TYPEERASE_PAGES) || \
514                                                      ((__VALUE__) == FLASH_TYPEERASE_MASSERASE))
515 
516 #define IS_FLASH_TYPEPROGRAM(__VALUE__)             (((__VALUE__) == FLASH_TYPEPROGRAM_WORD) || \
517                                                      ((__VALUE__) == FLASH_TYPEPROGRAM_BURST))
518 
519 #define IS_PROTECTION_LEVEL(__VALUE__)              (((__VALUE__) == PROT_LEVEL_1)   ||\
520                                                      ((__VALUE__) == PROT_LEVEL_2)   ||\
521                                                      ((__VALUE__) == PROT_LEVEL_3)   ||\
522                                                      ((__VALUE__) == PROT_LEVEL_NONE))
523 
524 /**
525   * @}
526   */
527 
528 /**
529   * @}
530   */
531 
532 /**
533   * @}
534   */
535 
536 #ifdef __cplusplus
537 }
538 #endif
539 
540 #endif /* STM32WB0x_HAL_FLASH_H */
541