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