1 /**
2   ******************************************************************************
3   * @file    stm32l4xx_ll_usart.h
4   * @author  MCD Application Team
5   * @brief   Header file of USART LL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2017 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 STM32L4xx_LL_USART_H
21 #define STM32L4xx_LL_USART_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32l4xx.h"
29 
30 /** @addtogroup STM32L4xx_LL_Driver
31   * @{
32   */
33 
34 #if defined(USART1) || defined(USART2) || defined(USART3) || defined(UART4) || defined(UART5)
35 
36 /** @defgroup USART_LL USART
37   * @{
38   */
39 
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 #if defined(USART_PRESC_PRESCALER)
43 /** @defgroup USART_LL_Private_Variables USART Private Variables
44   * @{
45   */
46 /* Array used to get the USART prescaler division decimal values versus @ref USART_LL_EC_PRESCALER values */
47 static const uint32_t USART_PRESCALER_TAB[] =
48 {
49   1UL,
50   2UL,
51   4UL,
52   6UL,
53   8UL,
54   10UL,
55   12UL,
56   16UL,
57   32UL,
58   64UL,
59   128UL,
60   256UL
61 };
62 /**
63   * @}
64   */
65 #endif /* USART_PRESC_PRESCALER */
66 
67 /* Private constants ---------------------------------------------------------*/
68 /** @defgroup USART_LL_Private_Constants USART Private Constants
69   * @{
70   */
71 /**
72   * @}
73   */
74 /* Private macros ------------------------------------------------------------*/
75 #if defined(USE_FULL_LL_DRIVER)
76 /** @defgroup USART_LL_Private_Macros USART Private Macros
77   * @{
78   */
79 /**
80   * @}
81   */
82 #endif /*USE_FULL_LL_DRIVER*/
83 
84 /* Exported types ------------------------------------------------------------*/
85 #if defined(USE_FULL_LL_DRIVER)
86 /** @defgroup USART_LL_ES_INIT USART Exported Init structures
87   * @{
88   */
89 
90 /**
91   * @brief LL USART Init Structure definition
92   */
93 typedef struct
94 {
95 #if defined(USART_PRESC_PRESCALER)
96   uint32_t PrescalerValue;            /*!< Specifies the Prescaler to compute the communication baud rate.
97                                            This parameter can be a value of @ref USART_LL_EC_PRESCALER.
98 
99                                            This feature can be modified afterwards using unitary
100                                            function @ref LL_USART_SetPrescaler().*/
101 #endif /* USART_PRESC_PRESCALER */
102 
103   uint32_t BaudRate;                  /*!< This field defines expected Usart communication baud rate.
104 
105                                            This feature can be modified afterwards using unitary
106                                            function @ref LL_USART_SetBaudRate().*/
107 
108   uint32_t DataWidth;                 /*!< Specifies the number of data bits transmitted or received in a frame.
109                                            This parameter can be a value of @ref USART_LL_EC_DATAWIDTH.
110 
111                                            This feature can be modified afterwards using unitary
112                                            function @ref LL_USART_SetDataWidth().*/
113 
114   uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
115                                            This parameter can be a value of @ref USART_LL_EC_STOPBITS.
116 
117                                            This feature can be modified afterwards using unitary
118                                            function @ref LL_USART_SetStopBitsLength().*/
119 
120   uint32_t Parity;                    /*!< Specifies the parity mode.
121                                            This parameter can be a value of @ref USART_LL_EC_PARITY.
122 
123                                            This feature can be modified afterwards using unitary
124                                            function @ref LL_USART_SetParity().*/
125 
126   uint32_t TransferDirection;         /*!< Specifies whether the Receive and/or Transmit mode is enabled or disabled.
127                                            This parameter can be a value of @ref USART_LL_EC_DIRECTION.
128 
129                                            This feature can be modified afterwards using unitary
130                                            function @ref LL_USART_SetTransferDirection().*/
131 
132   uint32_t HardwareFlowControl;       /*!< Specifies whether the hardware flow control mode is enabled or disabled.
133                                            This parameter can be a value of @ref USART_LL_EC_HWCONTROL.
134 
135                                            This feature can be modified afterwards using unitary
136                                            function @ref LL_USART_SetHWFlowCtrl().*/
137 
138   uint32_t OverSampling;              /*!< Specifies whether USART oversampling mode is 16 or 8.
139                                            This parameter can be a value of @ref USART_LL_EC_OVERSAMPLING.
140 
141                                            This feature can be modified afterwards using unitary
142                                            function @ref LL_USART_SetOverSampling().*/
143 
144 } LL_USART_InitTypeDef;
145 
146 /**
147   * @brief LL USART Clock Init Structure definition
148   */
149 typedef struct
150 {
151   uint32_t ClockOutput;               /*!< Specifies whether the USART clock is enabled or disabled.
152                                            This parameter can be a value of @ref USART_LL_EC_CLOCK.
153 
154                                            USART HW configuration can be modified afterwards using unitary functions
155                                            @ref LL_USART_EnableSCLKOutput() or @ref LL_USART_DisableSCLKOutput().
156                                            For more details, refer to description of this function. */
157 
158   uint32_t ClockPolarity;             /*!< Specifies the steady state of the serial clock.
159                                            This parameter can be a value of @ref USART_LL_EC_POLARITY.
160 
161                                            USART HW configuration can be modified afterwards using unitary
162                                            functions @ref LL_USART_SetClockPolarity().
163                                            For more details, refer to description of this function. */
164 
165   uint32_t ClockPhase;                /*!< Specifies the clock transition on which the bit capture is made.
166                                            This parameter can be a value of @ref USART_LL_EC_PHASE.
167 
168                                            USART HW configuration can be modified afterwards using unitary
169                                            functions @ref LL_USART_SetClockPhase().
170                                            For more details, refer to description of this function. */
171 
172   uint32_t LastBitClockPulse;         /*!< Specifies whether the clock pulse corresponding to the last transmitted
173                                            data bit (MSB) has to be output on the SCLK pin in synchronous mode.
174                                            This parameter can be a value of @ref USART_LL_EC_LASTCLKPULSE.
175 
176                                            USART HW configuration can be modified afterwards using unitary
177                                            functions @ref LL_USART_SetLastClkPulseOutput().
178                                            For more details, refer to description of this function. */
179 
180 } LL_USART_ClockInitTypeDef;
181 
182 /**
183   * @}
184   */
185 #endif /* USE_FULL_LL_DRIVER */
186 
187 /* Exported constants --------------------------------------------------------*/
188 /** @defgroup USART_LL_Exported_Constants USART Exported Constants
189   * @{
190   */
191 
192 /** @defgroup USART_LL_EC_CLEAR_FLAG Clear Flags Defines
193   * @brief    Flags defines which can be used with LL_USART_WriteReg function
194   * @{
195   */
196 #define LL_USART_ICR_PECF                       USART_ICR_PECF                /*!< Parity error clear flag */
197 #define LL_USART_ICR_FECF                       USART_ICR_FECF                /*!< Framing error clear flag */
198 #define LL_USART_ICR_NECF                       USART_ICR_NECF                /*!< Noise error detected clear flag */
199 #define LL_USART_ICR_ORECF                      USART_ICR_ORECF               /*!< Overrun error clear flag */
200 #define LL_USART_ICR_IDLECF                     USART_ICR_IDLECF              /*!< Idle line detected clear flag */
201 #if defined(USART_CR1_FIFOEN)
202 #define LL_USART_ICR_TXFECF                     USART_ICR_TXFECF              /*!< TX FIFO Empty clear flag */
203 #endif /* USART_CR1_FIFOEN */
204 #define LL_USART_ICR_TCCF                       USART_ICR_TCCF                /*!< Transmission complete clear flag */
205 #if defined(USART_TCBGT_SUPPORT)
206 #define LL_USART_ICR_TCBGTCF                    USART_ICR_TCBGTCF             /*!< Transmission completed before guard time clear flag */
207 #endif /* USART_TCBGT_SUPPORT */
208 #define LL_USART_ICR_LBDCF                      USART_ICR_LBDCF               /*!< LIN break detection clear flag */
209 #define LL_USART_ICR_CTSCF                      USART_ICR_CTSCF               /*!< CTS clear flag */
210 #define LL_USART_ICR_RTOCF                      USART_ICR_RTOCF               /*!< Receiver timeout clear flag */
211 #define LL_USART_ICR_EOBCF                      USART_ICR_EOBCF               /*!< End of block clear flag */
212 #if defined(USART_CR2_SLVEN)
213 #define LL_USART_ICR_UDRCF                      USART_ICR_UDRCF               /*!< SPI Slave Underrun clear flag */
214 #endif /* USART_CR2_SLVEN */
215 #define LL_USART_ICR_CMCF                       USART_ICR_CMCF                /*!< Character match clear flag */
216 #define LL_USART_ICR_WUCF                       USART_ICR_WUCF                /*!< Wakeup from Stop mode clear flag */
217 /**
218   * @}
219   */
220 
221 /** @defgroup USART_LL_EC_GET_FLAG Get Flags Defines
222   * @brief    Flags defines which can be used with LL_USART_ReadReg function
223   * @{
224   */
225 #define LL_USART_ISR_PE                         USART_ISR_PE                  /*!< Parity error flag */
226 #define LL_USART_ISR_FE                         USART_ISR_FE                  /*!< Framing error flag */
227 #define LL_USART_ISR_NE                         USART_ISR_NE                  /*!< Noise detected flag */
228 #define LL_USART_ISR_ORE                        USART_ISR_ORE                 /*!< Overrun error flag */
229 #define LL_USART_ISR_IDLE                       USART_ISR_IDLE                /*!< Idle line detected flag */
230 #if defined(USART_CR1_FIFOEN)
231 #define LL_USART_ISR_RXNE_RXFNE                 USART_ISR_RXNE_RXFNE          /*!< Read data register or RX FIFO not empty flag */
232 #else
233 #define LL_USART_ISR_RXNE                       USART_ISR_RXNE                /*!< Read data register not empty flag */
234 #endif /* USART_CR1_FIFOEN */
235 #define LL_USART_ISR_TC                         USART_ISR_TC                  /*!< Transmission complete flag */
236 #if defined(USART_CR1_FIFOEN)
237 #define LL_USART_ISR_TXE_TXFNF                  USART_ISR_TXE_TXFNF           /*!< Transmit data register empty or TX FIFO Not Full flag*/
238 #else
239 #define LL_USART_ISR_TXE                        USART_ISR_TXE                 /*!< Transmit data register empty flag */
240 #endif /* USART_CR1_FIFOEN */
241 #define LL_USART_ISR_LBDF                       USART_ISR_LBDF                /*!< LIN break detection flag */
242 #define LL_USART_ISR_CTSIF                      USART_ISR_CTSIF               /*!< CTS interrupt flag */
243 #define LL_USART_ISR_CTS                        USART_ISR_CTS                 /*!< CTS flag */
244 #define LL_USART_ISR_RTOF                       USART_ISR_RTOF                /*!< Receiver timeout flag */
245 #define LL_USART_ISR_EOBF                       USART_ISR_EOBF                /*!< End of block flag */
246 #if defined(USART_CR2_SLVEN)
247 #define LL_USART_ISR_UDR                        USART_ISR_UDR                 /*!< SPI Slave underrun error flag */
248 #endif /* USART_CR2_SLVEN */
249 #define LL_USART_ISR_ABRE                       USART_ISR_ABRE                /*!< Auto baud rate error flag */
250 #define LL_USART_ISR_ABRF                       USART_ISR_ABRF                /*!< Auto baud rate flag */
251 #define LL_USART_ISR_BUSY                       USART_ISR_BUSY                /*!< Busy flag */
252 #define LL_USART_ISR_CMF                        USART_ISR_CMF                 /*!< Character match flag */
253 #define LL_USART_ISR_SBKF                       USART_ISR_SBKF                /*!< Send break flag */
254 #define LL_USART_ISR_RWU                        USART_ISR_RWU                 /*!< Receiver wakeup from Mute mode flag */
255 #define LL_USART_ISR_WUF                        USART_ISR_WUF                 /*!< Wakeup from Stop mode flag */
256 #define LL_USART_ISR_TEACK                      USART_ISR_TEACK               /*!< Transmit enable acknowledge flag */
257 #define LL_USART_ISR_REACK                      USART_ISR_REACK               /*!< Receive enable acknowledge flag */
258 #if defined(USART_CR1_FIFOEN)
259 #define LL_USART_ISR_TXFE                       USART_ISR_TXFE                /*!< TX FIFO empty flag */
260 #define LL_USART_ISR_RXFF                       USART_ISR_RXFF                /*!< RX FIFO full flag */
261 #endif /* USART_CR1_FIFOEN */
262 #if defined(USART_TCBGT_SUPPORT)
263 #define LL_USART_ISR_TCBGT                      USART_ISR_TCBGT               /*!< Transmission complete before guard time completion flag */
264 #endif /* USART_TCBGT_SUPPORT */
265 #if defined(USART_CR1_FIFOEN)
266 #define LL_USART_ISR_RXFT                       USART_ISR_RXFT                /*!< RX FIFO threshold flag */
267 #define LL_USART_ISR_TXFT                       USART_ISR_TXFT                /*!< TX FIFO threshold flag */
268 #endif /* USART_CR1_FIFOEN */
269 /**
270   * @}
271   */
272 
273 /** @defgroup USART_LL_EC_IT IT Defines
274   * @brief    IT defines which can be used with LL_USART_ReadReg and  LL_USART_WriteReg functions
275   * @{
276   */
277 #define LL_USART_CR1_IDLEIE                     USART_CR1_IDLEIE              /*!< IDLE interrupt enable */
278 #if defined(USART_CR1_FIFOEN)
279 #define LL_USART_CR1_RXNEIE_RXFNEIE             USART_CR1_RXNEIE_RXFNEIE      /*!< Read data register and RXFIFO not empty interrupt enable */
280 #else
281 #define LL_USART_CR1_RXNEIE                     USART_CR1_RXNEIE              /*!< Read data register not empty interrupt enable */
282 #endif /* USART_CR1_FIFOEN */
283 #define LL_USART_CR1_TCIE                       USART_CR1_TCIE                /*!< Transmission complete interrupt enable */
284 #if defined(USART_CR1_FIFOEN)
285 #define LL_USART_CR1_TXEIE_TXFNFIE              USART_CR1_TXEIE_TXFNFIE       /*!< Transmit data register empty and TX FIFO not full interrupt enable */
286 #else
287 #define LL_USART_CR1_TXEIE                      USART_CR1_TXEIE               /*!< Transmit data register empty interrupt enable */
288 #endif /* USART_CR1_FIFOEN */
289 #define LL_USART_CR1_PEIE                       USART_CR1_PEIE                /*!< Parity error */
290 #define LL_USART_CR1_CMIE                       USART_CR1_CMIE                /*!< Character match interrupt enable */
291 #define LL_USART_CR1_RTOIE                      USART_CR1_RTOIE               /*!< Receiver timeout interrupt enable */
292 #define LL_USART_CR1_EOBIE                      USART_CR1_EOBIE               /*!< End of Block interrupt enable */
293 #if defined(USART_CR1_FIFOEN)
294 #define LL_USART_CR1_TXFEIE                     USART_CR1_TXFEIE              /*!< TX FIFO empty interrupt enable */
295 #define LL_USART_CR1_RXFFIE                     USART_CR1_RXFFIE              /*!< RX FIFO full interrupt enable */
296 #endif /* USART_CR1_FIFOEN */
297 #define LL_USART_CR2_LBDIE                      USART_CR2_LBDIE               /*!< LIN break detection interrupt enable */
298 #define LL_USART_CR3_EIE                        USART_CR3_EIE                 /*!< Error interrupt enable */
299 #define LL_USART_CR3_CTSIE                      USART_CR3_CTSIE               /*!< CTS interrupt enable */
300 #define LL_USART_CR3_WUFIE                      USART_CR3_WUFIE               /*!< Wakeup from Stop mode interrupt enable */
301 #if defined(USART_CR1_FIFOEN)
302 #define LL_USART_CR3_TXFTIE                     USART_CR3_TXFTIE              /*!< TX FIFO threshold interrupt enable */
303 #endif /* USART_CR1_FIFOEN */
304 #if defined(USART_TCBGT_SUPPORT)
305 #define LL_USART_CR3_TCBGTIE                    USART_CR3_TCBGTIE             /*!< Transmission complete before guard time interrupt enable */
306 #endif /* USART_TCBGT_SUPPORT */
307 #if defined(USART_CR1_FIFOEN)
308 #define LL_USART_CR3_RXFTIE                     USART_CR3_RXFTIE              /*!< RX FIFO threshold interrupt enable */
309 #endif /* USART_CR1_FIFOEN */
310 /**
311   * @}
312   */
313 
314 #if defined(USART_CR1_FIFOEN)
315 /** @defgroup USART_LL_EC_FIFOTHRESHOLD FIFO Threshold
316   * @{
317   */
318 #define LL_USART_FIFOTHRESHOLD_1_8              0x00000000U /*!< FIFO reaches 1/8 of its depth */
319 #define LL_USART_FIFOTHRESHOLD_1_4              0x00000001U /*!< FIFO reaches 1/4 of its depth */
320 #define LL_USART_FIFOTHRESHOLD_1_2              0x00000002U /*!< FIFO reaches 1/2 of its depth */
321 #define LL_USART_FIFOTHRESHOLD_3_4              0x00000003U /*!< FIFO reaches 3/4 of its depth */
322 #define LL_USART_FIFOTHRESHOLD_7_8              0x00000004U /*!< FIFO reaches 7/8 of its depth */
323 #define LL_USART_FIFOTHRESHOLD_8_8              0x00000005U /*!< FIFO becomes empty for TX and full for RX */
324 /**
325   * @}
326   */
327 
328 #endif /* USART_CR1_FIFOEN */
329 /** @defgroup USART_LL_EC_DIRECTION Communication Direction
330   * @{
331   */
332 #define LL_USART_DIRECTION_NONE                 0x00000000U                        /*!< Transmitter and Receiver are disabled */
333 #define LL_USART_DIRECTION_RX                   USART_CR1_RE                       /*!< Transmitter is disabled and Receiver is enabled */
334 #define LL_USART_DIRECTION_TX                   USART_CR1_TE                       /*!< Transmitter is enabled and Receiver is disabled */
335 #define LL_USART_DIRECTION_TX_RX                (USART_CR1_TE |USART_CR1_RE)       /*!< Transmitter and Receiver are enabled */
336 /**
337   * @}
338   */
339 
340 /** @defgroup USART_LL_EC_PARITY Parity Control
341   * @{
342   */
343 #define LL_USART_PARITY_NONE                    0x00000000U                          /*!< Parity control disabled */
344 #define LL_USART_PARITY_EVEN                    USART_CR1_PCE                        /*!< Parity control enabled and Even Parity is selected */
345 #define LL_USART_PARITY_ODD                     (USART_CR1_PCE | USART_CR1_PS)       /*!< Parity control enabled and Odd Parity is selected */
346 /**
347   * @}
348   */
349 
350 /** @defgroup USART_LL_EC_WAKEUP Wakeup
351   * @{
352   */
353 #define LL_USART_WAKEUP_IDLELINE                0x00000000U           /*!<  USART wake up from Mute mode on Idle Line */
354 #define LL_USART_WAKEUP_ADDRESSMARK             USART_CR1_WAKE        /*!<  USART wake up from Mute mode on Address Mark */
355 /**
356   * @}
357   */
358 
359 /** @defgroup USART_LL_EC_DATAWIDTH Datawidth
360   * @{
361   */
362 #define LL_USART_DATAWIDTH_7B                   USART_CR1_M1            /*!< 7 bits word length : Start bit, 7 data bits, n stop bits */
363 #define LL_USART_DATAWIDTH_8B                   0x00000000U             /*!< 8 bits word length : Start bit, 8 data bits, n stop bits */
364 #define LL_USART_DATAWIDTH_9B                   USART_CR1_M0            /*!< 9 bits word length : Start bit, 9 data bits, n stop bits */
365 /**
366   * @}
367   */
368 
369 /** @defgroup USART_LL_EC_OVERSAMPLING Oversampling
370   * @{
371   */
372 #define LL_USART_OVERSAMPLING_16                0x00000000U            /*!< Oversampling by 16 */
373 #define LL_USART_OVERSAMPLING_8                 USART_CR1_OVER8        /*!< Oversampling by 8 */
374 /**
375   * @}
376   */
377 
378 #if defined(USE_FULL_LL_DRIVER)
379 /** @defgroup USART_LL_EC_CLOCK Clock Signal
380   * @{
381   */
382 
383 #define LL_USART_CLOCK_DISABLE                  0x00000000U            /*!< Clock signal not provided */
384 #define LL_USART_CLOCK_ENABLE                   USART_CR2_CLKEN        /*!< Clock signal provided */
385 /**
386   * @}
387   */
388 #endif /*USE_FULL_LL_DRIVER*/
389 
390 /** @defgroup USART_LL_EC_LASTCLKPULSE Last Clock Pulse
391   * @{
392   */
393 #define LL_USART_LASTCLKPULSE_NO_OUTPUT         0x00000000U           /*!< The clock pulse of the last data bit is not output to the SCLK pin */
394 #define LL_USART_LASTCLKPULSE_OUTPUT            USART_CR2_LBCL        /*!< The clock pulse of the last data bit is output to the SCLK pin */
395 /**
396   * @}
397   */
398 
399 /** @defgroup USART_LL_EC_PHASE Clock Phase
400   * @{
401   */
402 #define LL_USART_PHASE_1EDGE                    0x00000000U           /*!< The first clock transition is the first data capture edge */
403 #define LL_USART_PHASE_2EDGE                    USART_CR2_CPHA        /*!< The second clock transition is the first data capture edge */
404 /**
405   * @}
406   */
407 
408 /** @defgroup USART_LL_EC_POLARITY Clock Polarity
409   * @{
410   */
411 #define LL_USART_POLARITY_LOW                   0x00000000U           /*!< Steady low value on SCLK pin outside transmission window*/
412 #define LL_USART_POLARITY_HIGH                  USART_CR2_CPOL        /*!< Steady high value on SCLK pin outside transmission window */
413 /**
414   * @}
415   */
416 
417 #if defined(USART_PRESC_PRESCALER)
418 /** @defgroup USART_LL_EC_PRESCALER Clock Source Prescaler
419   * @{
420   */
421 #define LL_USART_PRESCALER_DIV1                 0x00000000U                                                                   /*!< Input clock not divided   */
422 #define LL_USART_PRESCALER_DIV2                 (USART_PRESC_PRESCALER_0)                                                     /*!< Input clock divided by 2  */
423 #define LL_USART_PRESCALER_DIV4                 (USART_PRESC_PRESCALER_1)                                                     /*!< Input clock divided by 4  */
424 #define LL_USART_PRESCALER_DIV6                 (USART_PRESC_PRESCALER_1 | USART_PRESC_PRESCALER_0)                           /*!< Input clock divided by 6  */
425 #define LL_USART_PRESCALER_DIV8                 (USART_PRESC_PRESCALER_2)                                                     /*!< Input clock divided by 8  */
426 #define LL_USART_PRESCALER_DIV10                (USART_PRESC_PRESCALER_2 | USART_PRESC_PRESCALER_0)                           /*!< Input clock divided by 10 */
427 #define LL_USART_PRESCALER_DIV12                (USART_PRESC_PRESCALER_2 | USART_PRESC_PRESCALER_1)                           /*!< Input clock divided by 12 */
428 #define LL_USART_PRESCALER_DIV16                (USART_PRESC_PRESCALER_2 | USART_PRESC_PRESCALER_1 | USART_PRESC_PRESCALER_0) /*!< Input clock divided by 16 */
429 #define LL_USART_PRESCALER_DIV32                (USART_PRESC_PRESCALER_3)                                                     /*!< Input clock divided by 32 */
430 #define LL_USART_PRESCALER_DIV64                (USART_PRESC_PRESCALER_3 | USART_PRESC_PRESCALER_0)                           /*!< Input clock divided by 64 */
431 #define LL_USART_PRESCALER_DIV128               (USART_PRESC_PRESCALER_3 | USART_PRESC_PRESCALER_1)                           /*!< Input clock divided by 128 */
432 #define LL_USART_PRESCALER_DIV256               (USART_PRESC_PRESCALER_3 | USART_PRESC_PRESCALER_1 | USART_PRESC_PRESCALER_0) /*!< Input clock divided by 256 */
433 /**
434   * @}
435   */
436 
437 #endif /* USART_PRESC_PRESCALER */
438 /** @defgroup USART_LL_EC_STOPBITS Stop Bits
439   * @{
440   */
441 #define LL_USART_STOPBITS_0_5                   USART_CR2_STOP_0                           /*!< 0.5 stop bit */
442 #define LL_USART_STOPBITS_1                     0x00000000U                                /*!< 1 stop bit */
443 #define LL_USART_STOPBITS_1_5                   (USART_CR2_STOP_0 | USART_CR2_STOP_1)      /*!< 1.5 stop bits */
444 #define LL_USART_STOPBITS_2                     USART_CR2_STOP_1                           /*!< 2 stop bits */
445 /**
446   * @}
447   */
448 
449 /** @defgroup USART_LL_EC_TXRX TX RX Pins Swap
450   * @{
451   */
452 #define LL_USART_TXRX_STANDARD                  0x00000000U           /*!< TX/RX pins are used as defined in standard pinout */
453 #define LL_USART_TXRX_SWAPPED                   (USART_CR2_SWAP)      /*!< TX and RX pins functions are swapped.             */
454 /**
455   * @}
456   */
457 
458 /** @defgroup USART_LL_EC_RXPIN_LEVEL RX Pin Active Level Inversion
459   * @{
460   */
461 #define LL_USART_RXPIN_LEVEL_STANDARD           0x00000000U           /*!< RX pin signal works using the standard logic levels */
462 #define LL_USART_RXPIN_LEVEL_INVERTED           (USART_CR2_RXINV)     /*!< RX pin signal values are inverted.                  */
463 /**
464   * @}
465   */
466 
467 /** @defgroup USART_LL_EC_TXPIN_LEVEL TX Pin Active Level Inversion
468   * @{
469   */
470 #define LL_USART_TXPIN_LEVEL_STANDARD           0x00000000U           /*!< TX pin signal works using the standard logic levels */
471 #define LL_USART_TXPIN_LEVEL_INVERTED           (USART_CR2_TXINV)     /*!< TX pin signal values are inverted.                  */
472 /**
473   * @}
474   */
475 
476 /** @defgroup USART_LL_EC_BINARY_LOGIC Binary Data Inversion
477   * @{
478   */
479 #define LL_USART_BINARY_LOGIC_POSITIVE          0x00000000U           /*!< Logical data from the data register are send/received in positive/direct logic. (1=H, 0=L) */
480 #define LL_USART_BINARY_LOGIC_NEGATIVE          USART_CR2_DATAINV     /*!< Logical data from the data register are send/received in negative/inverse logic. (1=L, 0=H). The parity bit is also inverted. */
481 /**
482   * @}
483   */
484 
485 /** @defgroup USART_LL_EC_BITORDER Bit Order
486   * @{
487   */
488 #define LL_USART_BITORDER_LSBFIRST              0x00000000U           /*!< data is transmitted/received with data bit 0 first, following the start bit */
489 #define LL_USART_BITORDER_MSBFIRST              USART_CR2_MSBFIRST    /*!< data is transmitted/received with the MSB first, following the start bit */
490 /**
491   * @}
492   */
493 
494 /** @defgroup USART_LL_EC_AUTOBAUD_DETECT_ON Autobaud Detection
495   * @{
496   */
497 #define LL_USART_AUTOBAUD_DETECT_ON_STARTBIT    0x00000000U                                 /*!< Measurement of the start bit is used to detect the baud rate */
498 #define LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE USART_CR2_ABRMODE_0                         /*!< Falling edge to falling edge measurement. Received frame must start with a single bit = 1 -> Frame = Start10xxxxxx */
499 #define LL_USART_AUTOBAUD_DETECT_ON_7F_FRAME    USART_CR2_ABRMODE_1                         /*!< 0x7F frame detection */
500 #define LL_USART_AUTOBAUD_DETECT_ON_55_FRAME    (USART_CR2_ABRMODE_1 | USART_CR2_ABRMODE_0) /*!< 0x55 frame detection */
501 /**
502   * @}
503   */
504 
505 /** @defgroup USART_LL_EC_ADDRESS_DETECT Address Length Detection
506   * @{
507   */
508 #define LL_USART_ADDRESS_DETECT_4B              0x00000000U           /*!< 4-bit address detection method selected */
509 #define LL_USART_ADDRESS_DETECT_7B              USART_CR2_ADDM7       /*!< 7-bit address detection (in 8-bit data mode) method selected */
510 /**
511   * @}
512   */
513 
514 /** @defgroup USART_LL_EC_HWCONTROL Hardware Control
515   * @{
516   */
517 #define LL_USART_HWCONTROL_NONE                 0x00000000U                          /*!< CTS and RTS hardware flow control disabled */
518 #define LL_USART_HWCONTROL_RTS                  USART_CR3_RTSE                       /*!< RTS output enabled, data is only requested when there is space in the receive buffer */
519 #define LL_USART_HWCONTROL_CTS                  USART_CR3_CTSE                       /*!< CTS mode enabled, data is only transmitted when the nCTS input is asserted (tied to 0) */
520 #define LL_USART_HWCONTROL_RTS_CTS              (USART_CR3_RTSE | USART_CR3_CTSE)    /*!< CTS and RTS hardware flow control enabled */
521 /**
522   * @}
523   */
524 
525 /** @defgroup USART_LL_EC_WAKEUP_ON Wakeup Activation
526   * @{
527   */
528 #define LL_USART_WAKEUP_ON_ADDRESS              0x00000000U                             /*!< Wake up active on address match */
529 #define LL_USART_WAKEUP_ON_STARTBIT             USART_CR3_WUS_1                         /*!< Wake up active on Start bit detection */
530 #define LL_USART_WAKEUP_ON_RXNE                 (USART_CR3_WUS_0 | USART_CR3_WUS_1)     /*!< Wake up active on RXNE */
531 /**
532   * @}
533   */
534 
535 /** @defgroup USART_LL_EC_IRDA_POWER IrDA Power
536   * @{
537   */
538 #define LL_USART_IRDA_POWER_NORMAL              0x00000000U           /*!< IrDA normal power mode */
539 #define LL_USART_IRDA_POWER_LOW                 USART_CR3_IRLP        /*!< IrDA low power mode */
540 /**
541   * @}
542   */
543 
544 /** @defgroup USART_LL_EC_LINBREAK_DETECT LIN Break Detection Length
545   * @{
546   */
547 #define LL_USART_LINBREAK_DETECT_10B            0x00000000U           /*!< 10-bit break detection method selected */
548 #define LL_USART_LINBREAK_DETECT_11B            USART_CR2_LBDL        /*!< 11-bit break detection method selected */
549 /**
550   * @}
551   */
552 
553 /** @defgroup USART_LL_EC_DE_POLARITY Driver Enable Polarity
554   * @{
555   */
556 #define LL_USART_DE_POLARITY_HIGH               0x00000000U           /*!< DE signal is active high */
557 #define LL_USART_DE_POLARITY_LOW                USART_CR3_DEP         /*!< DE signal is active low */
558 /**
559   * @}
560   */
561 
562 /** @defgroup USART_LL_EC_DMA_REG_DATA DMA Register Data
563   * @{
564   */
565 #define LL_USART_DMA_REG_DATA_TRANSMIT          0x00000000U          /*!< Get address of data register used for transmission */
566 #define LL_USART_DMA_REG_DATA_RECEIVE           0x00000001U          /*!< Get address of data register used for reception */
567 /**
568   * @}
569   */
570 
571 /**
572   * @}
573   */
574 
575 /* Exported macro ------------------------------------------------------------*/
576 /** @defgroup USART_LL_Exported_Macros USART Exported Macros
577   * @{
578   */
579 
580 /** @defgroup USART_LL_EM_WRITE_READ Common Write and read registers Macros
581   * @{
582   */
583 
584 /**
585   * @brief  Write a value in USART register
586   * @param  __INSTANCE__ USART Instance
587   * @param  __REG__ Register to be written
588   * @param  __VALUE__ Value to be written in the register
589   * @retval None
590   */
591 #define LL_USART_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
592 
593 /**
594   * @brief  Read a value in USART register
595   * @param  __INSTANCE__ USART Instance
596   * @param  __REG__ Register to be read
597   * @retval Register value
598   */
599 #define LL_USART_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
600 /**
601   * @}
602   */
603 
604 /** @defgroup USART_LL_EM_Exported_Macros_Helper Exported_Macros_Helper
605   * @{
606   */
607 
608 /**
609   * @brief  Compute USARTDIV value according to Peripheral Clock and
610   *         expected Baud Rate in 8 bits sampling mode (32 bits value of USARTDIV is returned)
611   * @param  __PERIPHCLK__ Peripheral Clock frequency used for USART instance
612   @if USART_PRESC_PRESCALER
613   * @param  __PRESCALER__ This parameter can be one of the following values:
614   *         @arg @ref LL_USART_PRESCALER_DIV1
615   *         @arg @ref LL_USART_PRESCALER_DIV2
616   *         @arg @ref LL_USART_PRESCALER_DIV4
617   *         @arg @ref LL_USART_PRESCALER_DIV6
618   *         @arg @ref LL_USART_PRESCALER_DIV8
619   *         @arg @ref LL_USART_PRESCALER_DIV10
620   *         @arg @ref LL_USART_PRESCALER_DIV12
621   *         @arg @ref LL_USART_PRESCALER_DIV16
622   *         @arg @ref LL_USART_PRESCALER_DIV32
623   *         @arg @ref LL_USART_PRESCALER_DIV64
624   *         @arg @ref LL_USART_PRESCALER_DIV128
625   *         @arg @ref LL_USART_PRESCALER_DIV256
626   @endif
627   * @param  __BAUDRATE__ Baud rate value to achieve
628   * @retval USARTDIV value to be used for BRR register filling in OverSampling_8 case
629   */
630 #if defined(USART_PRESC_PRESCALER)
631 #define __LL_USART_DIV_SAMPLING8(__PERIPHCLK__, __PRESCALER__, __BAUDRATE__) \
632   (((((__PERIPHCLK__)/(USART_PRESCALER_TAB[(__PRESCALER__)]))*2U)\
633     + ((__BAUDRATE__)/2U))/(__BAUDRATE__))
634 #else
635 #define __LL_USART_DIV_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) ((((__PERIPHCLK__)*2U)\
636                                                                 + ((__BAUDRATE__)/2U))/(__BAUDRATE__))
637 #endif /* USART_PRESC_PRESCALER */
638 
639 /**
640   * @brief  Compute USARTDIV value according to Peripheral Clock and
641   *         expected Baud Rate in 16 bits sampling mode (32 bits value of USARTDIV is returned)
642   * @param  __PERIPHCLK__ Peripheral Clock frequency used for USART instance
643   @if USART_PRESC_PRESCALER
644   * @param  __PRESCALER__ This parameter can be one of the following values:
645   *         @arg @ref LL_USART_PRESCALER_DIV1
646   *         @arg @ref LL_USART_PRESCALER_DIV2
647   *         @arg @ref LL_USART_PRESCALER_DIV4
648   *         @arg @ref LL_USART_PRESCALER_DIV6
649   *         @arg @ref LL_USART_PRESCALER_DIV8
650   *         @arg @ref LL_USART_PRESCALER_DIV10
651   *         @arg @ref LL_USART_PRESCALER_DIV12
652   *         @arg @ref LL_USART_PRESCALER_DIV16
653   *         @arg @ref LL_USART_PRESCALER_DIV32
654   *         @arg @ref LL_USART_PRESCALER_DIV64
655   *         @arg @ref LL_USART_PRESCALER_DIV128
656   *         @arg @ref LL_USART_PRESCALER_DIV256
657   @endif
658   * @param  __BAUDRATE__ Baud rate value to achieve
659   * @retval USARTDIV value to be used for BRR register filling in OverSampling_16 case
660   */
661 #if defined(USART_PRESC_PRESCALER)
662 #define __LL_USART_DIV_SAMPLING16(__PERIPHCLK__, __PRESCALER__, __BAUDRATE__) \
663   ((((__PERIPHCLK__)/(USART_PRESCALER_TAB[(__PRESCALER__)]))\
664     + ((__BAUDRATE__)/2U))/(__BAUDRATE__))
665 #else
666 #define __LL_USART_DIV_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (((__PERIPHCLK__) + ((__BAUDRATE__)/2U))/(__BAUDRATE__))
667 #endif /* USART_PRESC_PRESCALER */
668 
669 /**
670   * @}
671   */
672 
673 /**
674   * @}
675   */
676 
677 /* Exported functions --------------------------------------------------------*/
678 
679 /** @defgroup USART_LL_Exported_Functions USART Exported Functions
680   * @{
681   */
682 
683 /** @defgroup USART_LL_EF_Configuration Configuration functions
684   * @{
685   */
686 
687 /**
688   * @brief  USART Enable
689   * @rmtoll CR1          UE            LL_USART_Enable
690   * @param  USARTx USART Instance
691   * @retval None
692   */
LL_USART_Enable(USART_TypeDef * USARTx)693 __STATIC_INLINE void LL_USART_Enable(USART_TypeDef *USARTx)
694 {
695   SET_BIT(USARTx->CR1, USART_CR1_UE);
696 }
697 
698 /**
699   * @brief  USART Disable (all USART prescalers and outputs are disabled)
700   * @note   When USART is disabled, USART prescalers and outputs are stopped immediately,
701   *         and current operations are discarded. The configuration of the USART is kept, but all the status
702   *         flags, in the USARTx_ISR are set to their default values.
703   * @rmtoll CR1          UE            LL_USART_Disable
704   * @param  USARTx USART Instance
705   * @retval None
706   */
LL_USART_Disable(USART_TypeDef * USARTx)707 __STATIC_INLINE void LL_USART_Disable(USART_TypeDef *USARTx)
708 {
709   CLEAR_BIT(USARTx->CR1, USART_CR1_UE);
710 }
711 
712 /**
713   * @brief  Indicate if USART is enabled
714   * @rmtoll CR1          UE            LL_USART_IsEnabled
715   * @param  USARTx USART Instance
716   * @retval State of bit (1 or 0).
717   */
LL_USART_IsEnabled(const USART_TypeDef * USARTx)718 __STATIC_INLINE uint32_t LL_USART_IsEnabled(const USART_TypeDef *USARTx)
719 {
720   return ((READ_BIT(USARTx->CR1, USART_CR1_UE) == (USART_CR1_UE)) ? 1UL : 0UL);
721 }
722 
723 #if defined(USART_CR1_FIFOEN)
724 /**
725   * @brief  FIFO Mode Enable
726   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
727   *         FIFO mode feature is supported by the USARTx instance.
728   * @rmtoll CR1          FIFOEN        LL_USART_EnableFIFO
729   * @param  USARTx USART Instance
730   * @retval None
731   */
LL_USART_EnableFIFO(USART_TypeDef * USARTx)732 __STATIC_INLINE void LL_USART_EnableFIFO(USART_TypeDef *USARTx)
733 {
734   SET_BIT(USARTx->CR1, USART_CR1_FIFOEN);
735 }
736 
737 /**
738   * @brief  FIFO Mode Disable
739   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
740   *         FIFO mode feature is supported by the USARTx instance.
741   * @rmtoll CR1          FIFOEN        LL_USART_DisableFIFO
742   * @param  USARTx USART Instance
743   * @retval None
744   */
LL_USART_DisableFIFO(USART_TypeDef * USARTx)745 __STATIC_INLINE void LL_USART_DisableFIFO(USART_TypeDef *USARTx)
746 {
747   CLEAR_BIT(USARTx->CR1, USART_CR1_FIFOEN);
748 }
749 
750 /**
751   * @brief  Indicate if FIFO Mode is enabled
752   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
753   *         FIFO mode feature is supported by the USARTx instance.
754   * @rmtoll CR1          FIFOEN        LL_USART_IsEnabledFIFO
755   * @param  USARTx USART Instance
756   * @retval State of bit (1 or 0).
757   */
LL_USART_IsEnabledFIFO(const USART_TypeDef * USARTx)758 __STATIC_INLINE uint32_t LL_USART_IsEnabledFIFO(const USART_TypeDef *USARTx)
759 {
760   return ((READ_BIT(USARTx->CR1, USART_CR1_FIFOEN) == (USART_CR1_FIFOEN)) ? 1UL : 0UL);
761 }
762 
763 /**
764   * @brief  Configure TX FIFO Threshold
765   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
766   *         FIFO mode feature is supported by the USARTx instance.
767   * @rmtoll CR3          TXFTCFG       LL_USART_SetTXFIFOThreshold
768   * @param  USARTx USART Instance
769   * @param  Threshold This parameter can be one of the following values:
770   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_8
771   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_4
772   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_2
773   *         @arg @ref LL_USART_FIFOTHRESHOLD_3_4
774   *         @arg @ref LL_USART_FIFOTHRESHOLD_7_8
775   *         @arg @ref LL_USART_FIFOTHRESHOLD_8_8
776   * @retval None
777   */
LL_USART_SetTXFIFOThreshold(USART_TypeDef * USARTx,uint32_t Threshold)778 __STATIC_INLINE void LL_USART_SetTXFIFOThreshold(USART_TypeDef *USARTx, uint32_t Threshold)
779 {
780   ATOMIC_MODIFY_REG(USARTx->CR3, USART_CR3_TXFTCFG, Threshold << USART_CR3_TXFTCFG_Pos);
781 }
782 
783 /**
784   * @brief  Return TX FIFO Threshold Configuration
785   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
786   *         FIFO mode feature is supported by the USARTx instance.
787   * @rmtoll CR3          TXFTCFG       LL_USART_GetTXFIFOThreshold
788   * @param  USARTx USART Instance
789   * @retval Returned value can be one of the following values:
790   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_8
791   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_4
792   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_2
793   *         @arg @ref LL_USART_FIFOTHRESHOLD_3_4
794   *         @arg @ref LL_USART_FIFOTHRESHOLD_7_8
795   *         @arg @ref LL_USART_FIFOTHRESHOLD_8_8
796   */
LL_USART_GetTXFIFOThreshold(const USART_TypeDef * USARTx)797 __STATIC_INLINE uint32_t LL_USART_GetTXFIFOThreshold(const USART_TypeDef *USARTx)
798 {
799   return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_TXFTCFG) >> USART_CR3_TXFTCFG_Pos);
800 }
801 
802 /**
803   * @brief  Configure RX FIFO Threshold
804   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
805   *         FIFO mode feature is supported by the USARTx instance.
806   * @rmtoll CR3          RXFTCFG       LL_USART_SetRXFIFOThreshold
807   * @param  USARTx USART Instance
808   * @param  Threshold This parameter can be one of the following values:
809   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_8
810   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_4
811   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_2
812   *         @arg @ref LL_USART_FIFOTHRESHOLD_3_4
813   *         @arg @ref LL_USART_FIFOTHRESHOLD_7_8
814   *         @arg @ref LL_USART_FIFOTHRESHOLD_8_8
815   * @retval None
816   */
LL_USART_SetRXFIFOThreshold(USART_TypeDef * USARTx,uint32_t Threshold)817 __STATIC_INLINE void LL_USART_SetRXFIFOThreshold(USART_TypeDef *USARTx, uint32_t Threshold)
818 {
819   ATOMIC_MODIFY_REG(USARTx->CR3, USART_CR3_RXFTCFG, Threshold << USART_CR3_RXFTCFG_Pos);
820 }
821 
822 /**
823   * @brief  Return RX FIFO Threshold Configuration
824   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
825   *         FIFO mode feature is supported by the USARTx instance.
826   * @rmtoll CR3          RXFTCFG       LL_USART_GetRXFIFOThreshold
827   * @param  USARTx USART Instance
828   * @retval Returned value can be one of the following values:
829   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_8
830   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_4
831   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_2
832   *         @arg @ref LL_USART_FIFOTHRESHOLD_3_4
833   *         @arg @ref LL_USART_FIFOTHRESHOLD_7_8
834   *         @arg @ref LL_USART_FIFOTHRESHOLD_8_8
835   */
LL_USART_GetRXFIFOThreshold(const USART_TypeDef * USARTx)836 __STATIC_INLINE uint32_t LL_USART_GetRXFIFOThreshold(const USART_TypeDef *USARTx)
837 {
838   return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_RXFTCFG) >> USART_CR3_RXFTCFG_Pos);
839 }
840 
841 /**
842   * @brief  Configure TX and RX FIFOs Threshold
843   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
844   *         FIFO mode feature is supported by the USARTx instance.
845   * @rmtoll CR3          TXFTCFG       LL_USART_ConfigFIFOsThreshold\n
846   *         CR3          RXFTCFG       LL_USART_ConfigFIFOsThreshold
847   * @param  USARTx USART Instance
848   * @param  TXThreshold This parameter can be one of the following values:
849   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_8
850   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_4
851   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_2
852   *         @arg @ref LL_USART_FIFOTHRESHOLD_3_4
853   *         @arg @ref LL_USART_FIFOTHRESHOLD_7_8
854   *         @arg @ref LL_USART_FIFOTHRESHOLD_8_8
855   * @param  RXThreshold This parameter can be one of the following values:
856   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_8
857   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_4
858   *         @arg @ref LL_USART_FIFOTHRESHOLD_1_2
859   *         @arg @ref LL_USART_FIFOTHRESHOLD_3_4
860   *         @arg @ref LL_USART_FIFOTHRESHOLD_7_8
861   *         @arg @ref LL_USART_FIFOTHRESHOLD_8_8
862   * @retval None
863   */
LL_USART_ConfigFIFOsThreshold(USART_TypeDef * USARTx,uint32_t TXThreshold,uint32_t RXThreshold)864 __STATIC_INLINE void LL_USART_ConfigFIFOsThreshold(USART_TypeDef *USARTx, uint32_t TXThreshold, uint32_t RXThreshold)
865 {
866   ATOMIC_MODIFY_REG(USARTx->CR3, USART_CR3_TXFTCFG | USART_CR3_RXFTCFG, (TXThreshold << USART_CR3_TXFTCFG_Pos) |
867                     (RXThreshold << USART_CR3_RXFTCFG_Pos));
868 }
869 
870 #endif /* USART_CR1_FIFOEN */
871 /**
872   * @brief  USART enabled in STOP Mode.
873   * @note   When this function is enabled, USART is able to wake up the MCU from Stop mode, provided that
874   *         USART clock selection is HSI or LSE in RCC.
875   * @note   Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
876   *         Wake-up from Stop mode feature is supported by the USARTx instance.
877   * @rmtoll CR1          UESM          LL_USART_EnableInStopMode
878   * @param  USARTx USART Instance
879   * @retval None
880   */
LL_USART_EnableInStopMode(USART_TypeDef * USARTx)881 __STATIC_INLINE void LL_USART_EnableInStopMode(USART_TypeDef *USARTx)
882 {
883   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_UESM);
884 }
885 
886 /**
887   * @brief  USART disabled in STOP Mode.
888   * @note   When this function is disabled, USART is not able to wake up the MCU from Stop mode
889   * @note   Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
890   *         Wake-up from Stop mode feature is supported by the USARTx instance.
891   * @rmtoll CR1          UESM          LL_USART_DisableInStopMode
892   * @param  USARTx USART Instance
893   * @retval None
894   */
LL_USART_DisableInStopMode(USART_TypeDef * USARTx)895 __STATIC_INLINE void LL_USART_DisableInStopMode(USART_TypeDef *USARTx)
896 {
897   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_UESM);
898 }
899 
900 /**
901   * @brief  Indicate if USART is enabled in STOP Mode (able to wake up MCU from Stop mode or not)
902   * @note   Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
903   *         Wake-up from Stop mode feature is supported by the USARTx instance.
904   * @rmtoll CR1          UESM          LL_USART_IsEnabledInStopMode
905   * @param  USARTx USART Instance
906   * @retval State of bit (1 or 0).
907   */
LL_USART_IsEnabledInStopMode(const USART_TypeDef * USARTx)908 __STATIC_INLINE uint32_t LL_USART_IsEnabledInStopMode(const USART_TypeDef *USARTx)
909 {
910   return ((READ_BIT(USARTx->CR1, USART_CR1_UESM) == (USART_CR1_UESM)) ? 1UL : 0UL);
911 }
912 
913 #if defined(USART_CR3_UCESM)
914 /**
915   * @brief  USART Clock enabled in STOP Mode
916   * @note   When this function is called, USART Clock is enabled while in STOP mode
917   * @rmtoll CR3          UCESM         LL_USART_EnableClockInStopMode
918   * @param  USARTx USART Instance
919   * @retval None
920   */
LL_USART_EnableClockInStopMode(USART_TypeDef * USARTx)921 __STATIC_INLINE void LL_USART_EnableClockInStopMode(USART_TypeDef *USARTx)
922 {
923   ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_UCESM);
924 }
925 
926 /**
927   * @brief  USART clock disabled in STOP Mode
928   * @note   When this function is called, USART Clock is disabled while in STOP mode
929   * @rmtoll CR3          UCESM         LL_USART_DisableClockInStopMode
930   * @param  USARTx USART Instance
931   * @retval None
932   */
LL_USART_DisableClockInStopMode(USART_TypeDef * USARTx)933 __STATIC_INLINE void LL_USART_DisableClockInStopMode(USART_TypeDef *USARTx)
934 {
935   ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_UCESM);
936 }
937 
938 /**
939   * @brief  Indicate if USART clock is enabled in STOP Mode
940   * @rmtoll CR3          UCESM         LL_USART_IsClockEnabledInStopMode
941   * @param  USARTx USART Instance
942   * @retval State of bit (1 or 0).
943   */
LL_USART_IsClockEnabledInStopMode(const USART_TypeDef * USARTx)944 __STATIC_INLINE uint32_t LL_USART_IsClockEnabledInStopMode(const USART_TypeDef *USARTx)
945 {
946   return (READ_BIT(USARTx->CR3, USART_CR3_UCESM) == (USART_CR3_UCESM));
947 }
948 
949 #endif /* USART_CR3_UCESM */
950 /**
951   * @brief  Receiver Enable (Receiver is enabled and begins searching for a start bit)
952   * @rmtoll CR1          RE            LL_USART_EnableDirectionRx
953   * @param  USARTx USART Instance
954   * @retval None
955   */
LL_USART_EnableDirectionRx(USART_TypeDef * USARTx)956 __STATIC_INLINE void LL_USART_EnableDirectionRx(USART_TypeDef *USARTx)
957 {
958   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_RE);
959 }
960 
961 /**
962   * @brief  Receiver Disable
963   * @rmtoll CR1          RE            LL_USART_DisableDirectionRx
964   * @param  USARTx USART Instance
965   * @retval None
966   */
LL_USART_DisableDirectionRx(USART_TypeDef * USARTx)967 __STATIC_INLINE void LL_USART_DisableDirectionRx(USART_TypeDef *USARTx)
968 {
969   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_RE);
970 }
971 
972 /**
973   * @brief  Transmitter Enable
974   * @rmtoll CR1          TE            LL_USART_EnableDirectionTx
975   * @param  USARTx USART Instance
976   * @retval None
977   */
LL_USART_EnableDirectionTx(USART_TypeDef * USARTx)978 __STATIC_INLINE void LL_USART_EnableDirectionTx(USART_TypeDef *USARTx)
979 {
980   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TE);
981 }
982 
983 /**
984   * @brief  Transmitter Disable
985   * @rmtoll CR1          TE            LL_USART_DisableDirectionTx
986   * @param  USARTx USART Instance
987   * @retval None
988   */
LL_USART_DisableDirectionTx(USART_TypeDef * USARTx)989 __STATIC_INLINE void LL_USART_DisableDirectionTx(USART_TypeDef *USARTx)
990 {
991   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TE);
992 }
993 
994 /**
995   * @brief  Configure simultaneously enabled/disabled states
996   *         of Transmitter and Receiver
997   * @rmtoll CR1          RE            LL_USART_SetTransferDirection\n
998   *         CR1          TE            LL_USART_SetTransferDirection
999   * @param  USARTx USART Instance
1000   * @param  TransferDirection This parameter can be one of the following values:
1001   *         @arg @ref LL_USART_DIRECTION_NONE
1002   *         @arg @ref LL_USART_DIRECTION_RX
1003   *         @arg @ref LL_USART_DIRECTION_TX
1004   *         @arg @ref LL_USART_DIRECTION_TX_RX
1005   * @retval None
1006   */
LL_USART_SetTransferDirection(USART_TypeDef * USARTx,uint32_t TransferDirection)1007 __STATIC_INLINE void LL_USART_SetTransferDirection(USART_TypeDef *USARTx, uint32_t TransferDirection)
1008 {
1009   ATOMIC_MODIFY_REG(USARTx->CR1, USART_CR1_RE | USART_CR1_TE, TransferDirection);
1010 }
1011 
1012 /**
1013   * @brief  Return enabled/disabled states of Transmitter and Receiver
1014   * @rmtoll CR1          RE            LL_USART_GetTransferDirection\n
1015   *         CR1          TE            LL_USART_GetTransferDirection
1016   * @param  USARTx USART Instance
1017   * @retval Returned value can be one of the following values:
1018   *         @arg @ref LL_USART_DIRECTION_NONE
1019   *         @arg @ref LL_USART_DIRECTION_RX
1020   *         @arg @ref LL_USART_DIRECTION_TX
1021   *         @arg @ref LL_USART_DIRECTION_TX_RX
1022   */
LL_USART_GetTransferDirection(const USART_TypeDef * USARTx)1023 __STATIC_INLINE uint32_t LL_USART_GetTransferDirection(const USART_TypeDef *USARTx)
1024 {
1025   return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_RE | USART_CR1_TE));
1026 }
1027 
1028 /**
1029   * @brief  Configure Parity (enabled/disabled and parity mode if enabled).
1030   * @note   This function selects if hardware parity control (generation and detection) is enabled or disabled.
1031   *         When the parity control is enabled (Odd or Even), computed parity bit is inserted at the MSB position
1032   *         (9th or 8th bit depending on data width) and parity is checked on the received data.
1033   * @rmtoll CR1          PS            LL_USART_SetParity\n
1034   *         CR1          PCE           LL_USART_SetParity
1035   * @param  USARTx USART Instance
1036   * @param  Parity This parameter can be one of the following values:
1037   *         @arg @ref LL_USART_PARITY_NONE
1038   *         @arg @ref LL_USART_PARITY_EVEN
1039   *         @arg @ref LL_USART_PARITY_ODD
1040   * @retval None
1041   */
LL_USART_SetParity(USART_TypeDef * USARTx,uint32_t Parity)1042 __STATIC_INLINE void LL_USART_SetParity(USART_TypeDef *USARTx, uint32_t Parity)
1043 {
1044   MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE, Parity);
1045 }
1046 
1047 /**
1048   * @brief  Return Parity configuration (enabled/disabled and parity mode if enabled)
1049   * @rmtoll CR1          PS            LL_USART_GetParity\n
1050   *         CR1          PCE           LL_USART_GetParity
1051   * @param  USARTx USART Instance
1052   * @retval Returned value can be one of the following values:
1053   *         @arg @ref LL_USART_PARITY_NONE
1054   *         @arg @ref LL_USART_PARITY_EVEN
1055   *         @arg @ref LL_USART_PARITY_ODD
1056   */
LL_USART_GetParity(const USART_TypeDef * USARTx)1057 __STATIC_INLINE uint32_t LL_USART_GetParity(const USART_TypeDef *USARTx)
1058 {
1059   return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE));
1060 }
1061 
1062 /**
1063   * @brief  Set Receiver Wake Up method from Mute mode.
1064   * @rmtoll CR1          WAKE          LL_USART_SetWakeUpMethod
1065   * @param  USARTx USART Instance
1066   * @param  Method This parameter can be one of the following values:
1067   *         @arg @ref LL_USART_WAKEUP_IDLELINE
1068   *         @arg @ref LL_USART_WAKEUP_ADDRESSMARK
1069   * @retval None
1070   */
LL_USART_SetWakeUpMethod(USART_TypeDef * USARTx,uint32_t Method)1071 __STATIC_INLINE void LL_USART_SetWakeUpMethod(USART_TypeDef *USARTx, uint32_t Method)
1072 {
1073   MODIFY_REG(USARTx->CR1, USART_CR1_WAKE, Method);
1074 }
1075 
1076 /**
1077   * @brief  Return Receiver Wake Up method from Mute mode
1078   * @rmtoll CR1          WAKE          LL_USART_GetWakeUpMethod
1079   * @param  USARTx USART Instance
1080   * @retval Returned value can be one of the following values:
1081   *         @arg @ref LL_USART_WAKEUP_IDLELINE
1082   *         @arg @ref LL_USART_WAKEUP_ADDRESSMARK
1083   */
LL_USART_GetWakeUpMethod(const USART_TypeDef * USARTx)1084 __STATIC_INLINE uint32_t LL_USART_GetWakeUpMethod(const USART_TypeDef *USARTx)
1085 {
1086   return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_WAKE));
1087 }
1088 
1089 /**
1090   * @brief  Set Word length (i.e. nb of data bits, excluding start and stop bits)
1091   * @rmtoll CR1          M0            LL_USART_SetDataWidth\n
1092   *         CR1          M1            LL_USART_SetDataWidth
1093   * @param  USARTx USART Instance
1094   * @param  DataWidth This parameter can be one of the following values:
1095   *         @arg @ref LL_USART_DATAWIDTH_7B
1096   *         @arg @ref LL_USART_DATAWIDTH_8B
1097   *         @arg @ref LL_USART_DATAWIDTH_9B
1098   * @retval None
1099   */
LL_USART_SetDataWidth(USART_TypeDef * USARTx,uint32_t DataWidth)1100 __STATIC_INLINE void LL_USART_SetDataWidth(USART_TypeDef *USARTx, uint32_t DataWidth)
1101 {
1102   MODIFY_REG(USARTx->CR1, USART_CR1_M, DataWidth);
1103 }
1104 
1105 /**
1106   * @brief  Return Word length (i.e. nb of data bits, excluding start and stop bits)
1107   * @rmtoll CR1          M0            LL_USART_GetDataWidth\n
1108   *         CR1          M1            LL_USART_GetDataWidth
1109   * @param  USARTx USART Instance
1110   * @retval Returned value can be one of the following values:
1111   *         @arg @ref LL_USART_DATAWIDTH_7B
1112   *         @arg @ref LL_USART_DATAWIDTH_8B
1113   *         @arg @ref LL_USART_DATAWIDTH_9B
1114   */
LL_USART_GetDataWidth(const USART_TypeDef * USARTx)1115 __STATIC_INLINE uint32_t LL_USART_GetDataWidth(const USART_TypeDef *USARTx)
1116 {
1117   return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_M));
1118 }
1119 
1120 /**
1121   * @brief  Allow switch between Mute Mode and Active mode
1122   * @rmtoll CR1          MME           LL_USART_EnableMuteMode
1123   * @param  USARTx USART Instance
1124   * @retval None
1125   */
LL_USART_EnableMuteMode(USART_TypeDef * USARTx)1126 __STATIC_INLINE void LL_USART_EnableMuteMode(USART_TypeDef *USARTx)
1127 {
1128   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_MME);
1129 }
1130 
1131 /**
1132   * @brief  Prevent Mute Mode use. Set Receiver in active mode permanently.
1133   * @rmtoll CR1          MME           LL_USART_DisableMuteMode
1134   * @param  USARTx USART Instance
1135   * @retval None
1136   */
LL_USART_DisableMuteMode(USART_TypeDef * USARTx)1137 __STATIC_INLINE void LL_USART_DisableMuteMode(USART_TypeDef *USARTx)
1138 {
1139   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_MME);
1140 }
1141 
1142 /**
1143   * @brief  Indicate if switch between Mute Mode and Active mode is allowed
1144   * @rmtoll CR1          MME           LL_USART_IsEnabledMuteMode
1145   * @param  USARTx USART Instance
1146   * @retval State of bit (1 or 0).
1147   */
LL_USART_IsEnabledMuteMode(const USART_TypeDef * USARTx)1148 __STATIC_INLINE uint32_t LL_USART_IsEnabledMuteMode(const USART_TypeDef *USARTx)
1149 {
1150   return ((READ_BIT(USARTx->CR1, USART_CR1_MME) == (USART_CR1_MME)) ? 1UL : 0UL);
1151 }
1152 
1153 /**
1154   * @brief  Set Oversampling to 8-bit or 16-bit mode
1155   * @rmtoll CR1          OVER8         LL_USART_SetOverSampling
1156   * @param  USARTx USART Instance
1157   * @param  OverSampling This parameter can be one of the following values:
1158   *         @arg @ref LL_USART_OVERSAMPLING_16
1159   *         @arg @ref LL_USART_OVERSAMPLING_8
1160   * @retval None
1161   */
LL_USART_SetOverSampling(USART_TypeDef * USARTx,uint32_t OverSampling)1162 __STATIC_INLINE void LL_USART_SetOverSampling(USART_TypeDef *USARTx, uint32_t OverSampling)
1163 {
1164   MODIFY_REG(USARTx->CR1, USART_CR1_OVER8, OverSampling);
1165 }
1166 
1167 /**
1168   * @brief  Return Oversampling mode
1169   * @rmtoll CR1          OVER8         LL_USART_GetOverSampling
1170   * @param  USARTx USART Instance
1171   * @retval Returned value can be one of the following values:
1172   *         @arg @ref LL_USART_OVERSAMPLING_16
1173   *         @arg @ref LL_USART_OVERSAMPLING_8
1174   */
LL_USART_GetOverSampling(const USART_TypeDef * USARTx)1175 __STATIC_INLINE uint32_t LL_USART_GetOverSampling(const USART_TypeDef *USARTx)
1176 {
1177   return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_OVER8));
1178 }
1179 
1180 /**
1181   * @brief  Configure if Clock pulse of the last data bit is output to the SCLK pin or not
1182   * @note   Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
1183   *         Synchronous mode is supported by the USARTx instance.
1184   * @rmtoll CR2          LBCL          LL_USART_SetLastClkPulseOutput
1185   * @param  USARTx USART Instance
1186   * @param  LastBitClockPulse This parameter can be one of the following values:
1187   *         @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
1188   *         @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
1189   * @retval None
1190   */
LL_USART_SetLastClkPulseOutput(USART_TypeDef * USARTx,uint32_t LastBitClockPulse)1191 __STATIC_INLINE void LL_USART_SetLastClkPulseOutput(USART_TypeDef *USARTx, uint32_t LastBitClockPulse)
1192 {
1193   MODIFY_REG(USARTx->CR2, USART_CR2_LBCL, LastBitClockPulse);
1194 }
1195 
1196 /**
1197   * @brief  Retrieve Clock pulse of the last data bit output configuration
1198   *         (Last bit Clock pulse output to the SCLK pin or not)
1199   * @note   Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
1200   *         Synchronous mode is supported by the USARTx instance.
1201   * @rmtoll CR2          LBCL          LL_USART_GetLastClkPulseOutput
1202   * @param  USARTx USART Instance
1203   * @retval Returned value can be one of the following values:
1204   *         @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
1205   *         @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
1206   */
LL_USART_GetLastClkPulseOutput(const USART_TypeDef * USARTx)1207 __STATIC_INLINE uint32_t LL_USART_GetLastClkPulseOutput(const USART_TypeDef *USARTx)
1208 {
1209   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBCL));
1210 }
1211 
1212 /**
1213   * @brief  Select the phase of the clock output on the SCLK pin in synchronous mode
1214   * @note   Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
1215   *         Synchronous mode is supported by the USARTx instance.
1216   * @rmtoll CR2          CPHA          LL_USART_SetClockPhase
1217   * @param  USARTx USART Instance
1218   * @param  ClockPhase This parameter can be one of the following values:
1219   *         @arg @ref LL_USART_PHASE_1EDGE
1220   *         @arg @ref LL_USART_PHASE_2EDGE
1221   * @retval None
1222   */
LL_USART_SetClockPhase(USART_TypeDef * USARTx,uint32_t ClockPhase)1223 __STATIC_INLINE void LL_USART_SetClockPhase(USART_TypeDef *USARTx, uint32_t ClockPhase)
1224 {
1225   MODIFY_REG(USARTx->CR2, USART_CR2_CPHA, ClockPhase);
1226 }
1227 
1228 /**
1229   * @brief  Return phase of the clock output on the SCLK pin in synchronous mode
1230   * @note   Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
1231   *         Synchronous mode is supported by the USARTx instance.
1232   * @rmtoll CR2          CPHA          LL_USART_GetClockPhase
1233   * @param  USARTx USART Instance
1234   * @retval Returned value can be one of the following values:
1235   *         @arg @ref LL_USART_PHASE_1EDGE
1236   *         @arg @ref LL_USART_PHASE_2EDGE
1237   */
LL_USART_GetClockPhase(const USART_TypeDef * USARTx)1238 __STATIC_INLINE uint32_t LL_USART_GetClockPhase(const USART_TypeDef *USARTx)
1239 {
1240   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPHA));
1241 }
1242 
1243 /**
1244   * @brief  Select the polarity of the clock output on the SCLK pin in synchronous mode
1245   * @note   Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
1246   *         Synchronous mode is supported by the USARTx instance.
1247   * @rmtoll CR2          CPOL          LL_USART_SetClockPolarity
1248   * @param  USARTx USART Instance
1249   * @param  ClockPolarity This parameter can be one of the following values:
1250   *         @arg @ref LL_USART_POLARITY_LOW
1251   *         @arg @ref LL_USART_POLARITY_HIGH
1252   * @retval None
1253   */
LL_USART_SetClockPolarity(USART_TypeDef * USARTx,uint32_t ClockPolarity)1254 __STATIC_INLINE void LL_USART_SetClockPolarity(USART_TypeDef *USARTx, uint32_t ClockPolarity)
1255 {
1256   MODIFY_REG(USARTx->CR2, USART_CR2_CPOL, ClockPolarity);
1257 }
1258 
1259 /**
1260   * @brief  Return polarity of the clock output on the SCLK pin in synchronous mode
1261   * @note   Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
1262   *         Synchronous mode is supported by the USARTx instance.
1263   * @rmtoll CR2          CPOL          LL_USART_GetClockPolarity
1264   * @param  USARTx USART Instance
1265   * @retval Returned value can be one of the following values:
1266   *         @arg @ref LL_USART_POLARITY_LOW
1267   *         @arg @ref LL_USART_POLARITY_HIGH
1268   */
LL_USART_GetClockPolarity(const USART_TypeDef * USARTx)1269 __STATIC_INLINE uint32_t LL_USART_GetClockPolarity(const USART_TypeDef *USARTx)
1270 {
1271   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPOL));
1272 }
1273 
1274 /**
1275   * @brief  Configure Clock signal format (Phase Polarity and choice about output of last bit clock pulse)
1276   * @note   Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
1277   *         Synchronous mode is supported by the USARTx instance.
1278   * @note   Call of this function is equivalent to following function call sequence :
1279   *         - Clock Phase configuration using @ref LL_USART_SetClockPhase() function
1280   *         - Clock Polarity configuration using @ref LL_USART_SetClockPolarity() function
1281   *         - Output of Last bit Clock pulse configuration using @ref LL_USART_SetLastClkPulseOutput() function
1282   * @rmtoll CR2          CPHA          LL_USART_ConfigClock\n
1283   *         CR2          CPOL          LL_USART_ConfigClock\n
1284   *         CR2          LBCL          LL_USART_ConfigClock
1285   * @param  USARTx USART Instance
1286   * @param  Phase This parameter can be one of the following values:
1287   *         @arg @ref LL_USART_PHASE_1EDGE
1288   *         @arg @ref LL_USART_PHASE_2EDGE
1289   * @param  Polarity This parameter can be one of the following values:
1290   *         @arg @ref LL_USART_POLARITY_LOW
1291   *         @arg @ref LL_USART_POLARITY_HIGH
1292   * @param  LBCPOutput This parameter can be one of the following values:
1293   *         @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
1294   *         @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
1295   * @retval None
1296   */
LL_USART_ConfigClock(USART_TypeDef * USARTx,uint32_t Phase,uint32_t Polarity,uint32_t LBCPOutput)1297 __STATIC_INLINE void LL_USART_ConfigClock(USART_TypeDef *USARTx, uint32_t Phase, uint32_t Polarity, uint32_t LBCPOutput)
1298 {
1299   MODIFY_REG(USARTx->CR2, USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL, Phase | Polarity | LBCPOutput);
1300 }
1301 
1302 #if defined(USART_PRESC_PRESCALER)
1303 /**
1304   * @brief  Configure Clock source prescaler for baudrate generator and oversampling
1305   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
1306   *         FIFO mode feature is supported by the USARTx instance.
1307   * @rmtoll PRESC        PRESCALER     LL_USART_SetPrescaler
1308   * @param  USARTx USART Instance
1309   * @param  PrescalerValue This parameter can be one of the following values:
1310   *         @arg @ref LL_USART_PRESCALER_DIV1
1311   *         @arg @ref LL_USART_PRESCALER_DIV2
1312   *         @arg @ref LL_USART_PRESCALER_DIV4
1313   *         @arg @ref LL_USART_PRESCALER_DIV6
1314   *         @arg @ref LL_USART_PRESCALER_DIV8
1315   *         @arg @ref LL_USART_PRESCALER_DIV10
1316   *         @arg @ref LL_USART_PRESCALER_DIV12
1317   *         @arg @ref LL_USART_PRESCALER_DIV16
1318   *         @arg @ref LL_USART_PRESCALER_DIV32
1319   *         @arg @ref LL_USART_PRESCALER_DIV64
1320   *         @arg @ref LL_USART_PRESCALER_DIV128
1321   *         @arg @ref LL_USART_PRESCALER_DIV256
1322   * @retval None
1323   */
LL_USART_SetPrescaler(USART_TypeDef * USARTx,uint32_t PrescalerValue)1324 __STATIC_INLINE void LL_USART_SetPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
1325 {
1326   MODIFY_REG(USARTx->PRESC, USART_PRESC_PRESCALER, (uint16_t)PrescalerValue);
1327 }
1328 
1329 /**
1330   * @brief  Retrieve the Clock source prescaler for baudrate generator and oversampling
1331   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
1332   *         FIFO mode feature is supported by the USARTx instance.
1333   * @rmtoll PRESC        PRESCALER     LL_USART_GetPrescaler
1334   * @param  USARTx USART Instance
1335   * @retval Returned value can be one of the following values:
1336   *         @arg @ref LL_USART_PRESCALER_DIV1
1337   *         @arg @ref LL_USART_PRESCALER_DIV2
1338   *         @arg @ref LL_USART_PRESCALER_DIV4
1339   *         @arg @ref LL_USART_PRESCALER_DIV6
1340   *         @arg @ref LL_USART_PRESCALER_DIV8
1341   *         @arg @ref LL_USART_PRESCALER_DIV10
1342   *         @arg @ref LL_USART_PRESCALER_DIV12
1343   *         @arg @ref LL_USART_PRESCALER_DIV16
1344   *         @arg @ref LL_USART_PRESCALER_DIV32
1345   *         @arg @ref LL_USART_PRESCALER_DIV64
1346   *         @arg @ref LL_USART_PRESCALER_DIV128
1347   *         @arg @ref LL_USART_PRESCALER_DIV256
1348   */
LL_USART_GetPrescaler(const USART_TypeDef * USARTx)1349 __STATIC_INLINE uint32_t LL_USART_GetPrescaler(const USART_TypeDef *USARTx)
1350 {
1351   return (uint32_t)(READ_BIT(USARTx->PRESC, USART_PRESC_PRESCALER));
1352 }
1353 
1354 #endif /* USART_PRESC_PRESCALER */
1355 /**
1356   * @brief  Enable Clock output on SCLK pin
1357   * @note   Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
1358   *         Synchronous mode is supported by the USARTx instance.
1359   * @rmtoll CR2          CLKEN         LL_USART_EnableSCLKOutput
1360   * @param  USARTx USART Instance
1361   * @retval None
1362   */
LL_USART_EnableSCLKOutput(USART_TypeDef * USARTx)1363 __STATIC_INLINE void LL_USART_EnableSCLKOutput(USART_TypeDef *USARTx)
1364 {
1365   SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
1366 }
1367 
1368 /**
1369   * @brief  Disable Clock output on SCLK pin
1370   * @note   Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
1371   *         Synchronous mode is supported by the USARTx instance.
1372   * @rmtoll CR2          CLKEN         LL_USART_DisableSCLKOutput
1373   * @param  USARTx USART Instance
1374   * @retval None
1375   */
LL_USART_DisableSCLKOutput(USART_TypeDef * USARTx)1376 __STATIC_INLINE void LL_USART_DisableSCLKOutput(USART_TypeDef *USARTx)
1377 {
1378   CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
1379 }
1380 
1381 /**
1382   * @brief  Indicate if Clock output on SCLK pin is enabled
1383   * @note   Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
1384   *         Synchronous mode is supported by the USARTx instance.
1385   * @rmtoll CR2          CLKEN         LL_USART_IsEnabledSCLKOutput
1386   * @param  USARTx USART Instance
1387   * @retval State of bit (1 or 0).
1388   */
LL_USART_IsEnabledSCLKOutput(const USART_TypeDef * USARTx)1389 __STATIC_INLINE uint32_t LL_USART_IsEnabledSCLKOutput(const USART_TypeDef *USARTx)
1390 {
1391   return ((READ_BIT(USARTx->CR2, USART_CR2_CLKEN) == (USART_CR2_CLKEN)) ? 1UL : 0UL);
1392 }
1393 
1394 /**
1395   * @brief  Set the length of the stop bits
1396   * @rmtoll CR2          STOP          LL_USART_SetStopBitsLength
1397   * @param  USARTx USART Instance
1398   * @param  StopBits This parameter can be one of the following values:
1399   *         @arg @ref LL_USART_STOPBITS_0_5
1400   *         @arg @ref LL_USART_STOPBITS_1
1401   *         @arg @ref LL_USART_STOPBITS_1_5
1402   *         @arg @ref LL_USART_STOPBITS_2
1403   * @retval None
1404   */
LL_USART_SetStopBitsLength(USART_TypeDef * USARTx,uint32_t StopBits)1405 __STATIC_INLINE void LL_USART_SetStopBitsLength(USART_TypeDef *USARTx, uint32_t StopBits)
1406 {
1407   MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
1408 }
1409 
1410 /**
1411   * @brief  Retrieve the length of the stop bits
1412   * @rmtoll CR2          STOP          LL_USART_GetStopBitsLength
1413   * @param  USARTx USART Instance
1414   * @retval Returned value can be one of the following values:
1415   *         @arg @ref LL_USART_STOPBITS_0_5
1416   *         @arg @ref LL_USART_STOPBITS_1
1417   *         @arg @ref LL_USART_STOPBITS_1_5
1418   *         @arg @ref LL_USART_STOPBITS_2
1419   */
LL_USART_GetStopBitsLength(const USART_TypeDef * USARTx)1420 __STATIC_INLINE uint32_t LL_USART_GetStopBitsLength(const USART_TypeDef *USARTx)
1421 {
1422   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_STOP));
1423 }
1424 
1425 /**
1426   * @brief  Configure Character frame format (Datawidth, Parity control, Stop Bits)
1427   * @note   Call of this function is equivalent to following function call sequence :
1428   *         - Data Width configuration using @ref LL_USART_SetDataWidth() function
1429   *         - Parity Control and mode configuration using @ref LL_USART_SetParity() function
1430   *         - Stop bits configuration using @ref LL_USART_SetStopBitsLength() function
1431   * @rmtoll CR1          PS            LL_USART_ConfigCharacter\n
1432   *         CR1          PCE           LL_USART_ConfigCharacter\n
1433   *         CR1          M0            LL_USART_ConfigCharacter\n
1434   *         CR1          M1            LL_USART_ConfigCharacter\n
1435   *         CR2          STOP          LL_USART_ConfigCharacter
1436   * @param  USARTx USART Instance
1437   * @param  DataWidth This parameter can be one of the following values:
1438   *         @arg @ref LL_USART_DATAWIDTH_7B
1439   *         @arg @ref LL_USART_DATAWIDTH_8B
1440   *         @arg @ref LL_USART_DATAWIDTH_9B
1441   * @param  Parity This parameter can be one of the following values:
1442   *         @arg @ref LL_USART_PARITY_NONE
1443   *         @arg @ref LL_USART_PARITY_EVEN
1444   *         @arg @ref LL_USART_PARITY_ODD
1445   * @param  StopBits This parameter can be one of the following values:
1446   *         @arg @ref LL_USART_STOPBITS_0_5
1447   *         @arg @ref LL_USART_STOPBITS_1
1448   *         @arg @ref LL_USART_STOPBITS_1_5
1449   *         @arg @ref LL_USART_STOPBITS_2
1450   * @retval None
1451   */
LL_USART_ConfigCharacter(USART_TypeDef * USARTx,uint32_t DataWidth,uint32_t Parity,uint32_t StopBits)1452 __STATIC_INLINE void LL_USART_ConfigCharacter(USART_TypeDef *USARTx, uint32_t DataWidth, uint32_t Parity,
1453                                               uint32_t StopBits)
1454 {
1455   MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE | USART_CR1_M, Parity | DataWidth);
1456   MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
1457 }
1458 
1459 /**
1460   * @brief  Configure TX/RX pins swapping setting.
1461   * @rmtoll CR2          SWAP          LL_USART_SetTXRXSwap
1462   * @param  USARTx USART Instance
1463   * @param  SwapConfig This parameter can be one of the following values:
1464   *         @arg @ref LL_USART_TXRX_STANDARD
1465   *         @arg @ref LL_USART_TXRX_SWAPPED
1466   * @retval None
1467   */
LL_USART_SetTXRXSwap(USART_TypeDef * USARTx,uint32_t SwapConfig)1468 __STATIC_INLINE void LL_USART_SetTXRXSwap(USART_TypeDef *USARTx, uint32_t SwapConfig)
1469 {
1470   MODIFY_REG(USARTx->CR2, USART_CR2_SWAP, SwapConfig);
1471 }
1472 
1473 /**
1474   * @brief  Retrieve TX/RX pins swapping configuration.
1475   * @rmtoll CR2          SWAP          LL_USART_GetTXRXSwap
1476   * @param  USARTx USART Instance
1477   * @retval Returned value can be one of the following values:
1478   *         @arg @ref LL_USART_TXRX_STANDARD
1479   *         @arg @ref LL_USART_TXRX_SWAPPED
1480   */
LL_USART_GetTXRXSwap(const USART_TypeDef * USARTx)1481 __STATIC_INLINE uint32_t LL_USART_GetTXRXSwap(const USART_TypeDef *USARTx)
1482 {
1483   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_SWAP));
1484 }
1485 
1486 /**
1487   * @brief  Configure RX pin active level logic
1488   * @rmtoll CR2          RXINV         LL_USART_SetRXPinLevel
1489   * @param  USARTx USART Instance
1490   * @param  PinInvMethod This parameter can be one of the following values:
1491   *         @arg @ref LL_USART_RXPIN_LEVEL_STANDARD
1492   *         @arg @ref LL_USART_RXPIN_LEVEL_INVERTED
1493   * @retval None
1494   */
LL_USART_SetRXPinLevel(USART_TypeDef * USARTx,uint32_t PinInvMethod)1495 __STATIC_INLINE void LL_USART_SetRXPinLevel(USART_TypeDef *USARTx, uint32_t PinInvMethod)
1496 {
1497   MODIFY_REG(USARTx->CR2, USART_CR2_RXINV, PinInvMethod);
1498 }
1499 
1500 /**
1501   * @brief  Retrieve RX pin active level logic configuration
1502   * @rmtoll CR2          RXINV         LL_USART_GetRXPinLevel
1503   * @param  USARTx USART Instance
1504   * @retval Returned value can be one of the following values:
1505   *         @arg @ref LL_USART_RXPIN_LEVEL_STANDARD
1506   *         @arg @ref LL_USART_RXPIN_LEVEL_INVERTED
1507   */
LL_USART_GetRXPinLevel(const USART_TypeDef * USARTx)1508 __STATIC_INLINE uint32_t LL_USART_GetRXPinLevel(const USART_TypeDef *USARTx)
1509 {
1510   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_RXINV));
1511 }
1512 
1513 /**
1514   * @brief  Configure TX pin active level logic
1515   * @rmtoll CR2          TXINV         LL_USART_SetTXPinLevel
1516   * @param  USARTx USART Instance
1517   * @param  PinInvMethod This parameter can be one of the following values:
1518   *         @arg @ref LL_USART_TXPIN_LEVEL_STANDARD
1519   *         @arg @ref LL_USART_TXPIN_LEVEL_INVERTED
1520   * @retval None
1521   */
LL_USART_SetTXPinLevel(USART_TypeDef * USARTx,uint32_t PinInvMethod)1522 __STATIC_INLINE void LL_USART_SetTXPinLevel(USART_TypeDef *USARTx, uint32_t PinInvMethod)
1523 {
1524   MODIFY_REG(USARTx->CR2, USART_CR2_TXINV, PinInvMethod);
1525 }
1526 
1527 /**
1528   * @brief  Retrieve TX pin active level logic configuration
1529   * @rmtoll CR2          TXINV         LL_USART_GetTXPinLevel
1530   * @param  USARTx USART Instance
1531   * @retval Returned value can be one of the following values:
1532   *         @arg @ref LL_USART_TXPIN_LEVEL_STANDARD
1533   *         @arg @ref LL_USART_TXPIN_LEVEL_INVERTED
1534   */
LL_USART_GetTXPinLevel(const USART_TypeDef * USARTx)1535 __STATIC_INLINE uint32_t LL_USART_GetTXPinLevel(const USART_TypeDef *USARTx)
1536 {
1537   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_TXINV));
1538 }
1539 
1540 /**
1541   * @brief  Configure Binary data logic.
1542   * @note   Allow to define how Logical data from the data register are send/received :
1543   *         either in positive/direct logic (1=H, 0=L) or in negative/inverse logic (1=L, 0=H)
1544   * @rmtoll CR2          DATAINV       LL_USART_SetBinaryDataLogic
1545   * @param  USARTx USART Instance
1546   * @param  DataLogic This parameter can be one of the following values:
1547   *         @arg @ref LL_USART_BINARY_LOGIC_POSITIVE
1548   *         @arg @ref LL_USART_BINARY_LOGIC_NEGATIVE
1549   * @retval None
1550   */
LL_USART_SetBinaryDataLogic(USART_TypeDef * USARTx,uint32_t DataLogic)1551 __STATIC_INLINE void LL_USART_SetBinaryDataLogic(USART_TypeDef *USARTx, uint32_t DataLogic)
1552 {
1553   MODIFY_REG(USARTx->CR2, USART_CR2_DATAINV, DataLogic);
1554 }
1555 
1556 /**
1557   * @brief  Retrieve Binary data configuration
1558   * @rmtoll CR2          DATAINV       LL_USART_GetBinaryDataLogic
1559   * @param  USARTx USART Instance
1560   * @retval Returned value can be one of the following values:
1561   *         @arg @ref LL_USART_BINARY_LOGIC_POSITIVE
1562   *         @arg @ref LL_USART_BINARY_LOGIC_NEGATIVE
1563   */
LL_USART_GetBinaryDataLogic(const USART_TypeDef * USARTx)1564 __STATIC_INLINE uint32_t LL_USART_GetBinaryDataLogic(const USART_TypeDef *USARTx)
1565 {
1566   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_DATAINV));
1567 }
1568 
1569 /**
1570   * @brief  Configure transfer bit order (either Less or Most Significant Bit First)
1571   * @note   MSB First means data is transmitted/received with the MSB first, following the start bit.
1572   *         LSB First means data is transmitted/received with data bit 0 first, following the start bit.
1573   * @rmtoll CR2          MSBFIRST      LL_USART_SetTransferBitOrder
1574   * @param  USARTx USART Instance
1575   * @param  BitOrder This parameter can be one of the following values:
1576   *         @arg @ref LL_USART_BITORDER_LSBFIRST
1577   *         @arg @ref LL_USART_BITORDER_MSBFIRST
1578   * @retval None
1579   */
LL_USART_SetTransferBitOrder(USART_TypeDef * USARTx,uint32_t BitOrder)1580 __STATIC_INLINE void LL_USART_SetTransferBitOrder(USART_TypeDef *USARTx, uint32_t BitOrder)
1581 {
1582   MODIFY_REG(USARTx->CR2, USART_CR2_MSBFIRST, BitOrder);
1583 }
1584 
1585 /**
1586   * @brief  Return transfer bit order (either Less or Most Significant Bit First)
1587   * @note   MSB First means data is transmitted/received with the MSB first, following the start bit.
1588   *         LSB First means data is transmitted/received with data bit 0 first, following the start bit.
1589   * @rmtoll CR2          MSBFIRST      LL_USART_GetTransferBitOrder
1590   * @param  USARTx USART Instance
1591   * @retval Returned value can be one of the following values:
1592   *         @arg @ref LL_USART_BITORDER_LSBFIRST
1593   *         @arg @ref LL_USART_BITORDER_MSBFIRST
1594   */
LL_USART_GetTransferBitOrder(const USART_TypeDef * USARTx)1595 __STATIC_INLINE uint32_t LL_USART_GetTransferBitOrder(const USART_TypeDef *USARTx)
1596 {
1597   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_MSBFIRST));
1598 }
1599 
1600 /**
1601   * @brief  Enable Auto Baud-Rate Detection
1602   * @note   Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
1603   *         Auto Baud Rate detection feature is supported by the USARTx instance.
1604   * @rmtoll CR2          ABREN         LL_USART_EnableAutoBaudRate
1605   * @param  USARTx USART Instance
1606   * @retval None
1607   */
LL_USART_EnableAutoBaudRate(USART_TypeDef * USARTx)1608 __STATIC_INLINE void LL_USART_EnableAutoBaudRate(USART_TypeDef *USARTx)
1609 {
1610   SET_BIT(USARTx->CR2, USART_CR2_ABREN);
1611 }
1612 
1613 /**
1614   * @brief  Disable Auto Baud-Rate Detection
1615   * @note   Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
1616   *         Auto Baud Rate detection feature is supported by the USARTx instance.
1617   * @rmtoll CR2          ABREN         LL_USART_DisableAutoBaudRate
1618   * @param  USARTx USART Instance
1619   * @retval None
1620   */
LL_USART_DisableAutoBaudRate(USART_TypeDef * USARTx)1621 __STATIC_INLINE void LL_USART_DisableAutoBaudRate(USART_TypeDef *USARTx)
1622 {
1623   CLEAR_BIT(USARTx->CR2, USART_CR2_ABREN);
1624 }
1625 
1626 /**
1627   * @brief  Indicate if Auto Baud-Rate Detection mechanism is enabled
1628   * @note   Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
1629   *         Auto Baud Rate detection feature is supported by the USARTx instance.
1630   * @rmtoll CR2          ABREN         LL_USART_IsEnabledAutoBaud
1631   * @param  USARTx USART Instance
1632   * @retval State of bit (1 or 0).
1633   */
LL_USART_IsEnabledAutoBaud(const USART_TypeDef * USARTx)1634 __STATIC_INLINE uint32_t LL_USART_IsEnabledAutoBaud(const USART_TypeDef *USARTx)
1635 {
1636   return ((READ_BIT(USARTx->CR2, USART_CR2_ABREN) == (USART_CR2_ABREN)) ? 1UL : 0UL);
1637 }
1638 
1639 /**
1640   * @brief  Set Auto Baud-Rate mode bits
1641   * @note   Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
1642   *         Auto Baud Rate detection feature is supported by the USARTx instance.
1643   * @rmtoll CR2          ABRMODE       LL_USART_SetAutoBaudRateMode
1644   * @param  USARTx USART Instance
1645   * @param  AutoBaudRateMode This parameter can be one of the following values:
1646   *         @arg @ref LL_USART_AUTOBAUD_DETECT_ON_STARTBIT
1647   *         @arg @ref LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE
1648   *         @arg @ref LL_USART_AUTOBAUD_DETECT_ON_7F_FRAME
1649   *         @arg @ref LL_USART_AUTOBAUD_DETECT_ON_55_FRAME
1650   * @retval None
1651   */
LL_USART_SetAutoBaudRateMode(USART_TypeDef * USARTx,uint32_t AutoBaudRateMode)1652 __STATIC_INLINE void LL_USART_SetAutoBaudRateMode(USART_TypeDef *USARTx, uint32_t AutoBaudRateMode)
1653 {
1654   MODIFY_REG(USARTx->CR2, USART_CR2_ABRMODE, AutoBaudRateMode);
1655 }
1656 
1657 /**
1658   * @brief  Return Auto Baud-Rate mode
1659   * @note   Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
1660   *         Auto Baud Rate detection feature is supported by the USARTx instance.
1661   * @rmtoll CR2          ABRMODE       LL_USART_GetAutoBaudRateMode
1662   * @param  USARTx USART Instance
1663   * @retval Returned value can be one of the following values:
1664   *         @arg @ref LL_USART_AUTOBAUD_DETECT_ON_STARTBIT
1665   *         @arg @ref LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE
1666   *         @arg @ref LL_USART_AUTOBAUD_DETECT_ON_7F_FRAME
1667   *         @arg @ref LL_USART_AUTOBAUD_DETECT_ON_55_FRAME
1668   */
LL_USART_GetAutoBaudRateMode(const USART_TypeDef * USARTx)1669 __STATIC_INLINE uint32_t LL_USART_GetAutoBaudRateMode(const USART_TypeDef *USARTx)
1670 {
1671   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ABRMODE));
1672 }
1673 
1674 /**
1675   * @brief  Enable Receiver Timeout
1676   * @rmtoll CR2          RTOEN         LL_USART_EnableRxTimeout
1677   * @param  USARTx USART Instance
1678   * @retval None
1679   */
LL_USART_EnableRxTimeout(USART_TypeDef * USARTx)1680 __STATIC_INLINE void LL_USART_EnableRxTimeout(USART_TypeDef *USARTx)
1681 {
1682   SET_BIT(USARTx->CR2, USART_CR2_RTOEN);
1683 }
1684 
1685 /**
1686   * @brief  Disable Receiver Timeout
1687   * @rmtoll CR2          RTOEN         LL_USART_DisableRxTimeout
1688   * @param  USARTx USART Instance
1689   * @retval None
1690   */
LL_USART_DisableRxTimeout(USART_TypeDef * USARTx)1691 __STATIC_INLINE void LL_USART_DisableRxTimeout(USART_TypeDef *USARTx)
1692 {
1693   CLEAR_BIT(USARTx->CR2, USART_CR2_RTOEN);
1694 }
1695 
1696 /**
1697   * @brief  Indicate if Receiver Timeout feature is enabled
1698   * @rmtoll CR2          RTOEN         LL_USART_IsEnabledRxTimeout
1699   * @param  USARTx USART Instance
1700   * @retval State of bit (1 or 0).
1701   */
LL_USART_IsEnabledRxTimeout(const USART_TypeDef * USARTx)1702 __STATIC_INLINE uint32_t LL_USART_IsEnabledRxTimeout(const USART_TypeDef *USARTx)
1703 {
1704   return ((READ_BIT(USARTx->CR2, USART_CR2_RTOEN) == (USART_CR2_RTOEN)) ? 1UL : 0UL);
1705 }
1706 
1707 /**
1708   * @brief  Set Address of the USART node.
1709   * @note   This is used in multiprocessor communication during Mute mode or Stop mode,
1710   *         for wake up with address mark detection.
1711   * @note   4bits address node is used when 4-bit Address Detection is selected in ADDM7.
1712   *         (b7-b4 should be set to 0)
1713   *         8bits address node is used when 7-bit Address Detection is selected in ADDM7.
1714   *         (This is used in multiprocessor communication during Mute mode or Stop mode,
1715   *         for wake up with 7-bit address mark detection.
1716   *         The MSB of the character sent by the transmitter should be equal to 1.
1717   *         It may also be used for character detection during normal reception,
1718   *         Mute mode inactive (for example, end of block detection in ModBus protocol).
1719   *         In this case, the whole received character (8-bit) is compared to the ADD[7:0]
1720   *         value and CMF flag is set on match)
1721   * @rmtoll CR2          ADD           LL_USART_ConfigNodeAddress\n
1722   *         CR2          ADDM7         LL_USART_ConfigNodeAddress
1723   * @param  USARTx USART Instance
1724   * @param  AddressLen This parameter can be one of the following values:
1725   *         @arg @ref LL_USART_ADDRESS_DETECT_4B
1726   *         @arg @ref LL_USART_ADDRESS_DETECT_7B
1727   * @param  NodeAddress 4 or 7 bit Address of the USART node.
1728   * @retval None
1729   */
LL_USART_ConfigNodeAddress(USART_TypeDef * USARTx,uint32_t AddressLen,uint32_t NodeAddress)1730 __STATIC_INLINE void LL_USART_ConfigNodeAddress(USART_TypeDef *USARTx, uint32_t AddressLen, uint32_t NodeAddress)
1731 {
1732   MODIFY_REG(USARTx->CR2, USART_CR2_ADD | USART_CR2_ADDM7,
1733              (uint32_t)(AddressLen | (NodeAddress << USART_CR2_ADD_Pos)));
1734 }
1735 
1736 /**
1737   * @brief  Return 8 bit Address of the USART node as set in ADD field of CR2.
1738   * @note   If 4-bit Address Detection is selected in ADDM7,
1739   *         only 4bits (b3-b0) of returned value are relevant (b31-b4 are not relevant)
1740   *         If 7-bit Address Detection is selected in ADDM7,
1741   *         only 8bits (b7-b0) of returned value are relevant (b31-b8 are not relevant)
1742   * @rmtoll CR2          ADD           LL_USART_GetNodeAddress
1743   * @param  USARTx USART Instance
1744   * @retval Address of the USART node (Value between Min_Data=0 and Max_Data=255)
1745   */
LL_USART_GetNodeAddress(const USART_TypeDef * USARTx)1746 __STATIC_INLINE uint32_t LL_USART_GetNodeAddress(const USART_TypeDef *USARTx)
1747 {
1748   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ADD) >> USART_CR2_ADD_Pos);
1749 }
1750 
1751 /**
1752   * @brief  Return Length of Node Address used in Address Detection mode (7-bit or 4-bit)
1753   * @rmtoll CR2          ADDM7         LL_USART_GetNodeAddressLen
1754   * @param  USARTx USART Instance
1755   * @retval Returned value can be one of the following values:
1756   *         @arg @ref LL_USART_ADDRESS_DETECT_4B
1757   *         @arg @ref LL_USART_ADDRESS_DETECT_7B
1758   */
LL_USART_GetNodeAddressLen(const USART_TypeDef * USARTx)1759 __STATIC_INLINE uint32_t LL_USART_GetNodeAddressLen(const USART_TypeDef *USARTx)
1760 {
1761   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ADDM7));
1762 }
1763 
1764 /**
1765   * @brief  Enable RTS HW Flow Control
1766   * @note   Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
1767   *         Hardware Flow control feature is supported by the USARTx instance.
1768   * @rmtoll CR3          RTSE          LL_USART_EnableRTSHWFlowCtrl
1769   * @param  USARTx USART Instance
1770   * @retval None
1771   */
LL_USART_EnableRTSHWFlowCtrl(USART_TypeDef * USARTx)1772 __STATIC_INLINE void LL_USART_EnableRTSHWFlowCtrl(USART_TypeDef *USARTx)
1773 {
1774   SET_BIT(USARTx->CR3, USART_CR3_RTSE);
1775 }
1776 
1777 /**
1778   * @brief  Disable RTS HW Flow Control
1779   * @note   Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
1780   *         Hardware Flow control feature is supported by the USARTx instance.
1781   * @rmtoll CR3          RTSE          LL_USART_DisableRTSHWFlowCtrl
1782   * @param  USARTx USART Instance
1783   * @retval None
1784   */
LL_USART_DisableRTSHWFlowCtrl(USART_TypeDef * USARTx)1785 __STATIC_INLINE void LL_USART_DisableRTSHWFlowCtrl(USART_TypeDef *USARTx)
1786 {
1787   CLEAR_BIT(USARTx->CR3, USART_CR3_RTSE);
1788 }
1789 
1790 /**
1791   * @brief  Enable CTS HW Flow Control
1792   * @note   Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
1793   *         Hardware Flow control feature is supported by the USARTx instance.
1794   * @rmtoll CR3          CTSE          LL_USART_EnableCTSHWFlowCtrl
1795   * @param  USARTx USART Instance
1796   * @retval None
1797   */
LL_USART_EnableCTSHWFlowCtrl(USART_TypeDef * USARTx)1798 __STATIC_INLINE void LL_USART_EnableCTSHWFlowCtrl(USART_TypeDef *USARTx)
1799 {
1800   SET_BIT(USARTx->CR3, USART_CR3_CTSE);
1801 }
1802 
1803 /**
1804   * @brief  Disable CTS HW Flow Control
1805   * @note   Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
1806   *         Hardware Flow control feature is supported by the USARTx instance.
1807   * @rmtoll CR3          CTSE          LL_USART_DisableCTSHWFlowCtrl
1808   * @param  USARTx USART Instance
1809   * @retval None
1810   */
LL_USART_DisableCTSHWFlowCtrl(USART_TypeDef * USARTx)1811 __STATIC_INLINE void LL_USART_DisableCTSHWFlowCtrl(USART_TypeDef *USARTx)
1812 {
1813   CLEAR_BIT(USARTx->CR3, USART_CR3_CTSE);
1814 }
1815 
1816 /**
1817   * @brief  Configure HW Flow Control mode (both CTS and RTS)
1818   * @note   Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
1819   *         Hardware Flow control feature is supported by the USARTx instance.
1820   * @rmtoll CR3          RTSE          LL_USART_SetHWFlowCtrl\n
1821   *         CR3          CTSE          LL_USART_SetHWFlowCtrl
1822   * @param  USARTx USART Instance
1823   * @param  HardwareFlowControl This parameter can be one of the following values:
1824   *         @arg @ref LL_USART_HWCONTROL_NONE
1825   *         @arg @ref LL_USART_HWCONTROL_RTS
1826   *         @arg @ref LL_USART_HWCONTROL_CTS
1827   *         @arg @ref LL_USART_HWCONTROL_RTS_CTS
1828   * @retval None
1829   */
LL_USART_SetHWFlowCtrl(USART_TypeDef * USARTx,uint32_t HardwareFlowControl)1830 __STATIC_INLINE void LL_USART_SetHWFlowCtrl(USART_TypeDef *USARTx, uint32_t HardwareFlowControl)
1831 {
1832   MODIFY_REG(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE, HardwareFlowControl);
1833 }
1834 
1835 /**
1836   * @brief  Return HW Flow Control configuration (both CTS and RTS)
1837   * @note   Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
1838   *         Hardware Flow control feature is supported by the USARTx instance.
1839   * @rmtoll CR3          RTSE          LL_USART_GetHWFlowCtrl\n
1840   *         CR3          CTSE          LL_USART_GetHWFlowCtrl
1841   * @param  USARTx USART Instance
1842   * @retval Returned value can be one of the following values:
1843   *         @arg @ref LL_USART_HWCONTROL_NONE
1844   *         @arg @ref LL_USART_HWCONTROL_RTS
1845   *         @arg @ref LL_USART_HWCONTROL_CTS
1846   *         @arg @ref LL_USART_HWCONTROL_RTS_CTS
1847   */
LL_USART_GetHWFlowCtrl(const USART_TypeDef * USARTx)1848 __STATIC_INLINE uint32_t LL_USART_GetHWFlowCtrl(const USART_TypeDef *USARTx)
1849 {
1850   return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE));
1851 }
1852 
1853 /**
1854   * @brief  Enable One bit sampling method
1855   * @rmtoll CR3          ONEBIT        LL_USART_EnableOneBitSamp
1856   * @param  USARTx USART Instance
1857   * @retval None
1858   */
LL_USART_EnableOneBitSamp(USART_TypeDef * USARTx)1859 __STATIC_INLINE void LL_USART_EnableOneBitSamp(USART_TypeDef *USARTx)
1860 {
1861   SET_BIT(USARTx->CR3, USART_CR3_ONEBIT);
1862 }
1863 
1864 /**
1865   * @brief  Disable One bit sampling method
1866   * @rmtoll CR3          ONEBIT        LL_USART_DisableOneBitSamp
1867   * @param  USARTx USART Instance
1868   * @retval None
1869   */
LL_USART_DisableOneBitSamp(USART_TypeDef * USARTx)1870 __STATIC_INLINE void LL_USART_DisableOneBitSamp(USART_TypeDef *USARTx)
1871 {
1872   CLEAR_BIT(USARTx->CR3, USART_CR3_ONEBIT);
1873 }
1874 
1875 /**
1876   * @brief  Indicate if One bit sampling method is enabled
1877   * @rmtoll CR3          ONEBIT        LL_USART_IsEnabledOneBitSamp
1878   * @param  USARTx USART Instance
1879   * @retval State of bit (1 or 0).
1880   */
LL_USART_IsEnabledOneBitSamp(const USART_TypeDef * USARTx)1881 __STATIC_INLINE uint32_t LL_USART_IsEnabledOneBitSamp(const USART_TypeDef *USARTx)
1882 {
1883   return ((READ_BIT(USARTx->CR3, USART_CR3_ONEBIT) == (USART_CR3_ONEBIT)) ? 1UL : 0UL);
1884 }
1885 
1886 /**
1887   * @brief  Enable Overrun detection
1888   * @rmtoll CR3          OVRDIS        LL_USART_EnableOverrunDetect
1889   * @param  USARTx USART Instance
1890   * @retval None
1891   */
LL_USART_EnableOverrunDetect(USART_TypeDef * USARTx)1892 __STATIC_INLINE void LL_USART_EnableOverrunDetect(USART_TypeDef *USARTx)
1893 {
1894   CLEAR_BIT(USARTx->CR3, USART_CR3_OVRDIS);
1895 }
1896 
1897 /**
1898   * @brief  Disable Overrun detection
1899   * @rmtoll CR3          OVRDIS        LL_USART_DisableOverrunDetect
1900   * @param  USARTx USART Instance
1901   * @retval None
1902   */
LL_USART_DisableOverrunDetect(USART_TypeDef * USARTx)1903 __STATIC_INLINE void LL_USART_DisableOverrunDetect(USART_TypeDef *USARTx)
1904 {
1905   SET_BIT(USARTx->CR3, USART_CR3_OVRDIS);
1906 }
1907 
1908 /**
1909   * @brief  Indicate if Overrun detection is enabled
1910   * @rmtoll CR3          OVRDIS        LL_USART_IsEnabledOverrunDetect
1911   * @param  USARTx USART Instance
1912   * @retval State of bit (1 or 0).
1913   */
LL_USART_IsEnabledOverrunDetect(const USART_TypeDef * USARTx)1914 __STATIC_INLINE uint32_t LL_USART_IsEnabledOverrunDetect(const USART_TypeDef *USARTx)
1915 {
1916   return ((READ_BIT(USARTx->CR3, USART_CR3_OVRDIS) != USART_CR3_OVRDIS) ? 1UL : 0UL);
1917 }
1918 
1919 /**
1920   * @brief  Select event type for Wake UP Interrupt Flag (WUS[1:0] bits)
1921   * @note   Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
1922   *         Wake-up from Stop mode feature is supported by the USARTx instance.
1923   * @rmtoll CR3          WUS           LL_USART_SetWKUPType
1924   * @param  USARTx USART Instance
1925   * @param  Type This parameter can be one of the following values:
1926   *         @arg @ref LL_USART_WAKEUP_ON_ADDRESS
1927   *         @arg @ref LL_USART_WAKEUP_ON_STARTBIT
1928   *         @arg @ref LL_USART_WAKEUP_ON_RXNE
1929   * @retval None
1930   */
LL_USART_SetWKUPType(USART_TypeDef * USARTx,uint32_t Type)1931 __STATIC_INLINE void LL_USART_SetWKUPType(USART_TypeDef *USARTx, uint32_t Type)
1932 {
1933   MODIFY_REG(USARTx->CR3, USART_CR3_WUS, Type);
1934 }
1935 
1936 /**
1937   * @brief  Return event type for Wake UP Interrupt Flag (WUS[1:0] bits)
1938   * @note   Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
1939   *         Wake-up from Stop mode feature is supported by the USARTx instance.
1940   * @rmtoll CR3          WUS           LL_USART_GetWKUPType
1941   * @param  USARTx USART Instance
1942   * @retval Returned value can be one of the following values:
1943   *         @arg @ref LL_USART_WAKEUP_ON_ADDRESS
1944   *         @arg @ref LL_USART_WAKEUP_ON_STARTBIT
1945   *         @arg @ref LL_USART_WAKEUP_ON_RXNE
1946   */
LL_USART_GetWKUPType(const USART_TypeDef * USARTx)1947 __STATIC_INLINE uint32_t LL_USART_GetWKUPType(const USART_TypeDef *USARTx)
1948 {
1949   return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_WUS));
1950 }
1951 
1952 /**
1953   * @brief  Configure USART BRR register for achieving expected Baud Rate value.
1954   * @note   Compute and set USARTDIV value in BRR Register (full BRR content)
1955   *         according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
1956   * @note   Peripheral clock and Baud rate values provided as function parameters should be valid
1957   *         (Baud rate value != 0)
1958   * @note   In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d.
1959   * @rmtoll BRR          BRR           LL_USART_SetBaudRate
1960   * @param  USARTx USART Instance
1961   * @param  PeriphClk Peripheral Clock
1962   @if USART_PRESC_PRESCALER
1963   * @param  PrescalerValue This parameter can be one of the following values:
1964   *         @arg @ref LL_USART_PRESCALER_DIV1
1965   *         @arg @ref LL_USART_PRESCALER_DIV2
1966   *         @arg @ref LL_USART_PRESCALER_DIV4
1967   *         @arg @ref LL_USART_PRESCALER_DIV6
1968   *         @arg @ref LL_USART_PRESCALER_DIV8
1969   *         @arg @ref LL_USART_PRESCALER_DIV10
1970   *         @arg @ref LL_USART_PRESCALER_DIV12
1971   *         @arg @ref LL_USART_PRESCALER_DIV16
1972   *         @arg @ref LL_USART_PRESCALER_DIV32
1973   *         @arg @ref LL_USART_PRESCALER_DIV64
1974   *         @arg @ref LL_USART_PRESCALER_DIV128
1975   *         @arg @ref LL_USART_PRESCALER_DIV256
1976   @endif
1977   * @param  OverSampling This parameter can be one of the following values:
1978   *         @arg @ref LL_USART_OVERSAMPLING_16
1979   *         @arg @ref LL_USART_OVERSAMPLING_8
1980   * @param  BaudRate Baud Rate
1981   * @retval None
1982   */
1983 #if defined(USART_PRESC_PRESCALER)
LL_USART_SetBaudRate(USART_TypeDef * USARTx,uint32_t PeriphClk,uint32_t PrescalerValue,uint32_t OverSampling,uint32_t BaudRate)1984 __STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t PrescalerValue,
1985                                           uint32_t OverSampling,
1986                                           uint32_t BaudRate)
1987 #else
1988 __STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling,
1989                                           uint32_t BaudRate)
1990 #endif /* USART_PRESC_PRESCALER */
1991 {
1992   uint32_t usartdiv;
1993   uint32_t brrtemp;
1994 
1995 #if defined(USART_PRESC_PRESCALER)
1996   if (PrescalerValue > LL_USART_PRESCALER_DIV256)
1997   {
1998     /* Do not overstep the size of USART_PRESCALER_TAB */
1999   }
2000   else if (BaudRate == 0U)
2001   {
2002     /* Can Not divide per 0 */
2003   }
2004   else if (OverSampling == LL_USART_OVERSAMPLING_8)
2005 #else
2006   if (OverSampling == LL_USART_OVERSAMPLING_8)
2007 #endif /* USART_PRESC_PRESCALER */
2008   {
2009 #if defined(USART_PRESC_PRESCALER)
2010     usartdiv = (uint16_t)(__LL_USART_DIV_SAMPLING8(PeriphClk, (uint8_t)PrescalerValue, BaudRate));
2011 #else
2012     usartdiv = (uint16_t)(__LL_USART_DIV_SAMPLING8(PeriphClk, BaudRate));
2013 #endif /* USART_PRESC_PRESCALER */
2014     brrtemp = usartdiv & 0xFFF0U;
2015     brrtemp |= (uint16_t)((usartdiv & (uint16_t)0x000FU) >> 1U);
2016     USARTx->BRR = brrtemp;
2017   }
2018   else
2019   {
2020 #if defined(USART_PRESC_PRESCALER)
2021     USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk, (uint8_t)PrescalerValue, BaudRate));
2022 #else
2023     USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk, BaudRate));
2024 #endif /* USART_PRESC_PRESCALER */
2025   }
2026 }
2027 
2028 /**
2029   * @brief  Return current Baud Rate value, according to USARTDIV present in BRR register
2030   *         (full BRR content), and to used Peripheral Clock and Oversampling mode values
2031   * @note   In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
2032   * @note   In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d.
2033   * @rmtoll BRR          BRR           LL_USART_GetBaudRate
2034   * @param  USARTx USART Instance
2035   * @param  PeriphClk Peripheral Clock
2036   @if USART_PRESC_PRESCALER
2037   * @param  PrescalerValue This parameter can be one of the following values:
2038   *         @arg @ref LL_USART_PRESCALER_DIV1
2039   *         @arg @ref LL_USART_PRESCALER_DIV2
2040   *         @arg @ref LL_USART_PRESCALER_DIV4
2041   *         @arg @ref LL_USART_PRESCALER_DIV6
2042   *         @arg @ref LL_USART_PRESCALER_DIV8
2043   *         @arg @ref LL_USART_PRESCALER_DIV10
2044   *         @arg @ref LL_USART_PRESCALER_DIV12
2045   *         @arg @ref LL_USART_PRESCALER_DIV16
2046   *         @arg @ref LL_USART_PRESCALER_DIV32
2047   *         @arg @ref LL_USART_PRESCALER_DIV64
2048   *         @arg @ref LL_USART_PRESCALER_DIV128
2049   *         @arg @ref LL_USART_PRESCALER_DIV256
2050   @endif
2051   * @param  OverSampling This parameter can be one of the following values:
2052   *         @arg @ref LL_USART_OVERSAMPLING_16
2053   *         @arg @ref LL_USART_OVERSAMPLING_8
2054   * @retval Baud Rate
2055   */
2056 #if defined(USART_PRESC_PRESCALER)
LL_USART_GetBaudRate(const USART_TypeDef * USARTx,uint32_t PeriphClk,uint32_t PrescalerValue,uint32_t OverSampling)2057 __STATIC_INLINE uint32_t LL_USART_GetBaudRate(const USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t PrescalerValue,
2058                                               uint32_t OverSampling)
2059 #else
2060 __STATIC_INLINE uint32_t LL_USART_GetBaudRate(const USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling)
2061 #endif /* USART_PRESC_PRESCALER */
2062 {
2063   uint32_t usartdiv;
2064   uint32_t brrresult = 0x0U;
2065 #if defined(USART_PRESC_PRESCALER)
2066   uint32_t periphclkpresc = (uint32_t)(PeriphClk / (USART_PRESCALER_TAB[(uint8_t)PrescalerValue]));
2067 #endif /* USART_PRESC_PRESCALER */
2068 
2069   usartdiv = USARTx->BRR;
2070 
2071   if (usartdiv == 0U)
2072   {
2073     /* Do not perform a division by 0 */
2074   }
2075   else if (OverSampling == LL_USART_OVERSAMPLING_8)
2076   {
2077     usartdiv = (uint16_t)((usartdiv & 0xFFF0U) | ((usartdiv & 0x0007U) << 1U)) ;
2078     if (usartdiv != 0U)
2079     {
2080 #if defined(USART_PRESC_PRESCALER)
2081       brrresult = (periphclkpresc * 2U) / usartdiv;
2082 #else
2083       brrresult = (PeriphClk * 2U) / usartdiv;
2084 #endif /* USART_PRESC_PRESCALER */
2085     }
2086   }
2087   else
2088   {
2089     if ((usartdiv & 0xFFFFU) != 0U)
2090     {
2091 #if defined(USART_PRESC_PRESCALER)
2092       brrresult = periphclkpresc / usartdiv;
2093 #else
2094       brrresult = PeriphClk / usartdiv;
2095 #endif /* USART_PRESC_PRESCALER */
2096     }
2097   }
2098   return (brrresult);
2099 }
2100 
2101 /**
2102   * @brief  Set Receiver Time Out Value (expressed in nb of bits duration)
2103   * @rmtoll RTOR         RTO           LL_USART_SetRxTimeout
2104   * @param  USARTx USART Instance
2105   * @param  Timeout Value between Min_Data=0x00 and Max_Data=0x00FFFFFF
2106   * @retval None
2107   */
LL_USART_SetRxTimeout(USART_TypeDef * USARTx,uint32_t Timeout)2108 __STATIC_INLINE void LL_USART_SetRxTimeout(USART_TypeDef *USARTx, uint32_t Timeout)
2109 {
2110   MODIFY_REG(USARTx->RTOR, USART_RTOR_RTO, Timeout);
2111 }
2112 
2113 /**
2114   * @brief  Get Receiver Time Out Value (expressed in nb of bits duration)
2115   * @rmtoll RTOR         RTO           LL_USART_GetRxTimeout
2116   * @param  USARTx USART Instance
2117   * @retval Value between Min_Data=0x00 and Max_Data=0x00FFFFFF
2118   */
LL_USART_GetRxTimeout(const USART_TypeDef * USARTx)2119 __STATIC_INLINE uint32_t LL_USART_GetRxTimeout(const USART_TypeDef *USARTx)
2120 {
2121   return (uint32_t)(READ_BIT(USARTx->RTOR, USART_RTOR_RTO));
2122 }
2123 
2124 /**
2125   * @brief  Set Block Length value in reception
2126   * @rmtoll RTOR         BLEN          LL_USART_SetBlockLength
2127   * @param  USARTx USART Instance
2128   * @param  BlockLength Value between Min_Data=0x00 and Max_Data=0xFF
2129   * @retval None
2130   */
LL_USART_SetBlockLength(USART_TypeDef * USARTx,uint32_t BlockLength)2131 __STATIC_INLINE void LL_USART_SetBlockLength(USART_TypeDef *USARTx, uint32_t BlockLength)
2132 {
2133   MODIFY_REG(USARTx->RTOR, USART_RTOR_BLEN, BlockLength << USART_RTOR_BLEN_Pos);
2134 }
2135 
2136 /**
2137   * @brief  Get Block Length value in reception
2138   * @rmtoll RTOR         BLEN          LL_USART_GetBlockLength
2139   * @param  USARTx USART Instance
2140   * @retval Value between Min_Data=0x00 and Max_Data=0xFF
2141   */
LL_USART_GetBlockLength(const USART_TypeDef * USARTx)2142 __STATIC_INLINE uint32_t LL_USART_GetBlockLength(const USART_TypeDef *USARTx)
2143 {
2144   return (uint32_t)(READ_BIT(USARTx->RTOR, USART_RTOR_BLEN) >> USART_RTOR_BLEN_Pos);
2145 }
2146 
2147 /**
2148   * @}
2149   */
2150 
2151 /** @defgroup USART_LL_EF_Configuration_IRDA Configuration functions related to Irda feature
2152   * @{
2153   */
2154 
2155 /**
2156   * @brief  Enable IrDA mode
2157   * @note   Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
2158   *         IrDA feature is supported by the USARTx instance.
2159   * @rmtoll CR3          IREN          LL_USART_EnableIrda
2160   * @param  USARTx USART Instance
2161   * @retval None
2162   */
LL_USART_EnableIrda(USART_TypeDef * USARTx)2163 __STATIC_INLINE void LL_USART_EnableIrda(USART_TypeDef *USARTx)
2164 {
2165   SET_BIT(USARTx->CR3, USART_CR3_IREN);
2166 }
2167 
2168 /**
2169   * @brief  Disable IrDA mode
2170   * @note   Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
2171   *         IrDA feature is supported by the USARTx instance.
2172   * @rmtoll CR3          IREN          LL_USART_DisableIrda
2173   * @param  USARTx USART Instance
2174   * @retval None
2175   */
LL_USART_DisableIrda(USART_TypeDef * USARTx)2176 __STATIC_INLINE void LL_USART_DisableIrda(USART_TypeDef *USARTx)
2177 {
2178   CLEAR_BIT(USARTx->CR3, USART_CR3_IREN);
2179 }
2180 
2181 /**
2182   * @brief  Indicate if IrDA mode is enabled
2183   * @note   Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
2184   *         IrDA feature is supported by the USARTx instance.
2185   * @rmtoll CR3          IREN          LL_USART_IsEnabledIrda
2186   * @param  USARTx USART Instance
2187   * @retval State of bit (1 or 0).
2188   */
LL_USART_IsEnabledIrda(const USART_TypeDef * USARTx)2189 __STATIC_INLINE uint32_t LL_USART_IsEnabledIrda(const USART_TypeDef *USARTx)
2190 {
2191   return ((READ_BIT(USARTx->CR3, USART_CR3_IREN) == (USART_CR3_IREN)) ? 1UL : 0UL);
2192 }
2193 
2194 /**
2195   * @brief  Configure IrDA Power Mode (Normal or Low Power)
2196   * @note   Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
2197   *         IrDA feature is supported by the USARTx instance.
2198   * @rmtoll CR3          IRLP          LL_USART_SetIrdaPowerMode
2199   * @param  USARTx USART Instance
2200   * @param  PowerMode This parameter can be one of the following values:
2201   *         @arg @ref LL_USART_IRDA_POWER_NORMAL
2202   *         @arg @ref LL_USART_IRDA_POWER_LOW
2203   * @retval None
2204   */
LL_USART_SetIrdaPowerMode(USART_TypeDef * USARTx,uint32_t PowerMode)2205 __STATIC_INLINE void LL_USART_SetIrdaPowerMode(USART_TypeDef *USARTx, uint32_t PowerMode)
2206 {
2207   MODIFY_REG(USARTx->CR3, USART_CR3_IRLP, PowerMode);
2208 }
2209 
2210 /**
2211   * @brief  Retrieve IrDA Power Mode configuration (Normal or Low Power)
2212   * @note   Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
2213   *         IrDA feature is supported by the USARTx instance.
2214   * @rmtoll CR3          IRLP          LL_USART_GetIrdaPowerMode
2215   * @param  USARTx USART Instance
2216   * @retval Returned value can be one of the following values:
2217   *         @arg @ref LL_USART_IRDA_POWER_NORMAL
2218   *         @arg @ref LL_USART_PHASE_2EDGE
2219   */
LL_USART_GetIrdaPowerMode(const USART_TypeDef * USARTx)2220 __STATIC_INLINE uint32_t LL_USART_GetIrdaPowerMode(const USART_TypeDef *USARTx)
2221 {
2222   return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_IRLP));
2223 }
2224 
2225 /**
2226   * @brief  Set Irda prescaler value, used for dividing the USART clock source
2227   *         to achieve the Irda Low Power frequency (8 bits value)
2228   * @note   Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
2229   *         IrDA feature is supported by the USARTx instance.
2230   * @rmtoll GTPR         PSC           LL_USART_SetIrdaPrescaler
2231   * @param  USARTx USART Instance
2232   * @param  PrescalerValue Value between Min_Data=0x00 and Max_Data=0xFF
2233   * @retval None
2234   */
LL_USART_SetIrdaPrescaler(USART_TypeDef * USARTx,uint32_t PrescalerValue)2235 __STATIC_INLINE void LL_USART_SetIrdaPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
2236 {
2237   MODIFY_REG(USARTx->GTPR, USART_GTPR_PSC, (uint16_t)PrescalerValue);
2238 }
2239 
2240 /**
2241   * @brief  Return Irda prescaler value, used for dividing the USART clock source
2242   *         to achieve the Irda Low Power frequency (8 bits value)
2243   * @note   Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
2244   *         IrDA feature is supported by the USARTx instance.
2245   * @rmtoll GTPR         PSC           LL_USART_GetIrdaPrescaler
2246   * @param  USARTx USART Instance
2247   * @retval Irda prescaler value (Value between Min_Data=0x00 and Max_Data=0xFF)
2248   */
LL_USART_GetIrdaPrescaler(const USART_TypeDef * USARTx)2249 __STATIC_INLINE uint32_t LL_USART_GetIrdaPrescaler(const USART_TypeDef *USARTx)
2250 {
2251   return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_PSC));
2252 }
2253 
2254 /**
2255   * @}
2256   */
2257 
2258 /** @defgroup USART_LL_EF_Configuration_Smartcard Configuration functions related to Smartcard feature
2259   * @{
2260   */
2261 
2262 /**
2263   * @brief  Enable Smartcard NACK transmission
2264   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2265   *         Smartcard feature is supported by the USARTx instance.
2266   * @rmtoll CR3          NACK          LL_USART_EnableSmartcardNACK
2267   * @param  USARTx USART Instance
2268   * @retval None
2269   */
LL_USART_EnableSmartcardNACK(USART_TypeDef * USARTx)2270 __STATIC_INLINE void LL_USART_EnableSmartcardNACK(USART_TypeDef *USARTx)
2271 {
2272   SET_BIT(USARTx->CR3, USART_CR3_NACK);
2273 }
2274 
2275 /**
2276   * @brief  Disable Smartcard NACK transmission
2277   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2278   *         Smartcard feature is supported by the USARTx instance.
2279   * @rmtoll CR3          NACK          LL_USART_DisableSmartcardNACK
2280   * @param  USARTx USART Instance
2281   * @retval None
2282   */
LL_USART_DisableSmartcardNACK(USART_TypeDef * USARTx)2283 __STATIC_INLINE void LL_USART_DisableSmartcardNACK(USART_TypeDef *USARTx)
2284 {
2285   CLEAR_BIT(USARTx->CR3, USART_CR3_NACK);
2286 }
2287 
2288 /**
2289   * @brief  Indicate if Smartcard NACK transmission is enabled
2290   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2291   *         Smartcard feature is supported by the USARTx instance.
2292   * @rmtoll CR3          NACK          LL_USART_IsEnabledSmartcardNACK
2293   * @param  USARTx USART Instance
2294   * @retval State of bit (1 or 0).
2295   */
LL_USART_IsEnabledSmartcardNACK(const USART_TypeDef * USARTx)2296 __STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcardNACK(const USART_TypeDef *USARTx)
2297 {
2298   return ((READ_BIT(USARTx->CR3, USART_CR3_NACK) == (USART_CR3_NACK)) ? 1UL : 0UL);
2299 }
2300 
2301 /**
2302   * @brief  Enable Smartcard mode
2303   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2304   *         Smartcard feature is supported by the USARTx instance.
2305   * @rmtoll CR3          SCEN          LL_USART_EnableSmartcard
2306   * @param  USARTx USART Instance
2307   * @retval None
2308   */
LL_USART_EnableSmartcard(USART_TypeDef * USARTx)2309 __STATIC_INLINE void LL_USART_EnableSmartcard(USART_TypeDef *USARTx)
2310 {
2311   SET_BIT(USARTx->CR3, USART_CR3_SCEN);
2312 }
2313 
2314 /**
2315   * @brief  Disable Smartcard mode
2316   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2317   *         Smartcard feature is supported by the USARTx instance.
2318   * @rmtoll CR3          SCEN          LL_USART_DisableSmartcard
2319   * @param  USARTx USART Instance
2320   * @retval None
2321   */
LL_USART_DisableSmartcard(USART_TypeDef * USARTx)2322 __STATIC_INLINE void LL_USART_DisableSmartcard(USART_TypeDef *USARTx)
2323 {
2324   CLEAR_BIT(USARTx->CR3, USART_CR3_SCEN);
2325 }
2326 
2327 /**
2328   * @brief  Indicate if Smartcard mode is enabled
2329   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2330   *         Smartcard feature is supported by the USARTx instance.
2331   * @rmtoll CR3          SCEN          LL_USART_IsEnabledSmartcard
2332   * @param  USARTx USART Instance
2333   * @retval State of bit (1 or 0).
2334   */
LL_USART_IsEnabledSmartcard(const USART_TypeDef * USARTx)2335 __STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcard(const USART_TypeDef *USARTx)
2336 {
2337   return ((READ_BIT(USARTx->CR3, USART_CR3_SCEN) == (USART_CR3_SCEN)) ? 1UL : 0UL);
2338 }
2339 
2340 /**
2341   * @brief  Set Smartcard Auto-Retry Count value (SCARCNT[2:0] bits)
2342   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2343   *         Smartcard feature is supported by the USARTx instance.
2344   * @note   This bit-field specifies the number of retries in transmit and receive, in Smartcard mode.
2345   *         In transmission mode, it specifies the number of automatic retransmission retries, before
2346   *         generating a transmission error (FE bit set).
2347   *         In reception mode, it specifies the number or erroneous reception trials, before generating a
2348   *         reception error (RXNE and PE bits set)
2349   * @rmtoll CR3          SCARCNT       LL_USART_SetSmartcardAutoRetryCount
2350   * @param  USARTx USART Instance
2351   * @param  AutoRetryCount Value between Min_Data=0 and Max_Data=7
2352   * @retval None
2353   */
LL_USART_SetSmartcardAutoRetryCount(USART_TypeDef * USARTx,uint32_t AutoRetryCount)2354 __STATIC_INLINE void LL_USART_SetSmartcardAutoRetryCount(USART_TypeDef *USARTx, uint32_t AutoRetryCount)
2355 {
2356   MODIFY_REG(USARTx->CR3, USART_CR3_SCARCNT, AutoRetryCount << USART_CR3_SCARCNT_Pos);
2357 }
2358 
2359 /**
2360   * @brief  Return Smartcard Auto-Retry Count value (SCARCNT[2:0] bits)
2361   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2362   *         Smartcard feature is supported by the USARTx instance.
2363   * @rmtoll CR3          SCARCNT       LL_USART_GetSmartcardAutoRetryCount
2364   * @param  USARTx USART Instance
2365   * @retval Smartcard Auto-Retry Count value (Value between Min_Data=0 and Max_Data=7)
2366   */
LL_USART_GetSmartcardAutoRetryCount(const USART_TypeDef * USARTx)2367 __STATIC_INLINE uint32_t LL_USART_GetSmartcardAutoRetryCount(const USART_TypeDef *USARTx)
2368 {
2369   return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_SCARCNT) >> USART_CR3_SCARCNT_Pos);
2370 }
2371 
2372 /**
2373   * @brief  Set Smartcard prescaler value, used for dividing the USART clock
2374   *         source to provide the SMARTCARD Clock (5 bits value)
2375   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2376   *         Smartcard feature is supported by the USARTx instance.
2377   * @rmtoll GTPR         PSC           LL_USART_SetSmartcardPrescaler
2378   * @param  USARTx USART Instance
2379   * @param  PrescalerValue Value between Min_Data=0 and Max_Data=31
2380   * @retval None
2381   */
LL_USART_SetSmartcardPrescaler(USART_TypeDef * USARTx,uint32_t PrescalerValue)2382 __STATIC_INLINE void LL_USART_SetSmartcardPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
2383 {
2384   MODIFY_REG(USARTx->GTPR, USART_GTPR_PSC, (uint16_t)PrescalerValue);
2385 }
2386 
2387 /**
2388   * @brief  Return Smartcard prescaler value, used for dividing the USART clock
2389   *         source to provide the SMARTCARD Clock (5 bits value)
2390   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2391   *         Smartcard feature is supported by the USARTx instance.
2392   * @rmtoll GTPR         PSC           LL_USART_GetSmartcardPrescaler
2393   * @param  USARTx USART Instance
2394   * @retval Smartcard prescaler value (Value between Min_Data=0 and Max_Data=31)
2395   */
LL_USART_GetSmartcardPrescaler(const USART_TypeDef * USARTx)2396 __STATIC_INLINE uint32_t LL_USART_GetSmartcardPrescaler(const USART_TypeDef *USARTx)
2397 {
2398   return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_PSC));
2399 }
2400 
2401 /**
2402   * @brief  Set Smartcard Guard time value, expressed in nb of baud clocks periods
2403   *         (GT[7:0] bits : Guard time value)
2404   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2405   *         Smartcard feature is supported by the USARTx instance.
2406   * @rmtoll GTPR         GT            LL_USART_SetSmartcardGuardTime
2407   * @param  USARTx USART Instance
2408   * @param  GuardTime Value between Min_Data=0x00 and Max_Data=0xFF
2409   * @retval None
2410   */
LL_USART_SetSmartcardGuardTime(USART_TypeDef * USARTx,uint32_t GuardTime)2411 __STATIC_INLINE void LL_USART_SetSmartcardGuardTime(USART_TypeDef *USARTx, uint32_t GuardTime)
2412 {
2413   MODIFY_REG(USARTx->GTPR, USART_GTPR_GT, (uint16_t)(GuardTime << USART_GTPR_GT_Pos));
2414 }
2415 
2416 /**
2417   * @brief  Return Smartcard Guard time value, expressed in nb of baud clocks periods
2418   *         (GT[7:0] bits : Guard time value)
2419   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2420   *         Smartcard feature is supported by the USARTx instance.
2421   * @rmtoll GTPR         GT            LL_USART_GetSmartcardGuardTime
2422   * @param  USARTx USART Instance
2423   * @retval Smartcard Guard time value (Value between Min_Data=0x00 and Max_Data=0xFF)
2424   */
LL_USART_GetSmartcardGuardTime(const USART_TypeDef * USARTx)2425 __STATIC_INLINE uint32_t LL_USART_GetSmartcardGuardTime(const USART_TypeDef *USARTx)
2426 {
2427   return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_GT) >> USART_GTPR_GT_Pos);
2428 }
2429 
2430 /**
2431   * @}
2432   */
2433 
2434 /** @defgroup USART_LL_EF_Configuration_HalfDuplex Configuration functions related to Half Duplex feature
2435   * @{
2436   */
2437 
2438 /**
2439   * @brief  Enable Single Wire Half-Duplex mode
2440   * @note   Macro IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
2441   *         Half-Duplex mode is supported by the USARTx instance.
2442   * @rmtoll CR3          HDSEL         LL_USART_EnableHalfDuplex
2443   * @param  USARTx USART Instance
2444   * @retval None
2445   */
LL_USART_EnableHalfDuplex(USART_TypeDef * USARTx)2446 __STATIC_INLINE void LL_USART_EnableHalfDuplex(USART_TypeDef *USARTx)
2447 {
2448   SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
2449 }
2450 
2451 /**
2452   * @brief  Disable Single Wire Half-Duplex mode
2453   * @note   Macro IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
2454   *         Half-Duplex mode is supported by the USARTx instance.
2455   * @rmtoll CR3          HDSEL         LL_USART_DisableHalfDuplex
2456   * @param  USARTx USART Instance
2457   * @retval None
2458   */
LL_USART_DisableHalfDuplex(USART_TypeDef * USARTx)2459 __STATIC_INLINE void LL_USART_DisableHalfDuplex(USART_TypeDef *USARTx)
2460 {
2461   CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
2462 }
2463 
2464 /**
2465   * @brief  Indicate if Single Wire Half-Duplex mode is enabled
2466   * @note   Macro IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
2467   *         Half-Duplex mode is supported by the USARTx instance.
2468   * @rmtoll CR3          HDSEL         LL_USART_IsEnabledHalfDuplex
2469   * @param  USARTx USART Instance
2470   * @retval State of bit (1 or 0).
2471   */
LL_USART_IsEnabledHalfDuplex(const USART_TypeDef * USARTx)2472 __STATIC_INLINE uint32_t LL_USART_IsEnabledHalfDuplex(const USART_TypeDef *USARTx)
2473 {
2474   return ((READ_BIT(USARTx->CR3, USART_CR3_HDSEL) == (USART_CR3_HDSEL)) ? 1UL : 0UL);
2475 }
2476 
2477 /**
2478   * @}
2479   */
2480 
2481 #if defined(USART_CR2_SLVEN)
2482 /** @defgroup USART_LL_EF_Configuration_SPI_SLAVE Configuration functions related to SPI Slave feature
2483   * @{
2484   */
2485 /**
2486   * @brief  Enable SPI Synchronous Slave mode
2487   * @note   Macro IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
2488   *         SPI Slave mode feature is supported by the USARTx instance.
2489   * @rmtoll CR2          SLVEN         LL_USART_EnableSPISlave
2490   * @param  USARTx USART Instance
2491   * @retval None
2492   */
LL_USART_EnableSPISlave(USART_TypeDef * USARTx)2493 __STATIC_INLINE void LL_USART_EnableSPISlave(USART_TypeDef *USARTx)
2494 {
2495   SET_BIT(USARTx->CR2, USART_CR2_SLVEN);
2496 }
2497 
2498 /**
2499   * @brief  Disable SPI Synchronous Slave mode
2500   * @note   Macro IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
2501   *         SPI Slave mode feature is supported by the USARTx instance.
2502   * @rmtoll CR2          SLVEN         LL_USART_DisableSPISlave
2503   * @param  USARTx USART Instance
2504   * @retval None
2505   */
LL_USART_DisableSPISlave(USART_TypeDef * USARTx)2506 __STATIC_INLINE void LL_USART_DisableSPISlave(USART_TypeDef *USARTx)
2507 {
2508   CLEAR_BIT(USARTx->CR2, USART_CR2_SLVEN);
2509 }
2510 
2511 /**
2512   * @brief  Indicate if  SPI Synchronous Slave mode is enabled
2513   * @note   Macro IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
2514   *         SPI Slave mode feature is supported by the USARTx instance.
2515   * @rmtoll CR2          SLVEN         LL_USART_IsEnabledSPISlave
2516   * @param  USARTx USART Instance
2517   * @retval State of bit (1 or 0).
2518   */
LL_USART_IsEnabledSPISlave(const USART_TypeDef * USARTx)2519 __STATIC_INLINE uint32_t LL_USART_IsEnabledSPISlave(const USART_TypeDef *USARTx)
2520 {
2521   return ((READ_BIT(USARTx->CR2, USART_CR2_SLVEN) == (USART_CR2_SLVEN)) ? 1UL : 0UL);
2522 }
2523 
2524 /**
2525   * @brief  Enable SPI Slave Selection using NSS input pin
2526   * @note   Macro IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
2527   *         SPI Slave mode feature is supported by the USARTx instance.
2528   * @note   SPI Slave Selection depends on NSS input pin
2529   *         (The slave is selected when NSS is low and deselected when NSS is high).
2530   * @rmtoll CR2          DIS_NSS       LL_USART_EnableSPISlaveSelect
2531   * @param  USARTx USART Instance
2532   * @retval None
2533   */
LL_USART_EnableSPISlaveSelect(USART_TypeDef * USARTx)2534 __STATIC_INLINE void LL_USART_EnableSPISlaveSelect(USART_TypeDef *USARTx)
2535 {
2536   CLEAR_BIT(USARTx->CR2, USART_CR2_DIS_NSS);
2537 }
2538 
2539 /**
2540   * @brief  Disable SPI Slave Selection using NSS input pin
2541   * @note   Macro IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
2542   *         SPI Slave mode feature is supported by the USARTx instance.
2543   * @note   SPI Slave will be always selected and NSS input pin will be ignored.
2544   * @rmtoll CR2          DIS_NSS       LL_USART_DisableSPISlaveSelect
2545   * @param  USARTx USART Instance
2546   * @retval None
2547   */
LL_USART_DisableSPISlaveSelect(USART_TypeDef * USARTx)2548 __STATIC_INLINE void LL_USART_DisableSPISlaveSelect(USART_TypeDef *USARTx)
2549 {
2550   SET_BIT(USARTx->CR2, USART_CR2_DIS_NSS);
2551 }
2552 
2553 /**
2554   * @brief  Indicate if  SPI Slave Selection depends on NSS input pin
2555   * @note   Macro IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
2556   *         SPI Slave mode feature is supported by the USARTx instance.
2557   * @rmtoll CR2          DIS_NSS       LL_USART_IsEnabledSPISlaveSelect
2558   * @param  USARTx USART Instance
2559   * @retval State of bit (1 or 0).
2560   */
LL_USART_IsEnabledSPISlaveSelect(const USART_TypeDef * USARTx)2561 __STATIC_INLINE uint32_t LL_USART_IsEnabledSPISlaveSelect(const USART_TypeDef *USARTx)
2562 {
2563   return ((READ_BIT(USARTx->CR2, USART_CR2_DIS_NSS) != (USART_CR2_DIS_NSS)) ? 1UL : 0UL);
2564 }
2565 
2566 /**
2567   * @}
2568   */
2569 
2570 #endif /* USART_CR2_SLVEN */
2571 /** @defgroup USART_LL_EF_Configuration_LIN Configuration functions related to LIN feature
2572   * @{
2573   */
2574 
2575 /**
2576   * @brief  Set LIN Break Detection Length
2577   * @note   Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2578   *         LIN feature is supported by the USARTx instance.
2579   * @rmtoll CR2          LBDL          LL_USART_SetLINBrkDetectionLen
2580   * @param  USARTx USART Instance
2581   * @param  LINBDLength This parameter can be one of the following values:
2582   *         @arg @ref LL_USART_LINBREAK_DETECT_10B
2583   *         @arg @ref LL_USART_LINBREAK_DETECT_11B
2584   * @retval None
2585   */
LL_USART_SetLINBrkDetectionLen(USART_TypeDef * USARTx,uint32_t LINBDLength)2586 __STATIC_INLINE void LL_USART_SetLINBrkDetectionLen(USART_TypeDef *USARTx, uint32_t LINBDLength)
2587 {
2588   MODIFY_REG(USARTx->CR2, USART_CR2_LBDL, LINBDLength);
2589 }
2590 
2591 /**
2592   * @brief  Return LIN Break Detection Length
2593   * @note   Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2594   *         LIN feature is supported by the USARTx instance.
2595   * @rmtoll CR2          LBDL          LL_USART_GetLINBrkDetectionLen
2596   * @param  USARTx USART Instance
2597   * @retval Returned value can be one of the following values:
2598   *         @arg @ref LL_USART_LINBREAK_DETECT_10B
2599   *         @arg @ref LL_USART_LINBREAK_DETECT_11B
2600   */
LL_USART_GetLINBrkDetectionLen(const USART_TypeDef * USARTx)2601 __STATIC_INLINE uint32_t LL_USART_GetLINBrkDetectionLen(const USART_TypeDef *USARTx)
2602 {
2603   return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBDL));
2604 }
2605 
2606 /**
2607   * @brief  Enable LIN mode
2608   * @note   Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2609   *         LIN feature is supported by the USARTx instance.
2610   * @rmtoll CR2          LINEN         LL_USART_EnableLIN
2611   * @param  USARTx USART Instance
2612   * @retval None
2613   */
LL_USART_EnableLIN(USART_TypeDef * USARTx)2614 __STATIC_INLINE void LL_USART_EnableLIN(USART_TypeDef *USARTx)
2615 {
2616   SET_BIT(USARTx->CR2, USART_CR2_LINEN);
2617 }
2618 
2619 /**
2620   * @brief  Disable LIN mode
2621   * @note   Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2622   *         LIN feature is supported by the USARTx instance.
2623   * @rmtoll CR2          LINEN         LL_USART_DisableLIN
2624   * @param  USARTx USART Instance
2625   * @retval None
2626   */
LL_USART_DisableLIN(USART_TypeDef * USARTx)2627 __STATIC_INLINE void LL_USART_DisableLIN(USART_TypeDef *USARTx)
2628 {
2629   CLEAR_BIT(USARTx->CR2, USART_CR2_LINEN);
2630 }
2631 
2632 /**
2633   * @brief  Indicate if LIN mode is enabled
2634   * @note   Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2635   *         LIN feature is supported by the USARTx instance.
2636   * @rmtoll CR2          LINEN         LL_USART_IsEnabledLIN
2637   * @param  USARTx USART Instance
2638   * @retval State of bit (1 or 0).
2639   */
LL_USART_IsEnabledLIN(const USART_TypeDef * USARTx)2640 __STATIC_INLINE uint32_t LL_USART_IsEnabledLIN(const USART_TypeDef *USARTx)
2641 {
2642   return ((READ_BIT(USARTx->CR2, USART_CR2_LINEN) == (USART_CR2_LINEN)) ? 1UL : 0UL);
2643 }
2644 
2645 /**
2646   * @}
2647   */
2648 
2649 /** @defgroup USART_LL_EF_Configuration_DE Configuration functions related to Driver Enable feature
2650   * @{
2651   */
2652 
2653 /**
2654   * @brief  Set DEDT (Driver Enable De-Assertion Time), Time value expressed on 5 bits ([4:0] bits).
2655   * @note   Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
2656   *         Driver Enable feature is supported by the USARTx instance.
2657   * @rmtoll CR1          DEDT          LL_USART_SetDEDeassertionTime
2658   * @param  USARTx USART Instance
2659   * @param  Time Value between Min_Data=0 and Max_Data=31
2660   * @retval None
2661   */
LL_USART_SetDEDeassertionTime(USART_TypeDef * USARTx,uint32_t Time)2662 __STATIC_INLINE void LL_USART_SetDEDeassertionTime(USART_TypeDef *USARTx, uint32_t Time)
2663 {
2664   MODIFY_REG(USARTx->CR1, USART_CR1_DEDT, Time << USART_CR1_DEDT_Pos);
2665 }
2666 
2667 /**
2668   * @brief  Return DEDT (Driver Enable De-Assertion Time)
2669   * @note   Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
2670   *         Driver Enable feature is supported by the USARTx instance.
2671   * @rmtoll CR1          DEDT          LL_USART_GetDEDeassertionTime
2672   * @param  USARTx USART Instance
2673   * @retval Time value expressed on 5 bits ([4:0] bits) : Value between Min_Data=0 and Max_Data=31
2674   */
LL_USART_GetDEDeassertionTime(const USART_TypeDef * USARTx)2675 __STATIC_INLINE uint32_t LL_USART_GetDEDeassertionTime(const USART_TypeDef *USARTx)
2676 {
2677   return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_DEDT) >> USART_CR1_DEDT_Pos);
2678 }
2679 
2680 /**
2681   * @brief  Set DEAT (Driver Enable Assertion Time), Time value expressed on 5 bits ([4:0] bits).
2682   * @note   Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
2683   *         Driver Enable feature is supported by the USARTx instance.
2684   * @rmtoll CR1          DEAT          LL_USART_SetDEAssertionTime
2685   * @param  USARTx USART Instance
2686   * @param  Time Value between Min_Data=0 and Max_Data=31
2687   * @retval None
2688   */
LL_USART_SetDEAssertionTime(USART_TypeDef * USARTx,uint32_t Time)2689 __STATIC_INLINE void LL_USART_SetDEAssertionTime(USART_TypeDef *USARTx, uint32_t Time)
2690 {
2691   MODIFY_REG(USARTx->CR1, USART_CR1_DEAT, Time << USART_CR1_DEAT_Pos);
2692 }
2693 
2694 /**
2695   * @brief  Return DEAT (Driver Enable Assertion Time)
2696   * @note   Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
2697   *         Driver Enable feature is supported by the USARTx instance.
2698   * @rmtoll CR1          DEAT          LL_USART_GetDEAssertionTime
2699   * @param  USARTx USART Instance
2700   * @retval Time value expressed on 5 bits ([4:0] bits) : Value between Min_Data=0 and Max_Data=31
2701   */
LL_USART_GetDEAssertionTime(const USART_TypeDef * USARTx)2702 __STATIC_INLINE uint32_t LL_USART_GetDEAssertionTime(const USART_TypeDef *USARTx)
2703 {
2704   return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_DEAT) >> USART_CR1_DEAT_Pos);
2705 }
2706 
2707 /**
2708   * @brief  Enable Driver Enable (DE) Mode
2709   * @note   Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
2710   *         Driver Enable feature is supported by the USARTx instance.
2711   * @rmtoll CR3          DEM           LL_USART_EnableDEMode
2712   * @param  USARTx USART Instance
2713   * @retval None
2714   */
LL_USART_EnableDEMode(USART_TypeDef * USARTx)2715 __STATIC_INLINE void LL_USART_EnableDEMode(USART_TypeDef *USARTx)
2716 {
2717   SET_BIT(USARTx->CR3, USART_CR3_DEM);
2718 }
2719 
2720 /**
2721   * @brief  Disable Driver Enable (DE) Mode
2722   * @note   Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
2723   *         Driver Enable feature is supported by the USARTx instance.
2724   * @rmtoll CR3          DEM           LL_USART_DisableDEMode
2725   * @param  USARTx USART Instance
2726   * @retval None
2727   */
LL_USART_DisableDEMode(USART_TypeDef * USARTx)2728 __STATIC_INLINE void LL_USART_DisableDEMode(USART_TypeDef *USARTx)
2729 {
2730   CLEAR_BIT(USARTx->CR3, USART_CR3_DEM);
2731 }
2732 
2733 /**
2734   * @brief  Indicate if Driver Enable (DE) Mode is enabled
2735   * @note   Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
2736   *         Driver Enable feature is supported by the USARTx instance.
2737   * @rmtoll CR3          DEM           LL_USART_IsEnabledDEMode
2738   * @param  USARTx USART Instance
2739   * @retval State of bit (1 or 0).
2740   */
LL_USART_IsEnabledDEMode(const USART_TypeDef * USARTx)2741 __STATIC_INLINE uint32_t LL_USART_IsEnabledDEMode(const USART_TypeDef *USARTx)
2742 {
2743   return ((READ_BIT(USARTx->CR3, USART_CR3_DEM) == (USART_CR3_DEM)) ? 1UL : 0UL);
2744 }
2745 
2746 /**
2747   * @brief  Select Driver Enable Polarity
2748   * @note   Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
2749   *         Driver Enable feature is supported by the USARTx instance.
2750   * @rmtoll CR3          DEP           LL_USART_SetDESignalPolarity
2751   * @param  USARTx USART Instance
2752   * @param  Polarity This parameter can be one of the following values:
2753   *         @arg @ref LL_USART_DE_POLARITY_HIGH
2754   *         @arg @ref LL_USART_DE_POLARITY_LOW
2755   * @retval None
2756   */
LL_USART_SetDESignalPolarity(USART_TypeDef * USARTx,uint32_t Polarity)2757 __STATIC_INLINE void LL_USART_SetDESignalPolarity(USART_TypeDef *USARTx, uint32_t Polarity)
2758 {
2759   MODIFY_REG(USARTx->CR3, USART_CR3_DEP, Polarity);
2760 }
2761 
2762 /**
2763   * @brief  Return Driver Enable Polarity
2764   * @note   Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
2765   *         Driver Enable feature is supported by the USARTx instance.
2766   * @rmtoll CR3          DEP           LL_USART_GetDESignalPolarity
2767   * @param  USARTx USART Instance
2768   * @retval Returned value can be one of the following values:
2769   *         @arg @ref LL_USART_DE_POLARITY_HIGH
2770   *         @arg @ref LL_USART_DE_POLARITY_LOW
2771   */
LL_USART_GetDESignalPolarity(const USART_TypeDef * USARTx)2772 __STATIC_INLINE uint32_t LL_USART_GetDESignalPolarity(const USART_TypeDef *USARTx)
2773 {
2774   return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_DEP));
2775 }
2776 
2777 /**
2778   * @}
2779   */
2780 
2781 /** @defgroup USART_LL_EF_AdvancedConfiguration Advanced Configurations services
2782   * @{
2783   */
2784 
2785 /**
2786   * @brief  Perform basic configuration of USART for enabling use in Asynchronous Mode (UART)
2787   * @note   In UART mode, the following bits must be kept cleared:
2788   *           - LINEN bit in the USART_CR2 register,
2789   *           - CLKEN bit in the USART_CR2 register,
2790   *           - SCEN bit in the USART_CR3 register,
2791   *           - IREN bit in the USART_CR3 register,
2792   *           - HDSEL bit in the USART_CR3 register.
2793   * @note   Call of this function is equivalent to following function call sequence :
2794   *         - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
2795   *         - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
2796   *         - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
2797   *         - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
2798   *         - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
2799   * @note   Other remaining configurations items related to Asynchronous Mode
2800   *         (as Baud Rate, Word length, Parity, ...) should be set using
2801   *         dedicated functions
2802   * @rmtoll CR2          LINEN         LL_USART_ConfigAsyncMode\n
2803   *         CR2          CLKEN         LL_USART_ConfigAsyncMode\n
2804   *         CR3          SCEN          LL_USART_ConfigAsyncMode\n
2805   *         CR3          IREN          LL_USART_ConfigAsyncMode\n
2806   *         CR3          HDSEL         LL_USART_ConfigAsyncMode
2807   * @param  USARTx USART Instance
2808   * @retval None
2809   */
LL_USART_ConfigAsyncMode(USART_TypeDef * USARTx)2810 __STATIC_INLINE void LL_USART_ConfigAsyncMode(USART_TypeDef *USARTx)
2811 {
2812   /* In Asynchronous mode, the following bits must be kept cleared:
2813   - LINEN, CLKEN bits in the USART_CR2 register,
2814   - SCEN, IREN and HDSEL bits in the USART_CR3 register.
2815   */
2816   CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
2817   CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN | USART_CR3_HDSEL));
2818 }
2819 
2820 /**
2821   * @brief  Perform basic configuration of USART for enabling use in Synchronous Mode
2822   * @note   In Synchronous mode, the following bits must be kept cleared:
2823   *           - LINEN bit in the USART_CR2 register,
2824   *           - SCEN bit in the USART_CR3 register,
2825   *           - IREN bit in the USART_CR3 register,
2826   *           - HDSEL bit in the USART_CR3 register.
2827   *         This function also sets the USART in Synchronous mode.
2828   * @note   Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
2829   *         Synchronous mode is supported by the USARTx instance.
2830   * @note   Call of this function is equivalent to following function call sequence :
2831   *         - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
2832   *         - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
2833   *         - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
2834   *         - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
2835   *         - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
2836   * @note   Other remaining configurations items related to Synchronous Mode
2837   *         (as Baud Rate, Word length, Parity, Clock Polarity, ...) should be set using
2838   *         dedicated functions
2839   * @rmtoll CR2          LINEN         LL_USART_ConfigSyncMode\n
2840   *         CR2          CLKEN         LL_USART_ConfigSyncMode\n
2841   *         CR3          SCEN          LL_USART_ConfigSyncMode\n
2842   *         CR3          IREN          LL_USART_ConfigSyncMode\n
2843   *         CR3          HDSEL         LL_USART_ConfigSyncMode
2844   * @param  USARTx USART Instance
2845   * @retval None
2846   */
LL_USART_ConfigSyncMode(USART_TypeDef * USARTx)2847 __STATIC_INLINE void LL_USART_ConfigSyncMode(USART_TypeDef *USARTx)
2848 {
2849   /* In Synchronous mode, the following bits must be kept cleared:
2850   - LINEN bit in the USART_CR2 register,
2851   - SCEN, IREN and HDSEL bits in the USART_CR3 register.
2852   */
2853   CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN));
2854   CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN | USART_CR3_HDSEL));
2855   /* set the UART/USART in Synchronous mode */
2856   SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
2857 }
2858 
2859 /**
2860   * @brief  Perform basic configuration of USART for enabling use in LIN Mode
2861   * @note   In LIN mode, the following bits must be kept cleared:
2862   *           - STOP and CLKEN bits in the USART_CR2 register,
2863   *           - SCEN bit in the USART_CR3 register,
2864   *           - IREN bit in the USART_CR3 register,
2865   *           - HDSEL bit in the USART_CR3 register.
2866   *         This function also set the UART/USART in LIN mode.
2867   * @note   Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2868   *         LIN feature is supported by the USARTx instance.
2869   * @note   Call of this function is equivalent to following function call sequence :
2870   *         - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
2871   *         - Clear STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
2872   *         - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
2873   *         - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
2874   *         - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
2875   *         - Set LINEN in CR2 using @ref LL_USART_EnableLIN() function
2876   * @note   Other remaining configurations items related to LIN Mode
2877   *         (as Baud Rate, Word length, LIN Break Detection Length, ...) should be set using
2878   *         dedicated functions
2879   * @rmtoll CR2          CLKEN         LL_USART_ConfigLINMode\n
2880   *         CR2          STOP          LL_USART_ConfigLINMode\n
2881   *         CR2          LINEN         LL_USART_ConfigLINMode\n
2882   *         CR3          IREN          LL_USART_ConfigLINMode\n
2883   *         CR3          SCEN          LL_USART_ConfigLINMode\n
2884   *         CR3          HDSEL         LL_USART_ConfigLINMode
2885   * @param  USARTx USART Instance
2886   * @retval None
2887   */
LL_USART_ConfigLINMode(USART_TypeDef * USARTx)2888 __STATIC_INLINE void LL_USART_ConfigLINMode(USART_TypeDef *USARTx)
2889 {
2890   /* In LIN mode, the following bits must be kept cleared:
2891   - STOP and CLKEN bits in the USART_CR2 register,
2892   - IREN, SCEN and HDSEL bits in the USART_CR3 register.
2893   */
2894   CLEAR_BIT(USARTx->CR2, (USART_CR2_CLKEN | USART_CR2_STOP));
2895   CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_SCEN | USART_CR3_HDSEL));
2896   /* Set the UART/USART in LIN mode */
2897   SET_BIT(USARTx->CR2, USART_CR2_LINEN);
2898 }
2899 
2900 /**
2901   * @brief  Perform basic configuration of USART for enabling use in Half Duplex Mode
2902   * @note   In Half Duplex mode, the following bits must be kept cleared:
2903   *           - LINEN bit in the USART_CR2 register,
2904   *           - CLKEN bit in the USART_CR2 register,
2905   *           - SCEN bit in the USART_CR3 register,
2906   *           - IREN bit in the USART_CR3 register,
2907   *         This function also sets the UART/USART in Half Duplex mode.
2908   * @note   Macro IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
2909   *         Half-Duplex mode is supported by the USARTx instance.
2910   * @note   Call of this function is equivalent to following function call sequence :
2911   *         - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
2912   *         - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
2913   *         - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
2914   *         - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
2915   *         - Set HDSEL in CR3 using @ref LL_USART_EnableHalfDuplex() function
2916   * @note   Other remaining configurations items related to Half Duplex Mode
2917   *         (as Baud Rate, Word length, Parity, ...) should be set using
2918   *         dedicated functions
2919   * @rmtoll CR2          LINEN         LL_USART_ConfigHalfDuplexMode\n
2920   *         CR2          CLKEN         LL_USART_ConfigHalfDuplexMode\n
2921   *         CR3          HDSEL         LL_USART_ConfigHalfDuplexMode\n
2922   *         CR3          SCEN          LL_USART_ConfigHalfDuplexMode\n
2923   *         CR3          IREN          LL_USART_ConfigHalfDuplexMode
2924   * @param  USARTx USART Instance
2925   * @retval None
2926   */
LL_USART_ConfigHalfDuplexMode(USART_TypeDef * USARTx)2927 __STATIC_INLINE void LL_USART_ConfigHalfDuplexMode(USART_TypeDef *USARTx)
2928 {
2929   /* In Half Duplex mode, the following bits must be kept cleared:
2930   - LINEN and CLKEN bits in the USART_CR2 register,
2931   - SCEN and IREN bits in the USART_CR3 register.
2932   */
2933   CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
2934   CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN));
2935   /* set the UART/USART in Half Duplex mode */
2936   SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
2937 }
2938 
2939 /**
2940   * @brief  Perform basic configuration of USART for enabling use in Smartcard Mode
2941   * @note   In Smartcard mode, the following bits must be kept cleared:
2942   *           - LINEN bit in the USART_CR2 register,
2943   *           - IREN bit in the USART_CR3 register,
2944   *           - HDSEL bit in the USART_CR3 register.
2945   *         This function also configures Stop bits to 1.5 bits and
2946   *         sets the USART in Smartcard mode (SCEN bit).
2947   *         Clock Output is also enabled (CLKEN).
2948   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
2949   *         Smartcard feature is supported by the USARTx instance.
2950   * @note   Call of this function is equivalent to following function call sequence :
2951   *         - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
2952   *         - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
2953   *         - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
2954   *         - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
2955   *         - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
2956   *         - Set SCEN in CR3 using @ref LL_USART_EnableSmartcard() function
2957   * @note   Other remaining configurations items related to Smartcard Mode
2958   *         (as Baud Rate, Word length, Parity, ...) should be set using
2959   *         dedicated functions
2960   * @rmtoll CR2          LINEN         LL_USART_ConfigSmartcardMode\n
2961   *         CR2          STOP          LL_USART_ConfigSmartcardMode\n
2962   *         CR2          CLKEN         LL_USART_ConfigSmartcardMode\n
2963   *         CR3          HDSEL         LL_USART_ConfigSmartcardMode\n
2964   *         CR3          SCEN          LL_USART_ConfigSmartcardMode
2965   * @param  USARTx USART Instance
2966   * @retval None
2967   */
LL_USART_ConfigSmartcardMode(USART_TypeDef * USARTx)2968 __STATIC_INLINE void LL_USART_ConfigSmartcardMode(USART_TypeDef *USARTx)
2969 {
2970   /* In Smartcard mode, the following bits must be kept cleared:
2971   - LINEN bit in the USART_CR2 register,
2972   - IREN and HDSEL bits in the USART_CR3 register.
2973   */
2974   CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN));
2975   CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_HDSEL));
2976   /* Configure Stop bits to 1.5 bits */
2977   /* Synchronous mode is activated by default */
2978   SET_BIT(USARTx->CR2, (USART_CR2_STOP_0 | USART_CR2_STOP_1 | USART_CR2_CLKEN));
2979   /* set the UART/USART in Smartcard mode */
2980   SET_BIT(USARTx->CR3, USART_CR3_SCEN);
2981 }
2982 
2983 /**
2984   * @brief  Perform basic configuration of USART for enabling use in Irda Mode
2985   * @note   In IRDA mode, the following bits must be kept cleared:
2986   *           - LINEN bit in the USART_CR2 register,
2987   *           - STOP and CLKEN bits in the USART_CR2 register,
2988   *           - SCEN bit in the USART_CR3 register,
2989   *           - HDSEL bit in the USART_CR3 register.
2990   *         This function also sets the UART/USART in IRDA mode (IREN bit).
2991   * @note   Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
2992   *         IrDA feature is supported by the USARTx instance.
2993   * @note   Call of this function is equivalent to following function call sequence :
2994   *         - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
2995   *         - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
2996   *         - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
2997   *         - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
2998   *         - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
2999   *         - Set IREN in CR3 using @ref LL_USART_EnableIrda() function
3000   * @note   Other remaining configurations items related to Irda Mode
3001   *         (as Baud Rate, Word length, Power mode, ...) should be set using
3002   *         dedicated functions
3003   * @rmtoll CR2          LINEN         LL_USART_ConfigIrdaMode\n
3004   *         CR2          CLKEN         LL_USART_ConfigIrdaMode\n
3005   *         CR2          STOP          LL_USART_ConfigIrdaMode\n
3006   *         CR3          SCEN          LL_USART_ConfigIrdaMode\n
3007   *         CR3          HDSEL         LL_USART_ConfigIrdaMode\n
3008   *         CR3          IREN          LL_USART_ConfigIrdaMode
3009   * @param  USARTx USART Instance
3010   * @retval None
3011   */
LL_USART_ConfigIrdaMode(USART_TypeDef * USARTx)3012 __STATIC_INLINE void LL_USART_ConfigIrdaMode(USART_TypeDef *USARTx)
3013 {
3014   /* In IRDA mode, the following bits must be kept cleared:
3015   - LINEN, STOP and CLKEN bits in the USART_CR2 register,
3016   - SCEN and HDSEL bits in the USART_CR3 register.
3017   */
3018   CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP));
3019   CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
3020   /* set the UART/USART in IRDA mode */
3021   SET_BIT(USARTx->CR3, USART_CR3_IREN);
3022 }
3023 
3024 /**
3025   * @brief  Perform basic configuration of USART for enabling use in Multi processor Mode
3026   *         (several USARTs connected in a network, one of the USARTs can be the master,
3027   *         its TX output connected to the RX inputs of the other slaves USARTs).
3028   * @note   In MultiProcessor mode, the following bits must be kept cleared:
3029   *           - LINEN bit in the USART_CR2 register,
3030   *           - CLKEN bit in the USART_CR2 register,
3031   *           - SCEN bit in the USART_CR3 register,
3032   *           - IREN bit in the USART_CR3 register,
3033   *           - HDSEL bit in the USART_CR3 register.
3034   * @note   Call of this function is equivalent to following function call sequence :
3035   *         - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
3036   *         - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
3037   *         - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
3038   *         - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
3039   *         - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
3040   * @note   Other remaining configurations items related to Multi processor Mode
3041   *         (as Baud Rate, Wake Up Method, Node address, ...) should be set using
3042   *         dedicated functions
3043   * @rmtoll CR2          LINEN         LL_USART_ConfigMultiProcessMode\n
3044   *         CR2          CLKEN         LL_USART_ConfigMultiProcessMode\n
3045   *         CR3          SCEN          LL_USART_ConfigMultiProcessMode\n
3046   *         CR3          HDSEL         LL_USART_ConfigMultiProcessMode\n
3047   *         CR3          IREN          LL_USART_ConfigMultiProcessMode
3048   * @param  USARTx USART Instance
3049   * @retval None
3050   */
LL_USART_ConfigMultiProcessMode(USART_TypeDef * USARTx)3051 __STATIC_INLINE void LL_USART_ConfigMultiProcessMode(USART_TypeDef *USARTx)
3052 {
3053   /* In Multi Processor mode, the following bits must be kept cleared:
3054   - LINEN and CLKEN bits in the USART_CR2 register,
3055   - IREN, SCEN and HDSEL bits in the USART_CR3 register.
3056   */
3057   CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
3058   CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
3059 }
3060 
3061 /**
3062   * @}
3063   */
3064 
3065 /** @defgroup USART_LL_EF_FLAG_Management FLAG_Management
3066   * @{
3067   */
3068 
3069 /**
3070   * @brief  Check if the USART Parity Error Flag is set or not
3071   * @rmtoll ISR          PE            LL_USART_IsActiveFlag_PE
3072   * @param  USARTx USART Instance
3073   * @retval State of bit (1 or 0).
3074   */
LL_USART_IsActiveFlag_PE(const USART_TypeDef * USARTx)3075 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_PE(const USART_TypeDef *USARTx)
3076 {
3077   return ((READ_BIT(USARTx->ISR, USART_ISR_PE) == (USART_ISR_PE)) ? 1UL : 0UL);
3078 }
3079 
3080 /**
3081   * @brief  Check if the USART Framing Error Flag is set or not
3082   * @rmtoll ISR          FE            LL_USART_IsActiveFlag_FE
3083   * @param  USARTx USART Instance
3084   * @retval State of bit (1 or 0).
3085   */
LL_USART_IsActiveFlag_FE(const USART_TypeDef * USARTx)3086 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_FE(const USART_TypeDef *USARTx)
3087 {
3088   return ((READ_BIT(USARTx->ISR, USART_ISR_FE) == (USART_ISR_FE)) ? 1UL : 0UL);
3089 }
3090 
3091 /**
3092   * @brief  Check if the USART Noise error detected Flag is set or not
3093   * @rmtoll ISR          NE            LL_USART_IsActiveFlag_NE
3094   * @param  USARTx USART Instance
3095   * @retval State of bit (1 or 0).
3096   */
LL_USART_IsActiveFlag_NE(const USART_TypeDef * USARTx)3097 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_NE(const USART_TypeDef *USARTx)
3098 {
3099   return ((READ_BIT(USARTx->ISR, USART_ISR_NE) == (USART_ISR_NE)) ? 1UL : 0UL);
3100 }
3101 
3102 /**
3103   * @brief  Check if the USART OverRun Error Flag is set or not
3104   * @rmtoll ISR          ORE           LL_USART_IsActiveFlag_ORE
3105   * @param  USARTx USART Instance
3106   * @retval State of bit (1 or 0).
3107   */
LL_USART_IsActiveFlag_ORE(const USART_TypeDef * USARTx)3108 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ORE(const USART_TypeDef *USARTx)
3109 {
3110   return ((READ_BIT(USARTx->ISR, USART_ISR_ORE) == (USART_ISR_ORE)) ? 1UL : 0UL);
3111 }
3112 
3113 /**
3114   * @brief  Check if the USART IDLE line detected Flag is set or not
3115   * @rmtoll ISR          IDLE          LL_USART_IsActiveFlag_IDLE
3116   * @param  USARTx USART Instance
3117   * @retval State of bit (1 or 0).
3118   */
LL_USART_IsActiveFlag_IDLE(const USART_TypeDef * USARTx)3119 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_IDLE(const USART_TypeDef *USARTx)
3120 {
3121   return ((READ_BIT(USARTx->ISR, USART_ISR_IDLE) == (USART_ISR_IDLE)) ? 1UL : 0UL);
3122 }
3123 
3124 #if defined(USART_CR1_FIFOEN)
3125 #define LL_USART_IsActiveFlag_RXNE  LL_USART_IsActiveFlag_RXNE_RXFNE /* Redefinition for legacy purpose */
3126 
3127 /**
3128   * @brief  Check if the USART Read Data Register or USART RX FIFO Not Empty Flag is set or not
3129   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3130   *         FIFO mode feature is supported by the USARTx instance.
3131   * @rmtoll ISR          RXNE_RXFNE    LL_USART_IsActiveFlag_RXNE_RXFNE
3132   * @param  USARTx USART Instance
3133   * @retval State of bit (1 or 0).
3134   */
LL_USART_IsActiveFlag_RXNE_RXFNE(const USART_TypeDef * USARTx)3135 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RXNE_RXFNE(const USART_TypeDef *USARTx)
3136 {
3137   return ((READ_BIT(USARTx->ISR, USART_ISR_RXNE_RXFNE) == (USART_ISR_RXNE_RXFNE)) ? 1UL : 0UL);
3138 }
3139 
3140 #else
3141 /**
3142   * @brief  Check if the USART Read Data Register Not Empty Flag is set or not
3143   * @rmtoll ISR          RXNE          LL_USART_IsActiveFlag_RXNE
3144   * @param  USARTx USART Instance
3145   * @retval State of bit (1 or 0).
3146   */
LL_USART_IsActiveFlag_RXNE(const USART_TypeDef * USARTx)3147 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RXNE(const USART_TypeDef *USARTx)
3148 {
3149   return ((READ_BIT(USARTx->ISR, USART_ISR_RXNE) == (USART_ISR_RXNE)) ? 1UL : 0UL);
3150 }
3151 
3152 #endif /* USART_CR1_FIFOEN */
3153 /**
3154   * @brief  Check if the USART Transmission Complete Flag is set or not
3155   * @rmtoll ISR          TC            LL_USART_IsActiveFlag_TC
3156   * @param  USARTx USART Instance
3157   * @retval State of bit (1 or 0).
3158   */
LL_USART_IsActiveFlag_TC(const USART_TypeDef * USARTx)3159 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TC(const USART_TypeDef *USARTx)
3160 {
3161   return ((READ_BIT(USARTx->ISR, USART_ISR_TC) == (USART_ISR_TC)) ? 1UL : 0UL);
3162 }
3163 
3164 #if defined(USART_CR1_FIFOEN)
3165 #define LL_USART_IsActiveFlag_TXE  LL_USART_IsActiveFlag_TXE_TXFNF /* Redefinition for legacy purpose */
3166 
3167 /**
3168   * @brief  Check if the USART Transmit Data Register Empty or USART TX FIFO Not Full Flag is set or not
3169   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3170   *         FIFO mode feature is supported by the USARTx instance.
3171   * @rmtoll ISR          TXE_TXFNF     LL_USART_IsActiveFlag_TXE_TXFNF
3172   * @param  USARTx USART Instance
3173   * @retval State of bit (1 or 0).
3174   */
LL_USART_IsActiveFlag_TXE_TXFNF(const USART_TypeDef * USARTx)3175 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXE_TXFNF(const USART_TypeDef *USARTx)
3176 {
3177   return ((READ_BIT(USARTx->ISR, USART_ISR_TXE_TXFNF) == (USART_ISR_TXE_TXFNF)) ? 1UL : 0UL);
3178 }
3179 
3180 #else
3181 /**
3182   * @brief  Check if the USART Transmit Data Register Empty Flag is set or not
3183   * @rmtoll ISR          TXE           LL_USART_IsActiveFlag_TXE
3184   * @param  USARTx USART Instance
3185   * @retval State of bit (1 or 0).
3186   */
LL_USART_IsActiveFlag_TXE(const USART_TypeDef * USARTx)3187 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXE(const USART_TypeDef *USARTx)
3188 {
3189   return ((READ_BIT(USARTx->ISR, USART_ISR_TXE) == (USART_ISR_TXE)) ? 1UL : 0UL);
3190 }
3191 
3192 #endif /* USART_CR1_FIFOEN */
3193 /**
3194   * @brief  Check if the USART LIN Break Detection Flag is set or not
3195   * @note   Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
3196   *         LIN feature is supported by the USARTx instance.
3197   * @rmtoll ISR          LBDF          LL_USART_IsActiveFlag_LBD
3198   * @param  USARTx USART Instance
3199   * @retval State of bit (1 or 0).
3200   */
LL_USART_IsActiveFlag_LBD(const USART_TypeDef * USARTx)3201 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_LBD(const USART_TypeDef *USARTx)
3202 {
3203   return ((READ_BIT(USARTx->ISR, USART_ISR_LBDF) == (USART_ISR_LBDF)) ? 1UL : 0UL);
3204 }
3205 
3206 /**
3207   * @brief  Check if the USART CTS interrupt Flag is set or not
3208   * @note   Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
3209   *         Hardware Flow control feature is supported by the USARTx instance.
3210   * @rmtoll ISR          CTSIF         LL_USART_IsActiveFlag_nCTS
3211   * @param  USARTx USART Instance
3212   * @retval State of bit (1 or 0).
3213   */
LL_USART_IsActiveFlag_nCTS(const USART_TypeDef * USARTx)3214 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_nCTS(const USART_TypeDef *USARTx)
3215 {
3216   return ((READ_BIT(USARTx->ISR, USART_ISR_CTSIF) == (USART_ISR_CTSIF)) ? 1UL : 0UL);
3217 }
3218 
3219 /**
3220   * @brief  Check if the USART CTS Flag is set or not
3221   * @note   Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
3222   *         Hardware Flow control feature is supported by the USARTx instance.
3223   * @rmtoll ISR          CTS           LL_USART_IsActiveFlag_CTS
3224   * @param  USARTx USART Instance
3225   * @retval State of bit (1 or 0).
3226   */
LL_USART_IsActiveFlag_CTS(const USART_TypeDef * USARTx)3227 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_CTS(const USART_TypeDef *USARTx)
3228 {
3229   return ((READ_BIT(USARTx->ISR, USART_ISR_CTS) == (USART_ISR_CTS)) ? 1UL : 0UL);
3230 }
3231 
3232 /**
3233   * @brief  Check if the USART Receiver Time Out Flag is set or not
3234   * @rmtoll ISR          RTOF          LL_USART_IsActiveFlag_RTO
3235   * @param  USARTx USART Instance
3236   * @retval State of bit (1 or 0).
3237   */
LL_USART_IsActiveFlag_RTO(const USART_TypeDef * USARTx)3238 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RTO(const USART_TypeDef *USARTx)
3239 {
3240   return ((READ_BIT(USARTx->ISR, USART_ISR_RTOF) == (USART_ISR_RTOF)) ? 1UL : 0UL);
3241 }
3242 
3243 /**
3244   * @brief  Check if the USART End Of Block Flag is set or not
3245   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
3246   *         Smartcard feature is supported by the USARTx instance.
3247   * @rmtoll ISR          EOBF          LL_USART_IsActiveFlag_EOB
3248   * @param  USARTx USART Instance
3249   * @retval State of bit (1 or 0).
3250   */
LL_USART_IsActiveFlag_EOB(const USART_TypeDef * USARTx)3251 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_EOB(const USART_TypeDef *USARTx)
3252 {
3253   return ((READ_BIT(USARTx->ISR, USART_ISR_EOBF) == (USART_ISR_EOBF)) ? 1UL : 0UL);
3254 }
3255 
3256 #if defined(USART_CR2_SLVEN)
3257 /**
3258   * @brief  Check if the SPI Slave Underrun error flag is set or not
3259   * @note   Macro IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
3260   *         SPI Slave mode feature is supported by the USARTx instance.
3261   * @rmtoll ISR          UDR           LL_USART_IsActiveFlag_UDR
3262   * @param  USARTx USART Instance
3263   * @retval State of bit (1 or 0).
3264   */
LL_USART_IsActiveFlag_UDR(const USART_TypeDef * USARTx)3265 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_UDR(const USART_TypeDef *USARTx)
3266 {
3267   return ((READ_BIT(USARTx->ISR, USART_ISR_UDR) == (USART_ISR_UDR)) ? 1UL : 0UL);
3268 }
3269 
3270 #endif /* USART_CR2_SLVEN */
3271 /**
3272   * @brief  Check if the USART Auto-Baud Rate Error Flag is set or not
3273   * @note   Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
3274   *         Auto Baud Rate detection feature is supported by the USARTx instance.
3275   * @rmtoll ISR          ABRE          LL_USART_IsActiveFlag_ABRE
3276   * @param  USARTx USART Instance
3277   * @retval State of bit (1 or 0).
3278   */
LL_USART_IsActiveFlag_ABRE(const USART_TypeDef * USARTx)3279 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ABRE(const USART_TypeDef *USARTx)
3280 {
3281   return ((READ_BIT(USARTx->ISR, USART_ISR_ABRE) == (USART_ISR_ABRE)) ? 1UL : 0UL);
3282 }
3283 
3284 /**
3285   * @brief  Check if the USART Auto-Baud Rate Flag is set or not
3286   * @note   Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
3287   *         Auto Baud Rate detection feature is supported by the USARTx instance.
3288   * @rmtoll ISR          ABRF          LL_USART_IsActiveFlag_ABR
3289   * @param  USARTx USART Instance
3290   * @retval State of bit (1 or 0).
3291   */
LL_USART_IsActiveFlag_ABR(const USART_TypeDef * USARTx)3292 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ABR(const USART_TypeDef *USARTx)
3293 {
3294   return ((READ_BIT(USARTx->ISR, USART_ISR_ABRF) == (USART_ISR_ABRF)) ? 1UL : 0UL);
3295 }
3296 
3297 /**
3298   * @brief  Check if the USART Busy Flag is set or not
3299   * @rmtoll ISR          BUSY          LL_USART_IsActiveFlag_BUSY
3300   * @param  USARTx USART Instance
3301   * @retval State of bit (1 or 0).
3302   */
LL_USART_IsActiveFlag_BUSY(const USART_TypeDef * USARTx)3303 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_BUSY(const USART_TypeDef *USARTx)
3304 {
3305   return ((READ_BIT(USARTx->ISR, USART_ISR_BUSY) == (USART_ISR_BUSY)) ? 1UL : 0UL);
3306 }
3307 
3308 /**
3309   * @brief  Check if the USART Character Match Flag is set or not
3310   * @rmtoll ISR          CMF           LL_USART_IsActiveFlag_CM
3311   * @param  USARTx USART Instance
3312   * @retval State of bit (1 or 0).
3313   */
LL_USART_IsActiveFlag_CM(const USART_TypeDef * USARTx)3314 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_CM(const USART_TypeDef *USARTx)
3315 {
3316   return ((READ_BIT(USARTx->ISR, USART_ISR_CMF) == (USART_ISR_CMF)) ? 1UL : 0UL);
3317 }
3318 
3319 /**
3320   * @brief  Check if the USART Send Break Flag is set or not
3321   * @rmtoll ISR          SBKF          LL_USART_IsActiveFlag_SBK
3322   * @param  USARTx USART Instance
3323   * @retval State of bit (1 or 0).
3324   */
LL_USART_IsActiveFlag_SBK(const USART_TypeDef * USARTx)3325 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_SBK(const USART_TypeDef *USARTx)
3326 {
3327   return ((READ_BIT(USARTx->ISR, USART_ISR_SBKF) == (USART_ISR_SBKF)) ? 1UL : 0UL);
3328 }
3329 
3330 /**
3331   * @brief  Check if the USART Receive Wake Up from mute mode Flag is set or not
3332   * @rmtoll ISR          RWU           LL_USART_IsActiveFlag_RWU
3333   * @param  USARTx USART Instance
3334   * @retval State of bit (1 or 0).
3335   */
LL_USART_IsActiveFlag_RWU(const USART_TypeDef * USARTx)3336 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RWU(const USART_TypeDef *USARTx)
3337 {
3338   return ((READ_BIT(USARTx->ISR, USART_ISR_RWU) == (USART_ISR_RWU)) ? 1UL : 0UL);
3339 }
3340 
3341 /**
3342   * @brief  Check if the USART Wake Up from stop mode Flag is set or not
3343   * @note   Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
3344   *         Wake-up from Stop mode feature is supported by the USARTx instance.
3345   * @rmtoll ISR          WUF           LL_USART_IsActiveFlag_WKUP
3346   * @param  USARTx USART Instance
3347   * @retval State of bit (1 or 0).
3348   */
LL_USART_IsActiveFlag_WKUP(const USART_TypeDef * USARTx)3349 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_WKUP(const USART_TypeDef *USARTx)
3350 {
3351   return ((READ_BIT(USARTx->ISR, USART_ISR_WUF) == (USART_ISR_WUF)) ? 1UL : 0UL);
3352 }
3353 
3354 /**
3355   * @brief  Check if the USART Transmit Enable Acknowledge Flag is set or not
3356   * @rmtoll ISR          TEACK         LL_USART_IsActiveFlag_TEACK
3357   * @param  USARTx USART Instance
3358   * @retval State of bit (1 or 0).
3359   */
LL_USART_IsActiveFlag_TEACK(const USART_TypeDef * USARTx)3360 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TEACK(const USART_TypeDef *USARTx)
3361 {
3362   return ((READ_BIT(USARTx->ISR, USART_ISR_TEACK) == (USART_ISR_TEACK)) ? 1UL : 0UL);
3363 }
3364 
3365 /**
3366   * @brief  Check if the USART Receive Enable Acknowledge Flag is set or not
3367   * @rmtoll ISR          REACK         LL_USART_IsActiveFlag_REACK
3368   * @param  USARTx USART Instance
3369   * @retval State of bit (1 or 0).
3370   */
LL_USART_IsActiveFlag_REACK(const USART_TypeDef * USARTx)3371 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_REACK(const USART_TypeDef *USARTx)
3372 {
3373   return ((READ_BIT(USARTx->ISR, USART_ISR_REACK) == (USART_ISR_REACK)) ? 1UL : 0UL);
3374 }
3375 
3376 #if defined(USART_CR1_FIFOEN)
3377 /**
3378   * @brief  Check if the USART TX FIFO Empty Flag is set or not
3379   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3380   *         FIFO mode feature is supported by the USARTx instance.
3381   * @rmtoll ISR          TXFE          LL_USART_IsActiveFlag_TXFE
3382   * @param  USARTx USART Instance
3383   * @retval State of bit (1 or 0).
3384   */
LL_USART_IsActiveFlag_TXFE(const USART_TypeDef * USARTx)3385 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXFE(const USART_TypeDef *USARTx)
3386 {
3387   return ((READ_BIT(USARTx->ISR, USART_ISR_TXFE) == (USART_ISR_TXFE)) ? 1UL : 0UL);
3388 }
3389 
3390 /**
3391   * @brief  Check if the USART RX FIFO Full Flag is set or not
3392   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3393   *         FIFO mode feature is supported by the USARTx instance.
3394   * @rmtoll ISR          RXFF          LL_USART_IsActiveFlag_RXFF
3395   * @param  USARTx USART Instance
3396   * @retval State of bit (1 or 0).
3397   */
LL_USART_IsActiveFlag_RXFF(const USART_TypeDef * USARTx)3398 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RXFF(const USART_TypeDef *USARTx)
3399 {
3400   return ((READ_BIT(USARTx->ISR, USART_ISR_RXFF) == (USART_ISR_RXFF)) ? 1UL : 0UL);
3401 }
3402 
3403 #endif /* USART_CR1_FIFOEN */
3404 #if defined(USART_TCBGT_SUPPORT)
3405 /* Function available only on devices supporting Transmit Complete before Guard Time feature */
3406 /**
3407   * @brief  Check if the Smartcard Transmission Complete Before Guard Time Flag is set or not
3408   * @rmtoll ISR          TCBGT         LL_USART_IsActiveFlag_TCBGT
3409   * @param  USARTx USART Instance
3410   * @retval State of bit (1 or 0).
3411   */
LL_USART_IsActiveFlag_TCBGT(const USART_TypeDef * USARTx)3412 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TCBGT(const USART_TypeDef *USARTx)
3413 {
3414   return ((READ_BIT(USARTx->ISR, USART_ISR_TCBGT) == (USART_ISR_TCBGT)) ? 1UL : 0UL);
3415 }
3416 
3417 #endif /* USART_TCBGT_SUPPORT */
3418 #if defined(USART_CR1_FIFOEN)
3419 /**
3420   * @brief  Check if the USART TX FIFO Threshold Flag is set or not
3421   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3422   *         FIFO mode feature is supported by the USARTx instance.
3423   * @rmtoll ISR          TXFT          LL_USART_IsActiveFlag_TXFT
3424   * @param  USARTx USART Instance
3425   * @retval State of bit (1 or 0).
3426   */
LL_USART_IsActiveFlag_TXFT(const USART_TypeDef * USARTx)3427 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXFT(const USART_TypeDef *USARTx)
3428 {
3429   return ((READ_BIT(USARTx->ISR, USART_ISR_TXFT) == (USART_ISR_TXFT)) ? 1UL : 0UL);
3430 }
3431 
3432 /**
3433   * @brief  Check if the USART RX FIFO Threshold Flag is set or not
3434   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3435   *         FIFO mode feature is supported by the USARTx instance.
3436   * @rmtoll ISR          RXFT          LL_USART_IsActiveFlag_RXFT
3437   * @param  USARTx USART Instance
3438   * @retval State of bit (1 or 0).
3439   */
LL_USART_IsActiveFlag_RXFT(const USART_TypeDef * USARTx)3440 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RXFT(const USART_TypeDef *USARTx)
3441 {
3442   return ((READ_BIT(USARTx->ISR, USART_ISR_RXFT) == (USART_ISR_RXFT)) ? 1UL : 0UL);
3443 }
3444 
3445 #endif /* USART_CR1_FIFOEN */
3446 /**
3447   * @brief  Clear Parity Error Flag
3448   * @rmtoll ICR          PECF          LL_USART_ClearFlag_PE
3449   * @param  USARTx USART Instance
3450   * @retval None
3451   */
LL_USART_ClearFlag_PE(USART_TypeDef * USARTx)3452 __STATIC_INLINE void LL_USART_ClearFlag_PE(USART_TypeDef *USARTx)
3453 {
3454   WRITE_REG(USARTx->ICR, USART_ICR_PECF);
3455 }
3456 
3457 /**
3458   * @brief  Clear Framing Error Flag
3459   * @rmtoll ICR          FECF          LL_USART_ClearFlag_FE
3460   * @param  USARTx USART Instance
3461   * @retval None
3462   */
LL_USART_ClearFlag_FE(USART_TypeDef * USARTx)3463 __STATIC_INLINE void LL_USART_ClearFlag_FE(USART_TypeDef *USARTx)
3464 {
3465   WRITE_REG(USARTx->ICR, USART_ICR_FECF);
3466 }
3467 
3468 /**
3469   * @brief  Clear Noise Error detected Flag
3470   * @rmtoll ICR          NECF          LL_USART_ClearFlag_NE
3471   * @param  USARTx USART Instance
3472   * @retval None
3473   */
LL_USART_ClearFlag_NE(USART_TypeDef * USARTx)3474 __STATIC_INLINE void LL_USART_ClearFlag_NE(USART_TypeDef *USARTx)
3475 {
3476   WRITE_REG(USARTx->ICR, USART_ICR_NECF);
3477 }
3478 
3479 /**
3480   * @brief  Clear OverRun Error Flag
3481   * @rmtoll ICR          ORECF         LL_USART_ClearFlag_ORE
3482   * @param  USARTx USART Instance
3483   * @retval None
3484   */
LL_USART_ClearFlag_ORE(USART_TypeDef * USARTx)3485 __STATIC_INLINE void LL_USART_ClearFlag_ORE(USART_TypeDef *USARTx)
3486 {
3487   WRITE_REG(USARTx->ICR, USART_ICR_ORECF);
3488 }
3489 
3490 /**
3491   * @brief  Clear IDLE line detected Flag
3492   * @rmtoll ICR          IDLECF        LL_USART_ClearFlag_IDLE
3493   * @param  USARTx USART Instance
3494   * @retval None
3495   */
LL_USART_ClearFlag_IDLE(USART_TypeDef * USARTx)3496 __STATIC_INLINE void LL_USART_ClearFlag_IDLE(USART_TypeDef *USARTx)
3497 {
3498   WRITE_REG(USARTx->ICR, USART_ICR_IDLECF);
3499 }
3500 
3501 #if defined(USART_CR1_FIFOEN)
3502 /**
3503   * @brief  Clear TX FIFO Empty Flag
3504   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3505   *         FIFO mode feature is supported by the USARTx instance.
3506   * @rmtoll ICR          TXFECF        LL_USART_ClearFlag_TXFE
3507   * @param  USARTx USART Instance
3508   * @retval None
3509   */
LL_USART_ClearFlag_TXFE(USART_TypeDef * USARTx)3510 __STATIC_INLINE void LL_USART_ClearFlag_TXFE(USART_TypeDef *USARTx)
3511 {
3512   WRITE_REG(USARTx->ICR, USART_ICR_TXFECF);
3513 }
3514 
3515 #endif /* USART_CR1_FIFOEN */
3516 /**
3517   * @brief  Clear Transmission Complete Flag
3518   * @rmtoll ICR          TCCF          LL_USART_ClearFlag_TC
3519   * @param  USARTx USART Instance
3520   * @retval None
3521   */
LL_USART_ClearFlag_TC(USART_TypeDef * USARTx)3522 __STATIC_INLINE void LL_USART_ClearFlag_TC(USART_TypeDef *USARTx)
3523 {
3524   WRITE_REG(USARTx->ICR, USART_ICR_TCCF);
3525 }
3526 
3527 #if defined(USART_TCBGT_SUPPORT)
3528 /* Function available only on devices supporting Transmit Complete before Guard Time feature */
3529 /**
3530   * @brief  Clear Smartcard Transmission Complete Before Guard Time Flag
3531   * @rmtoll ICR          TCBGTCF       LL_USART_ClearFlag_TCBGT
3532   * @param  USARTx USART Instance
3533   * @retval None
3534   */
LL_USART_ClearFlag_TCBGT(USART_TypeDef * USARTx)3535 __STATIC_INLINE void LL_USART_ClearFlag_TCBGT(USART_TypeDef *USARTx)
3536 {
3537   WRITE_REG(USARTx->ICR, USART_ICR_TCBGTCF);
3538 }
3539 #endif /* USART_TCBGT_SUPPORT */
3540 
3541 /**
3542   * @brief  Clear LIN Break Detection Flag
3543   * @note   Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
3544   *         LIN feature is supported by the USARTx instance.
3545   * @rmtoll ICR          LBDCF         LL_USART_ClearFlag_LBD
3546   * @param  USARTx USART Instance
3547   * @retval None
3548   */
LL_USART_ClearFlag_LBD(USART_TypeDef * USARTx)3549 __STATIC_INLINE void LL_USART_ClearFlag_LBD(USART_TypeDef *USARTx)
3550 {
3551   WRITE_REG(USARTx->ICR, USART_ICR_LBDCF);
3552 }
3553 
3554 /**
3555   * @brief  Clear CTS Interrupt Flag
3556   * @note   Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
3557   *         Hardware Flow control feature is supported by the USARTx instance.
3558   * @rmtoll ICR          CTSCF         LL_USART_ClearFlag_nCTS
3559   * @param  USARTx USART Instance
3560   * @retval None
3561   */
LL_USART_ClearFlag_nCTS(USART_TypeDef * USARTx)3562 __STATIC_INLINE void LL_USART_ClearFlag_nCTS(USART_TypeDef *USARTx)
3563 {
3564   WRITE_REG(USARTx->ICR, USART_ICR_CTSCF);
3565 }
3566 
3567 /**
3568   * @brief  Clear Receiver Time Out Flag
3569   * @rmtoll ICR          RTOCF         LL_USART_ClearFlag_RTO
3570   * @param  USARTx USART Instance
3571   * @retval None
3572   */
LL_USART_ClearFlag_RTO(USART_TypeDef * USARTx)3573 __STATIC_INLINE void LL_USART_ClearFlag_RTO(USART_TypeDef *USARTx)
3574 {
3575   WRITE_REG(USARTx->ICR, USART_ICR_RTOCF);
3576 }
3577 
3578 /**
3579   * @brief  Clear End Of Block Flag
3580   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
3581   *         Smartcard feature is supported by the USARTx instance.
3582   * @rmtoll ICR          EOBCF         LL_USART_ClearFlag_EOB
3583   * @param  USARTx USART Instance
3584   * @retval None
3585   */
LL_USART_ClearFlag_EOB(USART_TypeDef * USARTx)3586 __STATIC_INLINE void LL_USART_ClearFlag_EOB(USART_TypeDef *USARTx)
3587 {
3588   WRITE_REG(USARTx->ICR, USART_ICR_EOBCF);
3589 }
3590 
3591 #if defined(USART_CR2_SLVEN)
3592 /**
3593   * @brief  Clear SPI Slave Underrun Flag
3594   * @note   Macro IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
3595   *         SPI Slave mode feature is supported by the USARTx instance.
3596   * @rmtoll ICR          UDRCF         LL_USART_ClearFlag_UDR
3597   * @param  USARTx USART Instance
3598   * @retval None
3599   */
LL_USART_ClearFlag_UDR(USART_TypeDef * USARTx)3600 __STATIC_INLINE void LL_USART_ClearFlag_UDR(USART_TypeDef *USARTx)
3601 {
3602   WRITE_REG(USARTx->ICR, USART_ICR_UDRCF);
3603 }
3604 
3605 #endif /* USART_CR2_SLVEN */
3606 /**
3607   * @brief  Clear Character Match Flag
3608   * @rmtoll ICR          CMCF          LL_USART_ClearFlag_CM
3609   * @param  USARTx USART Instance
3610   * @retval None
3611   */
LL_USART_ClearFlag_CM(USART_TypeDef * USARTx)3612 __STATIC_INLINE void LL_USART_ClearFlag_CM(USART_TypeDef *USARTx)
3613 {
3614   WRITE_REG(USARTx->ICR, USART_ICR_CMCF);
3615 }
3616 
3617 /**
3618   * @brief  Clear Wake Up from stop mode Flag
3619   * @note   Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
3620   *         Wake-up from Stop mode feature is supported by the USARTx instance.
3621   * @rmtoll ICR          WUCF          LL_USART_ClearFlag_WKUP
3622   * @param  USARTx USART Instance
3623   * @retval None
3624   */
LL_USART_ClearFlag_WKUP(USART_TypeDef * USARTx)3625 __STATIC_INLINE void LL_USART_ClearFlag_WKUP(USART_TypeDef *USARTx)
3626 {
3627   WRITE_REG(USARTx->ICR, USART_ICR_WUCF);
3628 }
3629 
3630 /**
3631   * @}
3632   */
3633 
3634 /** @defgroup USART_LL_EF_IT_Management IT_Management
3635   * @{
3636   */
3637 
3638 /**
3639   * @brief  Enable IDLE Interrupt
3640   * @rmtoll CR1          IDLEIE        LL_USART_EnableIT_IDLE
3641   * @param  USARTx USART Instance
3642   * @retval None
3643   */
LL_USART_EnableIT_IDLE(USART_TypeDef * USARTx)3644 __STATIC_INLINE void LL_USART_EnableIT_IDLE(USART_TypeDef *USARTx)
3645 {
3646   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_IDLEIE);
3647 }
3648 
3649 #if defined(USART_CR1_FIFOEN)
3650 #define LL_USART_EnableIT_RXNE  LL_USART_EnableIT_RXNE_RXFNE /* Redefinition for legacy purpose */
3651 
3652 /**
3653   * @brief  Enable RX Not Empty and RX FIFO Not Empty Interrupt
3654   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3655   *         FIFO mode feature is supported by the USARTx instance.
3656   * @rmtoll CR1        RXNEIE_RXFNEIE  LL_USART_EnableIT_RXNE_RXFNE
3657   * @param  USARTx USART Instance
3658   * @retval None
3659   */
LL_USART_EnableIT_RXNE_RXFNE(USART_TypeDef * USARTx)3660 __STATIC_INLINE void LL_USART_EnableIT_RXNE_RXFNE(USART_TypeDef *USARTx)
3661 {
3662   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_RXNEIE_RXFNEIE);
3663 }
3664 
3665 #else
3666 /**
3667   * @brief  Enable RX Not Empty Interrupt
3668   * @rmtoll CR1          RXNEIE        LL_USART_EnableIT_RXNE
3669   * @param  USARTx USART Instance
3670   * @retval None
3671   */
LL_USART_EnableIT_RXNE(USART_TypeDef * USARTx)3672 __STATIC_INLINE void LL_USART_EnableIT_RXNE(USART_TypeDef *USARTx)
3673 {
3674   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_RXNEIE);
3675 }
3676 
3677 #endif /* USART_CR1_FIFOEN */
3678 /**
3679   * @brief  Enable Transmission Complete Interrupt
3680   * @rmtoll CR1          TCIE          LL_USART_EnableIT_TC
3681   * @param  USARTx USART Instance
3682   * @retval None
3683   */
LL_USART_EnableIT_TC(USART_TypeDef * USARTx)3684 __STATIC_INLINE void LL_USART_EnableIT_TC(USART_TypeDef *USARTx)
3685 {
3686   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TCIE);
3687 }
3688 
3689 #if defined(USART_CR1_FIFOEN)
3690 #define LL_USART_EnableIT_TXE  LL_USART_EnableIT_TXE_TXFNF /* Redefinition for legacy purpose */
3691 
3692 /**
3693   * @brief  Enable TX Empty and TX FIFO Not Full Interrupt
3694   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3695   *         FIFO mode feature is supported by the USARTx instance.
3696   * @rmtoll CR1         TXEIE_TXFNFIE  LL_USART_EnableIT_TXE_TXFNF
3697   * @param  USARTx USART Instance
3698   * @retval None
3699   */
LL_USART_EnableIT_TXE_TXFNF(USART_TypeDef * USARTx)3700 __STATIC_INLINE void LL_USART_EnableIT_TXE_TXFNF(USART_TypeDef *USARTx)
3701 {
3702   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TXEIE_TXFNFIE);
3703 }
3704 
3705 #else
3706 /**
3707   * @brief  Enable TX Empty Interrupt
3708   * @rmtoll CR1          TXEIE         LL_USART_EnableIT_TXE
3709   * @param  USARTx USART Instance
3710   * @retval None
3711   */
LL_USART_EnableIT_TXE(USART_TypeDef * USARTx)3712 __STATIC_INLINE void LL_USART_EnableIT_TXE(USART_TypeDef *USARTx)
3713 {
3714   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TXEIE);
3715 }
3716 
3717 #endif /* USART_CR1_FIFOEN */
3718 /**
3719   * @brief  Enable Parity Error Interrupt
3720   * @rmtoll CR1          PEIE          LL_USART_EnableIT_PE
3721   * @param  USARTx USART Instance
3722   * @retval None
3723   */
LL_USART_EnableIT_PE(USART_TypeDef * USARTx)3724 __STATIC_INLINE void LL_USART_EnableIT_PE(USART_TypeDef *USARTx)
3725 {
3726   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_PEIE);
3727 }
3728 
3729 /**
3730   * @brief  Enable Character Match Interrupt
3731   * @rmtoll CR1          CMIE          LL_USART_EnableIT_CM
3732   * @param  USARTx USART Instance
3733   * @retval None
3734   */
LL_USART_EnableIT_CM(USART_TypeDef * USARTx)3735 __STATIC_INLINE void LL_USART_EnableIT_CM(USART_TypeDef *USARTx)
3736 {
3737   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_CMIE);
3738 }
3739 
3740 /**
3741   * @brief  Enable Receiver Timeout Interrupt
3742   * @rmtoll CR1          RTOIE         LL_USART_EnableIT_RTO
3743   * @param  USARTx USART Instance
3744   * @retval None
3745   */
LL_USART_EnableIT_RTO(USART_TypeDef * USARTx)3746 __STATIC_INLINE void LL_USART_EnableIT_RTO(USART_TypeDef *USARTx)
3747 {
3748   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_RTOIE);
3749 }
3750 
3751 /**
3752   * @brief  Enable End Of Block Interrupt
3753   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
3754   *         Smartcard feature is supported by the USARTx instance.
3755   * @rmtoll CR1          EOBIE         LL_USART_EnableIT_EOB
3756   * @param  USARTx USART Instance
3757   * @retval None
3758   */
LL_USART_EnableIT_EOB(USART_TypeDef * USARTx)3759 __STATIC_INLINE void LL_USART_EnableIT_EOB(USART_TypeDef *USARTx)
3760 {
3761   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_EOBIE);
3762 }
3763 
3764 #if defined(USART_CR1_FIFOEN)
3765 /**
3766   * @brief  Enable TX FIFO Empty Interrupt
3767   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3768   *         FIFO mode feature is supported by the USARTx instance.
3769   * @rmtoll CR1          TXFEIE        LL_USART_EnableIT_TXFE
3770   * @param  USARTx USART Instance
3771   * @retval None
3772   */
LL_USART_EnableIT_TXFE(USART_TypeDef * USARTx)3773 __STATIC_INLINE void LL_USART_EnableIT_TXFE(USART_TypeDef *USARTx)
3774 {
3775   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TXFEIE);
3776 }
3777 
3778 /**
3779   * @brief  Enable RX FIFO Full Interrupt
3780   * @rmtoll CR1          RXFFIE        LL_USART_EnableIT_RXFF
3781   * @param  USARTx USART Instance
3782   * @retval None
3783   */
LL_USART_EnableIT_RXFF(USART_TypeDef * USARTx)3784 __STATIC_INLINE void LL_USART_EnableIT_RXFF(USART_TypeDef *USARTx)
3785 {
3786   ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_RXFFIE);
3787 }
3788 
3789 #endif /* USART_CR1_FIFOEN */
3790 /**
3791   * @brief  Enable LIN Break Detection Interrupt
3792   * @note   Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
3793   *         LIN feature is supported by the USARTx instance.
3794   * @rmtoll CR2          LBDIE         LL_USART_EnableIT_LBD
3795   * @param  USARTx USART Instance
3796   * @retval None
3797   */
LL_USART_EnableIT_LBD(USART_TypeDef * USARTx)3798 __STATIC_INLINE void LL_USART_EnableIT_LBD(USART_TypeDef *USARTx)
3799 {
3800   SET_BIT(USARTx->CR2, USART_CR2_LBDIE);
3801 }
3802 
3803 /**
3804   * @brief  Enable Error Interrupt
3805   * @note   When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
3806   *         error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_ISR register).
3807   *           0: Interrupt is inhibited
3808   *           1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_ISR register.
3809   * @rmtoll CR3          EIE           LL_USART_EnableIT_ERROR
3810   * @param  USARTx USART Instance
3811   * @retval None
3812   */
LL_USART_EnableIT_ERROR(USART_TypeDef * USARTx)3813 __STATIC_INLINE void LL_USART_EnableIT_ERROR(USART_TypeDef *USARTx)
3814 {
3815   ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_EIE);
3816 }
3817 
3818 /**
3819   * @brief  Enable CTS Interrupt
3820   * @note   Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
3821   *         Hardware Flow control feature is supported by the USARTx instance.
3822   * @rmtoll CR3          CTSIE         LL_USART_EnableIT_CTS
3823   * @param  USARTx USART Instance
3824   * @retval None
3825   */
LL_USART_EnableIT_CTS(USART_TypeDef * USARTx)3826 __STATIC_INLINE void LL_USART_EnableIT_CTS(USART_TypeDef *USARTx)
3827 {
3828   ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_CTSIE);
3829 }
3830 
3831 /**
3832   * @brief  Enable Wake Up from Stop Mode Interrupt
3833   * @note   Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
3834   *         Wake-up from Stop mode feature is supported by the USARTx instance.
3835   * @rmtoll CR3          WUFIE         LL_USART_EnableIT_WKUP
3836   * @param  USARTx USART Instance
3837   * @retval None
3838   */
LL_USART_EnableIT_WKUP(USART_TypeDef * USARTx)3839 __STATIC_INLINE void LL_USART_EnableIT_WKUP(USART_TypeDef *USARTx)
3840 {
3841   ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_WUFIE);
3842 }
3843 
3844 #if defined(USART_CR1_FIFOEN)
3845 /**
3846   * @brief  Enable TX FIFO Threshold Interrupt
3847   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3848   *         FIFO mode feature is supported by the USARTx instance.
3849   * @rmtoll CR3          TXFTIE        LL_USART_EnableIT_TXFT
3850   * @param  USARTx USART Instance
3851   * @retval None
3852   */
LL_USART_EnableIT_TXFT(USART_TypeDef * USARTx)3853 __STATIC_INLINE void LL_USART_EnableIT_TXFT(USART_TypeDef *USARTx)
3854 {
3855   ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_TXFTIE);
3856 }
3857 
3858 #endif /* USART_CR1_FIFOEN */
3859 #if defined(USART_TCBGT_SUPPORT)
3860 /* Function available only on devices supporting Transmit Complete before Guard Time feature */
3861 /**
3862   * @brief  Enable Smartcard Transmission Complete Before Guard Time Interrupt
3863   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
3864   *         Smartcard feature is supported by the USARTx instance.
3865   * @rmtoll CR3          TCBGTIE       LL_USART_EnableIT_TCBGT
3866   * @param  USARTx USART Instance
3867   * @retval None
3868   */
LL_USART_EnableIT_TCBGT(USART_TypeDef * USARTx)3869 __STATIC_INLINE void LL_USART_EnableIT_TCBGT(USART_TypeDef *USARTx)
3870 {
3871   ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_TCBGTIE);
3872 }
3873 #endif /* USART_TCBGT_SUPPORT */
3874 
3875 #if defined(USART_CR1_FIFOEN)
3876 /**
3877   * @brief  Enable RX FIFO Threshold Interrupt
3878   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3879   *         FIFO mode feature is supported by the USARTx instance.
3880   * @rmtoll CR3          RXFTIE        LL_USART_EnableIT_RXFT
3881   * @param  USARTx USART Instance
3882   * @retval None
3883   */
LL_USART_EnableIT_RXFT(USART_TypeDef * USARTx)3884 __STATIC_INLINE void LL_USART_EnableIT_RXFT(USART_TypeDef *USARTx)
3885 {
3886   ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_RXFTIE);
3887 }
3888 
3889 #endif /* USART_CR1_FIFOEN */
3890 /**
3891   * @brief  Disable IDLE Interrupt
3892   * @rmtoll CR1          IDLEIE        LL_USART_DisableIT_IDLE
3893   * @param  USARTx USART Instance
3894   * @retval None
3895   */
LL_USART_DisableIT_IDLE(USART_TypeDef * USARTx)3896 __STATIC_INLINE void LL_USART_DisableIT_IDLE(USART_TypeDef *USARTx)
3897 {
3898   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_IDLEIE);
3899 }
3900 
3901 #if defined(USART_CR1_FIFOEN)
3902 #define LL_USART_DisableIT_RXNE  LL_USART_DisableIT_RXNE_RXFNE /* Redefinition for legacy purpose */
3903 
3904 /**
3905   * @brief  Disable RX Not Empty and RX FIFO Not Empty Interrupt
3906   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3907   *         FIFO mode feature is supported by the USARTx instance.
3908   * @rmtoll CR1        RXNEIE_RXFNEIE  LL_USART_DisableIT_RXNE_RXFNE
3909   * @param  USARTx USART Instance
3910   * @retval None
3911   */
LL_USART_DisableIT_RXNE_RXFNE(USART_TypeDef * USARTx)3912 __STATIC_INLINE void LL_USART_DisableIT_RXNE_RXFNE(USART_TypeDef *USARTx)
3913 {
3914   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_RXNEIE_RXFNEIE);
3915 }
3916 
3917 #else
3918 /**
3919   * @brief  Disable RX Not Empty Interrupt
3920   * @rmtoll CR1          RXNEIE        LL_USART_DisableIT_RXNE
3921   * @param  USARTx USART Instance
3922   * @retval None
3923   */
LL_USART_DisableIT_RXNE(USART_TypeDef * USARTx)3924 __STATIC_INLINE void LL_USART_DisableIT_RXNE(USART_TypeDef *USARTx)
3925 {
3926   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_RXNEIE);
3927 }
3928 
3929 #endif /* USART_CR1_FIFOEN */
3930 /**
3931   * @brief  Disable Transmission Complete Interrupt
3932   * @rmtoll CR1          TCIE          LL_USART_DisableIT_TC
3933   * @param  USARTx USART Instance
3934   * @retval None
3935   */
LL_USART_DisableIT_TC(USART_TypeDef * USARTx)3936 __STATIC_INLINE void LL_USART_DisableIT_TC(USART_TypeDef *USARTx)
3937 {
3938   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TCIE);
3939 }
3940 
3941 #if defined(USART_CR1_FIFOEN)
3942 #define LL_USART_DisableIT_TXE  LL_USART_DisableIT_TXE_TXFNF /* Redefinition for legacy purpose */
3943 
3944 /**
3945   * @brief  Disable TX Empty and TX FIFO Not Full Interrupt
3946   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
3947   *         FIFO mode feature is supported by the USARTx instance.
3948   * @rmtoll CR1        TXEIE_TXFNFIE  LL_USART_DisableIT_TXE_TXFNF
3949   * @param  USARTx USART Instance
3950   * @retval None
3951   */
LL_USART_DisableIT_TXE_TXFNF(USART_TypeDef * USARTx)3952 __STATIC_INLINE void LL_USART_DisableIT_TXE_TXFNF(USART_TypeDef *USARTx)
3953 {
3954   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TXEIE_TXFNFIE);
3955 }
3956 
3957 #else
3958 /**
3959   * @brief  Disable TX Empty Interrupt
3960   * @rmtoll CR1          TXEIE         LL_USART_DisableIT_TXE
3961   * @param  USARTx USART Instance
3962   * @retval None
3963   */
LL_USART_DisableIT_TXE(USART_TypeDef * USARTx)3964 __STATIC_INLINE void LL_USART_DisableIT_TXE(USART_TypeDef *USARTx)
3965 {
3966   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TXEIE);
3967 }
3968 
3969 #endif /* USART_CR1_FIFOEN */
3970 /**
3971   * @brief  Disable Parity Error Interrupt
3972   * @rmtoll CR1          PEIE          LL_USART_DisableIT_PE
3973   * @param  USARTx USART Instance
3974   * @retval None
3975   */
LL_USART_DisableIT_PE(USART_TypeDef * USARTx)3976 __STATIC_INLINE void LL_USART_DisableIT_PE(USART_TypeDef *USARTx)
3977 {
3978   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_PEIE);
3979 }
3980 
3981 /**
3982   * @brief  Disable Character Match Interrupt
3983   * @rmtoll CR1          CMIE          LL_USART_DisableIT_CM
3984   * @param  USARTx USART Instance
3985   * @retval None
3986   */
LL_USART_DisableIT_CM(USART_TypeDef * USARTx)3987 __STATIC_INLINE void LL_USART_DisableIT_CM(USART_TypeDef *USARTx)
3988 {
3989   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_CMIE);
3990 }
3991 
3992 /**
3993   * @brief  Disable Receiver Timeout Interrupt
3994   * @rmtoll CR1          RTOIE         LL_USART_DisableIT_RTO
3995   * @param  USARTx USART Instance
3996   * @retval None
3997   */
LL_USART_DisableIT_RTO(USART_TypeDef * USARTx)3998 __STATIC_INLINE void LL_USART_DisableIT_RTO(USART_TypeDef *USARTx)
3999 {
4000   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_RTOIE);
4001 }
4002 
4003 /**
4004   * @brief  Disable End Of Block Interrupt
4005   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
4006   *         Smartcard feature is supported by the USARTx instance.
4007   * @rmtoll CR1          EOBIE         LL_USART_DisableIT_EOB
4008   * @param  USARTx USART Instance
4009   * @retval None
4010   */
LL_USART_DisableIT_EOB(USART_TypeDef * USARTx)4011 __STATIC_INLINE void LL_USART_DisableIT_EOB(USART_TypeDef *USARTx)
4012 {
4013   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_EOBIE);
4014 }
4015 
4016 #if defined(USART_CR1_FIFOEN)
4017 /**
4018   * @brief  Disable TX FIFO Empty Interrupt
4019   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
4020   *         FIFO mode feature is supported by the USARTx instance.
4021   * @rmtoll CR1          TXFEIE        LL_USART_DisableIT_TXFE
4022   * @param  USARTx USART Instance
4023   * @retval None
4024   */
LL_USART_DisableIT_TXFE(USART_TypeDef * USARTx)4025 __STATIC_INLINE void LL_USART_DisableIT_TXFE(USART_TypeDef *USARTx)
4026 {
4027   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TXFEIE);
4028 }
4029 
4030 /**
4031   * @brief  Disable RX FIFO Full Interrupt
4032   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
4033   *         FIFO mode feature is supported by the USARTx instance.
4034   * @rmtoll CR1          RXFFIE        LL_USART_DisableIT_RXFF
4035   * @param  USARTx USART Instance
4036   * @retval None
4037   */
LL_USART_DisableIT_RXFF(USART_TypeDef * USARTx)4038 __STATIC_INLINE void LL_USART_DisableIT_RXFF(USART_TypeDef *USARTx)
4039 {
4040   ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_RXFFIE);
4041 }
4042 
4043 #endif /* USART_CR1_FIFOEN */
4044 /**
4045   * @brief  Disable LIN Break Detection Interrupt
4046   * @note   Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
4047   *         LIN feature is supported by the USARTx instance.
4048   * @rmtoll CR2          LBDIE         LL_USART_DisableIT_LBD
4049   * @param  USARTx USART Instance
4050   * @retval None
4051   */
LL_USART_DisableIT_LBD(USART_TypeDef * USARTx)4052 __STATIC_INLINE void LL_USART_DisableIT_LBD(USART_TypeDef *USARTx)
4053 {
4054   CLEAR_BIT(USARTx->CR2, USART_CR2_LBDIE);
4055 }
4056 
4057 /**
4058   * @brief  Disable Error Interrupt
4059   * @note   When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
4060   *         error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_ISR register).
4061   *           0: Interrupt is inhibited
4062   *           1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_ISR register.
4063   * @rmtoll CR3          EIE           LL_USART_DisableIT_ERROR
4064   * @param  USARTx USART Instance
4065   * @retval None
4066   */
LL_USART_DisableIT_ERROR(USART_TypeDef * USARTx)4067 __STATIC_INLINE void LL_USART_DisableIT_ERROR(USART_TypeDef *USARTx)
4068 {
4069   ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_EIE);
4070 }
4071 
4072 /**
4073   * @brief  Disable CTS Interrupt
4074   * @note   Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
4075   *         Hardware Flow control feature is supported by the USARTx instance.
4076   * @rmtoll CR3          CTSIE         LL_USART_DisableIT_CTS
4077   * @param  USARTx USART Instance
4078   * @retval None
4079   */
LL_USART_DisableIT_CTS(USART_TypeDef * USARTx)4080 __STATIC_INLINE void LL_USART_DisableIT_CTS(USART_TypeDef *USARTx)
4081 {
4082   ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_CTSIE);
4083 }
4084 
4085 /**
4086   * @brief  Disable Wake Up from Stop Mode Interrupt
4087   * @note   Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
4088   *         Wake-up from Stop mode feature is supported by the USARTx instance.
4089   * @rmtoll CR3          WUFIE         LL_USART_DisableIT_WKUP
4090   * @param  USARTx USART Instance
4091   * @retval None
4092   */
LL_USART_DisableIT_WKUP(USART_TypeDef * USARTx)4093 __STATIC_INLINE void LL_USART_DisableIT_WKUP(USART_TypeDef *USARTx)
4094 {
4095   ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_WUFIE);
4096 }
4097 
4098 #if defined(USART_CR1_FIFOEN)
4099 /**
4100   * @brief  Disable TX FIFO Threshold Interrupt
4101   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
4102   *         FIFO mode feature is supported by the USARTx instance.
4103   * @rmtoll CR3          TXFTIE        LL_USART_DisableIT_TXFT
4104   * @param  USARTx USART Instance
4105   * @retval None
4106   */
LL_USART_DisableIT_TXFT(USART_TypeDef * USARTx)4107 __STATIC_INLINE void LL_USART_DisableIT_TXFT(USART_TypeDef *USARTx)
4108 {
4109   ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_TXFTIE);
4110 }
4111 
4112 #endif /* USART_CR1_FIFOEN */
4113 #if defined(USART_TCBGT_SUPPORT)
4114 /* Function available only on devices supporting Transmit Complete before Guard Time feature */
4115 /**
4116   * @brief  Disable Smartcard Transmission Complete Before Guard Time Interrupt
4117   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
4118   *         Smartcard feature is supported by the USARTx instance.
4119   * @rmtoll CR3          TCBGTIE       LL_USART_DisableIT_TCBGT
4120   * @param  USARTx USART Instance
4121   * @retval None
4122   */
LL_USART_DisableIT_TCBGT(USART_TypeDef * USARTx)4123 __STATIC_INLINE void LL_USART_DisableIT_TCBGT(USART_TypeDef *USARTx)
4124 {
4125   ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_TCBGTIE);
4126 }
4127 #endif /* USART_TCBGT_SUPPORT */
4128 
4129 #if defined(USART_CR1_FIFOEN)
4130 /**
4131   * @brief  Disable RX FIFO Threshold Interrupt
4132   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
4133   *         FIFO mode feature is supported by the USARTx instance.
4134   * @rmtoll CR3          RXFTIE        LL_USART_DisableIT_RXFT
4135   * @param  USARTx USART Instance
4136   * @retval None
4137   */
LL_USART_DisableIT_RXFT(USART_TypeDef * USARTx)4138 __STATIC_INLINE void LL_USART_DisableIT_RXFT(USART_TypeDef *USARTx)
4139 {
4140   ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_RXFTIE);
4141 }
4142 
4143 #endif /* USART_CR1_FIFOEN */
4144 /**
4145   * @brief  Check if the USART IDLE Interrupt  source is enabled or disabled.
4146   * @rmtoll CR1          IDLEIE        LL_USART_IsEnabledIT_IDLE
4147   * @param  USARTx USART Instance
4148   * @retval State of bit (1 or 0).
4149   */
LL_USART_IsEnabledIT_IDLE(const USART_TypeDef * USARTx)4150 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_IDLE(const USART_TypeDef *USARTx)
4151 {
4152   return ((READ_BIT(USARTx->CR1, USART_CR1_IDLEIE) == (USART_CR1_IDLEIE)) ? 1UL : 0UL);
4153 }
4154 
4155 #if defined(USART_CR1_FIFOEN)
4156 #define LL_USART_IsEnabledIT_RXNE  LL_USART_IsEnabledIT_RXNE_RXFNE /* Redefinition for legacy purpose */
4157 
4158 /**
4159   * @brief  Check if the USART RX Not Empty and USART RX FIFO Not Empty Interrupt is enabled or disabled.
4160   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
4161   *         FIFO mode feature is supported by the USARTx instance.
4162   * @rmtoll CR1        RXNEIE_RXFNEIE  LL_USART_IsEnabledIT_RXNE_RXFNE
4163   * @param  USARTx USART Instance
4164   * @retval State of bit (1 or 0).
4165   */
LL_USART_IsEnabledIT_RXNE_RXFNE(const USART_TypeDef * USARTx)4166 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RXNE_RXFNE(const USART_TypeDef *USARTx)
4167 {
4168   return ((READ_BIT(USARTx->CR1, USART_CR1_RXNEIE_RXFNEIE) == (USART_CR1_RXNEIE_RXFNEIE)) ? 1UL : 0UL);
4169 }
4170 
4171 #else
4172 /**
4173   * @brief  Check if the USART RX Not Empty Interrupt is enabled or disabled.
4174   * @rmtoll CR1          RXNEIE        LL_USART_IsEnabledIT_RXNE
4175   * @param  USARTx USART Instance
4176   * @retval State of bit (1 or 0).
4177   */
LL_USART_IsEnabledIT_RXNE(const USART_TypeDef * USARTx)4178 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RXNE(const USART_TypeDef *USARTx)
4179 {
4180   return ((READ_BIT(USARTx->CR1, USART_CR1_RXNEIE) == (USART_CR1_RXNEIE)) ? 1U : 0U);
4181 }
4182 
4183 #endif /* USART_CR1_FIFOEN */
4184 /**
4185   * @brief  Check if the USART Transmission Complete Interrupt is enabled or disabled.
4186   * @rmtoll CR1          TCIE          LL_USART_IsEnabledIT_TC
4187   * @param  USARTx USART Instance
4188   * @retval State of bit (1 or 0).
4189   */
LL_USART_IsEnabledIT_TC(const USART_TypeDef * USARTx)4190 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TC(const USART_TypeDef *USARTx)
4191 {
4192   return ((READ_BIT(USARTx->CR1, USART_CR1_TCIE) == (USART_CR1_TCIE)) ? 1UL : 0UL);
4193 }
4194 
4195 #if defined(USART_CR1_FIFOEN)
4196 #define LL_USART_IsEnabledIT_TXE  LL_USART_IsEnabledIT_TXE_TXFNF /* Redefinition for legacy purpose */
4197 
4198 /**
4199   * @brief  Check if the USART TX Empty and USART TX FIFO Not Full Interrupt is enabled or disabled
4200   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
4201   *         FIFO mode feature is supported by the USARTx instance.
4202   * @rmtoll CR1         TXEIE_TXFNFIE  LL_USART_IsEnabledIT_TXE_TXFNF
4203   * @param  USARTx USART Instance
4204   * @retval State of bit (1 or 0).
4205   */
LL_USART_IsEnabledIT_TXE_TXFNF(const USART_TypeDef * USARTx)4206 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TXE_TXFNF(const USART_TypeDef *USARTx)
4207 {
4208   return ((READ_BIT(USARTx->CR1, USART_CR1_TXEIE_TXFNFIE) == (USART_CR1_TXEIE_TXFNFIE)) ? 1UL : 0UL);
4209 }
4210 
4211 #else
4212 /**
4213   * @brief  Check if the USART TX Empty Interrupt is enabled or disabled.
4214   * @rmtoll CR1          TXEIE         LL_USART_IsEnabledIT_TXE
4215   * @param  USARTx USART Instance
4216   * @retval State of bit (1 or 0).
4217   */
LL_USART_IsEnabledIT_TXE(const USART_TypeDef * USARTx)4218 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TXE(const USART_TypeDef *USARTx)
4219 {
4220   return ((READ_BIT(USARTx->CR1, USART_CR1_TXEIE) == (USART_CR1_TXEIE)) ? 1U : 0U);
4221 }
4222 
4223 #endif /* USART_CR1_FIFOEN */
4224 /**
4225   * @brief  Check if the USART Parity Error Interrupt is enabled or disabled.
4226   * @rmtoll CR1          PEIE          LL_USART_IsEnabledIT_PE
4227   * @param  USARTx USART Instance
4228   * @retval State of bit (1 or 0).
4229   */
LL_USART_IsEnabledIT_PE(const USART_TypeDef * USARTx)4230 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_PE(const USART_TypeDef *USARTx)
4231 {
4232   return ((READ_BIT(USARTx->CR1, USART_CR1_PEIE) == (USART_CR1_PEIE)) ? 1UL : 0UL);
4233 }
4234 
4235 /**
4236   * @brief  Check if the USART Character Match Interrupt is enabled or disabled.
4237   * @rmtoll CR1          CMIE          LL_USART_IsEnabledIT_CM
4238   * @param  USARTx USART Instance
4239   * @retval State of bit (1 or 0).
4240   */
LL_USART_IsEnabledIT_CM(const USART_TypeDef * USARTx)4241 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_CM(const USART_TypeDef *USARTx)
4242 {
4243   return ((READ_BIT(USARTx->CR1, USART_CR1_CMIE) == (USART_CR1_CMIE)) ? 1UL : 0UL);
4244 }
4245 
4246 /**
4247   * @brief  Check if the USART Receiver Timeout Interrupt is enabled or disabled.
4248   * @rmtoll CR1          RTOIE         LL_USART_IsEnabledIT_RTO
4249   * @param  USARTx USART Instance
4250   * @retval State of bit (1 or 0).
4251   */
LL_USART_IsEnabledIT_RTO(const USART_TypeDef * USARTx)4252 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RTO(const USART_TypeDef *USARTx)
4253 {
4254   return ((READ_BIT(USARTx->CR1, USART_CR1_RTOIE) == (USART_CR1_RTOIE)) ? 1UL : 0UL);
4255 }
4256 
4257 /**
4258   * @brief  Check if the USART End Of Block Interrupt is enabled or disabled.
4259   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
4260   *         Smartcard feature is supported by the USARTx instance.
4261   * @rmtoll CR1          EOBIE         LL_USART_IsEnabledIT_EOB
4262   * @param  USARTx USART Instance
4263   * @retval State of bit (1 or 0).
4264   */
LL_USART_IsEnabledIT_EOB(const USART_TypeDef * USARTx)4265 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_EOB(const USART_TypeDef *USARTx)
4266 {
4267   return ((READ_BIT(USARTx->CR1, USART_CR1_EOBIE) == (USART_CR1_EOBIE)) ? 1UL : 0UL);
4268 }
4269 
4270 #if defined(USART_CR1_FIFOEN)
4271 /**
4272   * @brief  Check if the USART TX FIFO Empty Interrupt is enabled or disabled
4273   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
4274   *         FIFO mode feature is supported by the USARTx instance.
4275   * @rmtoll CR1          TXFEIE        LL_USART_IsEnabledIT_TXFE
4276   * @param  USARTx USART Instance
4277   * @retval State of bit (1 or 0).
4278   */
LL_USART_IsEnabledIT_TXFE(const USART_TypeDef * USARTx)4279 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TXFE(const USART_TypeDef *USARTx)
4280 {
4281   return ((READ_BIT(USARTx->CR1, USART_CR1_TXFEIE) == (USART_CR1_TXFEIE)) ? 1UL : 0UL);
4282 }
4283 
4284 /**
4285   * @brief  Check if the USART RX FIFO Full Interrupt is enabled or disabled
4286   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
4287   *         FIFO mode feature is supported by the USARTx instance.
4288   * @rmtoll CR1          RXFFIE        LL_USART_IsEnabledIT_RXFF
4289   * @param  USARTx USART Instance
4290   * @retval State of bit (1 or 0).
4291   */
LL_USART_IsEnabledIT_RXFF(const USART_TypeDef * USARTx)4292 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RXFF(const USART_TypeDef *USARTx)
4293 {
4294   return ((READ_BIT(USARTx->CR1, USART_CR1_RXFFIE) == (USART_CR1_RXFFIE)) ? 1UL : 0UL);
4295 }
4296 
4297 #endif /* USART_CR1_FIFOEN */
4298 /**
4299   * @brief  Check if the USART LIN Break Detection Interrupt is enabled or disabled.
4300   * @note   Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
4301   *         LIN feature is supported by the USARTx instance.
4302   * @rmtoll CR2          LBDIE         LL_USART_IsEnabledIT_LBD
4303   * @param  USARTx USART Instance
4304   * @retval State of bit (1 or 0).
4305   */
LL_USART_IsEnabledIT_LBD(const USART_TypeDef * USARTx)4306 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_LBD(const USART_TypeDef *USARTx)
4307 {
4308   return ((READ_BIT(USARTx->CR2, USART_CR2_LBDIE) == (USART_CR2_LBDIE)) ? 1UL : 0UL);
4309 }
4310 
4311 /**
4312   * @brief  Check if the USART Error Interrupt is enabled or disabled.
4313   * @rmtoll CR3          EIE           LL_USART_IsEnabledIT_ERROR
4314   * @param  USARTx USART Instance
4315   * @retval State of bit (1 or 0).
4316   */
LL_USART_IsEnabledIT_ERROR(const USART_TypeDef * USARTx)4317 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_ERROR(const USART_TypeDef *USARTx)
4318 {
4319   return ((READ_BIT(USARTx->CR3, USART_CR3_EIE) == (USART_CR3_EIE)) ? 1UL : 0UL);
4320 }
4321 
4322 /**
4323   * @brief  Check if the USART CTS Interrupt is enabled or disabled.
4324   * @note   Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
4325   *         Hardware Flow control feature is supported by the USARTx instance.
4326   * @rmtoll CR3          CTSIE         LL_USART_IsEnabledIT_CTS
4327   * @param  USARTx USART Instance
4328   * @retval State of bit (1 or 0).
4329   */
LL_USART_IsEnabledIT_CTS(const USART_TypeDef * USARTx)4330 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_CTS(const USART_TypeDef *USARTx)
4331 {
4332   return ((READ_BIT(USARTx->CR3, USART_CR3_CTSIE) == (USART_CR3_CTSIE)) ? 1UL : 0UL);
4333 }
4334 
4335 /**
4336   * @brief  Check if the USART Wake Up from Stop Mode Interrupt is enabled or disabled.
4337   * @note   Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
4338   *         Wake-up from Stop mode feature is supported by the USARTx instance.
4339   * @rmtoll CR3          WUFIE         LL_USART_IsEnabledIT_WKUP
4340   * @param  USARTx USART Instance
4341   * @retval State of bit (1 or 0).
4342   */
LL_USART_IsEnabledIT_WKUP(const USART_TypeDef * USARTx)4343 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_WKUP(const USART_TypeDef *USARTx)
4344 {
4345   return ((READ_BIT(USARTx->CR3, USART_CR3_WUFIE) == (USART_CR3_WUFIE)) ? 1UL : 0UL);
4346 }
4347 
4348 #if defined(USART_CR1_FIFOEN)
4349 /**
4350   * @brief  Check if USART TX FIFO Threshold Interrupt is enabled or disabled
4351   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
4352   *         FIFO mode feature is supported by the USARTx instance.
4353   * @rmtoll CR3          TXFTIE        LL_USART_IsEnabledIT_TXFT
4354   * @param  USARTx USART Instance
4355   * @retval State of bit (1 or 0).
4356   */
LL_USART_IsEnabledIT_TXFT(const USART_TypeDef * USARTx)4357 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TXFT(const USART_TypeDef *USARTx)
4358 {
4359   return ((READ_BIT(USARTx->CR3, USART_CR3_TXFTIE) == (USART_CR3_TXFTIE)) ? 1UL : 0UL);
4360 }
4361 
4362 #endif /* USART_CR1_FIFOEN */
4363 #if defined(USART_TCBGT_SUPPORT)
4364 /* Function available only on devices supporting Transmit Complete before Guard Time feature */
4365 /**
4366   * @brief  Check if the Smartcard Transmission Complete Before Guard Time Interrupt is enabled or disabled.
4367   * @note   Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
4368   *         Smartcard feature is supported by the USARTx instance.
4369   * @rmtoll CR3          TCBGTIE       LL_USART_IsEnabledIT_TCBGT
4370   * @param  USARTx USART Instance
4371   * @retval State of bit (1 or 0).
4372   */
LL_USART_IsEnabledIT_TCBGT(const USART_TypeDef * USARTx)4373 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TCBGT(const USART_TypeDef *USARTx)
4374 {
4375   return ((READ_BIT(USARTx->CR3, USART_CR3_TCBGTIE) == (USART_CR3_TCBGTIE)) ? 1UL : 0UL);
4376 }
4377 #endif /* USART_TCBGT_SUPPORT */
4378 
4379 #if defined(USART_CR1_FIFOEN)
4380 /**
4381   * @brief  Check if USART RX FIFO Threshold Interrupt is enabled or disabled
4382   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
4383   *         FIFO mode feature is supported by the USARTx instance.
4384   * @rmtoll CR3          RXFTIE        LL_USART_IsEnabledIT_RXFT
4385   * @param  USARTx USART Instance
4386   * @retval State of bit (1 or 0).
4387   */
LL_USART_IsEnabledIT_RXFT(const USART_TypeDef * USARTx)4388 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RXFT(const USART_TypeDef *USARTx)
4389 {
4390   return ((READ_BIT(USARTx->CR3, USART_CR3_RXFTIE) == (USART_CR3_RXFTIE)) ? 1UL : 0UL);
4391 }
4392 
4393 #endif /* USART_CR1_FIFOEN */
4394 /**
4395   * @}
4396   */
4397 
4398 /** @defgroup USART_LL_EF_DMA_Management DMA_Management
4399   * @{
4400   */
4401 
4402 /**
4403   * @brief  Enable DMA Mode for reception
4404   * @rmtoll CR3          DMAR          LL_USART_EnableDMAReq_RX
4405   * @param  USARTx USART Instance
4406   * @retval None
4407   */
LL_USART_EnableDMAReq_RX(USART_TypeDef * USARTx)4408 __STATIC_INLINE void LL_USART_EnableDMAReq_RX(USART_TypeDef *USARTx)
4409 {
4410   ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_DMAR);
4411 }
4412 
4413 /**
4414   * @brief  Disable DMA Mode for reception
4415   * @rmtoll CR3          DMAR          LL_USART_DisableDMAReq_RX
4416   * @param  USARTx USART Instance
4417   * @retval None
4418   */
LL_USART_DisableDMAReq_RX(USART_TypeDef * USARTx)4419 __STATIC_INLINE void LL_USART_DisableDMAReq_RX(USART_TypeDef *USARTx)
4420 {
4421   ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_DMAR);
4422 }
4423 
4424 /**
4425   * @brief  Check if DMA Mode is enabled for reception
4426   * @rmtoll CR3          DMAR          LL_USART_IsEnabledDMAReq_RX
4427   * @param  USARTx USART Instance
4428   * @retval State of bit (1 or 0).
4429   */
LL_USART_IsEnabledDMAReq_RX(const USART_TypeDef * USARTx)4430 __STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_RX(const USART_TypeDef *USARTx)
4431 {
4432   return ((READ_BIT(USARTx->CR3, USART_CR3_DMAR) == (USART_CR3_DMAR)) ? 1UL : 0UL);
4433 }
4434 
4435 /**
4436   * @brief  Enable DMA Mode for transmission
4437   * @rmtoll CR3          DMAT          LL_USART_EnableDMAReq_TX
4438   * @param  USARTx USART Instance
4439   * @retval None
4440   */
LL_USART_EnableDMAReq_TX(USART_TypeDef * USARTx)4441 __STATIC_INLINE void LL_USART_EnableDMAReq_TX(USART_TypeDef *USARTx)
4442 {
4443   ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_DMAT);
4444 }
4445 
4446 /**
4447   * @brief  Disable DMA Mode for transmission
4448   * @rmtoll CR3          DMAT          LL_USART_DisableDMAReq_TX
4449   * @param  USARTx USART Instance
4450   * @retval None
4451   */
LL_USART_DisableDMAReq_TX(USART_TypeDef * USARTx)4452 __STATIC_INLINE void LL_USART_DisableDMAReq_TX(USART_TypeDef *USARTx)
4453 {
4454   ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_DMAT);
4455 }
4456 
4457 /**
4458   * @brief  Check if DMA Mode is enabled for transmission
4459   * @rmtoll CR3          DMAT          LL_USART_IsEnabledDMAReq_TX
4460   * @param  USARTx USART Instance
4461   * @retval State of bit (1 or 0).
4462   */
LL_USART_IsEnabledDMAReq_TX(const USART_TypeDef * USARTx)4463 __STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_TX(const USART_TypeDef *USARTx)
4464 {
4465   return ((READ_BIT(USARTx->CR3, USART_CR3_DMAT) == (USART_CR3_DMAT)) ? 1UL : 0UL);
4466 }
4467 
4468 /**
4469   * @brief  Enable DMA Disabling on Reception Error
4470   * @rmtoll CR3          DDRE          LL_USART_EnableDMADeactOnRxErr
4471   * @param  USARTx USART Instance
4472   * @retval None
4473   */
LL_USART_EnableDMADeactOnRxErr(USART_TypeDef * USARTx)4474 __STATIC_INLINE void LL_USART_EnableDMADeactOnRxErr(USART_TypeDef *USARTx)
4475 {
4476   SET_BIT(USARTx->CR3, USART_CR3_DDRE);
4477 }
4478 
4479 /**
4480   * @brief  Disable DMA Disabling on Reception Error
4481   * @rmtoll CR3          DDRE          LL_USART_DisableDMADeactOnRxErr
4482   * @param  USARTx USART Instance
4483   * @retval None
4484   */
LL_USART_DisableDMADeactOnRxErr(USART_TypeDef * USARTx)4485 __STATIC_INLINE void LL_USART_DisableDMADeactOnRxErr(USART_TypeDef *USARTx)
4486 {
4487   CLEAR_BIT(USARTx->CR3, USART_CR3_DDRE);
4488 }
4489 
4490 /**
4491   * @brief  Indicate if DMA Disabling on Reception Error is disabled
4492   * @rmtoll CR3          DDRE          LL_USART_IsEnabledDMADeactOnRxErr
4493   * @param  USARTx USART Instance
4494   * @retval State of bit (1 or 0).
4495   */
LL_USART_IsEnabledDMADeactOnRxErr(const USART_TypeDef * USARTx)4496 __STATIC_INLINE uint32_t LL_USART_IsEnabledDMADeactOnRxErr(const USART_TypeDef *USARTx)
4497 {
4498   return ((READ_BIT(USARTx->CR3, USART_CR3_DDRE) == (USART_CR3_DDRE)) ? 1UL : 0UL);
4499 }
4500 
4501 /**
4502   * @brief  Get the data register address used for DMA transfer
4503   * @rmtoll RDR          RDR           LL_USART_DMA_GetRegAddr\n
4504   * @rmtoll TDR          TDR           LL_USART_DMA_GetRegAddr
4505   * @param  USARTx USART Instance
4506   * @param  Direction This parameter can be one of the following values:
4507   *         @arg @ref LL_USART_DMA_REG_DATA_TRANSMIT
4508   *         @arg @ref LL_USART_DMA_REG_DATA_RECEIVE
4509   * @retval Address of data register
4510   */
LL_USART_DMA_GetRegAddr(const USART_TypeDef * USARTx,uint32_t Direction)4511 __STATIC_INLINE uint32_t LL_USART_DMA_GetRegAddr(const USART_TypeDef *USARTx, uint32_t Direction)
4512 {
4513   uint32_t data_reg_addr;
4514 
4515   if (Direction == LL_USART_DMA_REG_DATA_TRANSMIT)
4516   {
4517     /* return address of TDR register */
4518     data_reg_addr = (uint32_t) &(USARTx->TDR);
4519   }
4520   else
4521   {
4522     /* return address of RDR register */
4523     data_reg_addr = (uint32_t) &(USARTx->RDR);
4524   }
4525 
4526   return data_reg_addr;
4527 }
4528 
4529 /**
4530   * @}
4531   */
4532 
4533 /** @defgroup USART_LL_EF_Data_Management Data_Management
4534   * @{
4535   */
4536 
4537 /**
4538   * @brief  Read Receiver Data register (Receive Data value, 8 bits)
4539   * @rmtoll RDR          RDR           LL_USART_ReceiveData8
4540   * @param  USARTx USART Instance
4541   * @retval Value between Min_Data=0x00 and Max_Data=0xFF
4542   */
LL_USART_ReceiveData8(const USART_TypeDef * USARTx)4543 __STATIC_INLINE uint8_t LL_USART_ReceiveData8(const USART_TypeDef *USARTx)
4544 {
4545   return (uint8_t)(READ_BIT(USARTx->RDR, USART_RDR_RDR) & 0xFFU);
4546 }
4547 
4548 /**
4549   * @brief  Read Receiver Data register (Receive Data value, 9 bits)
4550   * @rmtoll RDR          RDR           LL_USART_ReceiveData9
4551   * @param  USARTx USART Instance
4552   * @retval Value between Min_Data=0x00 and Max_Data=0x1FF
4553   */
LL_USART_ReceiveData9(const USART_TypeDef * USARTx)4554 __STATIC_INLINE uint16_t LL_USART_ReceiveData9(const USART_TypeDef *USARTx)
4555 {
4556   return (uint16_t)(READ_BIT(USARTx->RDR, USART_RDR_RDR));
4557 }
4558 
4559 /**
4560   * @brief  Write in Transmitter Data Register (Transmit Data value, 8 bits)
4561   * @rmtoll TDR          TDR           LL_USART_TransmitData8
4562   * @param  USARTx USART Instance
4563   * @param  Value between Min_Data=0x00 and Max_Data=0xFF
4564   * @retval None
4565   */
LL_USART_TransmitData8(USART_TypeDef * USARTx,uint8_t Value)4566 __STATIC_INLINE void LL_USART_TransmitData8(USART_TypeDef *USARTx, uint8_t Value)
4567 {
4568   USARTx->TDR = Value;
4569 }
4570 
4571 /**
4572   * @brief  Write in Transmitter Data Register (Transmit Data value, 9 bits)
4573   * @rmtoll TDR          TDR           LL_USART_TransmitData9
4574   * @param  USARTx USART Instance
4575   * @param  Value between Min_Data=0x00 and Max_Data=0x1FF
4576   * @retval None
4577   */
LL_USART_TransmitData9(USART_TypeDef * USARTx,uint16_t Value)4578 __STATIC_INLINE void LL_USART_TransmitData9(USART_TypeDef *USARTx, uint16_t Value)
4579 {
4580   USARTx->TDR = (uint16_t)(Value & 0x1FFUL);
4581 }
4582 
4583 /**
4584   * @}
4585   */
4586 
4587 /** @defgroup USART_LL_EF_Execution Execution
4588   * @{
4589   */
4590 
4591 /**
4592   * @brief  Request an Automatic Baud Rate measurement on next received data frame
4593   * @note   Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
4594   *         Auto Baud Rate detection feature is supported by the USARTx instance.
4595   * @rmtoll RQR          ABRRQ         LL_USART_RequestAutoBaudRate
4596   * @param  USARTx USART Instance
4597   * @retval None
4598   */
LL_USART_RequestAutoBaudRate(USART_TypeDef * USARTx)4599 __STATIC_INLINE void LL_USART_RequestAutoBaudRate(USART_TypeDef *USARTx)
4600 {
4601   SET_BIT(USARTx->RQR, (uint16_t)USART_RQR_ABRRQ);
4602 }
4603 
4604 /**
4605   * @brief  Request Break sending
4606   * @rmtoll RQR          SBKRQ         LL_USART_RequestBreakSending
4607   * @param  USARTx USART Instance
4608   * @retval None
4609   */
LL_USART_RequestBreakSending(USART_TypeDef * USARTx)4610 __STATIC_INLINE void LL_USART_RequestBreakSending(USART_TypeDef *USARTx)
4611 {
4612   SET_BIT(USARTx->RQR, (uint16_t)USART_RQR_SBKRQ);
4613 }
4614 
4615 /**
4616   * @brief  Put USART in mute mode and set the RWU flag
4617   * @rmtoll RQR          MMRQ          LL_USART_RequestEnterMuteMode
4618   * @param  USARTx USART Instance
4619   * @retval None
4620   */
LL_USART_RequestEnterMuteMode(USART_TypeDef * USARTx)4621 __STATIC_INLINE void LL_USART_RequestEnterMuteMode(USART_TypeDef *USARTx)
4622 {
4623   SET_BIT(USARTx->RQR, (uint16_t)USART_RQR_MMRQ);
4624 }
4625 
4626 /**
4627   @if USART_CR1_FIFOEN
4628   * @brief  Request a Receive Data and FIFO flush
4629   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
4630   *         FIFO mode feature is supported by the USARTx instance.
4631   * @note   Allows to discard the received data without reading them, and avoid an overrun
4632   *         condition.
4633   @else
4634   * @brief  Request a Receive Data flush
4635   @endif
4636   * @rmtoll RQR          RXFRQ         LL_USART_RequestRxDataFlush
4637   * @param  USARTx USART Instance
4638   * @retval None
4639   */
LL_USART_RequestRxDataFlush(USART_TypeDef * USARTx)4640 __STATIC_INLINE void LL_USART_RequestRxDataFlush(USART_TypeDef *USARTx)
4641 {
4642   SET_BIT(USARTx->RQR, (uint16_t)USART_RQR_RXFRQ);
4643 }
4644 
4645 /**
4646   @if USART_CR1_FIFOEN
4647   * @brief  Request a Transmit data and FIFO flush
4648   * @note   Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
4649   *         FIFO mode feature is supported by the USARTx instance.
4650   @else
4651   * @brief  Request a Transmit data flush
4652   @endif
4653   * @rmtoll RQR          TXFRQ         LL_USART_RequestTxDataFlush
4654   * @param  USARTx USART Instance
4655   * @retval None
4656   */
LL_USART_RequestTxDataFlush(USART_TypeDef * USARTx)4657 __STATIC_INLINE void LL_USART_RequestTxDataFlush(USART_TypeDef *USARTx)
4658 {
4659   SET_BIT(USARTx->RQR, (uint16_t)USART_RQR_TXFRQ);
4660 }
4661 
4662 /**
4663   * @}
4664   */
4665 
4666 #if defined(USE_FULL_LL_DRIVER)
4667 /** @defgroup USART_LL_EF_Init Initialization and de-initialization functions
4668   * @{
4669   */
4670 ErrorStatus LL_USART_DeInit(const USART_TypeDef *USARTx);
4671 ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, const LL_USART_InitTypeDef *USART_InitStruct);
4672 void        LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct);
4673 ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, const LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
4674 void        LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
4675 /**
4676   * @}
4677   */
4678 #endif /* USE_FULL_LL_DRIVER */
4679 
4680 /**
4681   * @}
4682   */
4683 
4684 /**
4685   * @}
4686   */
4687 
4688 #endif /* USART1 || USART2 || USART3 || UART4 || UART5 */
4689 
4690 /**
4691   * @}
4692   */
4693 
4694 #ifdef __cplusplus
4695 }
4696 #endif
4697 
4698 #endif /* STM32L4xx_LL_USART_H */
4699 
4700