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