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