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