1 /**
2   ******************************************************************************
3   * @file    stm32wlxx.h
4   * @author  MCD Application Team
5   * @brief   CMSIS STM32WLxx 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 STM32WLxx 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) 2020-2021 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 stm32wlxx
34   * @{
35   */
36 
37 #ifndef __STM32WLxx_H
38 #define __STM32WLxx_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 (STM32WL)
52 #define STM32WL
53 #endif /* STM32WL */
54 
55 /* Uncomment the line below according to the target STM32WL device used in your
56    application
57   */
58 
59 #if !defined (STM32WL55xx) && !defined (STM32WL54xx) && !defined (STM32WLE5xx) && !defined (STM32WLE4xx) && !defined(STM32WL5Mxx)
60   /* #define STM32WL55xx */   /*!< STM32WL55xx Devices */
61   /* #define STM32WL54xx */   /*!< STM32WL54xx Devices */
62   /* #define STM32WLE5xx */   /*!< STM32WLE5xx Devices */
63   /* #define STM32WLE4xx */   /*!< STM32WLE4xx Devices */
64   /* #define STM32WL5Mxx */   /*!< STM32WL5Mxx Devices */
65 #endif /* STM32WL55xx ... */
66 
67 /*  Tip: To avoid modifying this file each time you need to switch between these
68         devices, you can define the device in your toolchain compiler preprocessor.
69   */
70 #if !defined  (USE_HAL_DRIVER)
71 /**
72  * @brief Comment the line below if you will not use the peripherals drivers.
73    In this case, these drivers will not be included and the application code will
74    be based on direct access to peripherals registers
75    */
76   /*#define USE_HAL_DRIVER */
77 #endif /* USE_HAL_DRIVER */
78 
79 /**
80   * @brief CMSIS Device version number
81   */
82 #define __STM32WLxx_CMSIS_VERSION_MAIN   (0x01U) /*!< [31:24] main version */
83 #define __STM32WLxx_CMSIS_VERSION_SUB1   (0x02U) /*!< [23:16] sub1 version */
84 #define __STM32WLxx_CMSIS_VERSION_SUB2   (0x00U) /*!< [15:8]  sub2 version */
85 #define __STM32WLxx_CMSIS_VERSION_RC     (0x00U) /*!< [7:0]  release candidate */
86 #define __STM32WLxx_CMSIS_DEVICE_VERSION        ((__STM32WLxx_CMSIS_VERSION_MAIN << 24)\
87                                                 |(__STM32WLxx_CMSIS_VERSION_SUB1 << 16)\
88                                                 |(__STM32WLxx_CMSIS_VERSION_SUB2 << 8 )\
89                                                 |(__STM32WLxx_CMSIS_VERSION_RC))
90 
91 /**
92   * @}
93   */
94 
95 /** @addtogroup Device_Included
96   * @{
97   */
98 
99 #if defined(STM32WL55xx)
100   #include "stm32wl55xx.h"
101 #elif defined(STM32WLE5xx)
102   #include "stm32wle5xx.h"
103 #elif defined(STM32WL54xx)
104   #include "stm32wl54xx.h"
105 #elif defined(STM32WLE4xx)
106   #include "stm32wle4xx.h"
107 #elif defined(STM32WL5Mxx)
108   #include "stm32wl5mxx.h"
109 #else
110  #error "Please select first the target STM32WLxx device used in your application, for instance xxx (in stm32wlxx.h file)"
111 #endif /* STM32WL55xx ... */
112 
113 /**
114   * @}
115   */
116 
117 /** @addtogroup Exported_types
118   * @{
119   */
120 typedef enum
121 {
122   RESET = 0,
123   SET = !RESET
124 } FlagStatus, ITStatus;
125 
126 typedef enum
127 {
128   DISABLE = 0,
129   ENABLE = !DISABLE
130 } FunctionalState;
131 #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
132 
133 typedef enum
134 {
135   ERROR = 0,
136   SUCCESS = !ERROR
137 } ErrorStatus;
138 
139 /**
140   * @}
141   */
142 
143 
144 /** @addtogroup Exported_macros
145   * @{
146   */
147 #define SET_BIT(REG, BIT)     ((REG) |= (BIT))
148 
149 #define CLEAR_BIT(REG, BIT)   ((REG) &= ~(BIT))
150 
151 #define READ_BIT(REG, BIT)    ((REG) & (BIT))
152 
153 #define CLEAR_REG(REG)        ((REG) = (0x0))
154 
155 #define WRITE_REG(REG, VAL)   ((REG) = (VAL))
156 
157 #define READ_REG(REG)         ((REG))
158 
159 #define MODIFY_REG(REG, CLEARMASK, SETMASK)  WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
160 
161 #if defined(CORE_CM0PLUS)
162 /* Use of interrupt control for register exclusive access (privileged mode only) */
163 /* Atomic 32-bit register access macro to set one or several bits */
164 #define ATOMIC_SET_BIT(REG, BIT) \
165   do {                           \
166     uint32_t primask;            \
167     primask = __get_PRIMASK();   \
168     __set_PRIMASK(1);            \
169     SET_BIT((REG), (BIT));       \
170     __set_PRIMASK(primask);      \
171   } while(0)
172 
173 /* Atomic 32-bit register access macro to clear one or several bits */
174 #define ATOMIC_CLEAR_BIT(REG, BIT) \
175   do {                             \
176     uint32_t primask;              \
177     primask = __get_PRIMASK();     \
178     __set_PRIMASK(1);              \
179     CLEAR_BIT((REG), (BIT));       \
180     __set_PRIMASK(primask);        \
181   } while(0)
182 
183 /* Atomic 32-bit register access macro to clear and set one or several bits */
184 #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \
185   do {                                            \
186     uint32_t primask;                             \
187     primask = __get_PRIMASK();                    \
188     __set_PRIMASK(1);                             \
189     MODIFY_REG((REG), (CLEARMSK), (SETMASK));     \
190     __set_PRIMASK(primask);                       \
191   } while(0)
192 
193 /* Atomic 16-bit register access macro to set one or several bits */
194 #define ATOMIC_SETH_BIT(REG, BIT)   ATOMIC_SET_BIT(REG, BIT)
195 
196 /* Atomic 16-bit register access macro to clear one or several bits */
197 #define ATOMIC_CLEARH_BIT(REG, BIT) ATOMIC_CLEAR_BIT(REG, BIT)
198 
199 /* Atomic 16-bit register access macro to clear and set one or several bits */
200 #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK)
201 
202 #else
203 /* Use of CMSIS compiler intrinsics for register exclusive access */
204 /* Atomic 32-bit register access macro to set one or several bits */
205 #define ATOMIC_SET_BIT(REG, BIT)                             \
206   do {                                                       \
207     uint32_t val;                                            \
208     do {                                                     \
209       val = __LDREXW((__IO uint32_t *)&(REG)) | (BIT);       \
210     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
211   } while(0)
212 
213 /* Atomic 32-bit register access macro to clear one or several bits */
214 #define ATOMIC_CLEAR_BIT(REG, BIT)                           \
215   do {                                                       \
216     uint32_t val;                                            \
217     do {                                                     \
218       val = __LDREXW((__IO uint32_t *)&(REG)) & ~(BIT);      \
219     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
220   } while(0)
221 
222 /* Atomic 32-bit register access macro to clear and set one or several bits */
223 #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK)                          \
224   do {                                                                     \
225     uint32_t val;                                                          \
226     do {                                                                   \
227       val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
228     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U);               \
229   } while(0)
230 
231 /* Atomic 16-bit register access macro to set one or several bits */
232 #define ATOMIC_SETH_BIT(REG, BIT)                            \
233   do {                                                       \
234     uint16_t val;                                            \
235     do {                                                     \
236       val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT);       \
237     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
238   } while(0)
239 
240 /* Atomic 16-bit register access macro to clear one or several bits */
241 #define ATOMIC_CLEARH_BIT(REG, BIT)                          \
242   do {                                                       \
243     uint16_t val;                                            \
244     do {                                                     \
245       val = __LDREXH((__IO uint16_t *)&(REG)) & ~(BIT);      \
246     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
247   } while(0)
248 
249 /* Atomic 16-bit register access macro to clear and set one or several bits */
250 #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK)                         \
251   do {                                                                     \
252     uint16_t val;                                                          \
253     do {                                                                   \
254       val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
255     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U);               \
256   } while(0)
257 
258 #define POSITION_VAL(VAL)     (__CLZ(__RBIT(VAL)))
259 #endif /* CORE_CM0PLUS */
260 
261 /**
262   * @}
263   */
264 
265 #if defined (USE_HAL_DRIVER)
266  #include "stm32wlxx_hal.h"
267 #endif /* USE_HAL_DRIVER */
268 
269 #ifdef __cplusplus
270 }
271 #endif /* __cplusplus */
272 
273 #endif /* __STM32WLxx_H */
274 /**
275   * @}
276   */
277 
278 /**
279   * @}
280   */
281