1 /**
2 ******************************************************************************
3 * @file stm32f4xx_ll_usart.h
4 * @author MCD Application Team
5 * @brief Header file of USART LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2016 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef __STM32F4xx_LL_USART_H
21 #define __STM32F4xx_LL_USART_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f4xx.h"
29
30 /** @addtogroup STM32F4xx_LL_Driver
31 * @{
32 */
33
34 #if defined (USART1) || defined (USART2) || defined (USART3) || defined (USART6) || defined (UART4) || defined (UART5) || defined (UART7) || defined (UART8) || defined (UART9) || defined (UART10)
35
36 /** @defgroup USART_LL USART
37 * @{
38 */
39
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42
43 /* Private constants ---------------------------------------------------------*/
44 /** @defgroup USART_LL_Private_Constants USART Private Constants
45 * @{
46 */
47
48 /* Defines used for the bit position in the register and perform offsets*/
49 #define USART_POSITION_GTPR_GT USART_GTPR_GT_Pos
50 /**
51 * @}
52 */
53
54 /* Private macros ------------------------------------------------------------*/
55 #if defined(USE_FULL_LL_DRIVER)
56 /** @defgroup USART_LL_Private_Macros USART Private Macros
57 * @{
58 */
59 /**
60 * @}
61 */
62 #endif /*USE_FULL_LL_DRIVER*/
63
64 /* Exported types ------------------------------------------------------------*/
65 #if defined(USE_FULL_LL_DRIVER)
66 /** @defgroup USART_LL_ES_INIT USART Exported Init structures
67 * @{
68 */
69
70 /**
71 * @brief LL USART Init Structure definition
72 */
73 typedef struct
74 {
75 uint32_t BaudRate; /*!< This field defines expected Usart communication baud rate.
76
77 This feature can be modified afterwards using unitary function @ref LL_USART_SetBaudRate().*/
78
79 uint32_t DataWidth; /*!< Specifies the number of data bits transmitted or received in a frame.
80 This parameter can be a value of @ref USART_LL_EC_DATAWIDTH.
81
82 This feature can be modified afterwards using unitary 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 function @ref LL_USART_SetStopBitsLength().*/
88
89 uint32_t Parity; /*!< Specifies the parity mode.
90 This parameter can be a value of @ref USART_LL_EC_PARITY.
91
92 This feature can be modified afterwards using unitary function @ref LL_USART_SetParity().*/
93
94 uint32_t TransferDirection; /*!< Specifies whether the Receive and/or Transmit mode is enabled or disabled.
95 This parameter can be a value of @ref USART_LL_EC_DIRECTION.
96
97 This feature can be modified afterwards using unitary function @ref LL_USART_SetTransferDirection().*/
98
99 uint32_t HardwareFlowControl; /*!< Specifies whether the hardware flow control mode is enabled or disabled.
100 This parameter can be a value of @ref USART_LL_EC_HWCONTROL.
101
102 This feature can be modified afterwards using unitary function @ref LL_USART_SetHWFlowCtrl().*/
103
104 uint32_t OverSampling; /*!< Specifies whether USART oversampling mode is 16 or 8.
105 This parameter can be a value of @ref USART_LL_EC_OVERSAMPLING.
106
107 This feature can be modified afterwards using unitary function @ref LL_USART_SetOverSampling().*/
108
109 } LL_USART_InitTypeDef;
110
111 /**
112 * @brief LL USART Clock Init Structure definition
113 */
114 typedef struct
115 {
116 uint32_t ClockOutput; /*!< Specifies whether the USART clock is enabled or disabled.
117 This parameter can be a value of @ref USART_LL_EC_CLOCK.
118
119 USART HW configuration can be modified afterwards using unitary functions
120 @ref LL_USART_EnableSCLKOutput() or @ref LL_USART_DisableSCLKOutput().
121 For more details, refer to description of this function. */
122
123 uint32_t ClockPolarity; /*!< Specifies the steady state of the serial clock.
124 This parameter can be a value of @ref USART_LL_EC_POLARITY.
125
126 USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetClockPolarity().
127 For more details, refer to description of this function. */
128
129 uint32_t ClockPhase; /*!< Specifies the clock transition on which the bit capture is made.
130 This parameter can be a value of @ref USART_LL_EC_PHASE.
131
132 USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetClockPhase().
133 For more details, refer to description of this function. */
134
135 uint32_t LastBitClockPulse; /*!< Specifies whether the clock pulse corresponding to the last transmitted
136 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
137 This parameter can be a value of @ref USART_LL_EC_LASTCLKPULSE.
138
139 USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetLastClkPulseOutput().
140 For more details, refer to description of this function. */
141
142 } LL_USART_ClockInitTypeDef;
143
144 /**
145 * @}
146 */
147 #endif /* USE_FULL_LL_DRIVER */
148
149 /* Exported constants --------------------------------------------------------*/
150 /** @defgroup USART_LL_Exported_Constants USART Exported Constants
151 * @{
152 */
153
154 /** @defgroup USART_LL_EC_GET_FLAG Get Flags Defines
155 * @brief Flags defines which can be used with LL_USART_ReadReg function
156 * @{
157 */
158 #define LL_USART_SR_PE USART_SR_PE /*!< Parity error flag */
159 #define LL_USART_SR_FE USART_SR_FE /*!< Framing error flag */
160 #define LL_USART_SR_NE USART_SR_NE /*!< Noise detected flag */
161 #define LL_USART_SR_ORE USART_SR_ORE /*!< Overrun error flag */
162 #define LL_USART_SR_IDLE USART_SR_IDLE /*!< Idle line detected flag */
163 #define LL_USART_SR_RXNE USART_SR_RXNE /*!< Read data register not empty flag */
164 #define LL_USART_SR_TC USART_SR_TC /*!< Transmission complete flag */
165 #define LL_USART_SR_TXE USART_SR_TXE /*!< Transmit data register empty flag */
166 #define LL_USART_SR_LBD USART_SR_LBD /*!< LIN break detection flag */
167 #define LL_USART_SR_CTS USART_SR_CTS /*!< CTS flag */
168 /**
169 * @}
170 */
171
172 /** @defgroup USART_LL_EC_IT IT Defines
173 * @brief IT defines which can be used with LL_USART_ReadReg and LL_USART_WriteReg functions
174 * @{
175 */
176 #define LL_USART_CR1_IDLEIE USART_CR1_IDLEIE /*!< IDLE interrupt enable */
177 #define LL_USART_CR1_RXNEIE USART_CR1_RXNEIE /*!< Read data register not empty interrupt enable */
178 #define LL_USART_CR1_TCIE USART_CR1_TCIE /*!< Transmission complete interrupt enable */
179 #define LL_USART_CR1_TXEIE USART_CR1_TXEIE /*!< Transmit data register empty interrupt enable */
180 #define LL_USART_CR1_PEIE USART_CR1_PEIE /*!< Parity error */
181 #define LL_USART_CR2_LBDIE USART_CR2_LBDIE /*!< LIN break detection interrupt enable */
182 #define LL_USART_CR3_EIE USART_CR3_EIE /*!< Error interrupt enable */
183 #define LL_USART_CR3_CTSIE USART_CR3_CTSIE /*!< CTS interrupt enable */
184 /**
185 * @}
186 */
187
188 /** @defgroup USART_LL_EC_DIRECTION Communication Direction
189 * @{
190 */
191 #define LL_USART_DIRECTION_NONE 0x00000000U /*!< Transmitter and Receiver are disabled */
192 #define LL_USART_DIRECTION_RX USART_CR1_RE /*!< Transmitter is disabled and Receiver is enabled */
193 #define LL_USART_DIRECTION_TX USART_CR1_TE /*!< Transmitter is enabled and Receiver is disabled */
194 #define LL_USART_DIRECTION_TX_RX (USART_CR1_TE |USART_CR1_RE) /*!< Transmitter and Receiver are enabled */
195 /**
196 * @}
197 */
198
199 /** @defgroup USART_LL_EC_PARITY Parity Control
200 * @{
201 */
202 #define LL_USART_PARITY_NONE 0x00000000U /*!< Parity control disabled */
203 #define LL_USART_PARITY_EVEN USART_CR1_PCE /*!< Parity control enabled and Even Parity is selected */
204 #define LL_USART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS) /*!< Parity control enabled and Odd Parity is selected */
205 /**
206 * @}
207 */
208
209 /** @defgroup USART_LL_EC_WAKEUP Wakeup
210 * @{
211 */
212 #define LL_USART_WAKEUP_IDLELINE 0x00000000U /*!< USART wake up from Mute mode on Idle Line */
213 #define LL_USART_WAKEUP_ADDRESSMARK USART_CR1_WAKE /*!< USART wake up from Mute mode on Address Mark */
214 /**
215 * @}
216 */
217
218 /** @defgroup USART_LL_EC_DATAWIDTH Datawidth
219 * @{
220 */
221 #define LL_USART_DATAWIDTH_8B 0x00000000U /*!< 8 bits word length : Start bit, 8 data bits, n stop bits */
222 #define LL_USART_DATAWIDTH_9B USART_CR1_M /*!< 9 bits word length : Start bit, 9 data bits, n stop bits */
223 /**
224 * @}
225 */
226
227 /** @defgroup USART_LL_EC_OVERSAMPLING Oversampling
228 * @{
229 */
230 #define LL_USART_OVERSAMPLING_16 0x00000000U /*!< Oversampling by 16 */
231 #define LL_USART_OVERSAMPLING_8 USART_CR1_OVER8 /*!< Oversampling by 8 */
232 /**
233 * @}
234 */
235
236 #if defined(USE_FULL_LL_DRIVER)
237 /** @defgroup USART_LL_EC_CLOCK Clock Signal
238 * @{
239 */
240
241 #define LL_USART_CLOCK_DISABLE 0x00000000U /*!< Clock signal not provided */
242 #define LL_USART_CLOCK_ENABLE USART_CR2_CLKEN /*!< Clock signal provided */
243 /**
244 * @}
245 */
246 #endif /*USE_FULL_LL_DRIVER*/
247
248 /** @defgroup USART_LL_EC_LASTCLKPULSE Last Clock Pulse
249 * @{
250 */
251 #define LL_USART_LASTCLKPULSE_NO_OUTPUT 0x00000000U /*!< The clock pulse of the last data bit is not output to the SCLK pin */
252 #define LL_USART_LASTCLKPULSE_OUTPUT USART_CR2_LBCL /*!< The clock pulse of the last data bit is output to the SCLK pin */
253 /**
254 * @}
255 */
256
257 /** @defgroup USART_LL_EC_PHASE Clock Phase
258 * @{
259 */
260 #define LL_USART_PHASE_1EDGE 0x00000000U /*!< The first clock transition is the first data capture edge */
261 #define LL_USART_PHASE_2EDGE USART_CR2_CPHA /*!< The second clock transition is the first data capture edge */
262 /**
263 * @}
264 */
265
266 /** @defgroup USART_LL_EC_POLARITY Clock Polarity
267 * @{
268 */
269 #define LL_USART_POLARITY_LOW 0x00000000U /*!< Steady low value on SCLK pin outside transmission window*/
270 #define LL_USART_POLARITY_HIGH USART_CR2_CPOL /*!< Steady high value on SCLK pin outside transmission window */
271 /**
272 * @}
273 */
274
275 /** @defgroup USART_LL_EC_STOPBITS Stop Bits
276 * @{
277 */
278 #define LL_USART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< 0.5 stop bit */
279 #define LL_USART_STOPBITS_1 0x00000000U /*!< 1 stop bit */
280 #define LL_USART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< 1.5 stop bits */
281 #define LL_USART_STOPBITS_2 USART_CR2_STOP_1 /*!< 2 stop bits */
282 /**
283 * @}
284 */
285
286 /** @defgroup USART_LL_EC_HWCONTROL Hardware Control
287 * @{
288 */
289 #define LL_USART_HWCONTROL_NONE 0x00000000U /*!< CTS and RTS hardware flow control disabled */
290 #define LL_USART_HWCONTROL_RTS USART_CR3_RTSE /*!< RTS output enabled, data is only requested when there is space in the receive buffer */
291 #define LL_USART_HWCONTROL_CTS USART_CR3_CTSE /*!< CTS mode enabled, data is only transmitted when the nCTS input is asserted (tied to 0) */
292 #define LL_USART_HWCONTROL_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE) /*!< CTS and RTS hardware flow control enabled */
293 /**
294 * @}
295 */
296
297 /** @defgroup USART_LL_EC_IRDA_POWER IrDA Power
298 * @{
299 */
300 #define LL_USART_IRDA_POWER_NORMAL 0x00000000U /*!< IrDA normal power mode */
301 #define LL_USART_IRDA_POWER_LOW USART_CR3_IRLP /*!< IrDA low power mode */
302 /**
303 * @}
304 */
305
306 /** @defgroup USART_LL_EC_LINBREAK_DETECT LIN Break Detection Length
307 * @{
308 */
309 #define LL_USART_LINBREAK_DETECT_10B 0x00000000U /*!< 10-bit break detection method selected */
310 #define LL_USART_LINBREAK_DETECT_11B USART_CR2_LBDL /*!< 11-bit break detection method selected */
311 /**
312 * @}
313 */
314
315 /**
316 * @}
317 */
318
319 /* Exported macro ------------------------------------------------------------*/
320 /** @defgroup USART_LL_Exported_Macros USART Exported Macros
321 * @{
322 */
323
324 /** @defgroup USART_LL_EM_WRITE_READ Common Write and read registers Macros
325 * @{
326 */
327
328 /**
329 * @brief Write a value in USART register
330 * @param __INSTANCE__ USART Instance
331 * @param __REG__ Register to be written
332 * @param __VALUE__ Value to be written in the register
333 * @retval None
334 */
335 #define LL_USART_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
336
337 /**
338 * @brief Read a value in USART register
339 * @param __INSTANCE__ USART Instance
340 * @param __REG__ Register to be read
341 * @retval Register value
342 */
343 #define LL_USART_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
344 /**
345 * @}
346 */
347
348 /** @defgroup USART_LL_EM_Exported_Macros_Helper Exported_Macros_Helper
349 * @{
350 */
351
352 /**
353 * @brief Compute USARTDIV value according to Peripheral Clock and
354 * expected Baud Rate in 8 bits sampling mode (32 bits value of USARTDIV is returned)
355 * @param __PERIPHCLK__ Peripheral Clock frequency used for USART instance
356 * @param __BAUDRATE__ Baud rate value to achieve
357 * @retval USARTDIV value to be used for BRR register filling in OverSampling_8 case
358 */
359 #define __LL_USART_DIV_SAMPLING8_100(__PERIPHCLK__, __BAUDRATE__) ((uint32_t)((((uint64_t)(__PERIPHCLK__))*25)/(2*((uint64_t)(__BAUDRATE__)))))
360 #define __LL_USART_DIVMANT_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) (__LL_USART_DIV_SAMPLING8_100((__PERIPHCLK__), (__BAUDRATE__))/100)
361 #define __LL_USART_DIVFRAQ_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) ((((__LL_USART_DIV_SAMPLING8_100((__PERIPHCLK__), (__BAUDRATE__)) - (__LL_USART_DIVMANT_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) * 100)) * 8)\
362 + 50) / 100)
363 /* UART BRR = mantissa + overflow + fraction
364 = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07) */
365 #define __LL_USART_DIV_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIVMANT_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) << 4) + \
366 ((__LL_USART_DIVFRAQ_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) & 0xF8) << 1)) + \
367 (__LL_USART_DIVFRAQ_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) & 0x07))
368
369 /**
370 * @brief Compute USARTDIV value according to Peripheral Clock and
371 * expected Baud Rate in 16 bits sampling mode (32 bits value of USARTDIV is returned)
372 * @param __PERIPHCLK__ Peripheral Clock frequency used for USART instance
373 * @param __BAUDRATE__ Baud rate value to achieve
374 * @retval USARTDIV value to be used for BRR register filling in OverSampling_16 case
375 */
376 #define __LL_USART_DIV_SAMPLING16_100(__PERIPHCLK__, __BAUDRATE__) ((uint32_t)((((uint64_t)(__PERIPHCLK__))*25)/(4*((uint64_t)(__BAUDRATE__)))))
377 #define __LL_USART_DIVMANT_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (__LL_USART_DIV_SAMPLING16_100((__PERIPHCLK__), (__BAUDRATE__))/100)
378 #define __LL_USART_DIVFRAQ_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) ((((__LL_USART_DIV_SAMPLING16_100((__PERIPHCLK__), (__BAUDRATE__)) - (__LL_USART_DIVMANT_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) * 100)) * 16)\
379 + 50) / 100)
380 /* USART BRR = mantissa + overflow + fraction
381 = (USART DIVMANT << 4) + (USART DIVFRAQ & 0xF0) + (USART DIVFRAQ & 0x0F) */
382 #define __LL_USART_DIV_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIVMANT_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) << 4) + \
383 (__LL_USART_DIVFRAQ_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) & 0xF0)) + \
384 (__LL_USART_DIVFRAQ_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) & 0x0F))
385
386 /**
387 * @}
388 */
389
390 /**
391 * @}
392 */
393
394 /* Exported functions --------------------------------------------------------*/
395
396 /** @defgroup USART_LL_Exported_Functions USART Exported Functions
397 * @{
398 */
399
400 /** @defgroup USART_LL_EF_Configuration Configuration functions
401 * @{
402 */
403
404 /**
405 * @brief USART Enable
406 * @rmtoll CR1 UE LL_USART_Enable
407 * @param USARTx USART Instance
408 * @retval None
409 */
LL_USART_Enable(USART_TypeDef * USARTx)410 __STATIC_INLINE void LL_USART_Enable(USART_TypeDef *USARTx)
411 {
412 SET_BIT(USARTx->CR1, USART_CR1_UE);
413 }
414
415 /**
416 * @brief USART Disable (all USART prescalers and outputs are disabled)
417 * @note When USART is disabled, USART prescalers and outputs are stopped immediately,
418 * and current operations are discarded. The configuration of the USART is kept, but all the status
419 * flags, in the USARTx_SR are set to their default values.
420 * @rmtoll CR1 UE LL_USART_Disable
421 * @param USARTx USART Instance
422 * @retval None
423 */
LL_USART_Disable(USART_TypeDef * USARTx)424 __STATIC_INLINE void LL_USART_Disable(USART_TypeDef *USARTx)
425 {
426 CLEAR_BIT(USARTx->CR1, USART_CR1_UE);
427 }
428
429 /**
430 * @brief Indicate if USART is enabled
431 * @rmtoll CR1 UE LL_USART_IsEnabled
432 * @param USARTx USART Instance
433 * @retval State of bit (1 or 0).
434 */
LL_USART_IsEnabled(USART_TypeDef * USARTx)435 __STATIC_INLINE uint32_t LL_USART_IsEnabled(USART_TypeDef *USARTx)
436 {
437 return (READ_BIT(USARTx->CR1, USART_CR1_UE) == (USART_CR1_UE));
438 }
439
440 /**
441 * @brief Receiver Enable (Receiver is enabled and begins searching for a start bit)
442 * @rmtoll CR1 RE LL_USART_EnableDirectionRx
443 * @param USARTx USART Instance
444 * @retval None
445 */
LL_USART_EnableDirectionRx(USART_TypeDef * USARTx)446 __STATIC_INLINE void LL_USART_EnableDirectionRx(USART_TypeDef *USARTx)
447 {
448 ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_RE);
449 }
450
451 /**
452 * @brief Receiver Disable
453 * @rmtoll CR1 RE LL_USART_DisableDirectionRx
454 * @param USARTx USART Instance
455 * @retval None
456 */
LL_USART_DisableDirectionRx(USART_TypeDef * USARTx)457 __STATIC_INLINE void LL_USART_DisableDirectionRx(USART_TypeDef *USARTx)
458 {
459 ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_RE);
460 }
461
462 /**
463 * @brief Transmitter Enable
464 * @rmtoll CR1 TE LL_USART_EnableDirectionTx
465 * @param USARTx USART Instance
466 * @retval None
467 */
LL_USART_EnableDirectionTx(USART_TypeDef * USARTx)468 __STATIC_INLINE void LL_USART_EnableDirectionTx(USART_TypeDef *USARTx)
469 {
470 ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TE);
471 }
472
473 /**
474 * @brief Transmitter Disable
475 * @rmtoll CR1 TE LL_USART_DisableDirectionTx
476 * @param USARTx USART Instance
477 * @retval None
478 */
LL_USART_DisableDirectionTx(USART_TypeDef * USARTx)479 __STATIC_INLINE void LL_USART_DisableDirectionTx(USART_TypeDef *USARTx)
480 {
481 ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TE);
482 }
483
484 /**
485 * @brief Configure simultaneously enabled/disabled states
486 * of Transmitter and Receiver
487 * @rmtoll CR1 RE LL_USART_SetTransferDirection\n
488 * CR1 TE LL_USART_SetTransferDirection
489 * @param USARTx USART Instance
490 * @param TransferDirection This parameter can be one of the following values:
491 * @arg @ref LL_USART_DIRECTION_NONE
492 * @arg @ref LL_USART_DIRECTION_RX
493 * @arg @ref LL_USART_DIRECTION_TX
494 * @arg @ref LL_USART_DIRECTION_TX_RX
495 * @retval None
496 */
LL_USART_SetTransferDirection(USART_TypeDef * USARTx,uint32_t TransferDirection)497 __STATIC_INLINE void LL_USART_SetTransferDirection(USART_TypeDef *USARTx, uint32_t TransferDirection)
498 {
499 ATOMIC_MODIFY_REG(USARTx->CR1, USART_CR1_RE | USART_CR1_TE, TransferDirection);
500 }
501
502 /**
503 * @brief Return enabled/disabled states of Transmitter and Receiver
504 * @rmtoll CR1 RE LL_USART_GetTransferDirection\n
505 * CR1 TE LL_USART_GetTransferDirection
506 * @param USARTx USART Instance
507 * @retval Returned value can be one of the following values:
508 * @arg @ref LL_USART_DIRECTION_NONE
509 * @arg @ref LL_USART_DIRECTION_RX
510 * @arg @ref LL_USART_DIRECTION_TX
511 * @arg @ref LL_USART_DIRECTION_TX_RX
512 */
LL_USART_GetTransferDirection(USART_TypeDef * USARTx)513 __STATIC_INLINE uint32_t LL_USART_GetTransferDirection(USART_TypeDef *USARTx)
514 {
515 return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_RE | USART_CR1_TE));
516 }
517
518 /**
519 * @brief Configure Parity (enabled/disabled and parity mode if enabled).
520 * @note This function selects if hardware parity control (generation and detection) is enabled or disabled.
521 * When the parity control is enabled (Odd or Even), computed parity bit is inserted at the MSB position
522 * (9th or 8th bit depending on data width) and parity is checked on the received data.
523 * @rmtoll CR1 PS LL_USART_SetParity\n
524 * CR1 PCE LL_USART_SetParity
525 * @param USARTx USART Instance
526 * @param Parity This parameter can be one of the following values:
527 * @arg @ref LL_USART_PARITY_NONE
528 * @arg @ref LL_USART_PARITY_EVEN
529 * @arg @ref LL_USART_PARITY_ODD
530 * @retval None
531 */
LL_USART_SetParity(USART_TypeDef * USARTx,uint32_t Parity)532 __STATIC_INLINE void LL_USART_SetParity(USART_TypeDef *USARTx, uint32_t Parity)
533 {
534 MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE, Parity);
535 }
536
537 /**
538 * @brief Return Parity configuration (enabled/disabled and parity mode if enabled)
539 * @rmtoll CR1 PS LL_USART_GetParity\n
540 * CR1 PCE LL_USART_GetParity
541 * @param USARTx USART Instance
542 * @retval Returned value can be one of the following values:
543 * @arg @ref LL_USART_PARITY_NONE
544 * @arg @ref LL_USART_PARITY_EVEN
545 * @arg @ref LL_USART_PARITY_ODD
546 */
LL_USART_GetParity(USART_TypeDef * USARTx)547 __STATIC_INLINE uint32_t LL_USART_GetParity(USART_TypeDef *USARTx)
548 {
549 return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE));
550 }
551
552 /**
553 * @brief Set Receiver Wake Up method from Mute mode.
554 * @rmtoll CR1 WAKE LL_USART_SetWakeUpMethod
555 * @param USARTx USART Instance
556 * @param Method This parameter can be one of the following values:
557 * @arg @ref LL_USART_WAKEUP_IDLELINE
558 * @arg @ref LL_USART_WAKEUP_ADDRESSMARK
559 * @retval None
560 */
LL_USART_SetWakeUpMethod(USART_TypeDef * USARTx,uint32_t Method)561 __STATIC_INLINE void LL_USART_SetWakeUpMethod(USART_TypeDef *USARTx, uint32_t Method)
562 {
563 MODIFY_REG(USARTx->CR1, USART_CR1_WAKE, Method);
564 }
565
566 /**
567 * @brief Return Receiver Wake Up method from Mute mode
568 * @rmtoll CR1 WAKE LL_USART_GetWakeUpMethod
569 * @param USARTx USART Instance
570 * @retval Returned value can be one of the following values:
571 * @arg @ref LL_USART_WAKEUP_IDLELINE
572 * @arg @ref LL_USART_WAKEUP_ADDRESSMARK
573 */
LL_USART_GetWakeUpMethod(USART_TypeDef * USARTx)574 __STATIC_INLINE uint32_t LL_USART_GetWakeUpMethod(USART_TypeDef *USARTx)
575 {
576 return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_WAKE));
577 }
578
579 /**
580 * @brief Set Word length (i.e. nb of data bits, excluding start and stop bits)
581 * @rmtoll CR1 M LL_USART_SetDataWidth
582 * @param USARTx USART Instance
583 * @param DataWidth This parameter can be one of the following values:
584 * @arg @ref LL_USART_DATAWIDTH_8B
585 * @arg @ref LL_USART_DATAWIDTH_9B
586 * @retval None
587 */
LL_USART_SetDataWidth(USART_TypeDef * USARTx,uint32_t DataWidth)588 __STATIC_INLINE void LL_USART_SetDataWidth(USART_TypeDef *USARTx, uint32_t DataWidth)
589 {
590 MODIFY_REG(USARTx->CR1, USART_CR1_M, DataWidth);
591 }
592
593 /**
594 * @brief Return Word length (i.e. nb of data bits, excluding start and stop bits)
595 * @rmtoll CR1 M LL_USART_GetDataWidth
596 * @param USARTx USART Instance
597 * @retval Returned value can be one of the following values:
598 * @arg @ref LL_USART_DATAWIDTH_8B
599 * @arg @ref LL_USART_DATAWIDTH_9B
600 */
LL_USART_GetDataWidth(USART_TypeDef * USARTx)601 __STATIC_INLINE uint32_t LL_USART_GetDataWidth(USART_TypeDef *USARTx)
602 {
603 return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_M));
604 }
605
606 /**
607 * @brief Set Oversampling to 8-bit or 16-bit mode
608 * @rmtoll CR1 OVER8 LL_USART_SetOverSampling
609 * @param USARTx USART Instance
610 * @param OverSampling This parameter can be one of the following values:
611 * @arg @ref LL_USART_OVERSAMPLING_16
612 * @arg @ref LL_USART_OVERSAMPLING_8
613 * @retval None
614 */
LL_USART_SetOverSampling(USART_TypeDef * USARTx,uint32_t OverSampling)615 __STATIC_INLINE void LL_USART_SetOverSampling(USART_TypeDef *USARTx, uint32_t OverSampling)
616 {
617 MODIFY_REG(USARTx->CR1, USART_CR1_OVER8, OverSampling);
618 }
619
620 /**
621 * @brief Return Oversampling mode
622 * @rmtoll CR1 OVER8 LL_USART_GetOverSampling
623 * @param USARTx USART Instance
624 * @retval Returned value can be one of the following values:
625 * @arg @ref LL_USART_OVERSAMPLING_16
626 * @arg @ref LL_USART_OVERSAMPLING_8
627 */
LL_USART_GetOverSampling(USART_TypeDef * USARTx)628 __STATIC_INLINE uint32_t LL_USART_GetOverSampling(USART_TypeDef *USARTx)
629 {
630 return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_OVER8));
631 }
632
633 /**
634 * @brief Configure if Clock pulse of the last data bit is output to the SCLK pin or not
635 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
636 * Synchronous mode is supported by the USARTx instance.
637 * @rmtoll CR2 LBCL LL_USART_SetLastClkPulseOutput
638 * @param USARTx USART Instance
639 * @param LastBitClockPulse This parameter can be one of the following values:
640 * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
641 * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
642 * @retval None
643 */
LL_USART_SetLastClkPulseOutput(USART_TypeDef * USARTx,uint32_t LastBitClockPulse)644 __STATIC_INLINE void LL_USART_SetLastClkPulseOutput(USART_TypeDef *USARTx, uint32_t LastBitClockPulse)
645 {
646 MODIFY_REG(USARTx->CR2, USART_CR2_LBCL, LastBitClockPulse);
647 }
648
649 /**
650 * @brief Retrieve Clock pulse of the last data bit output configuration
651 * (Last bit Clock pulse output to the SCLK pin or not)
652 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
653 * Synchronous mode is supported by the USARTx instance.
654 * @rmtoll CR2 LBCL LL_USART_GetLastClkPulseOutput
655 * @param USARTx USART Instance
656 * @retval Returned value can be one of the following values:
657 * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
658 * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
659 */
LL_USART_GetLastClkPulseOutput(USART_TypeDef * USARTx)660 __STATIC_INLINE uint32_t LL_USART_GetLastClkPulseOutput(USART_TypeDef *USARTx)
661 {
662 return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBCL));
663 }
664
665 /**
666 * @brief Select the phase of the clock output on the SCLK pin in synchronous mode
667 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
668 * Synchronous mode is supported by the USARTx instance.
669 * @rmtoll CR2 CPHA LL_USART_SetClockPhase
670 * @param USARTx USART Instance
671 * @param ClockPhase This parameter can be one of the following values:
672 * @arg @ref LL_USART_PHASE_1EDGE
673 * @arg @ref LL_USART_PHASE_2EDGE
674 * @retval None
675 */
LL_USART_SetClockPhase(USART_TypeDef * USARTx,uint32_t ClockPhase)676 __STATIC_INLINE void LL_USART_SetClockPhase(USART_TypeDef *USARTx, uint32_t ClockPhase)
677 {
678 MODIFY_REG(USARTx->CR2, USART_CR2_CPHA, ClockPhase);
679 }
680
681 /**
682 * @brief Return phase of the clock output on the SCLK pin in synchronous mode
683 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
684 * Synchronous mode is supported by the USARTx instance.
685 * @rmtoll CR2 CPHA LL_USART_GetClockPhase
686 * @param USARTx USART Instance
687 * @retval Returned value can be one of the following values:
688 * @arg @ref LL_USART_PHASE_1EDGE
689 * @arg @ref LL_USART_PHASE_2EDGE
690 */
LL_USART_GetClockPhase(USART_TypeDef * USARTx)691 __STATIC_INLINE uint32_t LL_USART_GetClockPhase(USART_TypeDef *USARTx)
692 {
693 return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPHA));
694 }
695
696 /**
697 * @brief Select the polarity of the clock output on the SCLK pin in synchronous mode
698 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
699 * Synchronous mode is supported by the USARTx instance.
700 * @rmtoll CR2 CPOL LL_USART_SetClockPolarity
701 * @param USARTx USART Instance
702 * @param ClockPolarity This parameter can be one of the following values:
703 * @arg @ref LL_USART_POLARITY_LOW
704 * @arg @ref LL_USART_POLARITY_HIGH
705 * @retval None
706 */
LL_USART_SetClockPolarity(USART_TypeDef * USARTx,uint32_t ClockPolarity)707 __STATIC_INLINE void LL_USART_SetClockPolarity(USART_TypeDef *USARTx, uint32_t ClockPolarity)
708 {
709 MODIFY_REG(USARTx->CR2, USART_CR2_CPOL, ClockPolarity);
710 }
711
712 /**
713 * @brief Return polarity of the clock output on the SCLK pin in synchronous mode
714 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
715 * Synchronous mode is supported by the USARTx instance.
716 * @rmtoll CR2 CPOL LL_USART_GetClockPolarity
717 * @param USARTx USART Instance
718 * @retval Returned value can be one of the following values:
719 * @arg @ref LL_USART_POLARITY_LOW
720 * @arg @ref LL_USART_POLARITY_HIGH
721 */
LL_USART_GetClockPolarity(USART_TypeDef * USARTx)722 __STATIC_INLINE uint32_t LL_USART_GetClockPolarity(USART_TypeDef *USARTx)
723 {
724 return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPOL));
725 }
726
727 /**
728 * @brief Configure Clock signal format (Phase Polarity and choice about output of last bit clock pulse)
729 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
730 * Synchronous mode is supported by the USARTx instance.
731 * @note Call of this function is equivalent to following function call sequence :
732 * - Clock Phase configuration using @ref LL_USART_SetClockPhase() function
733 * - Clock Polarity configuration using @ref LL_USART_SetClockPolarity() function
734 * - Output of Last bit Clock pulse configuration using @ref LL_USART_SetLastClkPulseOutput() function
735 * @rmtoll CR2 CPHA LL_USART_ConfigClock\n
736 * CR2 CPOL LL_USART_ConfigClock\n
737 * CR2 LBCL LL_USART_ConfigClock
738 * @param USARTx USART Instance
739 * @param Phase This parameter can be one of the following values:
740 * @arg @ref LL_USART_PHASE_1EDGE
741 * @arg @ref LL_USART_PHASE_2EDGE
742 * @param Polarity This parameter can be one of the following values:
743 * @arg @ref LL_USART_POLARITY_LOW
744 * @arg @ref LL_USART_POLARITY_HIGH
745 * @param LBCPOutput This parameter can be one of the following values:
746 * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
747 * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
748 * @retval None
749 */
LL_USART_ConfigClock(USART_TypeDef * USARTx,uint32_t Phase,uint32_t Polarity,uint32_t LBCPOutput)750 __STATIC_INLINE void LL_USART_ConfigClock(USART_TypeDef *USARTx, uint32_t Phase, uint32_t Polarity, uint32_t LBCPOutput)
751 {
752 MODIFY_REG(USARTx->CR2, USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL, Phase | Polarity | LBCPOutput);
753 }
754
755 /**
756 * @brief Enable Clock output on SCLK pin
757 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
758 * Synchronous mode is supported by the USARTx instance.
759 * @rmtoll CR2 CLKEN LL_USART_EnableSCLKOutput
760 * @param USARTx USART Instance
761 * @retval None
762 */
LL_USART_EnableSCLKOutput(USART_TypeDef * USARTx)763 __STATIC_INLINE void LL_USART_EnableSCLKOutput(USART_TypeDef *USARTx)
764 {
765 SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
766 }
767
768 /**
769 * @brief Disable Clock output on SCLK pin
770 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
771 * Synchronous mode is supported by the USARTx instance.
772 * @rmtoll CR2 CLKEN LL_USART_DisableSCLKOutput
773 * @param USARTx USART Instance
774 * @retval None
775 */
LL_USART_DisableSCLKOutput(USART_TypeDef * USARTx)776 __STATIC_INLINE void LL_USART_DisableSCLKOutput(USART_TypeDef *USARTx)
777 {
778 CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
779 }
780
781 /**
782 * @brief Indicate if Clock output on SCLK pin is enabled
783 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
784 * Synchronous mode is supported by the USARTx instance.
785 * @rmtoll CR2 CLKEN LL_USART_IsEnabledSCLKOutput
786 * @param USARTx USART Instance
787 * @retval State of bit (1 or 0).
788 */
LL_USART_IsEnabledSCLKOutput(USART_TypeDef * USARTx)789 __STATIC_INLINE uint32_t LL_USART_IsEnabledSCLKOutput(USART_TypeDef *USARTx)
790 {
791 return (READ_BIT(USARTx->CR2, USART_CR2_CLKEN) == (USART_CR2_CLKEN));
792 }
793
794 /**
795 * @brief Set the length of the stop bits
796 * @rmtoll CR2 STOP LL_USART_SetStopBitsLength
797 * @param USARTx USART Instance
798 * @param StopBits This parameter can be one of the following values:
799 * @arg @ref LL_USART_STOPBITS_0_5
800 * @arg @ref LL_USART_STOPBITS_1
801 * @arg @ref LL_USART_STOPBITS_1_5
802 * @arg @ref LL_USART_STOPBITS_2
803 * @retval None
804 */
LL_USART_SetStopBitsLength(USART_TypeDef * USARTx,uint32_t StopBits)805 __STATIC_INLINE void LL_USART_SetStopBitsLength(USART_TypeDef *USARTx, uint32_t StopBits)
806 {
807 MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
808 }
809
810 /**
811 * @brief Retrieve the length of the stop bits
812 * @rmtoll CR2 STOP LL_USART_GetStopBitsLength
813 * @param USARTx USART Instance
814 * @retval Returned value can be one of the following values:
815 * @arg @ref LL_USART_STOPBITS_0_5
816 * @arg @ref LL_USART_STOPBITS_1
817 * @arg @ref LL_USART_STOPBITS_1_5
818 * @arg @ref LL_USART_STOPBITS_2
819 */
LL_USART_GetStopBitsLength(USART_TypeDef * USARTx)820 __STATIC_INLINE uint32_t LL_USART_GetStopBitsLength(USART_TypeDef *USARTx)
821 {
822 return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_STOP));
823 }
824
825 /**
826 * @brief Configure Character frame format (Datawidth, Parity control, Stop Bits)
827 * @note Call of this function is equivalent to following function call sequence :
828 * - Data Width configuration using @ref LL_USART_SetDataWidth() function
829 * - Parity Control and mode configuration using @ref LL_USART_SetParity() function
830 * - Stop bits configuration using @ref LL_USART_SetStopBitsLength() function
831 * @rmtoll CR1 PS LL_USART_ConfigCharacter\n
832 * CR1 PCE LL_USART_ConfigCharacter\n
833 * CR1 M LL_USART_ConfigCharacter\n
834 * CR2 STOP LL_USART_ConfigCharacter
835 * @param USARTx USART Instance
836 * @param DataWidth This parameter can be one of the following values:
837 * @arg @ref LL_USART_DATAWIDTH_8B
838 * @arg @ref LL_USART_DATAWIDTH_9B
839 * @param Parity This parameter can be one of the following values:
840 * @arg @ref LL_USART_PARITY_NONE
841 * @arg @ref LL_USART_PARITY_EVEN
842 * @arg @ref LL_USART_PARITY_ODD
843 * @param StopBits This parameter can be one of the following values:
844 * @arg @ref LL_USART_STOPBITS_0_5
845 * @arg @ref LL_USART_STOPBITS_1
846 * @arg @ref LL_USART_STOPBITS_1_5
847 * @arg @ref LL_USART_STOPBITS_2
848 * @retval None
849 */
LL_USART_ConfigCharacter(USART_TypeDef * USARTx,uint32_t DataWidth,uint32_t Parity,uint32_t StopBits)850 __STATIC_INLINE void LL_USART_ConfigCharacter(USART_TypeDef *USARTx, uint32_t DataWidth, uint32_t Parity,
851 uint32_t StopBits)
852 {
853 MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE | USART_CR1_M, Parity | DataWidth);
854 MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
855 }
856
857 /**
858 * @brief Set Address of the USART node.
859 * @note This is used in multiprocessor communication during Mute mode or Stop mode,
860 * for wake up with address mark detection.
861 * @rmtoll CR2 ADD LL_USART_SetNodeAddress
862 * @param USARTx USART Instance
863 * @param NodeAddress 4 bit Address of the USART node.
864 * @retval None
865 */
LL_USART_SetNodeAddress(USART_TypeDef * USARTx,uint32_t NodeAddress)866 __STATIC_INLINE void LL_USART_SetNodeAddress(USART_TypeDef *USARTx, uint32_t NodeAddress)
867 {
868 MODIFY_REG(USARTx->CR2, USART_CR2_ADD, (NodeAddress & USART_CR2_ADD));
869 }
870
871 /**
872 * @brief Return 4 bit Address of the USART node as set in ADD field of CR2.
873 * @note only 4bits (b3-b0) of returned value are relevant (b31-b4 are not relevant)
874 * @rmtoll CR2 ADD LL_USART_GetNodeAddress
875 * @param USARTx USART Instance
876 * @retval Address of the USART node (Value between Min_Data=0 and Max_Data=255)
877 */
LL_USART_GetNodeAddress(USART_TypeDef * USARTx)878 __STATIC_INLINE uint32_t LL_USART_GetNodeAddress(USART_TypeDef *USARTx)
879 {
880 return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ADD));
881 }
882
883 /**
884 * @brief Enable RTS HW Flow Control
885 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
886 * Hardware Flow control feature is supported by the USARTx instance.
887 * @rmtoll CR3 RTSE LL_USART_EnableRTSHWFlowCtrl
888 * @param USARTx USART Instance
889 * @retval None
890 */
LL_USART_EnableRTSHWFlowCtrl(USART_TypeDef * USARTx)891 __STATIC_INLINE void LL_USART_EnableRTSHWFlowCtrl(USART_TypeDef *USARTx)
892 {
893 SET_BIT(USARTx->CR3, USART_CR3_RTSE);
894 }
895
896 /**
897 * @brief Disable RTS HW Flow Control
898 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
899 * Hardware Flow control feature is supported by the USARTx instance.
900 * @rmtoll CR3 RTSE LL_USART_DisableRTSHWFlowCtrl
901 * @param USARTx USART Instance
902 * @retval None
903 */
LL_USART_DisableRTSHWFlowCtrl(USART_TypeDef * USARTx)904 __STATIC_INLINE void LL_USART_DisableRTSHWFlowCtrl(USART_TypeDef *USARTx)
905 {
906 CLEAR_BIT(USARTx->CR3, USART_CR3_RTSE);
907 }
908
909 /**
910 * @brief Enable CTS HW Flow Control
911 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
912 * Hardware Flow control feature is supported by the USARTx instance.
913 * @rmtoll CR3 CTSE LL_USART_EnableCTSHWFlowCtrl
914 * @param USARTx USART Instance
915 * @retval None
916 */
LL_USART_EnableCTSHWFlowCtrl(USART_TypeDef * USARTx)917 __STATIC_INLINE void LL_USART_EnableCTSHWFlowCtrl(USART_TypeDef *USARTx)
918 {
919 SET_BIT(USARTx->CR3, USART_CR3_CTSE);
920 }
921
922 /**
923 * @brief Disable CTS HW Flow Control
924 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
925 * Hardware Flow control feature is supported by the USARTx instance.
926 * @rmtoll CR3 CTSE LL_USART_DisableCTSHWFlowCtrl
927 * @param USARTx USART Instance
928 * @retval None
929 */
LL_USART_DisableCTSHWFlowCtrl(USART_TypeDef * USARTx)930 __STATIC_INLINE void LL_USART_DisableCTSHWFlowCtrl(USART_TypeDef *USARTx)
931 {
932 CLEAR_BIT(USARTx->CR3, USART_CR3_CTSE);
933 }
934
935 /**
936 * @brief Configure HW Flow Control mode (both CTS and RTS)
937 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
938 * Hardware Flow control feature is supported by the USARTx instance.
939 * @rmtoll CR3 RTSE LL_USART_SetHWFlowCtrl\n
940 * CR3 CTSE LL_USART_SetHWFlowCtrl
941 * @param USARTx USART Instance
942 * @param HardwareFlowControl This parameter can be one of the following values:
943 * @arg @ref LL_USART_HWCONTROL_NONE
944 * @arg @ref LL_USART_HWCONTROL_RTS
945 * @arg @ref LL_USART_HWCONTROL_CTS
946 * @arg @ref LL_USART_HWCONTROL_RTS_CTS
947 * @retval None
948 */
LL_USART_SetHWFlowCtrl(USART_TypeDef * USARTx,uint32_t HardwareFlowControl)949 __STATIC_INLINE void LL_USART_SetHWFlowCtrl(USART_TypeDef *USARTx, uint32_t HardwareFlowControl)
950 {
951 MODIFY_REG(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE, HardwareFlowControl);
952 }
953
954 /**
955 * @brief Return HW Flow Control configuration (both CTS and RTS)
956 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
957 * Hardware Flow control feature is supported by the USARTx instance.
958 * @rmtoll CR3 RTSE LL_USART_GetHWFlowCtrl\n
959 * CR3 CTSE LL_USART_GetHWFlowCtrl
960 * @param USARTx USART Instance
961 * @retval Returned value can be one of the following values:
962 * @arg @ref LL_USART_HWCONTROL_NONE
963 * @arg @ref LL_USART_HWCONTROL_RTS
964 * @arg @ref LL_USART_HWCONTROL_CTS
965 * @arg @ref LL_USART_HWCONTROL_RTS_CTS
966 */
LL_USART_GetHWFlowCtrl(USART_TypeDef * USARTx)967 __STATIC_INLINE uint32_t LL_USART_GetHWFlowCtrl(USART_TypeDef *USARTx)
968 {
969 return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE));
970 }
971
972 /**
973 * @brief Enable One bit sampling method
974 * @rmtoll CR3 ONEBIT LL_USART_EnableOneBitSamp
975 * @param USARTx USART Instance
976 * @retval None
977 */
LL_USART_EnableOneBitSamp(USART_TypeDef * USARTx)978 __STATIC_INLINE void LL_USART_EnableOneBitSamp(USART_TypeDef *USARTx)
979 {
980 SET_BIT(USARTx->CR3, USART_CR3_ONEBIT);
981 }
982
983 /**
984 * @brief Disable One bit sampling method
985 * @rmtoll CR3 ONEBIT LL_USART_DisableOneBitSamp
986 * @param USARTx USART Instance
987 * @retval None
988 */
LL_USART_DisableOneBitSamp(USART_TypeDef * USARTx)989 __STATIC_INLINE void LL_USART_DisableOneBitSamp(USART_TypeDef *USARTx)
990 {
991 CLEAR_BIT(USARTx->CR3, USART_CR3_ONEBIT);
992 }
993
994 /**
995 * @brief Indicate if One bit sampling method is enabled
996 * @rmtoll CR3 ONEBIT LL_USART_IsEnabledOneBitSamp
997 * @param USARTx USART Instance
998 * @retval State of bit (1 or 0).
999 */
LL_USART_IsEnabledOneBitSamp(USART_TypeDef * USARTx)1000 __STATIC_INLINE uint32_t LL_USART_IsEnabledOneBitSamp(USART_TypeDef *USARTx)
1001 {
1002 return (READ_BIT(USARTx->CR3, USART_CR3_ONEBIT) == (USART_CR3_ONEBIT));
1003 }
1004
1005 /**
1006 * @brief Configure USART BRR register for achieving expected Baud Rate value.
1007 * @note Compute and set USARTDIV value in BRR Register (full BRR content)
1008 * according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
1009 * @note Peripheral clock and Baud rate values provided as function parameters should be valid
1010 * (Baud rate value != 0)
1011 * @rmtoll BRR BRR LL_USART_SetBaudRate
1012 * @param USARTx USART Instance
1013 * @param PeriphClk Peripheral Clock
1014 * @param OverSampling This parameter can be one of the following values:
1015 * @arg @ref LL_USART_OVERSAMPLING_16
1016 * @arg @ref LL_USART_OVERSAMPLING_8
1017 * @param BaudRate Baud Rate
1018 * @retval None
1019 */
LL_USART_SetBaudRate(USART_TypeDef * USARTx,uint32_t PeriphClk,uint32_t OverSampling,uint32_t BaudRate)1020 __STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling,
1021 uint32_t BaudRate)
1022 {
1023 if (OverSampling == LL_USART_OVERSAMPLING_8)
1024 {
1025 USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING8(PeriphClk, BaudRate));
1026 }
1027 else
1028 {
1029 USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk, BaudRate));
1030 }
1031 }
1032
1033 /**
1034 * @brief Return current Baud Rate value, according to USARTDIV present in BRR register
1035 * (full BRR content), and to used Peripheral Clock and Oversampling mode values
1036 * @note In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
1037 * @rmtoll BRR BRR LL_USART_GetBaudRate
1038 * @param USARTx USART Instance
1039 * @param PeriphClk Peripheral Clock
1040 * @param OverSampling This parameter can be one of the following values:
1041 * @arg @ref LL_USART_OVERSAMPLING_16
1042 * @arg @ref LL_USART_OVERSAMPLING_8
1043 * @retval Baud Rate
1044 */
LL_USART_GetBaudRate(USART_TypeDef * USARTx,uint32_t PeriphClk,uint32_t OverSampling)1045 __STATIC_INLINE uint32_t LL_USART_GetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling)
1046 {
1047 uint32_t usartdiv = 0x0U;
1048 uint32_t brrresult = 0x0U;
1049
1050 usartdiv = USARTx->BRR;
1051
1052 if (OverSampling == LL_USART_OVERSAMPLING_8)
1053 {
1054 if ((usartdiv & 0xFFF7U) != 0U)
1055 {
1056 usartdiv = (uint16_t)((usartdiv & 0xFFF0U) | ((usartdiv & 0x0007U) << 1U)) ;
1057 brrresult = (PeriphClk * 2U) / usartdiv;
1058 }
1059 }
1060 else
1061 {
1062 if ((usartdiv & 0xFFFFU) != 0U)
1063 {
1064 brrresult = PeriphClk / usartdiv;
1065 }
1066 }
1067 return (brrresult);
1068 }
1069
1070 /**
1071 * @}
1072 */
1073
1074 /** @defgroup USART_LL_EF_Configuration_IRDA Configuration functions related to Irda feature
1075 * @{
1076 */
1077
1078 /**
1079 * @brief Enable IrDA mode
1080 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1081 * IrDA feature is supported by the USARTx instance.
1082 * @rmtoll CR3 IREN LL_USART_EnableIrda
1083 * @param USARTx USART Instance
1084 * @retval None
1085 */
LL_USART_EnableIrda(USART_TypeDef * USARTx)1086 __STATIC_INLINE void LL_USART_EnableIrda(USART_TypeDef *USARTx)
1087 {
1088 SET_BIT(USARTx->CR3, USART_CR3_IREN);
1089 }
1090
1091 /**
1092 * @brief Disable IrDA mode
1093 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1094 * IrDA feature is supported by the USARTx instance.
1095 * @rmtoll CR3 IREN LL_USART_DisableIrda
1096 * @param USARTx USART Instance
1097 * @retval None
1098 */
LL_USART_DisableIrda(USART_TypeDef * USARTx)1099 __STATIC_INLINE void LL_USART_DisableIrda(USART_TypeDef *USARTx)
1100 {
1101 CLEAR_BIT(USARTx->CR3, USART_CR3_IREN);
1102 }
1103
1104 /**
1105 * @brief Indicate if IrDA mode is enabled
1106 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1107 * IrDA feature is supported by the USARTx instance.
1108 * @rmtoll CR3 IREN LL_USART_IsEnabledIrda
1109 * @param USARTx USART Instance
1110 * @retval State of bit (1 or 0).
1111 */
LL_USART_IsEnabledIrda(USART_TypeDef * USARTx)1112 __STATIC_INLINE uint32_t LL_USART_IsEnabledIrda(USART_TypeDef *USARTx)
1113 {
1114 return (READ_BIT(USARTx->CR3, USART_CR3_IREN) == (USART_CR3_IREN));
1115 }
1116
1117 /**
1118 * @brief Configure IrDA Power Mode (Normal or Low Power)
1119 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1120 * IrDA feature is supported by the USARTx instance.
1121 * @rmtoll CR3 IRLP LL_USART_SetIrdaPowerMode
1122 * @param USARTx USART Instance
1123 * @param PowerMode This parameter can be one of the following values:
1124 * @arg @ref LL_USART_IRDA_POWER_NORMAL
1125 * @arg @ref LL_USART_IRDA_POWER_LOW
1126 * @retval None
1127 */
LL_USART_SetIrdaPowerMode(USART_TypeDef * USARTx,uint32_t PowerMode)1128 __STATIC_INLINE void LL_USART_SetIrdaPowerMode(USART_TypeDef *USARTx, uint32_t PowerMode)
1129 {
1130 MODIFY_REG(USARTx->CR3, USART_CR3_IRLP, PowerMode);
1131 }
1132
1133 /**
1134 * @brief Retrieve IrDA Power Mode configuration (Normal or Low Power)
1135 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1136 * IrDA feature is supported by the USARTx instance.
1137 * @rmtoll CR3 IRLP LL_USART_GetIrdaPowerMode
1138 * @param USARTx USART Instance
1139 * @retval Returned value can be one of the following values:
1140 * @arg @ref LL_USART_IRDA_POWER_NORMAL
1141 * @arg @ref LL_USART_PHASE_2EDGE
1142 */
LL_USART_GetIrdaPowerMode(USART_TypeDef * USARTx)1143 __STATIC_INLINE uint32_t LL_USART_GetIrdaPowerMode(USART_TypeDef *USARTx)
1144 {
1145 return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_IRLP));
1146 }
1147
1148 /**
1149 * @brief Set Irda prescaler value, used for dividing the USART clock source
1150 * to achieve the Irda Low Power frequency (8 bits value)
1151 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1152 * IrDA feature is supported by the USARTx instance.
1153 * @rmtoll GTPR PSC LL_USART_SetIrdaPrescaler
1154 * @param USARTx USART Instance
1155 * @param PrescalerValue Value between Min_Data=0x00 and Max_Data=0xFF
1156 * @retval None
1157 */
LL_USART_SetIrdaPrescaler(USART_TypeDef * USARTx,uint32_t PrescalerValue)1158 __STATIC_INLINE void LL_USART_SetIrdaPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
1159 {
1160 MODIFY_REG(USARTx->GTPR, USART_GTPR_PSC, PrescalerValue);
1161 }
1162
1163 /**
1164 * @brief Return Irda prescaler value, used for dividing the USART clock source
1165 * to achieve the Irda Low Power frequency (8 bits value)
1166 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1167 * IrDA feature is supported by the USARTx instance.
1168 * @rmtoll GTPR PSC LL_USART_GetIrdaPrescaler
1169 * @param USARTx USART Instance
1170 * @retval Irda prescaler value (Value between Min_Data=0x00 and Max_Data=0xFF)
1171 */
LL_USART_GetIrdaPrescaler(USART_TypeDef * USARTx)1172 __STATIC_INLINE uint32_t LL_USART_GetIrdaPrescaler(USART_TypeDef *USARTx)
1173 {
1174 return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_PSC));
1175 }
1176
1177 /**
1178 * @}
1179 */
1180
1181 /** @defgroup USART_LL_EF_Configuration_Smartcard Configuration functions related to Smartcard feature
1182 * @{
1183 */
1184
1185 /**
1186 * @brief Enable Smartcard NACK transmission
1187 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1188 * Smartcard feature is supported by the USARTx instance.
1189 * @rmtoll CR3 NACK LL_USART_EnableSmartcardNACK
1190 * @param USARTx USART Instance
1191 * @retval None
1192 */
LL_USART_EnableSmartcardNACK(USART_TypeDef * USARTx)1193 __STATIC_INLINE void LL_USART_EnableSmartcardNACK(USART_TypeDef *USARTx)
1194 {
1195 SET_BIT(USARTx->CR3, USART_CR3_NACK);
1196 }
1197
1198 /**
1199 * @brief Disable Smartcard NACK transmission
1200 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1201 * Smartcard feature is supported by the USARTx instance.
1202 * @rmtoll CR3 NACK LL_USART_DisableSmartcardNACK
1203 * @param USARTx USART Instance
1204 * @retval None
1205 */
LL_USART_DisableSmartcardNACK(USART_TypeDef * USARTx)1206 __STATIC_INLINE void LL_USART_DisableSmartcardNACK(USART_TypeDef *USARTx)
1207 {
1208 CLEAR_BIT(USARTx->CR3, USART_CR3_NACK);
1209 }
1210
1211 /**
1212 * @brief Indicate if Smartcard NACK transmission is enabled
1213 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1214 * Smartcard feature is supported by the USARTx instance.
1215 * @rmtoll CR3 NACK LL_USART_IsEnabledSmartcardNACK
1216 * @param USARTx USART Instance
1217 * @retval State of bit (1 or 0).
1218 */
LL_USART_IsEnabledSmartcardNACK(USART_TypeDef * USARTx)1219 __STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcardNACK(USART_TypeDef *USARTx)
1220 {
1221 return (READ_BIT(USARTx->CR3, USART_CR3_NACK) == (USART_CR3_NACK));
1222 }
1223
1224 /**
1225 * @brief Enable Smartcard mode
1226 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1227 * Smartcard feature is supported by the USARTx instance.
1228 * @rmtoll CR3 SCEN LL_USART_EnableSmartcard
1229 * @param USARTx USART Instance
1230 * @retval None
1231 */
LL_USART_EnableSmartcard(USART_TypeDef * USARTx)1232 __STATIC_INLINE void LL_USART_EnableSmartcard(USART_TypeDef *USARTx)
1233 {
1234 SET_BIT(USARTx->CR3, USART_CR3_SCEN);
1235 }
1236
1237 /**
1238 * @brief Disable Smartcard mode
1239 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1240 * Smartcard feature is supported by the USARTx instance.
1241 * @rmtoll CR3 SCEN LL_USART_DisableSmartcard
1242 * @param USARTx USART Instance
1243 * @retval None
1244 */
LL_USART_DisableSmartcard(USART_TypeDef * USARTx)1245 __STATIC_INLINE void LL_USART_DisableSmartcard(USART_TypeDef *USARTx)
1246 {
1247 CLEAR_BIT(USARTx->CR3, USART_CR3_SCEN);
1248 }
1249
1250 /**
1251 * @brief Indicate if Smartcard mode is enabled
1252 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1253 * Smartcard feature is supported by the USARTx instance.
1254 * @rmtoll CR3 SCEN LL_USART_IsEnabledSmartcard
1255 * @param USARTx USART Instance
1256 * @retval State of bit (1 or 0).
1257 */
LL_USART_IsEnabledSmartcard(USART_TypeDef * USARTx)1258 __STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcard(USART_TypeDef *USARTx)
1259 {
1260 return (READ_BIT(USARTx->CR3, USART_CR3_SCEN) == (USART_CR3_SCEN));
1261 }
1262
1263 /**
1264 * @brief Set Smartcard prescaler value, used for dividing the USART clock
1265 * source to provide the SMARTCARD Clock (5 bits value)
1266 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1267 * Smartcard feature is supported by the USARTx instance.
1268 * @rmtoll GTPR PSC LL_USART_SetSmartcardPrescaler
1269 * @param USARTx USART Instance
1270 * @param PrescalerValue Value between Min_Data=0 and Max_Data=31
1271 * @retval None
1272 */
LL_USART_SetSmartcardPrescaler(USART_TypeDef * USARTx,uint32_t PrescalerValue)1273 __STATIC_INLINE void LL_USART_SetSmartcardPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
1274 {
1275 MODIFY_REG(USARTx->GTPR, USART_GTPR_PSC, PrescalerValue);
1276 }
1277
1278 /**
1279 * @brief Return Smartcard prescaler value, used for dividing the USART clock
1280 * source to provide the SMARTCARD Clock (5 bits value)
1281 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1282 * Smartcard feature is supported by the USARTx instance.
1283 * @rmtoll GTPR PSC LL_USART_GetSmartcardPrescaler
1284 * @param USARTx USART Instance
1285 * @retval Smartcard prescaler value (Value between Min_Data=0 and Max_Data=31)
1286 */
LL_USART_GetSmartcardPrescaler(USART_TypeDef * USARTx)1287 __STATIC_INLINE uint32_t LL_USART_GetSmartcardPrescaler(USART_TypeDef *USARTx)
1288 {
1289 return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_PSC));
1290 }
1291
1292 /**
1293 * @brief Set Smartcard Guard time value, expressed in nb of baud clocks periods
1294 * (GT[7:0] bits : Guard time value)
1295 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1296 * Smartcard feature is supported by the USARTx instance.
1297 * @rmtoll GTPR GT LL_USART_SetSmartcardGuardTime
1298 * @param USARTx USART Instance
1299 * @param GuardTime Value between Min_Data=0x00 and Max_Data=0xFF
1300 * @retval None
1301 */
LL_USART_SetSmartcardGuardTime(USART_TypeDef * USARTx,uint32_t GuardTime)1302 __STATIC_INLINE void LL_USART_SetSmartcardGuardTime(USART_TypeDef *USARTx, uint32_t GuardTime)
1303 {
1304 MODIFY_REG(USARTx->GTPR, USART_GTPR_GT, GuardTime << USART_POSITION_GTPR_GT);
1305 }
1306
1307 /**
1308 * @brief Return Smartcard Guard time value, expressed in nb of baud clocks periods
1309 * (GT[7:0] bits : Guard time value)
1310 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1311 * Smartcard feature is supported by the USARTx instance.
1312 * @rmtoll GTPR GT LL_USART_GetSmartcardGuardTime
1313 * @param USARTx USART Instance
1314 * @retval Smartcard Guard time value (Value between Min_Data=0x00 and Max_Data=0xFF)
1315 */
LL_USART_GetSmartcardGuardTime(USART_TypeDef * USARTx)1316 __STATIC_INLINE uint32_t LL_USART_GetSmartcardGuardTime(USART_TypeDef *USARTx)
1317 {
1318 return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_GT) >> USART_POSITION_GTPR_GT);
1319 }
1320
1321 /**
1322 * @}
1323 */
1324
1325 /** @defgroup USART_LL_EF_Configuration_HalfDuplex Configuration functions related to Half Duplex feature
1326 * @{
1327 */
1328
1329 /**
1330 * @brief Enable Single Wire Half-Duplex mode
1331 * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
1332 * Half-Duplex mode is supported by the USARTx instance.
1333 * @rmtoll CR3 HDSEL LL_USART_EnableHalfDuplex
1334 * @param USARTx USART Instance
1335 * @retval None
1336 */
LL_USART_EnableHalfDuplex(USART_TypeDef * USARTx)1337 __STATIC_INLINE void LL_USART_EnableHalfDuplex(USART_TypeDef *USARTx)
1338 {
1339 SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
1340 }
1341
1342 /**
1343 * @brief Disable Single Wire Half-Duplex mode
1344 * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
1345 * Half-Duplex mode is supported by the USARTx instance.
1346 * @rmtoll CR3 HDSEL LL_USART_DisableHalfDuplex
1347 * @param USARTx USART Instance
1348 * @retval None
1349 */
LL_USART_DisableHalfDuplex(USART_TypeDef * USARTx)1350 __STATIC_INLINE void LL_USART_DisableHalfDuplex(USART_TypeDef *USARTx)
1351 {
1352 CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
1353 }
1354
1355 /**
1356 * @brief Indicate if Single Wire Half-Duplex mode is enabled
1357 * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
1358 * Half-Duplex mode is supported by the USARTx instance.
1359 * @rmtoll CR3 HDSEL LL_USART_IsEnabledHalfDuplex
1360 * @param USARTx USART Instance
1361 * @retval State of bit (1 or 0).
1362 */
LL_USART_IsEnabledHalfDuplex(USART_TypeDef * USARTx)1363 __STATIC_INLINE uint32_t LL_USART_IsEnabledHalfDuplex(USART_TypeDef *USARTx)
1364 {
1365 return (READ_BIT(USARTx->CR3, USART_CR3_HDSEL) == (USART_CR3_HDSEL));
1366 }
1367
1368 /**
1369 * @}
1370 */
1371
1372 /** @defgroup USART_LL_EF_Configuration_LIN Configuration functions related to LIN feature
1373 * @{
1374 */
1375
1376 /**
1377 * @brief Set LIN Break Detection Length
1378 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1379 * LIN feature is supported by the USARTx instance.
1380 * @rmtoll CR2 LBDL LL_USART_SetLINBrkDetectionLen
1381 * @param USARTx USART Instance
1382 * @param LINBDLength This parameter can be one of the following values:
1383 * @arg @ref LL_USART_LINBREAK_DETECT_10B
1384 * @arg @ref LL_USART_LINBREAK_DETECT_11B
1385 * @retval None
1386 */
LL_USART_SetLINBrkDetectionLen(USART_TypeDef * USARTx,uint32_t LINBDLength)1387 __STATIC_INLINE void LL_USART_SetLINBrkDetectionLen(USART_TypeDef *USARTx, uint32_t LINBDLength)
1388 {
1389 MODIFY_REG(USARTx->CR2, USART_CR2_LBDL, LINBDLength);
1390 }
1391
1392 /**
1393 * @brief Return LIN Break Detection Length
1394 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1395 * LIN feature is supported by the USARTx instance.
1396 * @rmtoll CR2 LBDL LL_USART_GetLINBrkDetectionLen
1397 * @param USARTx USART Instance
1398 * @retval Returned value can be one of the following values:
1399 * @arg @ref LL_USART_LINBREAK_DETECT_10B
1400 * @arg @ref LL_USART_LINBREAK_DETECT_11B
1401 */
LL_USART_GetLINBrkDetectionLen(USART_TypeDef * USARTx)1402 __STATIC_INLINE uint32_t LL_USART_GetLINBrkDetectionLen(USART_TypeDef *USARTx)
1403 {
1404 return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBDL));
1405 }
1406
1407 /**
1408 * @brief Enable LIN mode
1409 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1410 * LIN feature is supported by the USARTx instance.
1411 * @rmtoll CR2 LINEN LL_USART_EnableLIN
1412 * @param USARTx USART Instance
1413 * @retval None
1414 */
LL_USART_EnableLIN(USART_TypeDef * USARTx)1415 __STATIC_INLINE void LL_USART_EnableLIN(USART_TypeDef *USARTx)
1416 {
1417 SET_BIT(USARTx->CR2, USART_CR2_LINEN);
1418 }
1419
1420 /**
1421 * @brief Disable LIN mode
1422 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1423 * LIN feature is supported by the USARTx instance.
1424 * @rmtoll CR2 LINEN LL_USART_DisableLIN
1425 * @param USARTx USART Instance
1426 * @retval None
1427 */
LL_USART_DisableLIN(USART_TypeDef * USARTx)1428 __STATIC_INLINE void LL_USART_DisableLIN(USART_TypeDef *USARTx)
1429 {
1430 CLEAR_BIT(USARTx->CR2, USART_CR2_LINEN);
1431 }
1432
1433 /**
1434 * @brief Indicate if LIN mode is enabled
1435 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1436 * LIN feature is supported by the USARTx instance.
1437 * @rmtoll CR2 LINEN LL_USART_IsEnabledLIN
1438 * @param USARTx USART Instance
1439 * @retval State of bit (1 or 0).
1440 */
LL_USART_IsEnabledLIN(USART_TypeDef * USARTx)1441 __STATIC_INLINE uint32_t LL_USART_IsEnabledLIN(USART_TypeDef *USARTx)
1442 {
1443 return (READ_BIT(USARTx->CR2, USART_CR2_LINEN) == (USART_CR2_LINEN));
1444 }
1445
1446 /**
1447 * @}
1448 */
1449
1450 /** @defgroup USART_LL_EF_AdvancedConfiguration Advanced Configurations services
1451 * @{
1452 */
1453
1454 /**
1455 * @brief Perform basic configuration of USART for enabling use in Asynchronous Mode (UART)
1456 * @note In UART mode, the following bits must be kept cleared:
1457 * - LINEN bit in the USART_CR2 register,
1458 * - CLKEN bit in the USART_CR2 register,
1459 * - SCEN bit in the USART_CR3 register,
1460 * - IREN bit in the USART_CR3 register,
1461 * - HDSEL bit in the USART_CR3 register.
1462 * @note Call of this function is equivalent to following function call sequence :
1463 * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1464 * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1465 * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1466 * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1467 * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1468 * @note Other remaining configurations items related to Asynchronous Mode
1469 * (as Baud Rate, Word length, Parity, ...) should be set using
1470 * dedicated functions
1471 * @rmtoll CR2 LINEN LL_USART_ConfigAsyncMode\n
1472 * CR2 CLKEN LL_USART_ConfigAsyncMode\n
1473 * CR3 SCEN LL_USART_ConfigAsyncMode\n
1474 * CR3 IREN LL_USART_ConfigAsyncMode\n
1475 * CR3 HDSEL LL_USART_ConfigAsyncMode
1476 * @param USARTx USART Instance
1477 * @retval None
1478 */
LL_USART_ConfigAsyncMode(USART_TypeDef * USARTx)1479 __STATIC_INLINE void LL_USART_ConfigAsyncMode(USART_TypeDef *USARTx)
1480 {
1481 /* In Asynchronous mode, the following bits must be kept cleared:
1482 - LINEN, CLKEN bits in the USART_CR2 register,
1483 - SCEN, IREN and HDSEL bits in the USART_CR3 register.*/
1484 CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
1485 CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN | USART_CR3_HDSEL));
1486 }
1487
1488 /**
1489 * @brief Perform basic configuration of USART for enabling use in Synchronous Mode
1490 * @note In Synchronous mode, the following bits must be kept cleared:
1491 * - LINEN bit in the USART_CR2 register,
1492 * - SCEN bit in the USART_CR3 register,
1493 * - IREN bit in the USART_CR3 register,
1494 * - HDSEL bit in the USART_CR3 register.
1495 * This function also sets the USART in Synchronous mode.
1496 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
1497 * Synchronous mode is supported by the USARTx instance.
1498 * @note Call of this function is equivalent to following function call sequence :
1499 * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1500 * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1501 * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1502 * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1503 * - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
1504 * @note Other remaining configurations items related to Synchronous Mode
1505 * (as Baud Rate, Word length, Parity, Clock Polarity, ...) should be set using
1506 * dedicated functions
1507 * @rmtoll CR2 LINEN LL_USART_ConfigSyncMode\n
1508 * CR2 CLKEN LL_USART_ConfigSyncMode\n
1509 * CR3 SCEN LL_USART_ConfigSyncMode\n
1510 * CR3 IREN LL_USART_ConfigSyncMode\n
1511 * CR3 HDSEL LL_USART_ConfigSyncMode
1512 * @param USARTx USART Instance
1513 * @retval None
1514 */
LL_USART_ConfigSyncMode(USART_TypeDef * USARTx)1515 __STATIC_INLINE void LL_USART_ConfigSyncMode(USART_TypeDef *USARTx)
1516 {
1517 /* In Synchronous mode, the following bits must be kept cleared:
1518 - LINEN bit in the USART_CR2 register,
1519 - SCEN, IREN and HDSEL bits in the USART_CR3 register.*/
1520 CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN));
1521 CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN | USART_CR3_HDSEL));
1522 /* set the UART/USART in Synchronous mode */
1523 SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
1524 }
1525
1526 /**
1527 * @brief Perform basic configuration of USART for enabling use in LIN Mode
1528 * @note In LIN mode, the following bits must be kept cleared:
1529 * - STOP and CLKEN bits in the USART_CR2 register,
1530 * - SCEN bit in the USART_CR3 register,
1531 * - IREN bit in the USART_CR3 register,
1532 * - HDSEL bit in the USART_CR3 register.
1533 * This function also set the UART/USART in LIN mode.
1534 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1535 * LIN feature is supported by the USARTx instance.
1536 * @note Call of this function is equivalent to following function call sequence :
1537 * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1538 * - Clear STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
1539 * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1540 * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1541 * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1542 * - Set LINEN in CR2 using @ref LL_USART_EnableLIN() function
1543 * @note Other remaining configurations items related to LIN Mode
1544 * (as Baud Rate, Word length, LIN Break Detection Length, ...) should be set using
1545 * dedicated functions
1546 * @rmtoll CR2 CLKEN LL_USART_ConfigLINMode\n
1547 * CR2 STOP LL_USART_ConfigLINMode\n
1548 * CR2 LINEN LL_USART_ConfigLINMode\n
1549 * CR3 IREN LL_USART_ConfigLINMode\n
1550 * CR3 SCEN LL_USART_ConfigLINMode\n
1551 * CR3 HDSEL LL_USART_ConfigLINMode
1552 * @param USARTx USART Instance
1553 * @retval None
1554 */
LL_USART_ConfigLINMode(USART_TypeDef * USARTx)1555 __STATIC_INLINE void LL_USART_ConfigLINMode(USART_TypeDef *USARTx)
1556 {
1557 /* In LIN mode, the following bits must be kept cleared:
1558 - STOP and CLKEN bits in the USART_CR2 register,
1559 - IREN, SCEN and HDSEL bits in the USART_CR3 register.*/
1560 CLEAR_BIT(USARTx->CR2, (USART_CR2_CLKEN | USART_CR2_STOP));
1561 CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_SCEN | USART_CR3_HDSEL));
1562 /* Set the UART/USART in LIN mode */
1563 SET_BIT(USARTx->CR2, USART_CR2_LINEN);
1564 }
1565
1566 /**
1567 * @brief Perform basic configuration of USART for enabling use in Half Duplex Mode
1568 * @note In Half Duplex mode, the following bits must be kept cleared:
1569 * - LINEN bit in the USART_CR2 register,
1570 * - CLKEN bit in the USART_CR2 register,
1571 * - SCEN bit in the USART_CR3 register,
1572 * - IREN bit in the USART_CR3 register,
1573 * This function also sets the UART/USART in Half Duplex mode.
1574 * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
1575 * Half-Duplex mode is supported by the USARTx instance.
1576 * @note Call of this function is equivalent to following function call sequence :
1577 * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1578 * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1579 * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1580 * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1581 * - Set HDSEL in CR3 using @ref LL_USART_EnableHalfDuplex() function
1582 * @note Other remaining configurations items related to Half Duplex Mode
1583 * (as Baud Rate, Word length, Parity, ...) should be set using
1584 * dedicated functions
1585 * @rmtoll CR2 LINEN LL_USART_ConfigHalfDuplexMode\n
1586 * CR2 CLKEN LL_USART_ConfigHalfDuplexMode\n
1587 * CR3 HDSEL LL_USART_ConfigHalfDuplexMode\n
1588 * CR3 SCEN LL_USART_ConfigHalfDuplexMode\n
1589 * CR3 IREN LL_USART_ConfigHalfDuplexMode
1590 * @param USARTx USART Instance
1591 * @retval None
1592 */
LL_USART_ConfigHalfDuplexMode(USART_TypeDef * USARTx)1593 __STATIC_INLINE void LL_USART_ConfigHalfDuplexMode(USART_TypeDef *USARTx)
1594 {
1595 /* In Half Duplex mode, the following bits must be kept cleared:
1596 - LINEN and CLKEN bits in the USART_CR2 register,
1597 - SCEN and IREN bits in the USART_CR3 register.*/
1598 CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
1599 CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN));
1600 /* set the UART/USART in Half Duplex mode */
1601 SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
1602 }
1603
1604 /**
1605 * @brief Perform basic configuration of USART for enabling use in Smartcard Mode
1606 * @note In Smartcard mode, the following bits must be kept cleared:
1607 * - LINEN bit in the USART_CR2 register,
1608 * - IREN bit in the USART_CR3 register,
1609 * - HDSEL bit in the USART_CR3 register.
1610 * This function also configures Stop bits to 1.5 bits and
1611 * sets the USART in Smartcard mode (SCEN bit).
1612 * Clock Output is also enabled (CLKEN).
1613 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1614 * Smartcard feature is supported by the USARTx instance.
1615 * @note Call of this function is equivalent to following function call sequence :
1616 * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1617 * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1618 * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1619 * - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
1620 * - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
1621 * - Set SCEN in CR3 using @ref LL_USART_EnableSmartcard() function
1622 * @note Other remaining configurations items related to Smartcard Mode
1623 * (as Baud Rate, Word length, Parity, ...) should be set using
1624 * dedicated functions
1625 * @rmtoll CR2 LINEN LL_USART_ConfigSmartcardMode\n
1626 * CR2 STOP LL_USART_ConfigSmartcardMode\n
1627 * CR2 CLKEN LL_USART_ConfigSmartcardMode\n
1628 * CR3 HDSEL LL_USART_ConfigSmartcardMode\n
1629 * CR3 SCEN LL_USART_ConfigSmartcardMode
1630 * @param USARTx USART Instance
1631 * @retval None
1632 */
LL_USART_ConfigSmartcardMode(USART_TypeDef * USARTx)1633 __STATIC_INLINE void LL_USART_ConfigSmartcardMode(USART_TypeDef *USARTx)
1634 {
1635 /* In Smartcard mode, the following bits must be kept cleared:
1636 - LINEN bit in the USART_CR2 register,
1637 - IREN and HDSEL bits in the USART_CR3 register.*/
1638 CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN));
1639 CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_HDSEL));
1640 /* Configure Stop bits to 1.5 bits */
1641 /* Synchronous mode is activated by default */
1642 SET_BIT(USARTx->CR2, (USART_CR2_STOP_0 | USART_CR2_STOP_1 | USART_CR2_CLKEN));
1643 /* set the UART/USART in Smartcard mode */
1644 SET_BIT(USARTx->CR3, USART_CR3_SCEN);
1645 }
1646
1647 /**
1648 * @brief Perform basic configuration of USART for enabling use in Irda Mode
1649 * @note In IRDA mode, the following bits must be kept cleared:
1650 * - LINEN bit in the USART_CR2 register,
1651 * - STOP and CLKEN bits in the USART_CR2 register,
1652 * - SCEN bit in the USART_CR3 register,
1653 * - HDSEL bit in the USART_CR3 register.
1654 * This function also sets the UART/USART in IRDA mode (IREN bit).
1655 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1656 * IrDA feature is supported by the USARTx instance.
1657 * @note Call of this function is equivalent to following function call sequence :
1658 * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1659 * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1660 * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1661 * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1662 * - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
1663 * - Set IREN in CR3 using @ref LL_USART_EnableIrda() function
1664 * @note Other remaining configurations items related to Irda Mode
1665 * (as Baud Rate, Word length, Power mode, ...) should be set using
1666 * dedicated functions
1667 * @rmtoll CR2 LINEN LL_USART_ConfigIrdaMode\n
1668 * CR2 CLKEN LL_USART_ConfigIrdaMode\n
1669 * CR2 STOP LL_USART_ConfigIrdaMode\n
1670 * CR3 SCEN LL_USART_ConfigIrdaMode\n
1671 * CR3 HDSEL LL_USART_ConfigIrdaMode\n
1672 * CR3 IREN LL_USART_ConfigIrdaMode
1673 * @param USARTx USART Instance
1674 * @retval None
1675 */
LL_USART_ConfigIrdaMode(USART_TypeDef * USARTx)1676 __STATIC_INLINE void LL_USART_ConfigIrdaMode(USART_TypeDef *USARTx)
1677 {
1678 /* In IRDA mode, the following bits must be kept cleared:
1679 - LINEN, STOP and CLKEN bits in the USART_CR2 register,
1680 - SCEN and HDSEL bits in the USART_CR3 register.*/
1681 CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP));
1682 CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
1683 /* set the UART/USART in IRDA mode */
1684 SET_BIT(USARTx->CR3, USART_CR3_IREN);
1685 }
1686
1687 /**
1688 * @brief Perform basic configuration of USART for enabling use in Multi processor Mode
1689 * (several USARTs connected in a network, one of the USARTs can be the master,
1690 * its TX output connected to the RX inputs of the other slaves USARTs).
1691 * @note In MultiProcessor mode, the following bits must be kept cleared:
1692 * - LINEN bit in the USART_CR2 register,
1693 * - CLKEN bit in the USART_CR2 register,
1694 * - SCEN bit in the USART_CR3 register,
1695 * - IREN bit in the USART_CR3 register,
1696 * - HDSEL bit in the USART_CR3 register.
1697 * @note Call of this function is equivalent to following function call sequence :
1698 * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1699 * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1700 * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1701 * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1702 * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1703 * @note Other remaining configurations items related to Multi processor Mode
1704 * (as Baud Rate, Wake Up Method, Node address, ...) should be set using
1705 * dedicated functions
1706 * @rmtoll CR2 LINEN LL_USART_ConfigMultiProcessMode\n
1707 * CR2 CLKEN LL_USART_ConfigMultiProcessMode\n
1708 * CR3 SCEN LL_USART_ConfigMultiProcessMode\n
1709 * CR3 HDSEL LL_USART_ConfigMultiProcessMode\n
1710 * CR3 IREN LL_USART_ConfigMultiProcessMode
1711 * @param USARTx USART Instance
1712 * @retval None
1713 */
LL_USART_ConfigMultiProcessMode(USART_TypeDef * USARTx)1714 __STATIC_INLINE void LL_USART_ConfigMultiProcessMode(USART_TypeDef *USARTx)
1715 {
1716 /* In Multi Processor mode, the following bits must be kept cleared:
1717 - LINEN and CLKEN bits in the USART_CR2 register,
1718 - IREN, SCEN and HDSEL bits in the USART_CR3 register.*/
1719 CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
1720 CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
1721 }
1722
1723 /**
1724 * @}
1725 */
1726
1727 /** @defgroup USART_LL_EF_FLAG_Management FLAG_Management
1728 * @{
1729 */
1730
1731 /**
1732 * @brief Check if the USART Parity Error Flag is set or not
1733 * @rmtoll SR PE LL_USART_IsActiveFlag_PE
1734 * @param USARTx USART Instance
1735 * @retval State of bit (1 or 0).
1736 */
LL_USART_IsActiveFlag_PE(USART_TypeDef * USARTx)1737 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_PE(USART_TypeDef *USARTx)
1738 {
1739 return (READ_BIT(USARTx->SR, USART_SR_PE) == (USART_SR_PE));
1740 }
1741
1742 /**
1743 * @brief Check if the USART Framing Error Flag is set or not
1744 * @rmtoll SR FE LL_USART_IsActiveFlag_FE
1745 * @param USARTx USART Instance
1746 * @retval State of bit (1 or 0).
1747 */
LL_USART_IsActiveFlag_FE(USART_TypeDef * USARTx)1748 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_FE(USART_TypeDef *USARTx)
1749 {
1750 return (READ_BIT(USARTx->SR, USART_SR_FE) == (USART_SR_FE));
1751 }
1752
1753 /**
1754 * @brief Check if the USART Noise error detected Flag is set or not
1755 * @rmtoll SR NF LL_USART_IsActiveFlag_NE
1756 * @param USARTx USART Instance
1757 * @retval State of bit (1 or 0).
1758 */
LL_USART_IsActiveFlag_NE(USART_TypeDef * USARTx)1759 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_NE(USART_TypeDef *USARTx)
1760 {
1761 return (READ_BIT(USARTx->SR, USART_SR_NE) == (USART_SR_NE));
1762 }
1763
1764 /**
1765 * @brief Check if the USART OverRun Error Flag is set or not
1766 * @rmtoll SR ORE LL_USART_IsActiveFlag_ORE
1767 * @param USARTx USART Instance
1768 * @retval State of bit (1 or 0).
1769 */
LL_USART_IsActiveFlag_ORE(USART_TypeDef * USARTx)1770 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ORE(USART_TypeDef *USARTx)
1771 {
1772 return (READ_BIT(USARTx->SR, USART_SR_ORE) == (USART_SR_ORE));
1773 }
1774
1775 /**
1776 * @brief Check if the USART IDLE line detected Flag is set or not
1777 * @rmtoll SR IDLE LL_USART_IsActiveFlag_IDLE
1778 * @param USARTx USART Instance
1779 * @retval State of bit (1 or 0).
1780 */
LL_USART_IsActiveFlag_IDLE(USART_TypeDef * USARTx)1781 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_IDLE(USART_TypeDef *USARTx)
1782 {
1783 return (READ_BIT(USARTx->SR, USART_SR_IDLE) == (USART_SR_IDLE));
1784 }
1785
1786 /**
1787 * @brief Check if the USART Read Data Register Not Empty Flag is set or not
1788 * @rmtoll SR RXNE LL_USART_IsActiveFlag_RXNE
1789 * @param USARTx USART Instance
1790 * @retval State of bit (1 or 0).
1791 */
LL_USART_IsActiveFlag_RXNE(USART_TypeDef * USARTx)1792 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RXNE(USART_TypeDef *USARTx)
1793 {
1794 return (READ_BIT(USARTx->SR, USART_SR_RXNE) == (USART_SR_RXNE));
1795 }
1796
1797 /**
1798 * @brief Check if the USART Transmission Complete Flag is set or not
1799 * @rmtoll SR TC LL_USART_IsActiveFlag_TC
1800 * @param USARTx USART Instance
1801 * @retval State of bit (1 or 0).
1802 */
LL_USART_IsActiveFlag_TC(USART_TypeDef * USARTx)1803 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TC(USART_TypeDef *USARTx)
1804 {
1805 return (READ_BIT(USARTx->SR, USART_SR_TC) == (USART_SR_TC));
1806 }
1807
1808 /**
1809 * @brief Check if the USART Transmit Data Register Empty Flag is set or not
1810 * @rmtoll SR TXE LL_USART_IsActiveFlag_TXE
1811 * @param USARTx USART Instance
1812 * @retval State of bit (1 or 0).
1813 */
LL_USART_IsActiveFlag_TXE(USART_TypeDef * USARTx)1814 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXE(USART_TypeDef *USARTx)
1815 {
1816 return (READ_BIT(USARTx->SR, USART_SR_TXE) == (USART_SR_TXE));
1817 }
1818
1819 /**
1820 * @brief Check if the USART LIN Break Detection Flag is set or not
1821 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1822 * LIN feature is supported by the USARTx instance.
1823 * @rmtoll SR LBD LL_USART_IsActiveFlag_LBD
1824 * @param USARTx USART Instance
1825 * @retval State of bit (1 or 0).
1826 */
LL_USART_IsActiveFlag_LBD(USART_TypeDef * USARTx)1827 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_LBD(USART_TypeDef *USARTx)
1828 {
1829 return (READ_BIT(USARTx->SR, USART_SR_LBD) == (USART_SR_LBD));
1830 }
1831
1832 /**
1833 * @brief Check if the USART CTS Flag is set or not
1834 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
1835 * Hardware Flow control feature is supported by the USARTx instance.
1836 * @rmtoll SR CTS LL_USART_IsActiveFlag_nCTS
1837 * @param USARTx USART Instance
1838 * @retval State of bit (1 or 0).
1839 */
LL_USART_IsActiveFlag_nCTS(USART_TypeDef * USARTx)1840 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_nCTS(USART_TypeDef *USARTx)
1841 {
1842 return (READ_BIT(USARTx->SR, USART_SR_CTS) == (USART_SR_CTS));
1843 }
1844
1845 /**
1846 * @brief Check if the USART Send Break Flag is set or not
1847 * @rmtoll CR1 SBK LL_USART_IsActiveFlag_SBK
1848 * @param USARTx USART Instance
1849 * @retval State of bit (1 or 0).
1850 */
LL_USART_IsActiveFlag_SBK(USART_TypeDef * USARTx)1851 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_SBK(USART_TypeDef *USARTx)
1852 {
1853 return (READ_BIT(USARTx->CR1, USART_CR1_SBK) == (USART_CR1_SBK));
1854 }
1855
1856 /**
1857 * @brief Check if the USART Receive Wake Up from mute mode Flag is set or not
1858 * @rmtoll CR1 RWU LL_USART_IsActiveFlag_RWU
1859 * @param USARTx USART Instance
1860 * @retval State of bit (1 or 0).
1861 */
LL_USART_IsActiveFlag_RWU(USART_TypeDef * USARTx)1862 __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RWU(USART_TypeDef *USARTx)
1863 {
1864 return (READ_BIT(USARTx->CR1, USART_CR1_RWU) == (USART_CR1_RWU));
1865 }
1866
1867 /**
1868 * @brief Clear Parity Error Flag
1869 * @note Clearing this flag is done by a read access to the USARTx_SR
1870 * register followed by a read access to the USARTx_DR register.
1871 * @note Please also consider that when clearing this flag, other flags as
1872 * NE, FE, ORE, IDLE would also be cleared.
1873 * @rmtoll SR PE LL_USART_ClearFlag_PE
1874 * @param USARTx USART Instance
1875 * @retval None
1876 */
LL_USART_ClearFlag_PE(USART_TypeDef * USARTx)1877 __STATIC_INLINE void LL_USART_ClearFlag_PE(USART_TypeDef *USARTx)
1878 {
1879 __IO uint32_t tmpreg;
1880 tmpreg = USARTx->SR;
1881 (void) tmpreg;
1882 tmpreg = USARTx->DR;
1883 (void) tmpreg;
1884 }
1885
1886 /**
1887 * @brief Clear Framing Error Flag
1888 * @note Clearing this flag is done by a read access to the USARTx_SR
1889 * register followed by a read access to the USARTx_DR register.
1890 * @note Please also consider that when clearing this flag, other flags as
1891 * PE, NE, ORE, IDLE would also be cleared.
1892 * @rmtoll SR FE LL_USART_ClearFlag_FE
1893 * @param USARTx USART Instance
1894 * @retval None
1895 */
LL_USART_ClearFlag_FE(USART_TypeDef * USARTx)1896 __STATIC_INLINE void LL_USART_ClearFlag_FE(USART_TypeDef *USARTx)
1897 {
1898 __IO uint32_t tmpreg;
1899 tmpreg = USARTx->SR;
1900 (void) tmpreg;
1901 tmpreg = USARTx->DR;
1902 (void) tmpreg;
1903 }
1904
1905 /**
1906 * @brief Clear Noise detected Flag
1907 * @note Clearing this flag is done by a read access to the USARTx_SR
1908 * register followed by a read access to the USARTx_DR register.
1909 * @note Please also consider that when clearing this flag, other flags as
1910 * PE, FE, ORE, IDLE would also be cleared.
1911 * @rmtoll SR NF LL_USART_ClearFlag_NE
1912 * @param USARTx USART Instance
1913 * @retval None
1914 */
LL_USART_ClearFlag_NE(USART_TypeDef * USARTx)1915 __STATIC_INLINE void LL_USART_ClearFlag_NE(USART_TypeDef *USARTx)
1916 {
1917 __IO uint32_t tmpreg;
1918 tmpreg = USARTx->SR;
1919 (void) tmpreg;
1920 tmpreg = USARTx->DR;
1921 (void) tmpreg;
1922 }
1923
1924 /**
1925 * @brief Clear OverRun Error Flag
1926 * @note Clearing this flag is done by a read access to the USARTx_SR
1927 * register followed by a read access to the USARTx_DR register.
1928 * @note Please also consider that when clearing this flag, other flags as
1929 * PE, NE, FE, IDLE would also be cleared.
1930 * @rmtoll SR ORE LL_USART_ClearFlag_ORE
1931 * @param USARTx USART Instance
1932 * @retval None
1933 */
LL_USART_ClearFlag_ORE(USART_TypeDef * USARTx)1934 __STATIC_INLINE void LL_USART_ClearFlag_ORE(USART_TypeDef *USARTx)
1935 {
1936 __IO uint32_t tmpreg;
1937 tmpreg = USARTx->SR;
1938 (void) tmpreg;
1939 tmpreg = USARTx->DR;
1940 (void) tmpreg;
1941 }
1942
1943 /**
1944 * @brief Clear IDLE line detected Flag
1945 * @note Clearing this flag is done by a read access to the USARTx_SR
1946 * register followed by a read access to the USARTx_DR register.
1947 * @note Please also consider that when clearing this flag, other flags as
1948 * PE, NE, FE, ORE would also be cleared.
1949 * @rmtoll SR IDLE LL_USART_ClearFlag_IDLE
1950 * @param USARTx USART Instance
1951 * @retval None
1952 */
LL_USART_ClearFlag_IDLE(USART_TypeDef * USARTx)1953 __STATIC_INLINE void LL_USART_ClearFlag_IDLE(USART_TypeDef *USARTx)
1954 {
1955 __IO uint32_t tmpreg;
1956 tmpreg = USARTx->SR;
1957 (void) tmpreg;
1958 tmpreg = USARTx->DR;
1959 (void) tmpreg;
1960 }
1961
1962 /**
1963 * @brief Clear Transmission Complete Flag
1964 * @rmtoll SR TC LL_USART_ClearFlag_TC
1965 * @param USARTx USART Instance
1966 * @retval None
1967 */
LL_USART_ClearFlag_TC(USART_TypeDef * USARTx)1968 __STATIC_INLINE void LL_USART_ClearFlag_TC(USART_TypeDef *USARTx)
1969 {
1970 WRITE_REG(USARTx->SR, ~(USART_SR_TC));
1971 }
1972
1973 /**
1974 * @brief Clear RX Not Empty Flag
1975 * @rmtoll SR RXNE LL_USART_ClearFlag_RXNE
1976 * @param USARTx USART Instance
1977 * @retval None
1978 */
LL_USART_ClearFlag_RXNE(USART_TypeDef * USARTx)1979 __STATIC_INLINE void LL_USART_ClearFlag_RXNE(USART_TypeDef *USARTx)
1980 {
1981 WRITE_REG(USARTx->SR, ~(USART_SR_RXNE));
1982 }
1983
1984 /**
1985 * @brief Clear LIN Break Detection Flag
1986 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1987 * LIN feature is supported by the USARTx instance.
1988 * @rmtoll SR LBD LL_USART_ClearFlag_LBD
1989 * @param USARTx USART Instance
1990 * @retval None
1991 */
LL_USART_ClearFlag_LBD(USART_TypeDef * USARTx)1992 __STATIC_INLINE void LL_USART_ClearFlag_LBD(USART_TypeDef *USARTx)
1993 {
1994 WRITE_REG(USARTx->SR, ~(USART_SR_LBD));
1995 }
1996
1997 /**
1998 * @brief Clear CTS Interrupt Flag
1999 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
2000 * Hardware Flow control feature is supported by the USARTx instance.
2001 * @rmtoll SR CTS LL_USART_ClearFlag_nCTS
2002 * @param USARTx USART Instance
2003 * @retval None
2004 */
LL_USART_ClearFlag_nCTS(USART_TypeDef * USARTx)2005 __STATIC_INLINE void LL_USART_ClearFlag_nCTS(USART_TypeDef *USARTx)
2006 {
2007 WRITE_REG(USARTx->SR, ~(USART_SR_CTS));
2008 }
2009
2010 /**
2011 * @}
2012 */
2013
2014 /** @defgroup USART_LL_EF_IT_Management IT_Management
2015 * @{
2016 */
2017
2018 /**
2019 * @brief Enable IDLE Interrupt
2020 * @rmtoll CR1 IDLEIE LL_USART_EnableIT_IDLE
2021 * @param USARTx USART Instance
2022 * @retval None
2023 */
LL_USART_EnableIT_IDLE(USART_TypeDef * USARTx)2024 __STATIC_INLINE void LL_USART_EnableIT_IDLE(USART_TypeDef *USARTx)
2025 {
2026 ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_IDLEIE);
2027 }
2028
2029 /**
2030 * @brief Enable RX Not Empty Interrupt
2031 * @rmtoll CR1 RXNEIE LL_USART_EnableIT_RXNE
2032 * @param USARTx USART Instance
2033 * @retval None
2034 */
LL_USART_EnableIT_RXNE(USART_TypeDef * USARTx)2035 __STATIC_INLINE void LL_USART_EnableIT_RXNE(USART_TypeDef *USARTx)
2036 {
2037 ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_RXNEIE);
2038 }
2039
2040 /**
2041 * @brief Enable Transmission Complete Interrupt
2042 * @rmtoll CR1 TCIE LL_USART_EnableIT_TC
2043 * @param USARTx USART Instance
2044 * @retval None
2045 */
LL_USART_EnableIT_TC(USART_TypeDef * USARTx)2046 __STATIC_INLINE void LL_USART_EnableIT_TC(USART_TypeDef *USARTx)
2047 {
2048 ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TCIE);
2049 }
2050
2051 /**
2052 * @brief Enable TX Empty Interrupt
2053 * @rmtoll CR1 TXEIE LL_USART_EnableIT_TXE
2054 * @param USARTx USART Instance
2055 * @retval None
2056 */
LL_USART_EnableIT_TXE(USART_TypeDef * USARTx)2057 __STATIC_INLINE void LL_USART_EnableIT_TXE(USART_TypeDef *USARTx)
2058 {
2059 ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TXEIE);
2060 }
2061
2062 /**
2063 * @brief Enable Parity Error Interrupt
2064 * @rmtoll CR1 PEIE LL_USART_EnableIT_PE
2065 * @param USARTx USART Instance
2066 * @retval None
2067 */
LL_USART_EnableIT_PE(USART_TypeDef * USARTx)2068 __STATIC_INLINE void LL_USART_EnableIT_PE(USART_TypeDef *USARTx)
2069 {
2070 ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_PEIE);
2071 }
2072
2073 /**
2074 * @brief Enable LIN Break Detection Interrupt
2075 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2076 * LIN feature is supported by the USARTx instance.
2077 * @rmtoll CR2 LBDIE LL_USART_EnableIT_LBD
2078 * @param USARTx USART Instance
2079 * @retval None
2080 */
LL_USART_EnableIT_LBD(USART_TypeDef * USARTx)2081 __STATIC_INLINE void LL_USART_EnableIT_LBD(USART_TypeDef *USARTx)
2082 {
2083 SET_BIT(USARTx->CR2, USART_CR2_LBDIE);
2084 }
2085
2086 /**
2087 * @brief Enable Error Interrupt
2088 * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
2089 * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_SR register).
2090 * 0: Interrupt is inhibited
2091 * 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_SR register.
2092 * @rmtoll CR3 EIE LL_USART_EnableIT_ERROR
2093 * @param USARTx USART Instance
2094 * @retval None
2095 */
LL_USART_EnableIT_ERROR(USART_TypeDef * USARTx)2096 __STATIC_INLINE void LL_USART_EnableIT_ERROR(USART_TypeDef *USARTx)
2097 {
2098 ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_EIE);
2099 }
2100
2101 /**
2102 * @brief Enable CTS Interrupt
2103 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
2104 * Hardware Flow control feature is supported by the USARTx instance.
2105 * @rmtoll CR3 CTSIE LL_USART_EnableIT_CTS
2106 * @param USARTx USART Instance
2107 * @retval None
2108 */
LL_USART_EnableIT_CTS(USART_TypeDef * USARTx)2109 __STATIC_INLINE void LL_USART_EnableIT_CTS(USART_TypeDef *USARTx)
2110 {
2111 ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_CTSIE);
2112 }
2113
2114 /**
2115 * @brief Disable IDLE Interrupt
2116 * @rmtoll CR1 IDLEIE LL_USART_DisableIT_IDLE
2117 * @param USARTx USART Instance
2118 * @retval None
2119 */
LL_USART_DisableIT_IDLE(USART_TypeDef * USARTx)2120 __STATIC_INLINE void LL_USART_DisableIT_IDLE(USART_TypeDef *USARTx)
2121 {
2122 ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_IDLEIE);
2123 }
2124
2125 /**
2126 * @brief Disable RX Not Empty Interrupt
2127 * @rmtoll CR1 RXNEIE LL_USART_DisableIT_RXNE
2128 * @param USARTx USART Instance
2129 * @retval None
2130 */
LL_USART_DisableIT_RXNE(USART_TypeDef * USARTx)2131 __STATIC_INLINE void LL_USART_DisableIT_RXNE(USART_TypeDef *USARTx)
2132 {
2133 ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_RXNEIE);
2134 }
2135
2136 /**
2137 * @brief Disable Transmission Complete Interrupt
2138 * @rmtoll CR1 TCIE LL_USART_DisableIT_TC
2139 * @param USARTx USART Instance
2140 * @retval None
2141 */
LL_USART_DisableIT_TC(USART_TypeDef * USARTx)2142 __STATIC_INLINE void LL_USART_DisableIT_TC(USART_TypeDef *USARTx)
2143 {
2144 ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TCIE);
2145 }
2146
2147 /**
2148 * @brief Disable TX Empty Interrupt
2149 * @rmtoll CR1 TXEIE LL_USART_DisableIT_TXE
2150 * @param USARTx USART Instance
2151 * @retval None
2152 */
LL_USART_DisableIT_TXE(USART_TypeDef * USARTx)2153 __STATIC_INLINE void LL_USART_DisableIT_TXE(USART_TypeDef *USARTx)
2154 {
2155 ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TXEIE);
2156 }
2157
2158 /**
2159 * @brief Disable Parity Error Interrupt
2160 * @rmtoll CR1 PEIE LL_USART_DisableIT_PE
2161 * @param USARTx USART Instance
2162 * @retval None
2163 */
LL_USART_DisableIT_PE(USART_TypeDef * USARTx)2164 __STATIC_INLINE void LL_USART_DisableIT_PE(USART_TypeDef *USARTx)
2165 {
2166 ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_PEIE);
2167 }
2168
2169 /**
2170 * @brief Disable LIN Break Detection Interrupt
2171 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2172 * LIN feature is supported by the USARTx instance.
2173 * @rmtoll CR2 LBDIE LL_USART_DisableIT_LBD
2174 * @param USARTx USART Instance
2175 * @retval None
2176 */
LL_USART_DisableIT_LBD(USART_TypeDef * USARTx)2177 __STATIC_INLINE void LL_USART_DisableIT_LBD(USART_TypeDef *USARTx)
2178 {
2179 CLEAR_BIT(USARTx->CR2, USART_CR2_LBDIE);
2180 }
2181
2182 /**
2183 * @brief Disable Error Interrupt
2184 * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
2185 * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_SR register).
2186 * 0: Interrupt is inhibited
2187 * 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_SR register.
2188 * @rmtoll CR3 EIE LL_USART_DisableIT_ERROR
2189 * @param USARTx USART Instance
2190 * @retval None
2191 */
LL_USART_DisableIT_ERROR(USART_TypeDef * USARTx)2192 __STATIC_INLINE void LL_USART_DisableIT_ERROR(USART_TypeDef *USARTx)
2193 {
2194 ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_EIE);
2195 }
2196
2197 /**
2198 * @brief Disable CTS Interrupt
2199 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
2200 * Hardware Flow control feature is supported by the USARTx instance.
2201 * @rmtoll CR3 CTSIE LL_USART_DisableIT_CTS
2202 * @param USARTx USART Instance
2203 * @retval None
2204 */
LL_USART_DisableIT_CTS(USART_TypeDef * USARTx)2205 __STATIC_INLINE void LL_USART_DisableIT_CTS(USART_TypeDef *USARTx)
2206 {
2207 ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_CTSIE);
2208 }
2209
2210 /**
2211 * @brief Check if the USART IDLE Interrupt source is enabled or disabled.
2212 * @rmtoll CR1 IDLEIE LL_USART_IsEnabledIT_IDLE
2213 * @param USARTx USART Instance
2214 * @retval State of bit (1 or 0).
2215 */
LL_USART_IsEnabledIT_IDLE(USART_TypeDef * USARTx)2216 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_IDLE(USART_TypeDef *USARTx)
2217 {
2218 return (READ_BIT(USARTx->CR1, USART_CR1_IDLEIE) == (USART_CR1_IDLEIE));
2219 }
2220
2221 /**
2222 * @brief Check if the USART RX Not Empty Interrupt is enabled or disabled.
2223 * @rmtoll CR1 RXNEIE LL_USART_IsEnabledIT_RXNE
2224 * @param USARTx USART Instance
2225 * @retval State of bit (1 or 0).
2226 */
LL_USART_IsEnabledIT_RXNE(USART_TypeDef * USARTx)2227 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RXNE(USART_TypeDef *USARTx)
2228 {
2229 return (READ_BIT(USARTx->CR1, USART_CR1_RXNEIE) == (USART_CR1_RXNEIE));
2230 }
2231
2232 /**
2233 * @brief Check if the USART Transmission Complete Interrupt is enabled or disabled.
2234 * @rmtoll CR1 TCIE LL_USART_IsEnabledIT_TC
2235 * @param USARTx USART Instance
2236 * @retval State of bit (1 or 0).
2237 */
LL_USART_IsEnabledIT_TC(USART_TypeDef * USARTx)2238 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TC(USART_TypeDef *USARTx)
2239 {
2240 return (READ_BIT(USARTx->CR1, USART_CR1_TCIE) == (USART_CR1_TCIE));
2241 }
2242
2243 /**
2244 * @brief Check if the USART TX Empty Interrupt is enabled or disabled.
2245 * @rmtoll CR1 TXEIE LL_USART_IsEnabledIT_TXE
2246 * @param USARTx USART Instance
2247 * @retval State of bit (1 or 0).
2248 */
LL_USART_IsEnabledIT_TXE(USART_TypeDef * USARTx)2249 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TXE(USART_TypeDef *USARTx)
2250 {
2251 return (READ_BIT(USARTx->CR1, USART_CR1_TXEIE) == (USART_CR1_TXEIE));
2252 }
2253
2254 /**
2255 * @brief Check if the USART Parity Error Interrupt is enabled or disabled.
2256 * @rmtoll CR1 PEIE LL_USART_IsEnabledIT_PE
2257 * @param USARTx USART Instance
2258 * @retval State of bit (1 or 0).
2259 */
LL_USART_IsEnabledIT_PE(USART_TypeDef * USARTx)2260 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_PE(USART_TypeDef *USARTx)
2261 {
2262 return (READ_BIT(USARTx->CR1, USART_CR1_PEIE) == (USART_CR1_PEIE));
2263 }
2264
2265 /**
2266 * @brief Check if the USART LIN Break Detection Interrupt is enabled or disabled.
2267 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2268 * LIN feature is supported by the USARTx instance.
2269 * @rmtoll CR2 LBDIE LL_USART_IsEnabledIT_LBD
2270 * @param USARTx USART Instance
2271 * @retval State of bit (1 or 0).
2272 */
LL_USART_IsEnabledIT_LBD(USART_TypeDef * USARTx)2273 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_LBD(USART_TypeDef *USARTx)
2274 {
2275 return (READ_BIT(USARTx->CR2, USART_CR2_LBDIE) == (USART_CR2_LBDIE));
2276 }
2277
2278 /**
2279 * @brief Check if the USART Error Interrupt is enabled or disabled.
2280 * @rmtoll CR3 EIE LL_USART_IsEnabledIT_ERROR
2281 * @param USARTx USART Instance
2282 * @retval State of bit (1 or 0).
2283 */
LL_USART_IsEnabledIT_ERROR(USART_TypeDef * USARTx)2284 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_ERROR(USART_TypeDef *USARTx)
2285 {
2286 return (READ_BIT(USARTx->CR3, USART_CR3_EIE) == (USART_CR3_EIE));
2287 }
2288
2289 /**
2290 * @brief Check if the USART CTS Interrupt is enabled or disabled.
2291 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
2292 * Hardware Flow control feature is supported by the USARTx instance.
2293 * @rmtoll CR3 CTSIE LL_USART_IsEnabledIT_CTS
2294 * @param USARTx USART Instance
2295 * @retval State of bit (1 or 0).
2296 */
LL_USART_IsEnabledIT_CTS(USART_TypeDef * USARTx)2297 __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_CTS(USART_TypeDef *USARTx)
2298 {
2299 return (READ_BIT(USARTx->CR3, USART_CR3_CTSIE) == (USART_CR3_CTSIE));
2300 }
2301
2302 /**
2303 * @}
2304 */
2305
2306 /** @defgroup USART_LL_EF_DMA_Management DMA_Management
2307 * @{
2308 */
2309
2310 /**
2311 * @brief Enable DMA Mode for reception
2312 * @rmtoll CR3 DMAR LL_USART_EnableDMAReq_RX
2313 * @param USARTx USART Instance
2314 * @retval None
2315 */
LL_USART_EnableDMAReq_RX(USART_TypeDef * USARTx)2316 __STATIC_INLINE void LL_USART_EnableDMAReq_RX(USART_TypeDef *USARTx)
2317 {
2318 ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_DMAR);
2319 }
2320
2321 /**
2322 * @brief Disable DMA Mode for reception
2323 * @rmtoll CR3 DMAR LL_USART_DisableDMAReq_RX
2324 * @param USARTx USART Instance
2325 * @retval None
2326 */
LL_USART_DisableDMAReq_RX(USART_TypeDef * USARTx)2327 __STATIC_INLINE void LL_USART_DisableDMAReq_RX(USART_TypeDef *USARTx)
2328 {
2329 ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_DMAR);
2330 }
2331
2332 /**
2333 * @brief Check if DMA Mode is enabled for reception
2334 * @rmtoll CR3 DMAR LL_USART_IsEnabledDMAReq_RX
2335 * @param USARTx USART Instance
2336 * @retval State of bit (1 or 0).
2337 */
LL_USART_IsEnabledDMAReq_RX(USART_TypeDef * USARTx)2338 __STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_RX(USART_TypeDef *USARTx)
2339 {
2340 return (READ_BIT(USARTx->CR3, USART_CR3_DMAR) == (USART_CR3_DMAR));
2341 }
2342
2343 /**
2344 * @brief Enable DMA Mode for transmission
2345 * @rmtoll CR3 DMAT LL_USART_EnableDMAReq_TX
2346 * @param USARTx USART Instance
2347 * @retval None
2348 */
LL_USART_EnableDMAReq_TX(USART_TypeDef * USARTx)2349 __STATIC_INLINE void LL_USART_EnableDMAReq_TX(USART_TypeDef *USARTx)
2350 {
2351 ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_DMAT);
2352 }
2353
2354 /**
2355 * @brief Disable DMA Mode for transmission
2356 * @rmtoll CR3 DMAT LL_USART_DisableDMAReq_TX
2357 * @param USARTx USART Instance
2358 * @retval None
2359 */
LL_USART_DisableDMAReq_TX(USART_TypeDef * USARTx)2360 __STATIC_INLINE void LL_USART_DisableDMAReq_TX(USART_TypeDef *USARTx)
2361 {
2362 ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_DMAT);
2363 }
2364
2365 /**
2366 * @brief Check if DMA Mode is enabled for transmission
2367 * @rmtoll CR3 DMAT LL_USART_IsEnabledDMAReq_TX
2368 * @param USARTx USART Instance
2369 * @retval State of bit (1 or 0).
2370 */
LL_USART_IsEnabledDMAReq_TX(USART_TypeDef * USARTx)2371 __STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_TX(USART_TypeDef *USARTx)
2372 {
2373 return (READ_BIT(USARTx->CR3, USART_CR3_DMAT) == (USART_CR3_DMAT));
2374 }
2375
2376 /**
2377 * @brief Get the data register address used for DMA transfer
2378 * @rmtoll DR DR LL_USART_DMA_GetRegAddr
2379 * @note Address of Data Register is valid for both Transmit and Receive transfers.
2380 * @param USARTx USART Instance
2381 * @retval Address of data register
2382 */
LL_USART_DMA_GetRegAddr(USART_TypeDef * USARTx)2383 __STATIC_INLINE uint32_t LL_USART_DMA_GetRegAddr(USART_TypeDef *USARTx)
2384 {
2385 /* return address of DR register */
2386 return ((uint32_t) &(USARTx->DR));
2387 }
2388
2389 /**
2390 * @}
2391 */
2392
2393 /** @defgroup USART_LL_EF_Data_Management Data_Management
2394 * @{
2395 */
2396
2397 /**
2398 * @brief Read Receiver Data register (Receive Data value, 8 bits)
2399 * @rmtoll DR DR LL_USART_ReceiveData8
2400 * @param USARTx USART Instance
2401 * @retval Value between Min_Data=0x00 and Max_Data=0xFF
2402 */
LL_USART_ReceiveData8(USART_TypeDef * USARTx)2403 __STATIC_INLINE uint8_t LL_USART_ReceiveData8(USART_TypeDef *USARTx)
2404 {
2405 return (uint8_t)(READ_BIT(USARTx->DR, USART_DR_DR));
2406 }
2407
2408 /**
2409 * @brief Read Receiver Data register (Receive Data value, 9 bits)
2410 * @rmtoll DR DR LL_USART_ReceiveData9
2411 * @param USARTx USART Instance
2412 * @retval Value between Min_Data=0x00 and Max_Data=0x1FF
2413 */
LL_USART_ReceiveData9(USART_TypeDef * USARTx)2414 __STATIC_INLINE uint16_t LL_USART_ReceiveData9(USART_TypeDef *USARTx)
2415 {
2416 return (uint16_t)(READ_BIT(USARTx->DR, USART_DR_DR));
2417 }
2418
2419 /**
2420 * @brief Write in Transmitter Data Register (Transmit Data value, 8 bits)
2421 * @rmtoll DR DR LL_USART_TransmitData8
2422 * @param USARTx USART Instance
2423 * @param Value between Min_Data=0x00 and Max_Data=0xFF
2424 * @retval None
2425 */
LL_USART_TransmitData8(USART_TypeDef * USARTx,uint8_t Value)2426 __STATIC_INLINE void LL_USART_TransmitData8(USART_TypeDef *USARTx, uint8_t Value)
2427 {
2428 USARTx->DR = Value;
2429 }
2430
2431 /**
2432 * @brief Write in Transmitter Data Register (Transmit Data value, 9 bits)
2433 * @rmtoll DR DR LL_USART_TransmitData9
2434 * @param USARTx USART Instance
2435 * @param Value between Min_Data=0x00 and Max_Data=0x1FF
2436 * @retval None
2437 */
LL_USART_TransmitData9(USART_TypeDef * USARTx,uint16_t Value)2438 __STATIC_INLINE void LL_USART_TransmitData9(USART_TypeDef *USARTx, uint16_t Value)
2439 {
2440 USARTx->DR = Value & 0x1FFU;
2441 }
2442
2443 /**
2444 * @}
2445 */
2446
2447 /** @defgroup USART_LL_EF_Execution Execution
2448 * @{
2449 */
2450
2451 /**
2452 * @brief Request Break sending
2453 * @rmtoll CR1 SBK LL_USART_RequestBreakSending
2454 * @param USARTx USART Instance
2455 * @retval None
2456 */
LL_USART_RequestBreakSending(USART_TypeDef * USARTx)2457 __STATIC_INLINE void LL_USART_RequestBreakSending(USART_TypeDef *USARTx)
2458 {
2459 SET_BIT(USARTx->CR1, USART_CR1_SBK);
2460 }
2461
2462 /**
2463 * @brief Put USART in Mute mode
2464 * @rmtoll CR1 RWU LL_USART_RequestEnterMuteMode
2465 * @param USARTx USART Instance
2466 * @retval None
2467 */
LL_USART_RequestEnterMuteMode(USART_TypeDef * USARTx)2468 __STATIC_INLINE void LL_USART_RequestEnterMuteMode(USART_TypeDef *USARTx)
2469 {
2470 SET_BIT(USARTx->CR1, USART_CR1_RWU);
2471 }
2472
2473 /**
2474 * @brief Put USART in Active mode
2475 * @rmtoll CR1 RWU LL_USART_RequestExitMuteMode
2476 * @param USARTx USART Instance
2477 * @retval None
2478 */
LL_USART_RequestExitMuteMode(USART_TypeDef * USARTx)2479 __STATIC_INLINE void LL_USART_RequestExitMuteMode(USART_TypeDef *USARTx)
2480 {
2481 CLEAR_BIT(USARTx->CR1, USART_CR1_RWU);
2482 }
2483
2484 /**
2485 * @}
2486 */
2487
2488 #if defined(USE_FULL_LL_DRIVER)
2489 /** @defgroup USART_LL_EF_Init Initialization and de-initialization functions
2490 * @{
2491 */
2492 ErrorStatus LL_USART_DeInit(USART_TypeDef *USARTx);
2493 ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct);
2494 void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct);
2495 ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
2496 void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
2497 /**
2498 * @}
2499 */
2500 #endif /* USE_FULL_LL_DRIVER */
2501
2502 /**
2503 * @}
2504 */
2505
2506 /**
2507 * @}
2508 */
2509
2510 #endif /* USART1 || USART2 || USART3 || USART6 || UART4 || UART5 || UART7 || UART8 || UART9 || UART10 */
2511
2512 /**
2513 * @}
2514 */
2515
2516 #ifdef __cplusplus
2517 }
2518 #endif
2519
2520 #endif /* __STM32F4xx_LL_USART_H */
2521
2522