1 /**
2   ******************************************************************************
3   * @file    stm32g4xx.h
4   * @author  MCD Application Team
5   * @brief   CMSIS STM32G4xx 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 STM32G4xx 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) 2019 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 stm32g4xx
34   * @{
35   */
36 
37 #ifndef __STM32G4xx_H
38 #define __STM32G4xx_H
39 
40 #ifdef __cplusplus
41  extern "C" {
42 #endif /* __cplusplus */
43 
44 /** @addtogroup Library_configuration_section
45   * @{
46   */
47 
48 /**
49   * @brief STM32 Family
50   */
51 #if !defined (STM32G4)
52 #define STM32G4
53 #endif /* STM32G4 */
54 
55 /* Uncomment the line below according to the target STM32G4 device used in your
56    application
57   */
58 
59 #if !defined (STM32G431xx) && !defined (STM32G441xx) && !defined (STM32G471xx) && \
60     !defined (STM32G473xx) && !defined (STM32G474xx) && !defined (STM32G484xx) && \
61     !defined (STM32GBK1CB) && !defined (STM32G491xx) && !defined (STM32G4A1xx)
62   /* #define STM32G431xx */   /*!< STM32G431xx Devices */
63   /* #define STM32G441xx */   /*!< STM32G441xx Devices */
64   /* #define STM32G471xx */   /*!< STM32G471xx Devices */
65   /* #define STM32G473xx */   /*!< STM32G473xx Devices */
66   /* #define STM32G483xx */   /*!< STM32G483xx Devices */
67   /* #define STM32G474xx */   /*!< STM32G474xx Devices */
68   /* #define STM32G484xx */   /*!< STM32G484xx Devices */
69   /* #define STM32G491xx */   /*!< STM32G491xx Devices */
70   /* #define STM32G4A1xx */   /*!< STM32G4A1xx Devices */
71   /* #define STM32GBK1CB */   /*!< STM32GBK1CB Devices */
72 #endif
73 
74 /*  Tip: To avoid modifying this file each time you need to switch between these
75         devices, you can define the device in your toolchain compiler preprocessor.
76   */
77 #if !defined  (USE_HAL_DRIVER)
78 /**
79  * @brief Comment the line below if you will not use the peripherals drivers.
80    In this case, these drivers will not be included and the application code will
81    be based on direct access to peripherals registers
82    */
83   /*#define USE_HAL_DRIVER */
84 #endif /* USE_HAL_DRIVER */
85 
86 /**
87   * @brief CMSIS Device version number V1.2.2
88   */
89 #define __STM32G4_CMSIS_VERSION_MAIN   (0x01U) /*!< [31:24] main version */
90 #define __STM32G4_CMSIS_VERSION_SUB1   (0x02U) /*!< [23:16] sub1 version */
91 #define __STM32G4_CMSIS_VERSION_SUB2   (0x02U) /*!< [15:8]  sub2 version */
92 #define __STM32G4_CMSIS_VERSION_RC     (0x00U) /*!< [7:0]  release candidate */
93 #define __STM32G4_CMSIS_VERSION        ((__STM32G4_CMSIS_VERSION_MAIN << 24)\
94                                        |(__STM32G4_CMSIS_VERSION_SUB1 << 16)\
95                                        |(__STM32G4_CMSIS_VERSION_SUB2 << 8 )\
96                                        |(__STM32G4_CMSIS_VERSION_RC))
97 
98 /**
99   * @}
100   */
101 
102 /** @addtogroup Device_Included
103   * @{
104   */
105 
106 #if defined(STM32G431xx)
107   #include "stm32g431xx.h"
108 #elif defined(STM32G441xx)
109   #include "stm32g441xx.h"
110 #elif defined(STM32G471xx)
111   #include "stm32g471xx.h"
112 #elif defined(STM32G473xx)
113   #include "stm32g473xx.h"
114 #elif defined(STM32G483xx)
115   #include "stm32g483xx.h"
116 #elif defined(STM32G474xx)
117   #include "stm32g474xx.h"
118 #elif defined(STM32G484xx)
119   #include "stm32g484xx.h"
120 #elif defined(STM32G491xx)
121   #include "stm32g491xx.h"
122 #elif defined(STM32G4A1xx)
123   #include "stm32g4a1xx.h"
124 #elif defined(STM32GBK1CB)
125   #include "stm32gbk1cb.h"
126 #else
127   #error "Please select first the target STM32G4xx device used in your application (in stm32g4xx.h file)"
128 #endif
129 
130 /**
131   * @}
132   */
133 
134 /** @addtogroup Exported_types
135   * @{
136   */
137 typedef enum
138 {
139   RESET = 0,
140   SET = !RESET
141 } FlagStatus, ITStatus;
142 
143 typedef enum
144 {
145   DISABLE = 0,
146   ENABLE = !DISABLE
147 } FunctionalState;
148 #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
149 
150 typedef enum
151 {
152   SUCCESS = 0,
153   ERROR = !SUCCESS
154 } ErrorStatus;
155 
156 /**
157   * @}
158   */
159 
160 
161 /** @addtogroup Exported_macros
162   * @{
163   */
164 #define SET_BIT(REG, BIT)     ((REG) |= (BIT))
165 
166 #define CLEAR_BIT(REG, BIT)   ((REG) &= ~(BIT))
167 
168 #define READ_BIT(REG, BIT)    ((REG) & (BIT))
169 
170 #define CLEAR_REG(REG)        ((REG) = (0x0))
171 
172 #define WRITE_REG(REG, VAL)   ((REG) = (VAL))
173 
174 #define READ_REG(REG)         ((REG))
175 
176 #define MODIFY_REG(REG, CLEARMASK, SETMASK)  WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
177 
178 #define POSITION_VAL(VAL)     (__CLZ(__RBIT(VAL)))
179 
180 /* Use of CMSIS compiler intrinsics for register exclusive access */
181 /* Atomic 32-bit register access macro to set one or several bits */
182 #define ATOMIC_SET_BIT(REG, BIT)                             \
183   do {                                                       \
184     uint32_t val;                                            \
185     do {                                                     \
186       val = __LDREXW((__IO uint32_t *)&(REG)) | (BIT);       \
187     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
188   } while(0)
189 
190 /* Atomic 32-bit register access macro to clear one or several bits */
191 #define ATOMIC_CLEAR_BIT(REG, BIT)                           \
192   do {                                                       \
193     uint32_t val;                                            \
194     do {                                                     \
195       val = __LDREXW((__IO uint32_t *)&(REG)) & ~(BIT);      \
196     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
197   } while(0)
198 
199 /* Atomic 32-bit register access macro to clear and set one or several bits */
200 #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK)                          \
201   do {                                                                     \
202     uint32_t val;                                                          \
203     do {                                                                   \
204       val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
205     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U);               \
206   } while(0)
207 
208 /* Atomic 16-bit register access macro to set one or several bits */
209 #define ATOMIC_SETH_BIT(REG, BIT)                            \
210   do {                                                       \
211     uint16_t val;                                            \
212     do {                                                     \
213       val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT);       \
214     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
215   } while(0)
216 
217 /* Atomic 16-bit register access macro to clear one or several bits */
218 #define ATOMIC_CLEARH_BIT(REG, BIT)                          \
219   do {                                                       \
220     uint16_t val;                                            \
221     do {                                                     \
222       val = __LDREXH((__IO uint16_t *)&(REG)) & ~(BIT);      \
223     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
224   } while(0)
225 
226 /* Atomic 16-bit register access macro to clear and set one or several bits */
227 #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK)                         \
228   do {                                                                     \
229     uint16_t val;                                                          \
230     do {                                                                   \
231       val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
232     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U);               \
233   } while(0)
234 
235 
236 /**
237   * @}
238   */
239 
240 #if defined (USE_HAL_DRIVER)
241  #include "stm32g4xx_hal.h"
242 #endif /* USE_HAL_DRIVER */
243 
244 #ifdef __cplusplus
245 }
246 #endif /* __cplusplus */
247 
248 #endif /* __STM32G4xx_H */
249 /**
250   * @}
251   */
252 
253 /**
254   * @}
255   */
256 
257 
258 
259 
260