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