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