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