1 /**
2   ******************************************************************************
3   * @file    stm32f3xx.h
4   * @author  MCD Application Team
5   * @brief   CMSIS STM32F3xx 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 STM32F3xx 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) 2016 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 stm32f3xx
34   * @{
35   */
36 
37 #ifndef __STM32F3xx_H
38 #define __STM32F3xx_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 (STM32F3)
52 #define STM32F3
53 #endif /* STM32F3 */
54 
55 /* Uncomment the line below according to the target STM32 device used in your
56    application
57   */
58 
59 #if !defined (STM32F301x8) && !defined (STM32F302x8) && !defined (STM32F318xx) && \
60     !defined (STM32F302xC) && !defined (STM32F303xC) && !defined (STM32F358xx) && \
61     !defined (STM32F303x8) && !defined (STM32F334x8) && !defined (STM32F328xx) && \
62     !defined (STM32F302xE) && !defined (STM32F303xE) && !defined (STM32F398xx) && \
63     !defined (STM32F373xC) && !defined (STM32F378xx)
64 
65   /* #define STM32F301x8 */   /*!< STM32F301K6, STM32F301K8, STM32F301C6, STM32F301C8,
66                                    STM32F301R6 and STM32F301R8 Devices */
67   /* #define STM32F302x8 */   /*!< STM32F302K6, STM32F302K8, STM32F302C6, STM32F302C8,
68                                    STM32F302R6 and STM32F302R8 Devices */
69   /* #define STM32F302xC */   /*!< STM32F302CB, STM32F302CC, STM32F302RB, STM32F302RC,
70                                    STM32F302VB and STM32F302VC Devices */
71   /* #define STM32F302xE */   /*!< STM32F302RE, STM32F302VE, STM32F302ZE, STM32F302RD,
72                                    STM32F302VD and STM32F302ZD Devices */
73   /* #define STM32F303x8 */   /*!< STM32F303K6, STM32F303K8, STM32F303C6, STM32F303C8,
74                                    STM32F303R6 and STM32F303R8 Devices */
75   /* #define STM32F303xC */   /*!< STM32F303CB, STM32F303CC, STM32F303RB, STM32F303RC,
76                                    STM32F303VB and STM32F303VC Devices */
77   /* #define STM32F303xE */   /*!< STM32F303RE, STM32F303VE, STM32F303ZE, STM32F303RD,
78                                    STM32F303VD and STM32F303ZD Devices */
79   /* #define STM32F373xC */   /*!< STM32F373C8, STM32F373CB, STM32F373CC,
80                                    STM32F373R8, STM32F373RB, STM32F373RC,
81                                    STM32F373V8, STM32F373VB and STM32F373VC Devices */
82   /* #define STM32F334x8 */   /*!< STM32F334K4, STM32F334K6, STM32F334K8,
83                                    STM32F334C4, STM32F334C6, STM32F334C8,
84                                    STM32F334R4, STM32F334R6 and STM32F334R8 Devices */
85   /* #define STM32F318xx */   /*!< STM32F318K8, STM32F318C8: STM32F301x8 with regulator off: STM32F318xx Devices */
86   /* #define STM32F328xx */   /*!< STM32F328C8, STM32F328R8: STM32F334x8 with regulator off: STM32F328xx Devices */
87   /* #define STM32F358xx */   /*!< STM32F358CC, STM32F358RC, STM32F358VC: STM32F303xC with regulator off: STM32F358xx Devices */
88   /* #define STM32F378xx */   /*!< STM32F378CC, STM32F378RC, STM32F378VC: STM32F373xC with regulator off: STM32F378xx Devices */
89   /* #define STM32F398xx */   /*!< STM32F398VE: STM32F303xE with regulator off: STM32F398xx 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 V2.3.7
106   */
107 #define __STM32F3_CMSIS_VERSION_MAIN   (0x02) /*!< [31:24] main version */
108 #define __STM32F3_CMSIS_VERSION_SUB1   (0x03) /*!< [23:16] sub1 version */
109 #define __STM32F3_CMSIS_VERSION_SUB2   (0x07) /*!< [15:8]  sub2 version */
110 #define __STM32F3_CMSIS_VERSION_RC     (0x00) /*!< [7:0]  release candidate */
111 #define __STM32F3_CMSIS_VERSION        ((__STM32F3_CMSIS_VERSION_MAIN     << 24)\
112                                        |(__STM32F3_CMSIS_VERSION_SUB1 << 16)\
113                                        |(__STM32F3_CMSIS_VERSION_SUB2 << 8 )\
114                                        |(__STM32F3_CMSIS_VERSION_RC))
115 
116 /**
117   * @}
118   */
119 
120 /** @addtogroup Device_Included
121   * @{
122   */
123 
124 #if defined(STM32F301x8)
125   #include "stm32f301x8.h"
126 #elif defined(STM32F302x8)
127   #include "stm32f302x8.h"
128 #elif defined(STM32F302xC)
129   #include "stm32f302xc.h"
130 #elif defined(STM32F302xE)
131   #include "stm32f302xe.h"
132 #elif defined(STM32F303x8)
133   #include "stm32f303x8.h"
134 #elif defined(STM32F303xC)
135   #include "stm32f303xc.h"
136 #elif defined(STM32F303xE)
137   #include "stm32f303xe.h"
138 #elif defined(STM32F373xC)
139   #include "stm32f373xc.h"
140 #elif defined(STM32F334x8)
141   #include "stm32f334x8.h"
142 #elif defined(STM32F318xx)
143   #include "stm32f318xx.h"
144 #elif defined(STM32F328xx)
145   #include "stm32f328xx.h"
146 #elif defined(STM32F358xx)
147   #include "stm32f358xx.h"
148 #elif defined(STM32F378xx)
149   #include "stm32f378xx.h"
150 #elif defined(STM32F398xx)
151   #include "stm32f398xx.h"
152 #else
153  #error "Please select first the target STM32F3xx device used in your application (in stm32f3xx.h file)"
154 #endif
155 
156 /**
157   * @}
158   */
159 
160 /** @addtogroup Exported_types
161   * @{
162   */
163 typedef enum
164 {
165   RESET = 0U,
166   SET = !RESET
167 } FlagStatus, ITStatus;
168 
169 typedef enum
170 {
171   DISABLE = 0U,
172   ENABLE = !DISABLE
173 } FunctionalState;
174 #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
175 
176 typedef enum
177 {
178   SUCCESS = 0U,
179   ERROR = !SUCCESS
180 } ErrorStatus;
181 
182 /**
183   * @}
184   */
185 
186 
187 /** @addtogroup Exported_macros
188   * @{
189   */
190 #define SET_BIT(REG, BIT)     ((REG) |= (BIT))
191 
192 #define CLEAR_BIT(REG, BIT)   ((REG) &= ~(BIT))
193 
194 #define READ_BIT(REG, BIT)    ((REG) & (BIT))
195 
196 #define CLEAR_REG(REG)        ((REG) = (0x0))
197 
198 #define WRITE_REG(REG, VAL)   ((REG) = (VAL))
199 
200 #define READ_REG(REG)         ((REG))
201 
202 #define MODIFY_REG(REG, CLEARMASK, SETMASK)  WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
203 
204 #define POSITION_VAL(VAL)     (__CLZ(__RBIT(VAL)))
205 
206 /* Use of CMSIS compiler intrinsics for register exclusive access */
207 /* Atomic 32-bit register access macro to set one or several bits */
208 #define ATOMIC_SET_BIT(REG, BIT)                             \
209   do {                                                       \
210     uint32_t val;                                            \
211     do {                                                     \
212       val = __LDREXW((__IO uint32_t *)&(REG)) | (BIT);       \
213     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
214   } while(0)
215 
216 /* Atomic 32-bit register access macro to clear one or several bits */
217 #define ATOMIC_CLEAR_BIT(REG, BIT)                           \
218   do {                                                       \
219     uint32_t val;                                            \
220     do {                                                     \
221       val = __LDREXW((__IO uint32_t *)&(REG)) & ~(BIT);      \
222     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
223   } while(0)
224 
225 /* Atomic 32-bit register access macro to clear and set one or several bits */
226 #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK)                          \
227   do {                                                                     \
228     uint32_t val;                                                          \
229     do {                                                                   \
230       val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
231     } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U);               \
232   } while(0)
233 
234 /* Atomic 16-bit register access macro to set one or several bits */
235 #define ATOMIC_SETH_BIT(REG, BIT)                            \
236   do {                                                       \
237     uint16_t val;                                            \
238     do {                                                     \
239       val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT);       \
240     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
241   } while(0)
242 
243 /* Atomic 16-bit register access macro to clear one or several bits */
244 #define ATOMIC_CLEARH_BIT(REG, BIT)                          \
245   do {                                                       \
246     uint16_t val;                                            \
247     do {                                                     \
248       val = __LDREXH((__IO uint16_t *)&(REG)) & ~(BIT);      \
249     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
250   } while(0)
251 
252 /* Atomic 16-bit register access macro to clear and set one or several bits */
253 #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK)                         \
254   do {                                                                     \
255     uint16_t val;                                                          \
256     do {                                                                   \
257       val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
258     } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U);               \
259   } while(0)
260 
261 /**
262   * @}
263   */
264 
265 #if defined (USE_HAL_DRIVER)
266  #include "stm32f3xx_hal.h"
267 #endif /* USE_HAL_DRIVER */
268 
269 #ifdef __cplusplus
270 }
271 #endif /* __cplusplus */
272 
273 #endif /* __STM32F3xx_H */
274 /**
275   * @}
276   */
277 
278 /**
279   * @}
280   */
281