comparison l476rg/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h @ 0:32a3b1785697

a rough draft of Hardware Abstraction Layer for C++ STM32L476RG drivers
author cin
date Thu, 12 Jan 2017 02:45:43 +0300
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:32a3b1785697
1 /**
2 ******************************************************************************
3 * @file stm32l4xx_hal_uart_ex.h
4 * @author MCD Application Team
5 * @version V1.6.0
6 * @date 28-October-2016
7 * @brief Header file of UART HAL Extended module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2016 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 __STM32L4xx_HAL_UART_EX_H
40 #define __STM32L4xx_HAL_UART_EX_H
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32l4xx_hal_def.h"
48
49 /** @addtogroup STM32L4xx_HAL_Driver
50 * @{
51 */
52
53 /** @addtogroup UARTEx
54 * @{
55 */
56
57 /* Exported types ------------------------------------------------------------*/
58 /** @defgroup UARTEx_Exported_Types UARTEx Exported Types
59 * @{
60 */
61
62 /**
63 * @brief UART wake up from stop mode parameters
64 */
65 typedef struct
66 {
67 uint32_t WakeUpEvent; /*!< Specifies which event will activat the Wakeup from Stop mode flag (WUF).
68 This parameter can be a value of @ref UART_WakeUp_from_Stop_Selection.
69 If set to UART_WAKEUP_ON_ADDRESS, the two other fields below must
70 be filled up. */
71
72 uint16_t AddressLength; /*!< Specifies whether the address is 4 or 7-bit long.
73 This parameter can be a value of @ref UARTEx_WakeUp_Address_Length. */
74
75 uint8_t Address; /*!< UART/USART node address (7-bit long max). */
76 } UART_WakeUpTypeDef;
77
78 /**
79 * @}
80 */
81
82 /* Exported constants --------------------------------------------------------*/
83 /** @defgroup UARTEx_Exported_Constants UARTEx Exported Constants
84 * @{
85 */
86
87 /** @defgroup UARTEx_Word_Length UART Word Length
88 * @{
89 */
90 #define UART_WORDLENGTH_7B ((uint32_t)USART_CR1_M1) /*!< 7-bit long UART frame */
91 #define UART_WORDLENGTH_8B ((uint32_t)0x00000000) /*!< 8-bit long UART frame */
92 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M0) /*!< 9-bit long UART frame */
93 /**
94 * @}
95 */
96
97 /** @defgroup UARTEx_WakeUp_Address_Length UART Extended WakeUp Address Length
98 * @{
99 */
100 #define UART_ADDRESS_DETECT_4B ((uint32_t)0x00000000) /*!< 4-bit long wake-up address */
101 #define UART_ADDRESS_DETECT_7B ((uint32_t)USART_CR2_ADDM7) /*!< 7-bit long wake-up address */
102 /**
103 * @}
104 */
105
106 /**
107 * @}
108 */
109
110 /* Exported macros -----------------------------------------------------------*/
111 /* Exported functions --------------------------------------------------------*/
112 /** @addtogroup UARTEx_Exported_Functions
113 * @{
114 */
115
116 /** @addtogroup UARTEx_Exported_Functions_Group1
117 * @{
118 */
119
120 /* Initialization and de-initialization functions ****************************/
121 HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime, uint32_t DeassertionTime);
122
123 /**
124 * @}
125 */
126
127 /* IO operation functions *****************************************************/
128
129 /** @addtogroup UARTEx_Exported_Functions_Group3
130 * @{
131 */
132
133 /* Peripheral Control functions **********************************************/
134 HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection);
135 HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart);
136 HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart);
137 HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength);
138 void HAL_UARTEx_WakeupCallback(UART_HandleTypeDef *huart);
139
140 /**
141 * @}
142 */
143
144 /**
145 * @}
146 */
147
148 /* Private macros ------------------------------------------------------------*/
149 /** @defgroup UARTEx_Private_Macros UARTEx Private Macros
150 * @{
151 */
152
153 /** @brief Report the UART clock source.
154 * @param __HANDLE__: specifies the UART Handle.
155 * @param __CLOCKSOURCE__: output variable.
156 * @retval UART clocking source, written in __CLOCKSOURCE__.
157 */
158 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx)
159 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
160 do { \
161 if((__HANDLE__)->Instance == USART1) \
162 { \
163 switch(__HAL_RCC_GET_USART1_SOURCE()) \
164 { \
165 case RCC_USART1CLKSOURCE_PCLK2: \
166 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \
167 break; \
168 case RCC_USART1CLKSOURCE_HSI: \
169 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
170 break; \
171 case RCC_USART1CLKSOURCE_SYSCLK: \
172 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
173 break; \
174 case RCC_USART1CLKSOURCE_LSE: \
175 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
176 break; \
177 default: \
178 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
179 break; \
180 } \
181 } \
182 else if((__HANDLE__)->Instance == USART2) \
183 { \
184 switch(__HAL_RCC_GET_USART2_SOURCE()) \
185 { \
186 case RCC_USART2CLKSOURCE_PCLK1: \
187 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
188 break; \
189 case RCC_USART2CLKSOURCE_HSI: \
190 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
191 break; \
192 case RCC_USART2CLKSOURCE_SYSCLK: \
193 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
194 break; \
195 case RCC_USART2CLKSOURCE_LSE: \
196 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
197 break; \
198 default: \
199 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
200 break; \
201 } \
202 } \
203 else if((__HANDLE__)->Instance == USART3) \
204 { \
205 switch(__HAL_RCC_GET_USART3_SOURCE()) \
206 { \
207 case RCC_USART3CLKSOURCE_PCLK1: \
208 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
209 break; \
210 case RCC_USART3CLKSOURCE_HSI: \
211 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
212 break; \
213 case RCC_USART3CLKSOURCE_SYSCLK: \
214 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
215 break; \
216 case RCC_USART3CLKSOURCE_LSE: \
217 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
218 break; \
219 default: \
220 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
221 break; \
222 } \
223 } \
224 else if((__HANDLE__)->Instance == UART4) \
225 { \
226 switch(__HAL_RCC_GET_UART4_SOURCE()) \
227 { \
228 case RCC_UART4CLKSOURCE_PCLK1: \
229 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
230 break; \
231 case RCC_UART4CLKSOURCE_HSI: \
232 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
233 break; \
234 case RCC_UART4CLKSOURCE_SYSCLK: \
235 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
236 break; \
237 case RCC_UART4CLKSOURCE_LSE: \
238 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
239 break; \
240 default: \
241 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
242 break; \
243 } \
244 } \
245 else if ((__HANDLE__)->Instance == UART5) \
246 { \
247 switch(__HAL_RCC_GET_UART5_SOURCE()) \
248 { \
249 case RCC_UART5CLKSOURCE_PCLK1: \
250 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
251 break; \
252 case RCC_UART5CLKSOURCE_HSI: \
253 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
254 break; \
255 case RCC_UART5CLKSOURCE_SYSCLK: \
256 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
257 break; \
258 case RCC_UART5CLKSOURCE_LSE: \
259 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
260 break; \
261 default: \
262 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
263 break; \
264 } \
265 } \
266 else if((__HANDLE__)->Instance == LPUART1) \
267 { \
268 switch(__HAL_RCC_GET_LPUART1_SOURCE()) \
269 { \
270 case RCC_LPUART1CLKSOURCE_PCLK1: \
271 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
272 break; \
273 case RCC_LPUART1CLKSOURCE_HSI: \
274 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
275 break; \
276 case RCC_LPUART1CLKSOURCE_SYSCLK: \
277 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
278 break; \
279 case RCC_LPUART1CLKSOURCE_LSE: \
280 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
281 break; \
282 default: \
283 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
284 break; \
285 } \
286 } \
287 } while(0)
288 #elif defined (STM32L431xx) || defined (STM32L433xx) || defined (STM32L443xx)
289 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
290 do { \
291 if((__HANDLE__)->Instance == USART1) \
292 { \
293 switch(__HAL_RCC_GET_USART1_SOURCE()) \
294 { \
295 case RCC_USART1CLKSOURCE_PCLK2: \
296 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \
297 break; \
298 case RCC_USART1CLKSOURCE_HSI: \
299 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
300 break; \
301 case RCC_USART1CLKSOURCE_SYSCLK: \
302 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
303 break; \
304 case RCC_USART1CLKSOURCE_LSE: \
305 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
306 break; \
307 default: \
308 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
309 break; \
310 } \
311 } \
312 else if((__HANDLE__)->Instance == USART2) \
313 { \
314 switch(__HAL_RCC_GET_USART2_SOURCE()) \
315 { \
316 case RCC_USART2CLKSOURCE_PCLK1: \
317 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
318 break; \
319 case RCC_USART2CLKSOURCE_HSI: \
320 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
321 break; \
322 case RCC_USART2CLKSOURCE_SYSCLK: \
323 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
324 break; \
325 case RCC_USART2CLKSOURCE_LSE: \
326 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
327 break; \
328 default: \
329 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
330 break; \
331 } \
332 } \
333 else if((__HANDLE__)->Instance == USART3) \
334 { \
335 switch(__HAL_RCC_GET_USART3_SOURCE()) \
336 { \
337 case RCC_USART3CLKSOURCE_PCLK1: \
338 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
339 break; \
340 case RCC_USART3CLKSOURCE_HSI: \
341 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
342 break; \
343 case RCC_USART3CLKSOURCE_SYSCLK: \
344 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
345 break; \
346 case RCC_USART3CLKSOURCE_LSE: \
347 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
348 break; \
349 default: \
350 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
351 break; \
352 } \
353 } \
354 else if((__HANDLE__)->Instance == LPUART1) \
355 { \
356 switch(__HAL_RCC_GET_LPUART1_SOURCE()) \
357 { \
358 case RCC_LPUART1CLKSOURCE_PCLK1: \
359 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
360 break; \
361 case RCC_LPUART1CLKSOURCE_HSI: \
362 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
363 break; \
364 case RCC_LPUART1CLKSOURCE_SYSCLK: \
365 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
366 break; \
367 case RCC_LPUART1CLKSOURCE_LSE: \
368 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
369 break; \
370 default: \
371 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
372 break; \
373 } \
374 } \
375 } while(0)
376 #elif defined (STM32L432xx) || defined (STM32L442xx)
377 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
378 do { \
379 if((__HANDLE__)->Instance == USART1) \
380 { \
381 switch(__HAL_RCC_GET_USART1_SOURCE()) \
382 { \
383 case RCC_USART1CLKSOURCE_PCLK2: \
384 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \
385 break; \
386 case RCC_USART1CLKSOURCE_HSI: \
387 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
388 break; \
389 case RCC_USART1CLKSOURCE_SYSCLK: \
390 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
391 break; \
392 case RCC_USART1CLKSOURCE_LSE: \
393 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
394 break; \
395 default: \
396 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
397 break; \
398 } \
399 } \
400 else if((__HANDLE__)->Instance == USART2) \
401 { \
402 switch(__HAL_RCC_GET_USART2_SOURCE()) \
403 { \
404 case RCC_USART2CLKSOURCE_PCLK1: \
405 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
406 break; \
407 case RCC_USART2CLKSOURCE_HSI: \
408 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
409 break; \
410 case RCC_USART2CLKSOURCE_SYSCLK: \
411 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
412 break; \
413 case RCC_USART2CLKSOURCE_LSE: \
414 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
415 break; \
416 default: \
417 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
418 break; \
419 } \
420 } \
421 else if((__HANDLE__)->Instance == LPUART1) \
422 { \
423 switch(__HAL_RCC_GET_LPUART1_SOURCE()) \
424 { \
425 case RCC_LPUART1CLKSOURCE_PCLK1: \
426 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
427 break; \
428 case RCC_LPUART1CLKSOURCE_HSI: \
429 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
430 break; \
431 case RCC_LPUART1CLKSOURCE_SYSCLK: \
432 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
433 break; \
434 case RCC_LPUART1CLKSOURCE_LSE: \
435 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
436 break; \
437 default: \
438 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
439 break; \
440 } \
441 } \
442 } while(0)
443 #elif defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
444 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
445 do { \
446 if((__HANDLE__)->Instance == USART1) \
447 { \
448 switch(__HAL_RCC_GET_USART1_SOURCE()) \
449 { \
450 case RCC_USART1CLKSOURCE_PCLK2: \
451 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \
452 break; \
453 case RCC_USART1CLKSOURCE_HSI: \
454 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
455 break; \
456 case RCC_USART1CLKSOURCE_SYSCLK: \
457 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
458 break; \
459 case RCC_USART1CLKSOURCE_LSE: \
460 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
461 break; \
462 default: \
463 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
464 break; \
465 } \
466 } \
467 else if((__HANDLE__)->Instance == USART2) \
468 { \
469 switch(__HAL_RCC_GET_USART2_SOURCE()) \
470 { \
471 case RCC_USART2CLKSOURCE_PCLK1: \
472 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
473 break; \
474 case RCC_USART2CLKSOURCE_HSI: \
475 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
476 break; \
477 case RCC_USART2CLKSOURCE_SYSCLK: \
478 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
479 break; \
480 case RCC_USART2CLKSOURCE_LSE: \
481 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
482 break; \
483 default: \
484 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
485 break; \
486 } \
487 } \
488 else if((__HANDLE__)->Instance == USART3) \
489 { \
490 switch(__HAL_RCC_GET_USART3_SOURCE()) \
491 { \
492 case RCC_USART3CLKSOURCE_PCLK1: \
493 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
494 break; \
495 case RCC_USART3CLKSOURCE_HSI: \
496 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
497 break; \
498 case RCC_USART3CLKSOURCE_SYSCLK: \
499 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
500 break; \
501 case RCC_USART3CLKSOURCE_LSE: \
502 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
503 break; \
504 default: \
505 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
506 break; \
507 } \
508 } \
509 else if((__HANDLE__)->Instance == UART4) \
510 { \
511 switch(__HAL_RCC_GET_UART4_SOURCE()) \
512 { \
513 case RCC_UART4CLKSOURCE_PCLK1: \
514 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
515 break; \
516 case RCC_UART4CLKSOURCE_HSI: \
517 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
518 break; \
519 case RCC_UART4CLKSOURCE_SYSCLK: \
520 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
521 break; \
522 case RCC_UART4CLKSOURCE_LSE: \
523 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
524 break; \
525 default: \
526 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
527 break; \
528 } \
529 } \
530 else if((__HANDLE__)->Instance == LPUART1) \
531 { \
532 switch(__HAL_RCC_GET_LPUART1_SOURCE()) \
533 { \
534 case RCC_LPUART1CLKSOURCE_PCLK1: \
535 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
536 break; \
537 case RCC_LPUART1CLKSOURCE_HSI: \
538 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
539 break; \
540 case RCC_LPUART1CLKSOURCE_SYSCLK: \
541 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
542 break; \
543 case RCC_LPUART1CLKSOURCE_LSE: \
544 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
545 break; \
546 default: \
547 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
548 break; \
549 } \
550 } \
551 } while(0)
552 #endif
553
554 /** @brief Report the UART mask to apply to retrieve the received data
555 * according to the word length and to the parity bits activation.
556 * @note If PCE = 1, the parity bit is not included in the data extracted
557 * by the reception API().
558 * This masking operation is not carried out in the case of
559 * DMA transfers.
560 * @param __HANDLE__: specifies the UART Handle.
561 * @retval None, the mask to apply to UART RDR register is stored in (__HANDLE__)->Mask field.
562 */
563 #define UART_MASK_COMPUTATION(__HANDLE__) \
564 do { \
565 if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B) \
566 { \
567 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
568 { \
569 (__HANDLE__)->Mask = 0x01FF ; \
570 } \
571 else \
572 { \
573 (__HANDLE__)->Mask = 0x00FF ; \
574 } \
575 } \
576 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B) \
577 { \
578 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
579 { \
580 (__HANDLE__)->Mask = 0x00FF ; \
581 } \
582 else \
583 { \
584 (__HANDLE__)->Mask = 0x007F ; \
585 } \
586 } \
587 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_7B) \
588 { \
589 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
590 { \
591 (__HANDLE__)->Mask = 0x007F ; \
592 } \
593 else \
594 { \
595 (__HANDLE__)->Mask = 0x003F ; \
596 } \
597 } \
598 } while(0)
599
600
601 /**
602 * @brief Ensure that UART frame length is valid.
603 * @param __LENGTH__: UART frame length.
604 * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
605 */
606 #define IS_UART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == UART_WORDLENGTH_7B) || \
607 ((__LENGTH__) == UART_WORDLENGTH_8B) || \
608 ((__LENGTH__) == UART_WORDLENGTH_9B))
609
610 /**
611 * @brief Ensure that UART wake-up address length is valid.
612 * @param __ADDRESS__: UART wake-up address length.
613 * @retval SET (__ADDRESS__ is valid) or RESET (__ADDRESS__ is invalid)
614 */
615 #define IS_UART_ADDRESSLENGTH_DETECT(__ADDRESS__) (((__ADDRESS__) == UART_ADDRESS_DETECT_4B) || \
616 ((__ADDRESS__) == UART_ADDRESS_DETECT_7B))
617
618 /**
619 * @}
620 */
621
622 /* Private functions ---------------------------------------------------------*/
623
624 /**
625 * @}
626 */
627
628 /**
629 * @}
630 */
631
632 #ifdef __cplusplus
633 }
634 #endif
635
636 #endif /* __STM32L4xx_HAL_UART_EX_H */
637
638 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/