1 /**
2   ******************************************************************************
3   * @file    stm32h5xx.h
4   * @author  MCD Application Team
5   * @brief   CMSIS STM32H5xx Device Peripheral Access Layer Header File.
6   *
7   *          The file is the unique include file that the application programmer
8   *          is using in the C source code, usually in main.c. This file contains:
9   *           - Configuration section that allows to select:
10   *              - The STM32H5xx device used in the target application
11   *              - To use or not the peripheral�s drivers in application code(i.e.
12   *                code will be based on direct access to peripheral�s registers
13   *                rather than drivers API), this option is controlled by
14   *                "#define USE_HAL_DRIVER"
15   *
16   ******************************************************************************
17   * @attention
18   *
19   * Copyright (c) 2023 STMicroelectronics.
20   * All rights reserved.
21   *
22   * This software is licensed under terms that can be found in the LICENSE file
23   * in the root directory of this software component.
24   * If no LICENSE file comes with this software, it is provided AS-IS.
25   *
26   ******************************************************************************
27   */
28 
29 /** @addtogroup CMSIS
30   * @{
31   */
32 
33 /** @addtogroup stm32h5xx
34   * @{
35   */
36 
37 #ifndef STM32H5xx_H
38 #define STM32H5xx_H
39 #include "math.h"
40 
41 #ifdef __cplusplus
42  extern "C" {
43 #endif /* __cplusplus */
44 
45 /** @addtogroup Library_configuration_section
46   * @{
47   */
48 
49 /**
50   * @brief STM32 Family
51   */
52 #if !defined (STM32H5)
53 #define STM32H5
54 #endif /* STM32H5 */
55 
56 /* Uncomment the line below according to the target STM32H5 device used in your
57    application
58   */
59 
60 #if !defined (STM32H573xx) && !defined (STM32H563xx) \
61     && !defined (STM32H562xx) && !defined (STM32H503xx) \
62     && !defined (STM32H533xx) && !defined (STM32H523xx)
63   /* #define STM32H573xx  */   /*!< STM32H573xx Devices   */
64   /* #define STM32H563xx  */   /*!< STM32H563xx Devices   */
65   /* #define STM32H562xx  */   /*!< STM32H562xx Devices   */
66   /* #define STM32H503xx  */   /*!< STM32H503xx Devices   */
67   /* #define STM32H533xx  */   /*!< STM32H533xx Devices   */
68   /* #define STM32H523xx  */   /*!< STM32H523xx Devices   */
69 #endif
70 
71 /*  Tip: To avoid modifying this file each time you need to switch between these
72         devices, you can define the device in your toolchain compiler preprocessor.
73   */
74 #if !defined  (USE_HAL_DRIVER)
75 /**
76  * @brief Comment the line below if you will not use the peripherals drivers.
77    In this case, these drivers will not be included and the application code will
78    be based on direct access to peripherals registers
79    */
80   /*#define USE_HAL_DRIVER */
81 #endif /* USE_HAL_DRIVER */
82 
83 /**
84   * @brief CMSIS Device version number 1.3.1
85   */
86 #define __STM32H5_CMSIS_VERSION_MAIN   (0x01) /*!< [31:24] main version */
87 #define __STM32H5_CMSIS_VERSION_SUB1   (0x03) /*!< [23:16] sub1 version */
88 #define __STM32H5_CMSIS_VERSION_SUB2   (0x01) /*!< [15:8]  sub2 version */
89 #define __STM32H5_CMSIS_VERSION_RC     (0x00) /*!< [7:0]  release candidate */
90 #define __STM32H5_CMSIS_VERSION        ((__STM32H5_CMSIS_VERSION_MAIN << 24U)\
91                                        |(__STM32H5_CMSIS_VERSION_SUB1 << 16U)\
92                                        |(__STM32H5_CMSIS_VERSION_SUB2 << 8U )\
93                                        |(__STM32H5_CMSIS_VERSION_RC))
94 
95 /**
96   * @}
97   */
98 
99 /** @addtogroup Device_Included
100   * @{
101   */
102 #if defined(STM32H573xx)
103   #include "stm32h573xx.h"
104 #elif defined(STM32H563xx)
105   #include "stm32h563xx.h"
106 #elif defined(STM32H562xx)
107   #include "stm32h562xx.h"
108 #elif defined(STM32H503xx)
109   #include "stm32h503xx.h"
110 #elif defined(STM32H523xx)
111   #include "stm32h523xx.h"
112 #elif defined(STM32H533xx)
113   #include "stm32h533xx.h"
114 #else
115   #error "Please select first the target STM32H5xx device used in your application (in stm32h5xx.h file)"
116 #endif
117 
118 
119 /**
120   * @}
121   */
122 
123 /** @addtogroup Exported_types
124   * @{
125   */
126 typedef enum
127 {
128   RESET = 0,
129   SET = !RESET
130 } FlagStatus, ITStatus;
131 
132 typedef enum
133 {
134   DISABLE = 0,
135   ENABLE = !DISABLE
136 } FunctionalState;
137 #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
138 
139 typedef enum
140 {
141   SUCCESS = 0,
142   ERROR = !SUCCESS
143 } ErrorStatus;
144 
145 /**
146   * @}
147   */
148 
149 
150 /** @addtogroup Exported_macros
151   * @{
152   */
153 #define SET_BIT(REG, BIT)     ((REG) |= (BIT))
154 
155 #define CLEAR_BIT(REG, BIT)   ((REG) &= ~(BIT))
156 
157 #define READ_BIT(REG, BIT)    ((REG) & (BIT))
158 
159 #define CLEAR_REG(REG)        ((REG) = (0x0))
160 
161 #define WRITE_REG(REG, VAL)   ((REG) = (VAL))
162 
163 #define READ_REG(REG)         ((REG))
164 
165 #define MODIFY_REG(REG, CLEARMASK, SETMASK)  WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
166 
167 /* Use of CMSIS compiler intrinsics for register exclusive access */
168 /* Atomic 32-bit register access macro to set one or several bits */
169 #define ATOMIC_SET_BIT(REG, BIT)                             \
170   do {                                                       \
171     uint32_t val;                                            \
172     do {                                                     \
173       val = __LDREXW((__IO uint32_t *)&(REG)) | (BIT);       \
174     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
175   } while(0)
176 
177 /* Atomic 32-bit register access macro to clear one or several bits */
178 #define ATOMIC_CLEAR_BIT(REG, BIT)                           \
179   do {                                                       \
180     uint32_t val;                                            \
181     do {                                                     \
182       val = __LDREXW((__IO uint32_t *)&(REG)) & ~(BIT);      \
183     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
184   } while(0)
185 
186 /* Atomic 32-bit register access macro to clear and set one or several bits */
187 #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK)                          \
188   do {                                                                     \
189     uint32_t val;                                                          \
190     do {                                                                   \
191       val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
192     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U);               \
193   } while(0)
194 
195 /* Atomic 16-bit register access macro to set one or several bits */
196 #define ATOMIC_SETH_BIT(REG, BIT)                            \
197   do {                                                       \
198     uint16_t val;                                            \
199     do {                                                     \
200       val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT);       \
201     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
202   } while(0)
203 
204 /* Atomic 16-bit register access macro to clear one or several bits */
205 #define ATOMIC_CLEARH_BIT(REG, BIT)                          \
206   do {                                                       \
207     uint16_t val;                                            \
208     do {                                                     \
209       val = __LDREXH((__IO uint16_t *)&(REG)) & ~(BIT);      \
210     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
211   } while(0)
212 
213 /* Atomic 16-bit register access macro to clear and set one or several bits */
214 #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK)                         \
215   do {                                                                     \
216     uint16_t val;                                                          \
217     do {                                                                   \
218       val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
219     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U);               \
220   } while(0)
221 
222 #define POSITION_VAL(VAL)     (__CLZ(__RBIT(VAL)))
223 
224 
225 /**
226   * @}
227   */
228 
229 #if defined (USE_HAL_DRIVER)
230  #include "stm32h5xx_hal.h"
231 #endif /* USE_HAL_DRIVER */
232 
233 #ifdef __cplusplus
234 }
235 #endif /* __cplusplus */
236 
237 #endif /* STM32H5xx_H */
238 /**
239   * @}
240   */
241 
242 /**
243   * @}
244   */
245