1 /**
2   ******************************************************************************
3   * @file    stm32l4xx.h
4   * @author  MCD Application Team
5   * @brief   CMSIS STM32L4xx 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 STM32L4xx 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) 2017 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 stm32l4xx
34   * @{
35   */
36 
37 #ifndef __STM32L4xx_H
38 #define __STM32L4xx_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 (STM32L4)
52 #define STM32L4
53 #endif /* STM32L4 */
54 
55 /* Uncomment the line below according to the target STM32L4 device used in your
56    application
57   */
58 
59 #if !defined (STM32L412xx) && !defined (STM32L422xx) && \
60     !defined (STM32L431xx) && !defined (STM32L432xx) && !defined (STM32L433xx) && !defined (STM32L442xx) && !defined (STM32L443xx) && \
61     !defined (STM32L451xx) && !defined (STM32L452xx) && !defined (STM32L462xx) && \
62     !defined (STM32L471xx) && !defined (STM32L475xx) && !defined (STM32L476xx) && !defined (STM32L485xx) && !defined (STM32L486xx) && \
63     !defined (STM32L496xx) && !defined (STM32L4A6xx) && \
64     !defined (STM32L4P5xx) && !defined (STM32L4Q5xx) && \
65     !defined (STM32L4R5xx) && !defined (STM32L4R7xx) && !defined (STM32L4R9xx) && !defined (STM32L4S5xx) && !defined (STM32L4S7xx) && !defined (STM32L4S9xx)
66   /* #define STM32L412xx */   /*!< STM32L412xx Devices */
67   /* #define STM32L422xx */   /*!< STM32L422xx Devices */
68   /* #define STM32L431xx */   /*!< STM32L431xx Devices */
69   /* #define STM32L432xx */   /*!< STM32L432xx Devices */
70   /* #define STM32L433xx */   /*!< STM32L433xx Devices */
71   /* #define STM32L442xx */   /*!< STM32L442xx Devices */
72   /* #define STM32L443xx */   /*!< STM32L443xx Devices */
73   /* #define STM32L451xx */   /*!< STM32L451xx Devices */
74   /* #define STM32L452xx */   /*!< STM32L452xx Devices */
75   /* #define STM32L462xx */   /*!< STM32L462xx Devices */
76   /* #define STM32L471xx */   /*!< STM32L471xx Devices */
77   /* #define STM32L475xx */   /*!< STM32L475xx Devices */
78   /* #define STM32L476xx */   /*!< STM32L476xx Devices */
79   /* #define STM32L485xx */   /*!< STM32L485xx Devices */
80   /* #define STM32L486xx */   /*!< STM32L486xx Devices */
81   /* #define STM32L496xx */   /*!< STM32L496xx Devices */
82   /* #define STM32L4A6xx */   /*!< STM32L4A6xx Devices */
83   /* #define STM32L4P5xx */   /*!< STM32L4Q5xx Devices */
84   /* #define STM32L4R5xx */   /*!< STM32L4R5xx Devices */
85   /* #define STM32L4R7xx */   /*!< STM32L4R7xx Devices */
86   /* #define STM32L4R9xx */   /*!< STM32L4R9xx Devices */
87   /* #define STM32L4S5xx */   /*!< STM32L4S5xx Devices */
88   /* #define STM32L4S7xx */   /*!< STM32L4S7xx Devices */
89   /* #define STM32L4S9xx */   /*!< STM32L4S9xx Devices */
90 #endif
91 
92 /*  Tip: To avoid modifying this file each time you need to switch between these
93         devices, you can define the device in your toolchain compiler preprocessor.
94   */
95 #if !defined  (USE_HAL_DRIVER)
96 /**
97  * @brief Comment the line below if you will not use the peripherals drivers.
98    In this case, these drivers will not be included and the application code will
99    be based on direct access to peripherals registers
100    */
101   /*#define USE_HAL_DRIVER */
102 #endif /* USE_HAL_DRIVER */
103 
104 /**
105   * @brief CMSIS Device version number
106   */
107 #define __STM32L4_CMSIS_VERSION_MAIN   (0x01) /*!< [31:24] main version */
108 #define __STM32L4_CMSIS_VERSION_SUB1   (0x07) /*!< [23:16] sub1 version */
109 #define __STM32L4_CMSIS_VERSION_SUB2   (0x02) /*!< [15:8]  sub2 version */
110 #define __STM32L4_CMSIS_VERSION_RC     (0x00) /*!< [7:0]  release candidate */
111 #define __STM32L4_CMSIS_VERSION        ((__STM32L4_CMSIS_VERSION_MAIN << 24)\
112                                        |(__STM32L4_CMSIS_VERSION_SUB1 << 16)\
113                                        |(__STM32L4_CMSIS_VERSION_SUB2 << 8 )\
114                                        |(__STM32L4_CMSIS_VERSION_RC))
115 
116 /**
117   * @}
118   */
119 
120 /** @addtogroup Device_Included
121   * @{
122   */
123 
124 #if defined(STM32L412xx)
125   #include "stm32l412xx.h"
126 #elif defined(STM32L422xx)
127   #include "stm32l422xx.h"
128 #elif defined(STM32L431xx)
129   #include "stm32l431xx.h"
130 #elif defined(STM32L432xx)
131   #include "stm32l432xx.h"
132 #elif defined(STM32L433xx)
133   #include "stm32l433xx.h"
134 #elif defined(STM32L442xx)
135   #include "stm32l442xx.h"
136 #elif defined(STM32L443xx)
137   #include "stm32l443xx.h"
138 #elif defined(STM32L451xx)
139   #include "stm32l451xx.h"
140 #elif defined(STM32L452xx)
141   #include "stm32l452xx.h"
142 #elif defined(STM32L462xx)
143   #include "stm32l462xx.h"
144 #elif defined(STM32L471xx)
145   #include "stm32l471xx.h"
146 #elif defined(STM32L475xx)
147   #include "stm32l475xx.h"
148 #elif defined(STM32L476xx)
149   #include "stm32l476xx.h"
150 #elif defined(STM32L485xx)
151   #include "stm32l485xx.h"
152 #elif defined(STM32L486xx)
153   #include "stm32l486xx.h"
154 #elif defined(STM32L496xx)
155   #include "stm32l496xx.h"
156 #elif defined(STM32L4A6xx)
157   #include "stm32l4a6xx.h"
158 #elif defined(STM32L4P5xx)
159   #include "stm32l4p5xx.h"
160 #elif defined(STM32L4Q5xx)
161   #include "stm32l4q5xx.h"
162 #elif defined(STM32L4R5xx)
163   #include "stm32l4r5xx.h"
164 #elif defined(STM32L4R7xx)
165   #include "stm32l4r7xx.h"
166 #elif defined(STM32L4R9xx)
167   #include "stm32l4r9xx.h"
168 #elif defined(STM32L4S5xx)
169   #include "stm32l4s5xx.h"
170 #elif defined(STM32L4S7xx)
171   #include "stm32l4s7xx.h"
172 #elif defined(STM32L4S9xx)
173   #include "stm32l4s9xx.h"
174 #else
175  #error "Please select first the target STM32L4xx device used in your application (in stm32l4xx.h file)"
176 #endif
177 
178 /**
179   * @}
180   */
181 
182 /** @addtogroup Exported_types
183   * @{
184   */
185 typedef enum
186 {
187   RESET = 0,
188   SET = !RESET
189 } FlagStatus, ITStatus;
190 
191 typedef enum
192 {
193   DISABLE = 0,
194   ENABLE = !DISABLE
195 } FunctionalState;
196 #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
197 
198 typedef enum
199 {
200   SUCCESS = 0,
201   ERROR = !SUCCESS
202 } ErrorStatus;
203 
204 /**
205   * @}
206   */
207 
208 
209 /** @addtogroup Exported_macros
210   * @{
211   */
212 #define SET_BIT(REG, BIT)     ((REG) |= (BIT))
213 
214 #define CLEAR_BIT(REG, BIT)   ((REG) &= ~(BIT))
215 
216 #define READ_BIT(REG, BIT)    ((REG) & (BIT))
217 
218 #define CLEAR_REG(REG)        ((REG) = (0x0))
219 
220 #define WRITE_REG(REG, VAL)   ((REG) = (VAL))
221 
222 #define READ_REG(REG)         ((REG))
223 
224 #define MODIFY_REG(REG, CLEARMASK, SETMASK)  WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
225 
226 /* Use of CMSIS compiler intrinsics for register exclusive access */
227 /* Atomic 32-bit register access macro to set one or several bits */
228 #define ATOMIC_SET_BIT(REG, BIT)                             \
229   do {                                                       \
230     uint32_t val;                                            \
231     do {                                                     \
232       val = __LDREXW((__IO uint32_t *)&(REG)) | (BIT);       \
233     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
234   } while(0)
235 
236 /* Atomic 32-bit register access macro to clear one or several bits */
237 #define ATOMIC_CLEAR_BIT(REG, BIT)                           \
238   do {                                                       \
239     uint32_t val;                                            \
240     do {                                                     \
241       val = __LDREXW((__IO uint32_t *)&(REG)) & ~(BIT);      \
242     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
243   } while(0)
244 
245 /* Atomic 32-bit register access macro to clear and set one or several bits */
246 #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK)                          \
247   do {                                                                     \
248     uint32_t val;                                                          \
249     do {                                                                   \
250       val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
251     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U);               \
252   } while(0)
253 
254 /* Atomic 16-bit register access macro to set one or several bits */
255 #define ATOMIC_SETH_BIT(REG, BIT)                            \
256   do {                                                       \
257     uint16_t val;                                            \
258     do {                                                     \
259       val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT);       \
260     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
261   } while(0)
262 
263 /* Atomic 16-bit register access macro to clear one or several bits */
264 #define ATOMIC_CLEARH_BIT(REG, BIT)                          \
265   do {                                                       \
266     uint16_t val;                                            \
267     do {                                                     \
268       val = __LDREXH((__IO uint16_t *)&(REG)) & ~(BIT);      \
269     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
270   } while(0)
271 
272 /* Atomic 16-bit register access macro to clear and set one or several bits */
273 #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK)                         \
274   do {                                                                     \
275     uint16_t val;                                                          \
276     do {                                                                   \
277       val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
278     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U);               \
279   } while(0)
280 
281 #define POSITION_VAL(VAL)     (__CLZ(__RBIT(VAL)))
282 
283 /**
284   * @}
285   */
286 
287 #if defined (USE_HAL_DRIVER)
288  #include "stm32l4xx_hal.h"
289 #endif /* USE_HAL_DRIVER */
290 
291 #ifdef __cplusplus
292 }
293 #endif /* __cplusplus */
294 
295 #endif /* __STM32L4xx_H */
296 /**
297   * @}
298   */
299 
300 /**
301   * @}
302   */
303 
304