1 /**
2   ******************************************************************************
3   * @file    stm32f0xx_hal_uart_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of UART HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32F0xx_HAL_UART_EX_H
21 #define STM32F0xx_HAL_UART_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f0xx_hal_def.h"
29 
30 /** @addtogroup STM32F0xx_HAL_Driver
31   * @{
32   */
33 
34 /** @addtogroup UARTEx
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /** @defgroup UARTEx_Exported_Types UARTEx Exported Types
40   * @{
41   */
42 
43 #if defined(USART_CR1_UESM)
44 /**
45   * @brief  UART wake up from stop mode parameters
46   */
47 typedef struct
48 {
49   uint32_t WakeUpEvent;        /*!< Specifies which event will activate the Wakeup from Stop mode flag (WUF).
50                                     This parameter can be a value of @ref UART_WakeUp_from_Stop_Selection.
51                                     If set to UART_WAKEUP_ON_ADDRESS, the two other fields below must
52                                     be filled up. */
53 
54   uint16_t AddressLength;      /*!< Specifies whether the address is 4 or 7-bit long.
55                                     This parameter can be a value of @ref UARTEx_WakeUp_Address_Length.  */
56 
57   uint8_t Address;             /*!< UART/USART node address (7-bit long max). */
58 } UART_WakeUpTypeDef;
59 
60 #endif /* USART_CR1_UESM */
61 /**
62   * @}
63   */
64 
65 /* Exported constants --------------------------------------------------------*/
66 /** @defgroup UARTEx_Exported_Constants UARTEx Exported Constants
67   * @{
68   */
69 
70 /** @defgroup UARTEx_Word_Length UARTEx Word Length
71   * @{
72   */
73 #if defined(USART_CR1_M1)
74 #define UART_WORDLENGTH_7B          USART_CR1_M1   /*!< 7-bit long UART frame */
75 #endif /* USART_CR1_M1 */
76 #define UART_WORDLENGTH_8B          0x00000000U    /*!< 8-bit long UART frame */
77 #if defined (USART_CR1_M0)
78 #define UART_WORDLENGTH_9B          USART_CR1_M0   /*!< 9-bit long UART frame */
79 #else
80 #define UART_WORDLENGTH_9B          USART_CR1_M   /*!< 9-bit long UART frame */
81 #endif /* USART_CR1_M0 */
82 /**
83   * @}
84   */
85 
86 /** @defgroup UARTEx_WakeUp_Address_Length UARTEx WakeUp Address Length
87   * @{
88   */
89 #define UART_ADDRESS_DETECT_4B      0x00000000U      /*!< 4-bit long wake-up address */
90 #define UART_ADDRESS_DETECT_7B      USART_CR2_ADDM7  /*!< 7-bit long wake-up address */
91 /**
92   * @}
93   */
94 
95 /**
96   * @}
97   */
98 
99 /* Exported macros -----------------------------------------------------------*/
100 /* Exported functions --------------------------------------------------------*/
101 /** @addtogroup UARTEx_Exported_Functions
102   * @{
103   */
104 
105 /** @addtogroup UARTEx_Exported_Functions_Group1
106   * @{
107   */
108 
109 /* Initialization and de-initialization functions  ****************************/
110 HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime,
111                                    uint32_t DeassertionTime);
112 
113 /**
114   * @}
115   */
116 
117 /** @addtogroup UARTEx_Exported_Functions_Group2
118   * @{
119   */
120 
121 #if defined(USART_CR1_UESM)
122 void HAL_UARTEx_WakeupCallback(UART_HandleTypeDef *huart);
123 
124 #endif /* USART_CR1_UESM */
125 /**
126   * @}
127   */
128 
129 /** @addtogroup UARTEx_Exported_Functions_Group3
130   * @{
131   */
132 
133 /* Peripheral Control functions  **********************************************/
134 #if defined(USART_CR1_UESM)
135 HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection);
136 HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart);
137 HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart);
138 
139 #endif /* USART_CR1_UESM */
140 HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength);
141 
142 
143 HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint16_t *RxLen,
144                                            uint32_t Timeout);
145 HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
146 HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
147 
148 HAL_UART_RxEventTypeTypeDef HAL_UARTEx_GetRxEventType(const UART_HandleTypeDef *huart);
149 
150 
151 /**
152   * @}
153   */
154 
155 /**
156   * @}
157   */
158 
159 /* Private macros ------------------------------------------------------------*/
160 /** @defgroup UARTEx_Private_Macros UARTEx Private Macros
161   * @{
162   */
163 
164 /** @brief  Report the UART clock source.
165   * @param  __HANDLE__ specifies the UART Handle.
166   * @param  __CLOCKSOURCE__ output variable.
167   * @retval UART clocking source, written in __CLOCKSOURCE__.
168   */
169 
170 #if defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx)
171 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \
172   do {                                                        \
173     switch(__HAL_RCC_GET_USART1_SOURCE())                     \
174     {                                                         \
175       case RCC_USART1CLKSOURCE_PCLK1:                         \
176         (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;           \
177         break;                                                \
178       case RCC_USART1CLKSOURCE_HSI:                           \
179         (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;             \
180         break;                                                \
181       case RCC_USART1CLKSOURCE_SYSCLK:                        \
182         (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;          \
183         break;                                                \
184       case RCC_USART1CLKSOURCE_LSE:                           \
185         (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;             \
186         break;                                                \
187       default:                                                \
188         (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;       \
189         break;                                                \
190     }                                                         \
191   } while(0)
192 #elif defined (STM32F030x8) || defined (STM32F070x6) || defined (STM32F042x6) || defined (STM32F048xx) \
193    || defined (STM32F051x8) || defined (STM32F058xx)
194 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \
195   do {                                                        \
196     if((__HANDLE__)->Instance == USART1)                      \
197     {                                                         \
198       switch(__HAL_RCC_GET_USART1_SOURCE())                   \
199       {                                                       \
200         case RCC_USART1CLKSOURCE_PCLK1:                       \
201           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \
202           break;                                              \
203         case RCC_USART1CLKSOURCE_HSI:                         \
204           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \
205           break;                                              \
206         case RCC_USART1CLKSOURCE_SYSCLK:                      \
207           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \
208           break;                                              \
209         case RCC_USART1CLKSOURCE_LSE:                         \
210           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \
211           break;                                              \
212         default:                                              \
213           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \
214           break;                                              \
215       }                                                       \
216     }                                                         \
217     else if((__HANDLE__)->Instance == USART2)                 \
218     {                                                         \
219       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
220     }                                                         \
221     else                                                      \
222     {                                                         \
223       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;         \
224     }                                                         \
225   } while(0)
226 #elif defined(STM32F070xB)
227 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \
228   do {                                                        \
229     if((__HANDLE__)->Instance == USART1)                      \
230     {                                                         \
231       switch(__HAL_RCC_GET_USART1_SOURCE())                   \
232       {                                                       \
233         case RCC_USART1CLKSOURCE_PCLK1:                       \
234           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \
235           break;                                              \
236         case RCC_USART1CLKSOURCE_HSI:                         \
237           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \
238           break;                                              \
239         case RCC_USART1CLKSOURCE_SYSCLK:                      \
240           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \
241           break;                                              \
242         case RCC_USART1CLKSOURCE_LSE:                         \
243           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \
244           break;                                              \
245         default:                                              \
246           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \
247           break;                                              \
248       }                                                       \
249     }                                                         \
250     else if((__HANDLE__)->Instance == USART2)                 \
251     {                                                         \
252       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
253     }                                                         \
254     else if((__HANDLE__)->Instance == USART3)                 \
255     {                                                         \
256       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
257     }                                                         \
258     else if((__HANDLE__)->Instance == USART4)                 \
259     {                                                         \
260       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
261     }                                                         \
262     else                                                      \
263     {                                                         \
264       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;         \
265     }                                                         \
266   } while(0)
267 #elif defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)
268 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \
269   do {                                                        \
270     if((__HANDLE__)->Instance == USART1)                      \
271     {                                                         \
272       switch(__HAL_RCC_GET_USART1_SOURCE())                   \
273       {                                                       \
274         case RCC_USART1CLKSOURCE_PCLK1:                       \
275           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \
276           break;                                              \
277         case RCC_USART1CLKSOURCE_HSI:                         \
278           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \
279           break;                                              \
280         case RCC_USART1CLKSOURCE_SYSCLK:                      \
281           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \
282           break;                                              \
283         case RCC_USART1CLKSOURCE_LSE:                         \
284           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \
285           break;                                              \
286         default:                                              \
287           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \
288           break;                                              \
289       }                                                       \
290     }                                                         \
291     else if((__HANDLE__)->Instance == USART2)                 \
292     {                                                         \
293       switch(__HAL_RCC_GET_USART2_SOURCE())                   \
294       {                                                       \
295         case RCC_USART2CLKSOURCE_PCLK1:                       \
296           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \
297           break;                                              \
298         case RCC_USART2CLKSOURCE_HSI:                         \
299           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \
300           break;                                              \
301         case RCC_USART2CLKSOURCE_SYSCLK:                      \
302           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \
303           break;                                              \
304         case RCC_USART2CLKSOURCE_LSE:                         \
305           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \
306           break;                                              \
307         default:                                              \
308           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \
309           break;                                              \
310       }                                                       \
311     }                                                         \
312     else if((__HANDLE__)->Instance == USART3)                 \
313     {                                                         \
314       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
315     }                                                         \
316     else if((__HANDLE__)->Instance == USART4)                 \
317     {                                                         \
318       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
319     }                                                         \
320     else                                                      \
321     {                                                         \
322       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;         \
323     }                                                         \
324   } while(0)
325 #elif defined(STM32F091xC) || defined (STM32F098xx)
326 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \
327   do {                                                        \
328     if((__HANDLE__)->Instance == USART1)                      \
329     {                                                         \
330       switch(__HAL_RCC_GET_USART1_SOURCE())                   \
331       {                                                       \
332         case RCC_USART1CLKSOURCE_PCLK1:                       \
333           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \
334           break;                                              \
335         case RCC_USART1CLKSOURCE_HSI:                         \
336           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \
337           break;                                              \
338         case RCC_USART1CLKSOURCE_SYSCLK:                      \
339           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \
340           break;                                              \
341         case RCC_USART1CLKSOURCE_LSE:                         \
342           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \
343           break;                                              \
344         default:                                              \
345           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \
346           break;                                              \
347       }                                                       \
348     }                                                         \
349     else if((__HANDLE__)->Instance == USART2)                 \
350     {                                                         \
351       switch(__HAL_RCC_GET_USART2_SOURCE())                   \
352       {                                                       \
353         case RCC_USART2CLKSOURCE_PCLK1:                       \
354           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \
355           break;                                              \
356         case RCC_USART2CLKSOURCE_HSI:                         \
357           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \
358           break;                                              \
359         case RCC_USART2CLKSOURCE_SYSCLK:                      \
360           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \
361           break;                                              \
362         case RCC_USART2CLKSOURCE_LSE:                         \
363           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \
364           break;                                              \
365         default:                                              \
366           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \
367           break;                                              \
368       }                                                       \
369     }                                                         \
370     else if((__HANDLE__)->Instance == USART3)                 \
371     {                                                         \
372       switch(__HAL_RCC_GET_USART3_SOURCE())                   \
373       {                                                       \
374         case RCC_USART3CLKSOURCE_PCLK1:                       \
375           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \
376           break;                                              \
377         case RCC_USART3CLKSOURCE_HSI:                         \
378           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \
379           break;                                              \
380         case RCC_USART3CLKSOURCE_SYSCLK:                      \
381           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \
382           break;                                              \
383         case RCC_USART3CLKSOURCE_LSE:                         \
384           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \
385           break;                                              \
386         default:                                              \
387           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \
388           break;                                              \
389       }                                                       \
390     }                                                         \
391     else if((__HANDLE__)->Instance == USART4)                 \
392     {                                                         \
393       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
394     }                                                         \
395     else if((__HANDLE__)->Instance == USART5)                 \
396     {                                                         \
397       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
398     }                                                         \
399     else if((__HANDLE__)->Instance == USART6)                 \
400     {                                                         \
401       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
402     }                                                         \
403     else if((__HANDLE__)->Instance == USART7)                 \
404     {                                                         \
405       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
406     }                                                         \
407     else if((__HANDLE__)->Instance == USART8)                 \
408     {                                                         \
409       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
410     }                                                         \
411     else                                                      \
412     {                                                         \
413       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;         \
414     }                                                         \
415   } while(0)
416 #elif defined(STM32F030xC)
417 #define 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       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
443     }                                                         \
444     else if((__HANDLE__)->Instance == USART3)                 \
445     {                                                         \
446       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
447     }                                                         \
448     else if((__HANDLE__)->Instance == USART4)                 \
449     {                                                         \
450       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
451     }                                                         \
452     else if((__HANDLE__)->Instance == USART5)                 \
453     {                                                         \
454       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
455     }                                                         \
456     else if((__HANDLE__)->Instance == USART6)                 \
457     {                                                         \
458       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;             \
459     }                                                         \
460     else                                                      \
461     {                                                         \
462       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;         \
463     }                                                         \
464   } while(0)
465 
466 #endif /* defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx) */
467 
468 /** @brief  Report the UART mask to apply to retrieve the received data
469   *         according to the word length and to the parity bits activation.
470   * @note   If PCE = 1, the parity bit is not included in the data extracted
471   *         by the reception API().
472   *         This masking operation is not carried out in the case of
473   *         DMA transfers.
474   * @param  __HANDLE__ specifies the UART Handle.
475   * @retval None, the mask to apply to UART RDR register is stored in (__HANDLE__)->Mask field.
476   */
477 #if defined (USART_CR1_M1)
478 #define UART_MASK_COMPUTATION(__HANDLE__)                             \
479   do {                                                                \
480     if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B)          \
481     {                                                                 \
482       if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE)              \
483       {                                                               \
484         (__HANDLE__)->Mask = 0x01FFU ;                                \
485       }                                                               \
486       else                                                            \
487       {                                                               \
488         (__HANDLE__)->Mask = 0x00FFU ;                                \
489       }                                                               \
490     }                                                                 \
491     else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B)     \
492     {                                                                 \
493       if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE)              \
494       {                                                               \
495         (__HANDLE__)->Mask = 0x00FFU ;                                \
496       }                                                               \
497       else                                                            \
498       {                                                               \
499         (__HANDLE__)->Mask = 0x007FU ;                                \
500       }                                                               \
501     }                                                                 \
502     else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_7B)     \
503     {                                                                 \
504       if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE)              \
505       {                                                               \
506         (__HANDLE__)->Mask = 0x007FU ;                                \
507       }                                                               \
508       else                                                            \
509       {                                                               \
510         (__HANDLE__)->Mask = 0x003FU ;                                \
511       }                                                               \
512     }                                                                 \
513     else                                                              \
514     {                                                                 \
515       (__HANDLE__)->Mask = 0x0000U;                                   \
516     }                                                                 \
517   } while(0U)
518 
519 #else
520 #define UART_MASK_COMPUTATION(__HANDLE__)                             \
521   do {                                                                \
522     if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B)          \
523     {                                                                 \
524       if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE)              \
525       {                                                               \
526         (__HANDLE__)->Mask = 0x01FFU ;                                \
527       }                                                               \
528       else                                                            \
529       {                                                               \
530         (__HANDLE__)->Mask = 0x00FFU ;                                \
531       }                                                               \
532     }                                                                 \
533     else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B)     \
534     {                                                                 \
535       if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE)              \
536       {                                                               \
537         (__HANDLE__)->Mask = 0x00FFU ;                                \
538       }                                                               \
539       else                                                            \
540       {                                                               \
541         (__HANDLE__)->Mask = 0x007FU ;                                \
542       }                                                               \
543     }                                                                 \
544     else                                                              \
545     {                                                                 \
546       (__HANDLE__)->Mask = 0x0000U;                                   \
547     }                                                                 \
548   } while(0U)
549 
550 #endif /* USART_CR1_M1 */
551 
552 /**
553   * @brief Ensure that UART frame length is valid.
554   * @param __LENGTH__ UART frame length.
555   * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
556   */
557 #if defined (USART_CR1_M1)
558 #define IS_UART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == UART_WORDLENGTH_7B) || \
559                                          ((__LENGTH__) == UART_WORDLENGTH_8B) || \
560                                          ((__LENGTH__) == UART_WORDLENGTH_9B))
561 #else
562 #define IS_UART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == UART_WORDLENGTH_8B) || \
563                                          ((__LENGTH__) == UART_WORDLENGTH_9B))
564 #endif /* USART_CR1_M1 */
565 
566 /**
567   * @brief Ensure that UART wake-up address length is valid.
568   * @param __ADDRESS__ UART wake-up address length.
569   * @retval SET (__ADDRESS__ is valid) or RESET (__ADDRESS__ is invalid)
570   */
571 #define IS_UART_ADDRESSLENGTH_DETECT(__ADDRESS__) (((__ADDRESS__) == UART_ADDRESS_DETECT_4B) || \
572                                                    ((__ADDRESS__) == UART_ADDRESS_DETECT_7B))
573 
574 /**
575   * @}
576   */
577 
578 /* Private functions ---------------------------------------------------------*/
579 
580 /**
581   * @}
582   */
583 
584 /**
585   * @}
586   */
587 
588 #ifdef __cplusplus
589 }
590 #endif
591 
592 #endif /* STM32F0xx_HAL_UART_EX_H */
593 
594