]> git.sur5r.net Git - freertos/blob
b9835b5a1a4b4874cd223e3a4488ae095b6703d0
[freertos] /
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32l4xx_hal_uart_ex.h\r
4   * @author  MCD Application Team\r
5   * @brief   Header file of UART HAL Extended module.\r
6   ******************************************************************************\r
7   * @attention\r
8   *\r
9   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.\r
10   * All rights reserved.</center></h2>\r
11   *\r
12   * This software component is licensed by ST under BSD 3-Clause license,\r
13   * the "License"; You may not use this file except in compliance with the\r
14   * License. You may obtain a copy of the License at:\r
15   *                        opensource.org/licenses/BSD-3-Clause\r
16   *\r
17   ******************************************************************************\r
18   */\r
19 \r
20 /* Define to prevent recursive inclusion -------------------------------------*/\r
21 #ifndef STM32L4xx_HAL_UART_EX_H\r
22 #define STM32L4xx_HAL_UART_EX_H\r
23 \r
24 #ifdef __cplusplus\r
25 extern "C" {\r
26 #endif\r
27 \r
28 /* Includes ------------------------------------------------------------------*/\r
29 #include "stm32l4xx_hal_def.h"\r
30 \r
31 /** @addtogroup STM32L4xx_HAL_Driver\r
32   * @{\r
33   */\r
34 \r
35 /** @addtogroup UARTEx\r
36   * @{\r
37   */\r
38 \r
39 /* Exported types ------------------------------------------------------------*/\r
40 /** @defgroup UARTEx_Exported_Types UARTEx Exported Types\r
41   * @{\r
42   */\r
43 \r
44 /**\r
45   * @brief  UART wake up from stop mode parameters\r
46   */\r
47 typedef struct\r
48 {\r
49   uint32_t WakeUpEvent;        /*!< Specifies which event will activate the Wakeup from Stop mode flag (WUF).\r
50                                     This parameter can be a value of @ref UART_WakeUp_from_Stop_Selection.\r
51                                     If set to UART_WAKEUP_ON_ADDRESS, the two other fields below must\r
52                                     be filled up. */\r
53 \r
54   uint16_t AddressLength;      /*!< Specifies whether the address is 4 or 7-bit long.\r
55                                     This parameter can be a value of @ref UARTEx_WakeUp_Address_Length.  */\r
56 \r
57   uint8_t Address;             /*!< UART/USART node address (7-bit long max). */\r
58 } UART_WakeUpTypeDef;\r
59 \r
60 /**\r
61   * @}\r
62   */\r
63 \r
64 /* Exported constants --------------------------------------------------------*/\r
65 /** @defgroup UARTEx_Exported_Constants UARTEx Exported Constants\r
66   * @{\r
67   */\r
68 \r
69 /** @defgroup UARTEx_Word_Length UARTEx Word Length\r
70   * @{\r
71   */\r
72 #define UART_WORDLENGTH_7B                  USART_CR1_M1   /*!< 7-bit long UART frame */\r
73 #define UART_WORDLENGTH_8B                  0x00000000U    /*!< 8-bit long UART frame */\r
74 #define UART_WORDLENGTH_9B                  USART_CR1_M0   /*!< 9-bit long UART frame */\r
75 /**\r
76   * @}\r
77   */\r
78 \r
79 /** @defgroup UARTEx_WakeUp_Address_Length UARTEx WakeUp Address Length\r
80   * @{\r
81   */\r
82 #define UART_ADDRESS_DETECT_4B              0x00000000U      /*!< 4-bit long wake-up address */\r
83 #define UART_ADDRESS_DETECT_7B              USART_CR2_ADDM7  /*!< 7-bit long wake-up address */\r
84 /**\r
85   * @}\r
86   */\r
87 \r
88 #if defined(USART_CR1_FIFOEN)\r
89 /** @defgroup UARTEx_FIFO_mode UARTEx FIFO mode\r
90   * @brief    UART FIFO mode\r
91   * @{\r
92   */\r
93 #define UART_FIFOMODE_DISABLE        0x00000000U       /*!< FIFO mode disable */\r
94 #define UART_FIFOMODE_ENABLE         USART_CR1_FIFOEN  /*!< FIFO mode enable  */\r
95 /**\r
96   * @}\r
97   */\r
98 \r
99 /** @defgroup UARTEx_TXFIFO_threshold_level UARTEx TXFIFO threshold level\r
100   * @brief    UART TXFIFO threshold level\r
101   * @{\r
102   */\r
103 #define UART_TXFIFO_THRESHOLD_1_8   0x00000000U                               /*!< TXFIFO reaches 1/8 of its depth */\r
104 #define UART_TXFIFO_THRESHOLD_1_4   USART_CR3_TXFTCFG_0                       /*!< TXFIFO reaches 1/4 of its depth */\r
105 #define UART_TXFIFO_THRESHOLD_1_2   USART_CR3_TXFTCFG_1                       /*!< TXFIFO reaches 1/2 of its depth */\r
106 #define UART_TXFIFO_THRESHOLD_3_4   (USART_CR3_TXFTCFG_0|USART_CR3_TXFTCFG_1) /*!< TXFIFO reaches 3/4 of its depth */\r
107 #define UART_TXFIFO_THRESHOLD_7_8   USART_CR3_TXFTCFG_2                       /*!< TXFIFO reaches 7/8 of its depth */\r
108 #define UART_TXFIFO_THRESHOLD_8_8   (USART_CR3_TXFTCFG_2|USART_CR3_TXFTCFG_0) /*!< TXFIFO becomes empty            */\r
109 /**\r
110   * @}\r
111   */\r
112 \r
113 /** @defgroup UARTEx_RXFIFO_threshold_level UARTEx RXFIFO threshold level\r
114   * @brief    UART RXFIFO threshold level\r
115   * @{\r
116   */\r
117 #define UART_RXFIFO_THRESHOLD_1_8   0x00000000U                               /*!< RXFIFO FIFO reaches 1/8 of its depth */\r
118 #define UART_RXFIFO_THRESHOLD_1_4   USART_CR3_RXFTCFG_0                       /*!< RXFIFO FIFO reaches 1/4 of its depth */\r
119 #define UART_RXFIFO_THRESHOLD_1_2   USART_CR3_RXFTCFG_1                       /*!< RXFIFO FIFO reaches 1/2 of its depth */\r
120 #define UART_RXFIFO_THRESHOLD_3_4   (USART_CR3_RXFTCFG_0|USART_CR3_RXFTCFG_1) /*!< RXFIFO FIFO reaches 3/4 of its depth */\r
121 #define UART_RXFIFO_THRESHOLD_7_8   USART_CR3_RXFTCFG_2                       /*!< RXFIFO FIFO reaches 7/8 of its depth */\r
122 #define UART_RXFIFO_THRESHOLD_8_8   (USART_CR3_RXFTCFG_2|USART_CR3_RXFTCFG_0) /*!< RXFIFO FIFO becomes full             */\r
123 /**\r
124   * @}\r
125   */\r
126 #endif /* USART_CR1_FIFOEN */\r
127 \r
128 /**\r
129   * @}\r
130   */\r
131 \r
132 /* Exported macros -----------------------------------------------------------*/\r
133 /* Exported functions --------------------------------------------------------*/\r
134 /** @addtogroup UARTEx_Exported_Functions\r
135   * @{\r
136   */\r
137 \r
138 /** @addtogroup UARTEx_Exported_Functions_Group1\r
139   * @{\r
140   */\r
141 \r
142 /* Initialization and de-initialization functions  ****************************/\r
143 HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime,\r
144                                    uint32_t DeassertionTime);\r
145 \r
146 /**\r
147   * @}\r
148   */\r
149 \r
150 /** @addtogroup UARTEx_Exported_Functions_Group2\r
151   * @{\r
152   */\r
153 \r
154 void HAL_UARTEx_WakeupCallback(UART_HandleTypeDef *huart);\r
155 \r
156 #if defined(USART_CR1_FIFOEN)\r
157 void HAL_UARTEx_RxFifoFullCallback(UART_HandleTypeDef *huart);\r
158 void HAL_UARTEx_TxFifoEmptyCallback(UART_HandleTypeDef *huart);\r
159 #endif /* USART_CR1_FIFOEN */\r
160 \r
161 /**\r
162   * @}\r
163   */\r
164 \r
165 /** @addtogroup UARTEx_Exported_Functions_Group3\r
166   * @{\r
167   */\r
168 \r
169 /* Peripheral Control functions  **********************************************/\r
170 HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection);\r
171 HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart);\r
172 HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart);\r
173 #if defined(USART_CR3_UCESM)\r
174 HAL_StatusTypeDef HAL_UARTEx_EnableClockStopMode(UART_HandleTypeDef *huart);\r
175 HAL_StatusTypeDef HAL_UARTEx_DisableClockStopMode(UART_HandleTypeDef *huart);\r
176 #endif /* USART_CR3_UCESM */\r
177 HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength);\r
178 #if defined(USART_CR1_FIFOEN)\r
179 HAL_StatusTypeDef HAL_UARTEx_EnableFifoMode(UART_HandleTypeDef *huart);\r
180 HAL_StatusTypeDef HAL_UARTEx_DisableFifoMode(UART_HandleTypeDef *huart);\r
181 HAL_StatusTypeDef HAL_UARTEx_SetTxFifoThreshold(UART_HandleTypeDef *huart, uint32_t Threshold);\r
182 HAL_StatusTypeDef HAL_UARTEx_SetRxFifoThreshold(UART_HandleTypeDef *huart, uint32_t Threshold);\r
183 #endif /* USART_CR1_FIFOEN */\r
184 \r
185 /**\r
186   * @}\r
187   */\r
188 \r
189 /**\r
190   * @}\r
191   */\r
192 \r
193 /* Private macros ------------------------------------------------------------*/\r
194 /** @defgroup UARTEx_Private_Macros UARTEx Private Macros\r
195   * @{\r
196   */\r
197 \r
198 /** @brief  Report the UART clock source.\r
199   * @param  __HANDLE__ specifies the UART Handle.\r
200   * @param  __CLOCKSOURCE__ output variable.\r
201   * @retval UART clocking source, written in __CLOCKSOURCE__.\r
202   */\r
203 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) \\r
204     || defined (STM32L496xx) || defined (STM32L4A6xx) \\r
205     || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)\r
206 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \\r
207   do {                                                        \\r
208     if((__HANDLE__)->Instance == USART1)                      \\r
209     {                                                         \\r
210       switch(__HAL_RCC_GET_USART1_SOURCE())                   \\r
211       {                                                       \\r
212         case RCC_USART1CLKSOURCE_PCLK2:                       \\r
213           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2;         \\r
214           break;                                              \\r
215         case RCC_USART1CLKSOURCE_HSI:                         \\r
216           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
217           break;                                              \\r
218         case RCC_USART1CLKSOURCE_SYSCLK:                      \\r
219           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
220           break;                                              \\r
221         case RCC_USART1CLKSOURCE_LSE:                         \\r
222           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
223           break;                                              \\r
224         default:                                              \\r
225           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
226           break;                                              \\r
227       }                                                       \\r
228     }                                                         \\r
229     else if((__HANDLE__)->Instance == USART2)                 \\r
230     {                                                         \\r
231       switch(__HAL_RCC_GET_USART2_SOURCE())                   \\r
232       {                                                       \\r
233         case RCC_USART2CLKSOURCE_PCLK1:                       \\r
234           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
235           break;                                              \\r
236         case RCC_USART2CLKSOURCE_HSI:                         \\r
237           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
238           break;                                              \\r
239         case RCC_USART2CLKSOURCE_SYSCLK:                      \\r
240           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
241           break;                                              \\r
242         case RCC_USART2CLKSOURCE_LSE:                         \\r
243           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
244           break;                                              \\r
245         default:                                              \\r
246           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
247           break;                                              \\r
248       }                                                       \\r
249     }                                                         \\r
250     else if((__HANDLE__)->Instance == USART3)                 \\r
251     {                                                         \\r
252       switch(__HAL_RCC_GET_USART3_SOURCE())                   \\r
253       {                                                       \\r
254         case RCC_USART3CLKSOURCE_PCLK1:                       \\r
255           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
256           break;                                              \\r
257         case RCC_USART3CLKSOURCE_HSI:                         \\r
258           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
259           break;                                              \\r
260         case RCC_USART3CLKSOURCE_SYSCLK:                      \\r
261           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
262           break;                                              \\r
263         case RCC_USART3CLKSOURCE_LSE:                         \\r
264           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
265           break;                                              \\r
266         default:                                              \\r
267           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
268           break;                                              \\r
269       }                                                       \\r
270     }                                                         \\r
271     else if((__HANDLE__)->Instance == UART4)                  \\r
272     {                                                         \\r
273       switch(__HAL_RCC_GET_UART4_SOURCE())                    \\r
274       {                                                       \\r
275         case RCC_UART4CLKSOURCE_PCLK1:                        \\r
276           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
277           break;                                              \\r
278         case RCC_UART4CLKSOURCE_HSI:                          \\r
279           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
280           break;                                              \\r
281         case RCC_UART4CLKSOURCE_SYSCLK:                       \\r
282           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
283           break;                                              \\r
284         case RCC_UART4CLKSOURCE_LSE:                          \\r
285           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
286           break;                                              \\r
287         default:                                              \\r
288           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
289           break;                                              \\r
290       }                                                       \\r
291     }                                                         \\r
292     else if((__HANDLE__)->Instance == UART5)                  \\r
293     {                                                         \\r
294       switch(__HAL_RCC_GET_UART5_SOURCE())                    \\r
295       {                                                       \\r
296         case RCC_UART5CLKSOURCE_PCLK1:                        \\r
297           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
298           break;                                              \\r
299         case RCC_UART5CLKSOURCE_HSI:                          \\r
300           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
301           break;                                              \\r
302         case RCC_UART5CLKSOURCE_SYSCLK:                       \\r
303           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
304           break;                                              \\r
305         case RCC_UART5CLKSOURCE_LSE:                          \\r
306           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
307           break;                                              \\r
308         default:                                              \\r
309           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
310           break;                                              \\r
311       }                                                       \\r
312     }                                                         \\r
313     else if((__HANDLE__)->Instance == LPUART1)                \\r
314     {                                                         \\r
315       switch(__HAL_RCC_GET_LPUART1_SOURCE())                  \\r
316       {                                                       \\r
317         case RCC_LPUART1CLKSOURCE_PCLK1:                      \\r
318           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
319           break;                                              \\r
320         case RCC_LPUART1CLKSOURCE_HSI:                        \\r
321           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
322           break;                                              \\r
323         case RCC_LPUART1CLKSOURCE_SYSCLK:                     \\r
324           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
325           break;                                              \\r
326         case RCC_LPUART1CLKSOURCE_LSE:                        \\r
327           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
328           break;                                              \\r
329         default:                                              \\r
330           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
331           break;                                              \\r
332       }                                                       \\r
333     }                                                         \\r
334     else                                                      \\r
335     {                                                         \\r
336       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;         \\r
337     }                                                         \\r
338   } while(0U)\r
339 #elif defined (STM32L412xx) || defined (STM32L422xx) \\r
340    || defined (STM32L431xx) || defined (STM32L433xx) || defined (STM32L443xx)\r
341 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \\r
342   do {                                                        \\r
343     if((__HANDLE__)->Instance == USART1)                      \\r
344     {                                                         \\r
345       switch(__HAL_RCC_GET_USART1_SOURCE())                   \\r
346       {                                                       \\r
347         case RCC_USART1CLKSOURCE_PCLK2:                       \\r
348           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2;         \\r
349           break;                                              \\r
350         case RCC_USART1CLKSOURCE_HSI:                         \\r
351           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
352           break;                                              \\r
353         case RCC_USART1CLKSOURCE_SYSCLK:                      \\r
354           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
355           break;                                              \\r
356         case RCC_USART1CLKSOURCE_LSE:                         \\r
357           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
358           break;                                              \\r
359         default:                                              \\r
360           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
361           break;                                              \\r
362       }                                                       \\r
363     }                                                         \\r
364     else if((__HANDLE__)->Instance == USART2)                 \\r
365     {                                                         \\r
366       switch(__HAL_RCC_GET_USART2_SOURCE())                   \\r
367       {                                                       \\r
368         case RCC_USART2CLKSOURCE_PCLK1:                       \\r
369           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
370           break;                                              \\r
371         case RCC_USART2CLKSOURCE_HSI:                         \\r
372           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
373           break;                                              \\r
374         case RCC_USART2CLKSOURCE_SYSCLK:                      \\r
375           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
376           break;                                              \\r
377         case RCC_USART2CLKSOURCE_LSE:                         \\r
378           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
379           break;                                              \\r
380         default:                                              \\r
381           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
382           break;                                              \\r
383       }                                                       \\r
384     }                                                         \\r
385     else if((__HANDLE__)->Instance == USART3)                 \\r
386     {                                                         \\r
387       switch(__HAL_RCC_GET_USART3_SOURCE())                   \\r
388       {                                                       \\r
389         case RCC_USART3CLKSOURCE_PCLK1:                       \\r
390           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
391           break;                                              \\r
392         case RCC_USART3CLKSOURCE_HSI:                         \\r
393           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
394           break;                                              \\r
395         case RCC_USART3CLKSOURCE_SYSCLK:                      \\r
396           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
397           break;                                              \\r
398         case RCC_USART3CLKSOURCE_LSE:                         \\r
399           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
400           break;                                              \\r
401         default:                                              \\r
402           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
403           break;                                              \\r
404       }                                                       \\r
405     }                                                         \\r
406     else if((__HANDLE__)->Instance == LPUART1)                \\r
407     {                                                         \\r
408       switch(__HAL_RCC_GET_LPUART1_SOURCE())                  \\r
409       {                                                       \\r
410         case RCC_LPUART1CLKSOURCE_PCLK1:                      \\r
411           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
412           break;                                              \\r
413         case RCC_LPUART1CLKSOURCE_HSI:                        \\r
414           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
415           break;                                              \\r
416         case RCC_LPUART1CLKSOURCE_SYSCLK:                     \\r
417           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
418           break;                                              \\r
419         case RCC_LPUART1CLKSOURCE_LSE:                        \\r
420           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
421           break;                                              \\r
422         default:                                              \\r
423           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
424           break;                                              \\r
425       }                                                       \\r
426     }                                                         \\r
427     else                                                      \\r
428     {                                                         \\r
429       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;         \\r
430     }                                                         \\r
431   } while(0U)\r
432 #elif defined (STM32L432xx) || defined (STM32L442xx)\r
433 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \\r
434   do {                                                        \\r
435     if((__HANDLE__)->Instance == USART1)                      \\r
436     {                                                         \\r
437       switch(__HAL_RCC_GET_USART1_SOURCE())                   \\r
438       {                                                       \\r
439         case RCC_USART1CLKSOURCE_PCLK2:                       \\r
440           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2;         \\r
441           break;                                              \\r
442         case RCC_USART1CLKSOURCE_HSI:                         \\r
443           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
444           break;                                              \\r
445         case RCC_USART1CLKSOURCE_SYSCLK:                      \\r
446           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
447           break;                                              \\r
448         case RCC_USART1CLKSOURCE_LSE:                         \\r
449           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
450           break;                                              \\r
451         default:                                              \\r
452           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
453           break;                                              \\r
454       }                                                       \\r
455     }                                                         \\r
456     else if((__HANDLE__)->Instance == USART2)                 \\r
457     {                                                         \\r
458       switch(__HAL_RCC_GET_USART2_SOURCE())                   \\r
459       {                                                       \\r
460         case RCC_USART2CLKSOURCE_PCLK1:                       \\r
461           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
462           break;                                              \\r
463         case RCC_USART2CLKSOURCE_HSI:                         \\r
464           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
465           break;                                              \\r
466         case RCC_USART2CLKSOURCE_SYSCLK:                      \\r
467           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
468           break;                                              \\r
469         case RCC_USART2CLKSOURCE_LSE:                         \\r
470           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
471           break;                                              \\r
472         default:                                              \\r
473           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
474           break;                                              \\r
475       }                                                       \\r
476     }                                                         \\r
477     else if((__HANDLE__)->Instance == LPUART1)                \\r
478     {                                                         \\r
479       switch(__HAL_RCC_GET_LPUART1_SOURCE())                  \\r
480       {                                                       \\r
481         case RCC_LPUART1CLKSOURCE_PCLK1:                      \\r
482           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
483           break;                                              \\r
484         case RCC_LPUART1CLKSOURCE_HSI:                        \\r
485           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
486           break;                                              \\r
487         case RCC_LPUART1CLKSOURCE_SYSCLK:                     \\r
488           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
489           break;                                              \\r
490         case RCC_LPUART1CLKSOURCE_LSE:                        \\r
491           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
492           break;                                              \\r
493         default:                                              \\r
494           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
495           break;                                              \\r
496       }                                                       \\r
497     }                                                         \\r
498     else                                                      \\r
499     {                                                         \\r
500       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;         \\r
501     }                                                         \\r
502   } while(0U)\r
503 #elif defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)\r
504 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \\r
505   do {                                                        \\r
506     if((__HANDLE__)->Instance == USART1)                      \\r
507     {                                                         \\r
508       switch(__HAL_RCC_GET_USART1_SOURCE())                   \\r
509       {                                                       \\r
510         case RCC_USART1CLKSOURCE_PCLK2:                       \\r
511           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2;         \\r
512           break;                                              \\r
513         case RCC_USART1CLKSOURCE_HSI:                         \\r
514           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
515           break;                                              \\r
516         case RCC_USART1CLKSOURCE_SYSCLK:                      \\r
517           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
518           break;                                              \\r
519         case RCC_USART1CLKSOURCE_LSE:                         \\r
520           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
521           break;                                              \\r
522         default:                                              \\r
523           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
524           break;                                              \\r
525       }                                                       \\r
526     }                                                         \\r
527     else if((__HANDLE__)->Instance == USART2)                 \\r
528     {                                                         \\r
529       switch(__HAL_RCC_GET_USART2_SOURCE())                   \\r
530       {                                                       \\r
531         case RCC_USART2CLKSOURCE_PCLK1:                       \\r
532           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
533           break;                                              \\r
534         case RCC_USART2CLKSOURCE_HSI:                         \\r
535           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
536           break;                                              \\r
537         case RCC_USART2CLKSOURCE_SYSCLK:                      \\r
538           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
539           break;                                              \\r
540         case RCC_USART2CLKSOURCE_LSE:                         \\r
541           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
542           break;                                              \\r
543         default:                                              \\r
544           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
545           break;                                              \\r
546       }                                                       \\r
547     }                                                         \\r
548     else if((__HANDLE__)->Instance == USART3)                 \\r
549     {                                                         \\r
550       switch(__HAL_RCC_GET_USART3_SOURCE())                   \\r
551       {                                                       \\r
552         case RCC_USART3CLKSOURCE_PCLK1:                       \\r
553           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
554           break;                                              \\r
555         case RCC_USART3CLKSOURCE_HSI:                         \\r
556           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
557           break;                                              \\r
558         case RCC_USART3CLKSOURCE_SYSCLK:                      \\r
559           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
560           break;                                              \\r
561         case RCC_USART3CLKSOURCE_LSE:                         \\r
562           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
563           break;                                              \\r
564         default:                                              \\r
565           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
566           break;                                              \\r
567       }                                                       \\r
568     }                                                         \\r
569     else if((__HANDLE__)->Instance == UART4)                  \\r
570     {                                                         \\r
571       switch(__HAL_RCC_GET_UART4_SOURCE())                    \\r
572       {                                                       \\r
573         case RCC_UART4CLKSOURCE_PCLK1:                        \\r
574           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
575           break;                                              \\r
576         case RCC_UART4CLKSOURCE_HSI:                          \\r
577           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
578           break;                                              \\r
579         case RCC_UART4CLKSOURCE_SYSCLK:                       \\r
580           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
581           break;                                              \\r
582         case RCC_UART4CLKSOURCE_LSE:                          \\r
583           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
584           break;                                              \\r
585         default:                                              \\r
586           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
587           break;                                              \\r
588       }                                                       \\r
589     }                                                         \\r
590     else if((__HANDLE__)->Instance == LPUART1)                \\r
591     {                                                         \\r
592       switch(__HAL_RCC_GET_LPUART1_SOURCE())                  \\r
593       {                                                       \\r
594         case RCC_LPUART1CLKSOURCE_PCLK1:                      \\r
595           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1;         \\r
596           break;                                              \\r
597         case RCC_LPUART1CLKSOURCE_HSI:                        \\r
598           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI;           \\r
599           break;                                              \\r
600         case RCC_LPUART1CLKSOURCE_SYSCLK:                     \\r
601           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK;        \\r
602           break;                                              \\r
603         case RCC_LPUART1CLKSOURCE_LSE:                        \\r
604           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE;           \\r
605           break;                                              \\r
606         default:                                              \\r
607           (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;     \\r
608           break;                                              \\r
609       }                                                       \\r
610     }                                                         \\r
611     else                                                      \\r
612     {                                                         \\r
613       (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED;         \\r
614     }                                                         \\r
615   } while(0U)\r
616 #endif /* STM32L471xx ||  STM32L475xx ||  STM32L476xx ||  STM32L485xx ||  STM32L486xx ||\r
617         * STM32L496xx ||  STM32L4A6xx ||\r
618         * STM32L4R5xx ||  STM32L4R7xx ||  STM32L4R9xx ||  STM32L4S5xx ||  STM32L4S7xx ||  STM32L4S9xx\r
619         */\r
620 \r
621 /** @brief  Report the UART mask to apply to retrieve the received data\r
622   *         according to the word length and to the parity bits activation.\r
623   * @note   If PCE = 1, the parity bit is not included in the data extracted\r
624   *         by the reception API().\r
625   *         This masking operation is not carried out in the case of\r
626   *         DMA transfers.\r
627   * @param  __HANDLE__ specifies the UART Handle.\r
628   * @retval None, the mask to apply to UART RDR register is stored in (__HANDLE__)->Mask field.\r
629   */\r
630 #define UART_MASK_COMPUTATION(__HANDLE__)                             \\r
631   do {                                                                \\r
632     if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B)          \\r
633     {                                                                 \\r
634       if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE)              \\r
635       {                                                               \\r
636         (__HANDLE__)->Mask = 0x01FFU ;                                \\r
637       }                                                               \\r
638       else                                                            \\r
639       {                                                               \\r
640         (__HANDLE__)->Mask = 0x00FFU ;                                \\r
641       }                                                               \\r
642     }                                                                 \\r
643     else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B)     \\r
644     {                                                                 \\r
645       if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE)              \\r
646       {                                                               \\r
647         (__HANDLE__)->Mask = 0x00FFU ;                                \\r
648       }                                                               \\r
649       else                                                            \\r
650       {                                                               \\r
651         (__HANDLE__)->Mask = 0x007FU ;                                \\r
652       }                                                               \\r
653     }                                                                 \\r
654     else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_7B)     \\r
655     {                                                                 \\r
656       if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE)              \\r
657       {                                                               \\r
658         (__HANDLE__)->Mask = 0x007FU ;                                \\r
659       }                                                               \\r
660       else                                                            \\r
661       {                                                               \\r
662         (__HANDLE__)->Mask = 0x003FU ;                                \\r
663       }                                                               \\r
664     }                                                                 \\r
665     else                                                              \\r
666     {                                                                 \\r
667       (__HANDLE__)->Mask = 0x0000U;                                   \\r
668     }                                                                 \\r
669   } while(0U)\r
670 \r
671 /**\r
672   * @brief Ensure that UART frame length is valid.\r
673   * @param __LENGTH__ UART frame length.\r
674   * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)\r
675   */\r
676 #define IS_UART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == UART_WORDLENGTH_7B) || \\r
677                                          ((__LENGTH__) == UART_WORDLENGTH_8B) || \\r
678                                          ((__LENGTH__) == UART_WORDLENGTH_9B))\r
679 \r
680 /**\r
681   * @brief Ensure that UART wake-up address length is valid.\r
682   * @param __ADDRESS__ UART wake-up address length.\r
683   * @retval SET (__ADDRESS__ is valid) or RESET (__ADDRESS__ is invalid)\r
684   */\r
685 #define IS_UART_ADDRESSLENGTH_DETECT(__ADDRESS__) (((__ADDRESS__) == UART_ADDRESS_DETECT_4B) || \\r
686                                                    ((__ADDRESS__) == UART_ADDRESS_DETECT_7B))\r
687 \r
688 #if defined(USART_CR1_FIFOEN)\r
689 /**\r
690   * @brief Ensure that UART TXFIFO threshold level is valid.\r
691   * @param __THRESHOLD__ UART TXFIFO threshold level.\r
692   * @retval SET (__THRESHOLD__ is valid) or RESET (__THRESHOLD__ is invalid)\r
693   */\r
694 #define IS_UART_TXFIFO_THRESHOLD(__THRESHOLD__) (((__THRESHOLD__) == UART_TXFIFO_THRESHOLD_1_8) || \\r
695                                                  ((__THRESHOLD__) == UART_TXFIFO_THRESHOLD_1_4) || \\r
696                                                  ((__THRESHOLD__) == UART_TXFIFO_THRESHOLD_1_2) || \\r
697                                                  ((__THRESHOLD__) == UART_TXFIFO_THRESHOLD_3_4) || \\r
698                                                  ((__THRESHOLD__) == UART_TXFIFO_THRESHOLD_7_8) || \\r
699                                                  ((__THRESHOLD__) == UART_TXFIFO_THRESHOLD_8_8))\r
700 \r
701 /**\r
702   * @brief Ensure that UART RXFIFO threshold level is valid.\r
703   * @param __THRESHOLD__ UART RXFIFO threshold level.\r
704   * @retval SET (__THRESHOLD__ is valid) or RESET (__THRESHOLD__ is invalid)\r
705   */\r
706 #define IS_UART_RXFIFO_THRESHOLD(__THRESHOLD__) (((__THRESHOLD__) == UART_RXFIFO_THRESHOLD_1_8) || \\r
707                                                  ((__THRESHOLD__) == UART_RXFIFO_THRESHOLD_1_4) || \\r
708                                                  ((__THRESHOLD__) == UART_RXFIFO_THRESHOLD_1_2) || \\r
709                                                  ((__THRESHOLD__) == UART_RXFIFO_THRESHOLD_3_4) || \\r
710                                                  ((__THRESHOLD__) == UART_RXFIFO_THRESHOLD_7_8) || \\r
711                                                  ((__THRESHOLD__) == UART_RXFIFO_THRESHOLD_8_8))\r
712 #endif /* USART_CR1_FIFOEN */\r
713 \r
714 /**\r
715   * @}\r
716   */\r
717 \r
718 /* Private functions ---------------------------------------------------------*/\r
719 \r
720 /**\r
721   * @}\r
722   */\r
723 \r
724 /**\r
725   * @}\r
726   */\r
727 \r
728 #ifdef __cplusplus\r
729 }\r
730 #endif\r
731 \r
732 #endif /* STM32L4xx_HAL_UART_EX_H */\r
733 \r
734 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r