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