]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_uart_ex.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F0 / stm32f0xx_hal_uart_ex.h
1 /**
2 ******************************************************************************
3 * @file stm32f0xx_hal_uart_ex.h
4 * @author MCD Application Team
5 * @version V1.2.0
6 * @date 11-December-2014
7 * @brief Header file of UART HAL Extension module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12 *
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************
36 */
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F0xx_HAL_UART_EX_H
40 #define __STM32F0xx_HAL_UART_EX_H
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f0xx_hal_def.h"
48
49 /** @addtogroup STM32F0xx_HAL_Driver
50 * @{
51 */
52
53 /** @addtogroup UARTEx
54 * @{
55 */
56
57 /* Exported types ------------------------------------------------------------*/
58 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
59 /** @defgroup UARTEx_Exported_Types UARTEx Exported Types
60 * @{
61 */
62
63 /**
64 * @brief UART wake up from stop mode parameters
65 */
66 typedef struct
67 {
68 uint32_t WakeUpEvent; /*!< Specifies which event will activat the Wakeup from Stop mode flag (WUF).
69 This parameter can be a value of @ref UART_WakeUp_from_Stop_Selection.
70 If set to UART_WAKEUP_ON_ADDRESS, the two other fields below must
71 be filled up. */
72
73 uint16_t AddressLength; /*!< Specifies whether the address is 4 or 7-bit long.
74 This parameter can be a value of @ref UART_WakeUp_Address_Length */
75
76 uint8_t Address; /*!< UART/USART node address (7-bit long max) */
77 } UART_WakeUpTypeDef;
78 /**
79 * @}
80 */
81 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
82
83 /* Exported constants --------------------------------------------------------*/
84 /** @defgroup UARTEx_Exported_Constants UARTEx Exported Constants
85 * @{
86 */
87
88 /** @defgroup UARTEx_Word_Length UARTEx Word Length
89 * @{
90 */
91 #if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
92 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
93 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC)
94 #define UART_WORDLENGTH_7B ((uint32_t)USART_CR1_M1)
95 #define UART_WORDLENGTH_8B ((uint32_t)0x00000000)
96 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M0)
97 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_7B) || \
98 ((LENGTH) == UART_WORDLENGTH_8B) || \
99 ((LENGTH) == UART_WORDLENGTH_9B))
100 #else
101 #define UART_WORDLENGTH_8B ((uint32_t)0x00000000)
102 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
103 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \
104 ((LENGTH) == UART_WORDLENGTH_9B))
105 #endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
106 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
107 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */
108 /**
109 * @}
110 */
111
112 /** @defgroup UARTEx_AutoBaud_Rate_Mode UARTEx Advanced Feature AutoBaud Rate Mode
113 * @{
114 */
115 #if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
116 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
117 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC)
118 #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT ((uint32_t)0x0000)
119 #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE ((uint32_t)USART_CR2_ABRMODE_0)
120 #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME ((uint32_t)USART_CR2_ABRMODE_1)
121 #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME ((uint32_t)USART_CR2_ABRMODE)
122 #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(MODE) (((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT) || \
123 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE) || \
124 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME) || \
125 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME))
126 #else
127 #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT ((uint32_t)0x0000)
128 #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE ((uint32_t)USART_CR2_ABRMODE_0)
129 #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(MODE) (((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT) || \
130 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE))
131 #endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
132 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
133 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */
134 /**
135 * @}
136 */
137
138
139 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
140 /** @defgroup UARTEx_LIN UARTEx Local Interconnection Network mode
141 * @{
142 */
143 #define UART_LIN_DISABLE ((uint32_t)0x00000000)
144 #define UART_LIN_ENABLE ((uint32_t)USART_CR2_LINEN)
145 #define IS_UART_LIN(LIN) (((LIN) == UART_LIN_DISABLE) || \
146 ((LIN) == UART_LIN_ENABLE))
147 /**
148 * @}
149 */
150
151 /** @defgroup UARTEx_LIN_Break_Detection UARTEx LIN Break Detection
152 * @{
153 */
154 #define UART_LINBREAKDETECTLENGTH_10B ((uint32_t)0x00000000)
155 #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL)
156 #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
157 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
158 /**
159 * @}
160 */
161 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
162
163 /** @defgroup UART_Flags UARTEx Status Flags
164 * Elements values convention: 0xXXXX
165 * - 0xXXXX : Flag mask in the ISR register
166 * @{
167 */
168 #define UART_FLAG_REACK ((uint32_t)0x00400000)
169 #define UART_FLAG_TEACK ((uint32_t)0x00200000)
170 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
171 #define UART_FLAG_WUF ((uint32_t)0x00100000)
172 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
173 #define UART_FLAG_RWU ((uint32_t)0x00080000)
174 #define UART_FLAG_SBKF ((uint32_t)0x00040000
175 #define UART_FLAG_CMF ((uint32_t)0x00020000)
176 #define UART_FLAG_BUSY ((uint32_t)0x00010000)
177 #define UART_FLAG_ABRF ((uint32_t)0x00008000)
178 #define UART_FLAG_ABRE ((uint32_t)0x00004000)
179 #if !defined(STM32F030x6) && !defined(STM32F030x8)
180 #define UART_FLAG_EOBF ((uint32_t)0x00001000)
181 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) */
182 #define UART_FLAG_RTOF ((uint32_t)0x00000800)
183 #define UART_FLAG_CTS ((uint32_t)0x00000400)
184 #define UART_FLAG_CTSIF ((uint32_t)0x00000200)
185 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
186 #define UART_FLAG_LBDF ((uint32_t)0x00000100)
187 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
188 #define UART_FLAG_TXE ((uint32_t)0x00000080)
189 #define UART_FLAG_TC ((uint32_t)0x00000040)
190 #define UART_FLAG_RXNE ((uint32_t)0x00000020)
191 #define UART_FLAG_IDLE ((uint32_t)0x00000010)
192 #define UART_FLAG_ORE ((uint32_t)0x00000008)
193 #define UART_FLAG_NE ((uint32_t)0x00000004)
194 #define UART_FLAG_FE ((uint32_t)0x00000002)
195 #define UART_FLAG_PE ((uint32_t)0x00000001)
196 /**
197 * @}
198 */
199
200 /** @defgroup UART_Interrupt_definition UARTEx Interrupts Definition
201 * Elements values convention: 0000ZZZZZ0XXYYYYYb
202 * - YYYYY : Interrupt source position in the XX register (5bits)
203 * - XX : Interrupt source register (2bits)
204 * - 01: CR1 register
205 * - 10: CR2 register
206 * - 11: CR3 register
207 * - ZZZZZ : Flag position in the ISR register(5bits)
208 * @{
209 */
210 #define UART_IT_PE ((uint16_t)0x0028)
211 #define UART_IT_TXE ((uint16_t)0x0727)
212 #define UART_IT_TC ((uint16_t)0x0626)
213 #define UART_IT_RXNE ((uint16_t)0x0525)
214 #define UART_IT_IDLE ((uint16_t)0x0424)
215 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
216 #define UART_IT_LBD ((uint16_t)0x0846)
217 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
218 #define UART_IT_CTS ((uint16_t)0x096A)
219 #define UART_IT_CM ((uint16_t)0x112E)
220 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
221 #define UART_IT_WUF ((uint16_t)0x1476)
222 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
223 /**
224 * @}
225 */
226
227
228 /** @defgroup UART_IT_CLEAR_Flags UARTEx Interruption Clear Flags
229 * @{
230 */
231 #define UART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
232 #define UART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
233 #define UART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
234 #define UART_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
235 #define UART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
236 #define UART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
237 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
238 #define UART_CLEAR_LBDF USART_ICR_LBDCF /*!< LIN Break Detection Clear Flag (not available on F030xx devices)*/
239 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
240 #define UART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
241 #define UART_CLEAR_RTOF USART_ICR_RTOCF /*!< Receiver Time Out Clear Flag */
242 #define UART_CLEAR_EOBF USART_ICR_EOBCF /*!< End Of Block Clear Flag */
243 #define UART_CLEAR_CMF USART_ICR_CMCF /*!< Character Match Clear Flag */
244 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
245 #define UART_CLEAR_WUF USART_ICR_WUCF /*!< Wake Up from stop mode Clear Flag */
246 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
247 /**
248 * @}
249 */
250
251 /** @defgroup UART_Request_Parameters UARTEx Request Parameters
252 * @{
253 */
254 #define UART_AUTOBAUD_REQUEST ((uint32_t)USART_RQR_ABRRQ) /*!< Auto-Baud Rate Request */
255 #define UART_SENDBREAK_REQUEST ((uint32_t)USART_RQR_SBKRQ) /*!< Send Break Request */
256 #define UART_MUTE_MODE_REQUEST ((uint32_t)USART_RQR_MMRQ) /*!< Mute Mode Request */
257 #define UART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
258 #if !defined(STM32F030x6) && !defined(STM32F030x8)
259 #define UART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
260 #define IS_UART_REQUEST_PARAMETER(PARAM) (((PARAM) == UART_AUTOBAUD_REQUEST) || \
261 ((PARAM) == UART_SENDBREAK_REQUEST) || \
262 ((PARAM) == UART_MUTE_MODE_REQUEST) || \
263 ((PARAM) == UART_RXDATA_FLUSH_REQUEST) || \
264 ((PARAM) == UART_TXDATA_FLUSH_REQUEST))
265 #else
266 #define IS_UART_REQUEST_PARAMETER(PARAM) (((PARAM) == UART_AUTOBAUD_REQUEST) || \
267 ((PARAM) == UART_SENDBREAK_REQUEST) || \
268 ((PARAM) == UART_MUTE_MODE_REQUEST) || \
269 ((PARAM) == UART_RXDATA_FLUSH_REQUEST))
270 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) */
271 /**
272 * @}
273 */
274
275 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
276 /** @defgroup UART_Stop_Mode_Enable UARTEx Advanced Feature Stop Mode Enable
277 * @{
278 */
279 #define UART_ADVFEATURE_STOPMODE_DISABLE ((uint32_t)0x00000000)
280 #define UART_ADVFEATURE_STOPMODE_ENABLE ((uint32_t)USART_CR1_UESM)
281 #define IS_UART_ADVFEATURE_STOPMODE(STOPMODE) (((STOPMODE) == UART_ADVFEATURE_STOPMODE_DISABLE) || \
282 ((STOPMODE) == UART_ADVFEATURE_STOPMODE_ENABLE))
283 /**
284 * @}
285 */
286
287 /** @defgroup UART_WakeUp_from_Stop_Selection UART WakeUp From Stop Selection
288 * @{
289 */
290 #define UART_WAKEUP_ON_ADDRESS ((uint32_t)0x0000)
291 #define UART_WAKEUP_ON_STARTBIT ((uint32_t)USART_CR3_WUS_1)
292 #define UART_WAKEUP_ON_READDATA_NONEMPTY ((uint32_t)USART_CR3_WUS)
293 #define IS_UART_WAKEUP_SELECTION(WAKE) (((WAKE) == UART_WAKEUP_ON_ADDRESS) || \
294 ((WAKE) == UART_WAKEUP_ON_STARTBIT) || \
295 ((WAKE) == UART_WAKEUP_ON_READDATA_NONEMPTY))
296 /**
297 * @}
298 */
299 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
300
301 /**
302 * @}
303 */
304
305 /* Exported macro ------------------------------------------------------------*/
306
307 /** @defgroup UARTEx_Exported_Macros UARTEx Exported Macros
308 * @{
309 */
310
311 /** @brief Reports the UART clock source.
312 * @param __HANDLE__: specifies the UART Handle
313 * @param __CLOCKSOURCE__ : output variable
314 * @retval UART clocking source, written in __CLOCKSOURCE__.
315 */
316
317
318 #if defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx)
319 #define __HAL_UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
320 do { \
321 switch(__HAL_RCC_GET_USART1_SOURCE()) \
322 { \
323 case RCC_USART1CLKSOURCE_PCLK1: \
324 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
325 break; \
326 case RCC_USART1CLKSOURCE_HSI: \
327 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
328 break; \
329 case RCC_USART1CLKSOURCE_SYSCLK: \
330 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
331 break; \
332 case RCC_USART1CLKSOURCE_LSE: \
333 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
334 break; \
335 default: \
336 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
337 break; \
338 } \
339 } while(0)
340 #elif defined (STM32F030x8) || defined (STM32F070x6) || \
341 defined (STM32F042x6) || defined (STM32F048xx) || \
342 defined (STM32F051x8) || defined (STM32F058xx)
343 #define __HAL_UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
344 do { \
345 if((__HANDLE__)->Instance == USART1) \
346 { \
347 switch(__HAL_RCC_GET_USART1_SOURCE()) \
348 { \
349 case RCC_USART1CLKSOURCE_PCLK1: \
350 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
351 break; \
352 case RCC_USART1CLKSOURCE_HSI: \
353 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
354 break; \
355 case RCC_USART1CLKSOURCE_SYSCLK: \
356 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
357 break; \
358 case RCC_USART1CLKSOURCE_LSE: \
359 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
360 break; \
361 default: \
362 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
363 break; \
364 } \
365 } \
366 else if((__HANDLE__)->Instance == USART2) \
367 { \
368 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
369 } \
370 else \
371 { \
372 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
373 } \
374 } while(0)
375 #elif defined(STM32F070xB)
376 #define __HAL_UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
377 do { \
378 if((__HANDLE__)->Instance == USART1) \
379 { \
380 switch(__HAL_RCC_GET_USART1_SOURCE()) \
381 { \
382 case RCC_USART1CLKSOURCE_PCLK1: \
383 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
384 break; \
385 case RCC_USART1CLKSOURCE_HSI: \
386 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
387 break; \
388 case RCC_USART1CLKSOURCE_SYSCLK: \
389 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
390 break; \
391 case RCC_USART1CLKSOURCE_LSE: \
392 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
393 break; \
394 default: \
395 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
396 break; \
397 } \
398 } \
399 else if((__HANDLE__)->Instance == USART2) \
400 { \
401 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
402 } \
403 else if((__HANDLE__)->Instance == USART3) \
404 { \
405 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
406 } \
407 else if((__HANDLE__)->Instance == USART4) \
408 { \
409 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
410 } \
411 else \
412 { \
413 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
414 } \
415 } while(0)
416 #elif defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)
417 #define __HAL_UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
418 do { \
419 if((__HANDLE__)->Instance == USART1) \
420 { \
421 switch(__HAL_RCC_GET_USART1_SOURCE()) \
422 { \
423 case RCC_USART1CLKSOURCE_PCLK1: \
424 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
425 break; \
426 case RCC_USART1CLKSOURCE_HSI: \
427 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
428 break; \
429 case RCC_USART1CLKSOURCE_SYSCLK: \
430 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
431 break; \
432 case RCC_USART1CLKSOURCE_LSE: \
433 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
434 break; \
435 default: \
436 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
437 break; \
438 } \
439 } \
440 else if((__HANDLE__)->Instance == USART2) \
441 { \
442 switch(__HAL_RCC_GET_USART2_SOURCE()) \
443 { \
444 case RCC_USART2CLKSOURCE_PCLK1: \
445 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
446 break; \
447 case RCC_USART2CLKSOURCE_HSI: \
448 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
449 break; \
450 case RCC_USART2CLKSOURCE_SYSCLK: \
451 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
452 break; \
453 case RCC_USART2CLKSOURCE_LSE: \
454 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
455 break; \
456 default: \
457 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
458 break; \
459 } \
460 } \
461 else if((__HANDLE__)->Instance == USART3) \
462 { \
463 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
464 } \
465 else if((__HANDLE__)->Instance == USART4) \
466 { \
467 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
468 } \
469 else \
470 { \
471 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
472 } \
473 } while(0)
474 #elif defined(STM32F091xC) || defined (STM32F098xx)
475 #define __HAL_UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
476 do { \
477 if((__HANDLE__)->Instance == USART1) \
478 { \
479 switch(__HAL_RCC_GET_USART1_SOURCE()) \
480 { \
481 case RCC_USART1CLKSOURCE_PCLK1: \
482 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
483 break; \
484 case RCC_USART1CLKSOURCE_HSI: \
485 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
486 break; \
487 case RCC_USART1CLKSOURCE_SYSCLK: \
488 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
489 break; \
490 case RCC_USART1CLKSOURCE_LSE: \
491 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
492 break; \
493 default: \
494 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
495 break; \
496 } \
497 } \
498 else if((__HANDLE__)->Instance == USART2) \
499 { \
500 switch(__HAL_RCC_GET_USART2_SOURCE()) \
501 { \
502 case RCC_USART2CLKSOURCE_PCLK1: \
503 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
504 break; \
505 case RCC_USART2CLKSOURCE_HSI: \
506 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
507 break; \
508 case RCC_USART2CLKSOURCE_SYSCLK: \
509 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
510 break; \
511 case RCC_USART2CLKSOURCE_LSE: \
512 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
513 break; \
514 default: \
515 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
516 break; \
517 } \
518 } \
519 else if((__HANDLE__)->Instance == USART3) \
520 { \
521 switch(__HAL_RCC_GET_USART3_SOURCE()) \
522 { \
523 case RCC_USART3CLKSOURCE_PCLK1: \
524 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
525 break; \
526 case RCC_USART3CLKSOURCE_HSI: \
527 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
528 break; \
529 case RCC_USART3CLKSOURCE_SYSCLK: \
530 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
531 break; \
532 case RCC_USART3CLKSOURCE_LSE: \
533 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
534 break; \
535 default: \
536 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
537 break; \
538 } \
539 } \
540 else if((__HANDLE__)->Instance == USART4) \
541 { \
542 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
543 } \
544 else if((__HANDLE__)->Instance == USART5) \
545 { \
546 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
547 } \
548 else if((__HANDLE__)->Instance == USART6) \
549 { \
550 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
551 } \
552 else if((__HANDLE__)->Instance == USART7) \
553 { \
554 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
555 } \
556 else if((__HANDLE__)->Instance == USART8) \
557 { \
558 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
559 } \
560 else \
561 { \
562 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
563 } \
564 } while(0)
565 #elif defined(STM32F030xC)
566 #define __HAL_UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
567 do { \
568 if((__HANDLE__)->Instance == USART1) \
569 { \
570 switch(__HAL_RCC_GET_USART1_SOURCE()) \
571 { \
572 case RCC_USART1CLKSOURCE_PCLK1: \
573 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
574 break; \
575 case RCC_USART1CLKSOURCE_HSI: \
576 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
577 break; \
578 case RCC_USART1CLKSOURCE_SYSCLK: \
579 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
580 break; \
581 case RCC_USART1CLKSOURCE_LSE: \
582 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
583 break; \
584 default: \
585 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
586 break; \
587 } \
588 } \
589 else if((__HANDLE__)->Instance == USART2) \
590 { \
591 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
592 } \
593 else if((__HANDLE__)->Instance == USART3) \
594 { \
595 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
596 } \
597 else if((__HANDLE__)->Instance == USART4) \
598 { \
599 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
600 } \
601 else if((__HANDLE__)->Instance == USART5) \
602 { \
603 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
604 } \
605 else if((__HANDLE__)->Instance == USART6) \
606 { \
607 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
608 } \
609 else \
610 { \
611 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
612 } \
613 } while(0)
614
615 #endif /* defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx) */
616
617
618 /** @brief Computes the UART mask to apply to retrieve the received data
619 * according to the word length and to the parity bits activation.
620 * If PCE = 1, the parity bit is not included in the data extracted
621 * by the reception API().
622 * This masking operation is not carried out in the case of
623 * DMA transfers.
624 * @param __HANDLE__: specifies the UART Handle
625 * @retval none
626 */
627 #if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
628 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
629 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC)
630 #define __HAL_UART_MASK_COMPUTATION(__HANDLE__) \
631 do { \
632 if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B) \
633 { \
634 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
635 { \
636 (__HANDLE__)->Mask = 0x01FF ; \
637 } \
638 else \
639 { \
640 (__HANDLE__)->Mask = 0x00FF ; \
641 } \
642 } \
643 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B) \
644 { \
645 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
646 { \
647 (__HANDLE__)->Mask = 0x00FF ; \
648 } \
649 else \
650 { \
651 (__HANDLE__)->Mask = 0x007F ; \
652 } \
653 } \
654 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_7B) \
655 { \
656 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
657 { \
658 (__HANDLE__)->Mask = 0x007F ; \
659 } \
660 else \
661 { \
662 (__HANDLE__)->Mask = 0x003F ; \
663 } \
664 } \
665 } while(0)
666 #else
667 #define __HAL_UART_MASK_COMPUTATION(__HANDLE__) \
668 do { \
669 if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B) \
670 { \
671 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
672 { \
673 (__HANDLE__)->Mask = 0x01FF ; \
674 } \
675 else \
676 { \
677 (__HANDLE__)->Mask = 0x00FF ; \
678 } \
679 } \
680 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B) \
681 { \
682 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
683 { \
684 (__HANDLE__)->Mask = 0x00FF ; \
685 } \
686 else \
687 { \
688 (__HANDLE__)->Mask = 0x007F ; \
689 } \
690 } \
691 } while(0)
692 #endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
693 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
694 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */
695 /**
696 * @}
697 */
698
699 /* Exported functions --------------------------------------------------------*/
700 /** @addtogroup UARTEx_Exported_Functions
701 * @{
702 */
703
704 /** @addtogroup UARTEx_Exported_Functions_Group1
705 * @brief Extended Initialization and Configuration Functions
706 * @{
707 */
708 /* Initialization and de-initialization functions ****************************/
709 #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)
710 HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t UART_DEPolarity, uint32_t UART_DEAssertionTime, uint32_t UART_DEDeassertionTime);
711 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
712 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
713 /**
714 * @}
715 */
716
717 /** @addtogroup UARTEx_Exported_Functions_Group2
718 * @brief Extended UART Interrupt handling function
719 * @{
720 */
721
722 /* IO operation functions ***************************************************/
723 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
724
725 #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)
726 void HAL_UART_WakeupCallback(UART_HandleTypeDef *huart);
727 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
728 /**
729 * @}
730 */
731
732 /** @addtogroup UARTEx_Exported_Functions_Group3
733 * @brief Extended Peripheral Control functions
734 * @{
735 */
736
737 /* Peripheral Control functions **********************************************/
738 HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength);
739 #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6) && !defined(STM32F030xC)
740 HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection);
741 HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart);
742 HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart);
743 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
744 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
745 /**
746 * @}
747 */
748 /* Peripheral State functions ************************************************/
749
750 /**
751 * @}
752 */
753
754
755 /**
756 * @}
757 */
758
759 /**
760 * @}
761 */
762
763 #ifdef __cplusplus
764 }
765 #endif
766
767 #endif /* __STM32F0xx_HAL_UART_EX_H */
768
769 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
770
Imprint / Impressum