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