2 ******************************************************************************
3 * @file stm32f1xx_ll_usart.h
4 * @author MCD Application Team
7 * @brief Header file of USART LL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F1xx_LL_USART_H
40 #define __STM32F1xx_LL_USART_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f1xx.h"
49 /** @addtogroup STM32F1xx_LL_Driver
53 #if defined (USART1) || defined (USART2) || defined (USART3) || defined (UART4) || defined (UART5)
55 /** @defgroup USART_LL USART
59 /* Private types -------------------------------------------------------------*/
60 /* Private variables ---------------------------------------------------------*/
62 /* Private constants ---------------------------------------------------------*/
63 /** @defgroup USART_LL_Private_Constants USART Private Constants
67 /* Defines used for the bit position in the register and perform offsets*/
68 #define USART_POSITION_GTPR_GT USART_GTPR_GT_Pos
73 /* Private macros ------------------------------------------------------------*/
74 #if defined(USE_FULL_LL_DRIVER)
75 /** @defgroup USART_LL_Private_Macros USART Private Macros
81 #endif /*USE_FULL_LL_DRIVER*/
83 /* Exported types ------------------------------------------------------------*/
84 #if defined(USE_FULL_LL_DRIVER)
85 /** @defgroup USART_LL_ES_INIT USART Exported Init structures
90 * @brief LL USART Init Structure definition
94 uint32_t BaudRate
; /*!< This field defines expected Usart communication baud rate.
96 This feature can be modified afterwards using unitary function @ref LL_USART_SetBaudRate().*/
98 uint32_t DataWidth
; /*!< Specifies the number of data bits transmitted or received in a frame.
99 This parameter can be a value of @ref USART_LL_EC_DATAWIDTH.
101 This feature can be modified afterwards using unitary function @ref LL_USART_SetDataWidth().*/
103 uint32_t StopBits
; /*!< Specifies the number of stop bits transmitted.
104 This parameter can be a value of @ref USART_LL_EC_STOPBITS.
106 This feature can be modified afterwards using unitary function @ref LL_USART_SetStopBitsLength().*/
108 uint32_t Parity
; /*!< Specifies the parity mode.
109 This parameter can be a value of @ref USART_LL_EC_PARITY.
111 This feature can be modified afterwards using unitary function @ref LL_USART_SetParity().*/
113 uint32_t TransferDirection
; /*!< Specifies whether the Receive and/or Transmit mode is enabled or disabled.
114 This parameter can be a value of @ref USART_LL_EC_DIRECTION.
116 This feature can be modified afterwards using unitary function @ref LL_USART_SetTransferDirection().*/
118 uint32_t HardwareFlowControl
; /*!< Specifies whether the hardware flow control mode is enabled or disabled.
119 This parameter can be a value of @ref USART_LL_EC_HWCONTROL.
121 This feature can be modified afterwards using unitary function @ref LL_USART_SetHWFlowCtrl().*/
123 #if defined(USART_CR1_OVER8)
124 uint32_t OverSampling
; /*!< Specifies whether USART oversampling mode is 16 or 8.
125 This parameter can be a value of @ref USART_LL_EC_OVERSAMPLING.
127 This feature can be modified afterwards using unitary function @ref LL_USART_SetOverSampling().*/
129 #endif /* USART_OverSampling_Feature */
130 } LL_USART_InitTypeDef
;
133 * @brief LL USART Clock Init Structure definition
137 uint32_t ClockOutput
; /*!< Specifies whether the USART clock is enabled or disabled.
138 This parameter can be a value of @ref USART_LL_EC_CLOCK.
140 USART HW configuration can be modified afterwards using unitary functions
141 @ref LL_USART_EnableSCLKOutput() or @ref LL_USART_DisableSCLKOutput().
142 For more details, refer to description of this function. */
144 uint32_t ClockPolarity
; /*!< Specifies the steady state of the serial clock.
145 This parameter can be a value of @ref USART_LL_EC_POLARITY.
147 USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetClockPolarity().
148 For more details, refer to description of this function. */
150 uint32_t ClockPhase
; /*!< Specifies the clock transition on which the bit capture is made.
151 This parameter can be a value of @ref USART_LL_EC_PHASE.
153 USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetClockPhase().
154 For more details, refer to description of this function. */
156 uint32_t LastBitClockPulse
; /*!< Specifies whether the clock pulse corresponding to the last transmitted
157 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
158 This parameter can be a value of @ref USART_LL_EC_LASTCLKPULSE.
160 USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetLastClkPulseOutput().
161 For more details, refer to description of this function. */
163 } LL_USART_ClockInitTypeDef
;
168 #endif /* USE_FULL_LL_DRIVER */
170 /* Exported constants --------------------------------------------------------*/
171 /** @defgroup USART_LL_Exported_Constants USART Exported Constants
175 /** @defgroup USART_LL_EC_GET_FLAG Get Flags Defines
176 * @brief Flags defines which can be used with LL_USART_ReadReg function
179 #define LL_USART_SR_PE USART_SR_PE /*!< Parity error flag */
180 #define LL_USART_SR_FE USART_SR_FE /*!< Framing error flag */
181 #define LL_USART_SR_NE USART_SR_NE /*!< Noise detected flag */
182 #define LL_USART_SR_ORE USART_SR_ORE /*!< Overrun error flag */
183 #define LL_USART_SR_IDLE USART_SR_IDLE /*!< Idle line detected flag */
184 #define LL_USART_SR_RXNE USART_SR_RXNE /*!< Read data register not empty flag */
185 #define LL_USART_SR_TC USART_SR_TC /*!< Transmission complete flag */
186 #define LL_USART_SR_TXE USART_SR_TXE /*!< Transmit data register empty flag */
187 #define LL_USART_SR_LBD USART_SR_LBD /*!< LIN break detection flag */
188 #define LL_USART_SR_CTS USART_SR_CTS /*!< CTS flag */
193 /** @defgroup USART_LL_EC_IT IT Defines
194 * @brief IT defines which can be used with LL_USART_ReadReg and LL_USART_WriteReg functions
197 #define LL_USART_CR1_IDLEIE USART_CR1_IDLEIE /*!< IDLE interrupt enable */
198 #define LL_USART_CR1_RXNEIE USART_CR1_RXNEIE /*!< Read data register not empty interrupt enable */
199 #define LL_USART_CR1_TCIE USART_CR1_TCIE /*!< Transmission complete interrupt enable */
200 #define LL_USART_CR1_TXEIE USART_CR1_TXEIE /*!< Transmit data register empty interrupt enable */
201 #define LL_USART_CR1_PEIE USART_CR1_PEIE /*!< Parity error */
202 #define LL_USART_CR2_LBDIE USART_CR2_LBDIE /*!< LIN break detection interrupt enable */
203 #define LL_USART_CR3_EIE USART_CR3_EIE /*!< Error interrupt enable */
204 #define LL_USART_CR3_CTSIE USART_CR3_CTSIE /*!< CTS interrupt enable */
209 /** @defgroup USART_LL_EC_DIRECTION Communication Direction
212 #define LL_USART_DIRECTION_NONE 0x00000000U /*!< Transmitter and Receiver are disabled */
213 #define LL_USART_DIRECTION_RX USART_CR1_RE /*!< Transmitter is disabled and Receiver is enabled */
214 #define LL_USART_DIRECTION_TX USART_CR1_TE /*!< Transmitter is enabled and Receiver is disabled */
215 #define LL_USART_DIRECTION_TX_RX (USART_CR1_TE |USART_CR1_RE) /*!< Transmitter and Receiver are enabled */
220 /** @defgroup USART_LL_EC_PARITY Parity Control
223 #define LL_USART_PARITY_NONE 0x00000000U /*!< Parity control disabled */
224 #define LL_USART_PARITY_EVEN USART_CR1_PCE /*!< Parity control enabled and Even Parity is selected */
225 #define LL_USART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS) /*!< Parity control enabled and Odd Parity is selected */
230 /** @defgroup USART_LL_EC_WAKEUP Wakeup
233 #define LL_USART_WAKEUP_IDLELINE 0x00000000U /*!< USART wake up from Mute mode on Idle Line */
234 #define LL_USART_WAKEUP_ADDRESSMARK USART_CR1_WAKE /*!< USART wake up from Mute mode on Address Mark */
239 /** @defgroup USART_LL_EC_DATAWIDTH Datawidth
242 #define LL_USART_DATAWIDTH_8B 0x00000000U /*!< 8 bits word length : Start bit, 8 data bits, n stop bits */
243 #define LL_USART_DATAWIDTH_9B USART_CR1_M /*!< 9 bits word length : Start bit, 9 data bits, n stop bits */
248 #if defined(USART_CR1_OVER8)
249 /** @defgroup USART_LL_EC_OVERSAMPLING Oversampling
252 #define LL_USART_OVERSAMPLING_16 0x00000000U /*!< Oversampling by 16 */
253 #define LL_USART_OVERSAMPLING_8 USART_CR1_OVER8 /*!< Oversampling by 8 */
258 #endif /* USART_OverSampling_Feature */
259 #if defined(USE_FULL_LL_DRIVER)
260 /** @defgroup USART_LL_EC_CLOCK Clock Signal
264 #define LL_USART_CLOCK_DISABLE 0x00000000U /*!< Clock signal not provided */
265 #define LL_USART_CLOCK_ENABLE USART_CR2_CLKEN /*!< Clock signal provided */
269 #endif /*USE_FULL_LL_DRIVER*/
271 /** @defgroup USART_LL_EC_LASTCLKPULSE Last Clock Pulse
274 #define LL_USART_LASTCLKPULSE_NO_OUTPUT 0x00000000U /*!< The clock pulse of the last data bit is not output to the SCLK pin */
275 #define LL_USART_LASTCLKPULSE_OUTPUT USART_CR2_LBCL /*!< The clock pulse of the last data bit is output to the SCLK pin */
280 /** @defgroup USART_LL_EC_PHASE Clock Phase
283 #define LL_USART_PHASE_1EDGE 0x00000000U /*!< The first clock transition is the first data capture edge */
284 #define LL_USART_PHASE_2EDGE USART_CR2_CPHA /*!< The second clock transition is the first data capture edge */
289 /** @defgroup USART_LL_EC_POLARITY Clock Polarity
292 #define LL_USART_POLARITY_LOW 0x00000000U /*!< Steady low value on SCLK pin outside transmission window*/
293 #define LL_USART_POLARITY_HIGH USART_CR2_CPOL /*!< Steady high value on SCLK pin outside transmission window */
298 /** @defgroup USART_LL_EC_STOPBITS Stop Bits
301 #define LL_USART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< 0.5 stop bit */
302 #define LL_USART_STOPBITS_1 0x00000000U /*!< 1 stop bit */
303 #define LL_USART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< 1.5 stop bits */
304 #define LL_USART_STOPBITS_2 USART_CR2_STOP_1 /*!< 2 stop bits */
309 /** @defgroup USART_LL_EC_HWCONTROL Hardware Control
312 #define LL_USART_HWCONTROL_NONE 0x00000000U /*!< CTS and RTS hardware flow control disabled */
313 #define LL_USART_HWCONTROL_RTS USART_CR3_RTSE /*!< RTS output enabled, data is only requested when there is space in the receive buffer */
314 #define LL_USART_HWCONTROL_CTS USART_CR3_CTSE /*!< CTS mode enabled, data is only transmitted when the nCTS input is asserted (tied to 0) */
315 #define LL_USART_HWCONTROL_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE) /*!< CTS and RTS hardware flow control enabled */
320 /** @defgroup USART_LL_EC_IRDA_POWER IrDA Power
323 #define LL_USART_IRDA_POWER_NORMAL 0x00000000U /*!< IrDA normal power mode */
324 #define LL_USART_IRDA_POWER_LOW USART_CR3_IRLP /*!< IrDA low power mode */
329 /** @defgroup USART_LL_EC_LINBREAK_DETECT LIN Break Detection Length
332 #define LL_USART_LINBREAK_DETECT_10B 0x00000000U /*!< 10-bit break detection method selected */
333 #define LL_USART_LINBREAK_DETECT_11B USART_CR2_LBDL /*!< 11-bit break detection method selected */
342 /* Exported macro ------------------------------------------------------------*/
343 /** @defgroup USART_LL_Exported_Macros USART Exported Macros
347 /** @defgroup USART_LL_EM_WRITE_READ Common Write and read registers Macros
352 * @brief Write a value in USART register
353 * @param __INSTANCE__ USART Instance
354 * @param __REG__ Register to be written
355 * @param __VALUE__ Value to be written in the register
358 #define LL_USART_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
361 * @brief Read a value in USART register
362 * @param __INSTANCE__ USART Instance
363 * @param __REG__ Register to be read
364 * @retval Register value
366 #define LL_USART_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
371 /** @defgroup USART_LL_EM_Exported_Macros_Helper Exported_Macros_Helper
376 * @brief Compute USARTDIV value according to Peripheral Clock and
377 * expected Baud Rate in 8 bits sampling mode (32 bits value of USARTDIV is returned)
378 * @param __PERIPHCLK__ Peripheral Clock frequency used for USART instance
379 * @param __BAUDRATE__ Baud rate value to achieve
380 * @retval USARTDIV value to be used for BRR register filling in OverSampling_8 case
382 #define __LL_USART_DIV_SAMPLING8_100(__PERIPHCLK__, __BAUDRATE__) (((__PERIPHCLK__)*25)/(2*(__BAUDRATE__)))
383 #define __LL_USART_DIVMANT_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) (__LL_USART_DIV_SAMPLING8_100((__PERIPHCLK__), (__BAUDRATE__))/100)
384 #define __LL_USART_DIVFRAQ_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIV_SAMPLING8_100((__PERIPHCLK__), (__BAUDRATE__)) - (__LL_USART_DIVMANT_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) * 100)) * 8 + 50) / 100)
385 /* UART BRR = mantissa + overflow + fraction
386 = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07) */
387 #define __LL_USART_DIV_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIVMANT_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) << 4) + \
388 ((__LL_USART_DIVFRAQ_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) & 0xF8) << 1)) + \
389 (__LL_USART_DIVFRAQ_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) & 0x07))
392 * @brief Compute USARTDIV value according to Peripheral Clock and
393 * expected Baud Rate in 16 bits sampling mode (32 bits value of USARTDIV is returned)
394 * @param __PERIPHCLK__ Peripheral Clock frequency used for USART instance
395 * @param __BAUDRATE__ Baud rate value to achieve
396 * @retval USARTDIV value to be used for BRR register filling in OverSampling_16 case
398 #define __LL_USART_DIV_SAMPLING16_100(__PERIPHCLK__, __BAUDRATE__) (((__PERIPHCLK__)*25)/(4*(__BAUDRATE__)))
399 #define __LL_USART_DIVMANT_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (__LL_USART_DIV_SAMPLING16_100((__PERIPHCLK__), (__BAUDRATE__))/100)
400 #define __LL_USART_DIVFRAQ_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIV_SAMPLING16_100((__PERIPHCLK__), (__BAUDRATE__)) - (__LL_USART_DIVMANT_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) * 100)) * 16 + 50) / 100)
401 /* USART BRR = mantissa + overflow + fraction
402 = (USART DIVMANT << 4) + (USART DIVFRAQ & 0xF0) + (USART DIVFRAQ & 0x0F) */
403 #define __LL_USART_DIV_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIVMANT_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) << 4) + \
404 (__LL_USART_DIVFRAQ_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) & 0xF0)) + \
405 (__LL_USART_DIVFRAQ_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) & 0x0F))
415 /* Exported functions --------------------------------------------------------*/
417 /** @defgroup USART_LL_Exported_Functions USART Exported Functions
421 /** @defgroup USART_LL_EF_Configuration Configuration functions
426 * @brief USART Enable
427 * @rmtoll CR1 UE LL_USART_Enable
428 * @param USARTx USART Instance
431 __STATIC_INLINE
void LL_USART_Enable(USART_TypeDef
*USARTx
)
433 SET_BIT(USARTx
->CR1
, USART_CR1_UE
);
437 * @brief USART Disable (all USART prescalers and outputs are disabled)
438 * @note When USART is disabled, USART prescalers and outputs are stopped immediately,
439 * and current operations are discarded. The configuration of the USART is kept, but all the status
440 * flags, in the USARTx_SR are set to their default values.
441 * @rmtoll CR1 UE LL_USART_Disable
442 * @param USARTx USART Instance
445 __STATIC_INLINE
void LL_USART_Disable(USART_TypeDef
*USARTx
)
447 CLEAR_BIT(USARTx
->CR1
, USART_CR1_UE
);
451 * @brief Indicate if USART is enabled
452 * @rmtoll CR1 UE LL_USART_IsEnabled
453 * @param USARTx USART Instance
454 * @retval State of bit (1 or 0).
456 __STATIC_INLINE
uint32_t LL_USART_IsEnabled(USART_TypeDef
*USARTx
)
458 return (READ_BIT(USARTx
->CR1
, USART_CR1_UE
) == (USART_CR1_UE
));
462 * @brief Receiver Enable (Receiver is enabled and begins searching for a start bit)
463 * @rmtoll CR1 RE LL_USART_EnableDirectionRx
464 * @param USARTx USART Instance
467 __STATIC_INLINE
void LL_USART_EnableDirectionRx(USART_TypeDef
*USARTx
)
469 SET_BIT(USARTx
->CR1
, USART_CR1_RE
);
473 * @brief Receiver Disable
474 * @rmtoll CR1 RE LL_USART_DisableDirectionRx
475 * @param USARTx USART Instance
478 __STATIC_INLINE
void LL_USART_DisableDirectionRx(USART_TypeDef
*USARTx
)
480 CLEAR_BIT(USARTx
->CR1
, USART_CR1_RE
);
484 * @brief Transmitter Enable
485 * @rmtoll CR1 TE LL_USART_EnableDirectionTx
486 * @param USARTx USART Instance
489 __STATIC_INLINE
void LL_USART_EnableDirectionTx(USART_TypeDef
*USARTx
)
491 SET_BIT(USARTx
->CR1
, USART_CR1_TE
);
495 * @brief Transmitter Disable
496 * @rmtoll CR1 TE LL_USART_DisableDirectionTx
497 * @param USARTx USART Instance
500 __STATIC_INLINE
void LL_USART_DisableDirectionTx(USART_TypeDef
*USARTx
)
502 CLEAR_BIT(USARTx
->CR1
, USART_CR1_TE
);
506 * @brief Configure simultaneously enabled/disabled states
507 * of Transmitter and Receiver
508 * @rmtoll CR1 RE LL_USART_SetTransferDirection\n
509 * CR1 TE LL_USART_SetTransferDirection
510 * @param USARTx USART Instance
511 * @param TransferDirection This parameter can be one of the following values:
512 * @arg @ref LL_USART_DIRECTION_NONE
513 * @arg @ref LL_USART_DIRECTION_RX
514 * @arg @ref LL_USART_DIRECTION_TX
515 * @arg @ref LL_USART_DIRECTION_TX_RX
518 __STATIC_INLINE
void LL_USART_SetTransferDirection(USART_TypeDef
*USARTx
, uint32_t TransferDirection
)
520 MODIFY_REG(USARTx
->CR1
, USART_CR1_RE
| USART_CR1_TE
, TransferDirection
);
524 * @brief Return enabled/disabled states of Transmitter and Receiver
525 * @rmtoll CR1 RE LL_USART_GetTransferDirection\n
526 * CR1 TE LL_USART_GetTransferDirection
527 * @param USARTx USART Instance
528 * @retval Returned value can be one of the following values:
529 * @arg @ref LL_USART_DIRECTION_NONE
530 * @arg @ref LL_USART_DIRECTION_RX
531 * @arg @ref LL_USART_DIRECTION_TX
532 * @arg @ref LL_USART_DIRECTION_TX_RX
534 __STATIC_INLINE
uint32_t LL_USART_GetTransferDirection(USART_TypeDef
*USARTx
)
536 return (uint32_t)(READ_BIT(USARTx
->CR1
, USART_CR1_RE
| USART_CR1_TE
));
540 * @brief Configure Parity (enabled/disabled and parity mode if enabled).
541 * @note This function selects if hardware parity control (generation and detection) is enabled or disabled.
542 * When the parity control is enabled (Odd or Even), computed parity bit is inserted at the MSB position
543 * (9th or 8th bit depending on data width) and parity is checked on the received data.
544 * @rmtoll CR1 PS LL_USART_SetParity\n
545 * CR1 PCE LL_USART_SetParity
546 * @param USARTx USART Instance
547 * @param Parity This parameter can be one of the following values:
548 * @arg @ref LL_USART_PARITY_NONE
549 * @arg @ref LL_USART_PARITY_EVEN
550 * @arg @ref LL_USART_PARITY_ODD
553 __STATIC_INLINE
void LL_USART_SetParity(USART_TypeDef
*USARTx
, uint32_t Parity
)
555 MODIFY_REG(USARTx
->CR1
, USART_CR1_PS
| USART_CR1_PCE
, Parity
);
559 * @brief Return Parity configuration (enabled/disabled and parity mode if enabled)
560 * @rmtoll CR1 PS LL_USART_GetParity\n
561 * CR1 PCE LL_USART_GetParity
562 * @param USARTx USART Instance
563 * @retval Returned value can be one of the following values:
564 * @arg @ref LL_USART_PARITY_NONE
565 * @arg @ref LL_USART_PARITY_EVEN
566 * @arg @ref LL_USART_PARITY_ODD
568 __STATIC_INLINE
uint32_t LL_USART_GetParity(USART_TypeDef
*USARTx
)
570 return (uint32_t)(READ_BIT(USARTx
->CR1
, USART_CR1_PS
| USART_CR1_PCE
));
574 * @brief Set Receiver Wake Up method from Mute mode.
575 * @rmtoll CR1 WAKE LL_USART_SetWakeUpMethod
576 * @param USARTx USART Instance
577 * @param Method This parameter can be one of the following values:
578 * @arg @ref LL_USART_WAKEUP_IDLELINE
579 * @arg @ref LL_USART_WAKEUP_ADDRESSMARK
582 __STATIC_INLINE
void LL_USART_SetWakeUpMethod(USART_TypeDef
*USARTx
, uint32_t Method
)
584 MODIFY_REG(USARTx
->CR1
, USART_CR1_WAKE
, Method
);
588 * @brief Return Receiver Wake Up method from Mute mode
589 * @rmtoll CR1 WAKE LL_USART_GetWakeUpMethod
590 * @param USARTx USART Instance
591 * @retval Returned value can be one of the following values:
592 * @arg @ref LL_USART_WAKEUP_IDLELINE
593 * @arg @ref LL_USART_WAKEUP_ADDRESSMARK
595 __STATIC_INLINE
uint32_t LL_USART_GetWakeUpMethod(USART_TypeDef
*USARTx
)
597 return (uint32_t)(READ_BIT(USARTx
->CR1
, USART_CR1_WAKE
));
601 * @brief Set Word length (i.e. nb of data bits, excluding start and stop bits)
602 * @rmtoll CR1 M LL_USART_SetDataWidth
603 * @param USARTx USART Instance
604 * @param DataWidth This parameter can be one of the following values:
605 * @arg @ref LL_USART_DATAWIDTH_8B
606 * @arg @ref LL_USART_DATAWIDTH_9B
609 __STATIC_INLINE
void LL_USART_SetDataWidth(USART_TypeDef
*USARTx
, uint32_t DataWidth
)
611 MODIFY_REG(USARTx
->CR1
, USART_CR1_M
, DataWidth
);
615 * @brief Return Word length (i.e. nb of data bits, excluding start and stop bits)
616 * @rmtoll CR1 M LL_USART_GetDataWidth
617 * @param USARTx USART Instance
618 * @retval Returned value can be one of the following values:
619 * @arg @ref LL_USART_DATAWIDTH_8B
620 * @arg @ref LL_USART_DATAWIDTH_9B
622 __STATIC_INLINE
uint32_t LL_USART_GetDataWidth(USART_TypeDef
*USARTx
)
624 return (uint32_t)(READ_BIT(USARTx
->CR1
, USART_CR1_M
));
627 #if defined(USART_CR1_OVER8)
629 * @brief Set Oversampling to 8-bit or 16-bit mode
630 * @rmtoll CR1 OVER8 LL_USART_SetOverSampling
631 * @param USARTx USART Instance
632 * @param OverSampling This parameter can be one of the following values:
633 * @arg @ref LL_USART_OVERSAMPLING_16
634 * @arg @ref LL_USART_OVERSAMPLING_8
637 __STATIC_INLINE
void LL_USART_SetOverSampling(USART_TypeDef
*USARTx
, uint32_t OverSampling
)
639 MODIFY_REG(USARTx
->CR1
, USART_CR1_OVER8
, OverSampling
);
643 * @brief Return Oversampling mode
644 * @rmtoll CR1 OVER8 LL_USART_GetOverSampling
645 * @param USARTx USART Instance
646 * @retval Returned value can be one of the following values:
647 * @arg @ref LL_USART_OVERSAMPLING_16
648 * @arg @ref LL_USART_OVERSAMPLING_8
650 __STATIC_INLINE
uint32_t LL_USART_GetOverSampling(USART_TypeDef
*USARTx
)
652 return (uint32_t)(READ_BIT(USARTx
->CR1
, USART_CR1_OVER8
));
655 #endif /* USART_OverSampling_Feature */
657 * @brief Configure if Clock pulse of the last data bit is output to the SCLK pin or not
658 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
659 * Synchronous mode is supported by the USARTx instance.
660 * @rmtoll CR2 LBCL LL_USART_SetLastClkPulseOutput
661 * @param USARTx USART Instance
662 * @param LastBitClockPulse This parameter can be one of the following values:
663 * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
664 * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
667 __STATIC_INLINE
void LL_USART_SetLastClkPulseOutput(USART_TypeDef
*USARTx
, uint32_t LastBitClockPulse
)
669 MODIFY_REG(USARTx
->CR2
, USART_CR2_LBCL
, LastBitClockPulse
);
673 * @brief Retrieve Clock pulse of the last data bit output configuration
674 * (Last bit Clock pulse output to the SCLK pin or not)
675 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
676 * Synchronous mode is supported by the USARTx instance.
677 * @rmtoll CR2 LBCL LL_USART_GetLastClkPulseOutput
678 * @param USARTx USART Instance
679 * @retval Returned value can be one of the following values:
680 * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
681 * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
683 __STATIC_INLINE
uint32_t LL_USART_GetLastClkPulseOutput(USART_TypeDef
*USARTx
)
685 return (uint32_t)(READ_BIT(USARTx
->CR2
, USART_CR2_LBCL
));
689 * @brief Select the phase of the clock output on the SCLK pin in synchronous mode
690 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
691 * Synchronous mode is supported by the USARTx instance.
692 * @rmtoll CR2 CPHA LL_USART_SetClockPhase
693 * @param USARTx USART Instance
694 * @param ClockPhase This parameter can be one of the following values:
695 * @arg @ref LL_USART_PHASE_1EDGE
696 * @arg @ref LL_USART_PHASE_2EDGE
699 __STATIC_INLINE
void LL_USART_SetClockPhase(USART_TypeDef
*USARTx
, uint32_t ClockPhase
)
701 MODIFY_REG(USARTx
->CR2
, USART_CR2_CPHA
, ClockPhase
);
705 * @brief Return phase of the clock output on the SCLK pin in synchronous mode
706 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
707 * Synchronous mode is supported by the USARTx instance.
708 * @rmtoll CR2 CPHA LL_USART_GetClockPhase
709 * @param USARTx USART Instance
710 * @retval Returned value can be one of the following values:
711 * @arg @ref LL_USART_PHASE_1EDGE
712 * @arg @ref LL_USART_PHASE_2EDGE
714 __STATIC_INLINE
uint32_t LL_USART_GetClockPhase(USART_TypeDef
*USARTx
)
716 return (uint32_t)(READ_BIT(USARTx
->CR2
, USART_CR2_CPHA
));
720 * @brief Select the polarity of the clock output on the SCLK pin in synchronous mode
721 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
722 * Synchronous mode is supported by the USARTx instance.
723 * @rmtoll CR2 CPOL LL_USART_SetClockPolarity
724 * @param USARTx USART Instance
725 * @param ClockPolarity This parameter can be one of the following values:
726 * @arg @ref LL_USART_POLARITY_LOW
727 * @arg @ref LL_USART_POLARITY_HIGH
730 __STATIC_INLINE
void LL_USART_SetClockPolarity(USART_TypeDef
*USARTx
, uint32_t ClockPolarity
)
732 MODIFY_REG(USARTx
->CR2
, USART_CR2_CPOL
, ClockPolarity
);
736 * @brief Return polarity of the clock output on the SCLK pin in synchronous mode
737 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
738 * Synchronous mode is supported by the USARTx instance.
739 * @rmtoll CR2 CPOL LL_USART_GetClockPolarity
740 * @param USARTx USART Instance
741 * @retval Returned value can be one of the following values:
742 * @arg @ref LL_USART_POLARITY_LOW
743 * @arg @ref LL_USART_POLARITY_HIGH
745 __STATIC_INLINE
uint32_t LL_USART_GetClockPolarity(USART_TypeDef
*USARTx
)
747 return (uint32_t)(READ_BIT(USARTx
->CR2
, USART_CR2_CPOL
));
751 * @brief Configure Clock signal format (Phase Polarity and choice about output of last bit clock pulse)
752 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
753 * Synchronous mode is supported by the USARTx instance.
754 * @note Call of this function is equivalent to following function call sequence :
755 * - Clock Phase configuration using @ref LL_USART_SetClockPhase() function
756 * - Clock Polarity configuration using @ref LL_USART_SetClockPolarity() function
757 * - Output of Last bit Clock pulse configuration using @ref LL_USART_SetLastClkPulseOutput() function
758 * @rmtoll CR2 CPHA LL_USART_ConfigClock\n
759 * CR2 CPOL LL_USART_ConfigClock\n
760 * CR2 LBCL LL_USART_ConfigClock
761 * @param USARTx USART Instance
762 * @param Phase This parameter can be one of the following values:
763 * @arg @ref LL_USART_PHASE_1EDGE
764 * @arg @ref LL_USART_PHASE_2EDGE
765 * @param Polarity This parameter can be one of the following values:
766 * @arg @ref LL_USART_POLARITY_LOW
767 * @arg @ref LL_USART_POLARITY_HIGH
768 * @param LBCPOutput This parameter can be one of the following values:
769 * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
770 * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
773 __STATIC_INLINE
void LL_USART_ConfigClock(USART_TypeDef
*USARTx
, uint32_t Phase
, uint32_t Polarity
, uint32_t LBCPOutput
)
775 MODIFY_REG(USARTx
->CR2
, USART_CR2_CPHA
| USART_CR2_CPOL
| USART_CR2_LBCL
, Phase
| Polarity
| LBCPOutput
);
779 * @brief Enable Clock output on SCLK pin
780 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
781 * Synchronous mode is supported by the USARTx instance.
782 * @rmtoll CR2 CLKEN LL_USART_EnableSCLKOutput
783 * @param USARTx USART Instance
786 __STATIC_INLINE
void LL_USART_EnableSCLKOutput(USART_TypeDef
*USARTx
)
788 SET_BIT(USARTx
->CR2
, USART_CR2_CLKEN
);
792 * @brief Disable Clock output on SCLK pin
793 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
794 * Synchronous mode is supported by the USARTx instance.
795 * @rmtoll CR2 CLKEN LL_USART_DisableSCLKOutput
796 * @param USARTx USART Instance
799 __STATIC_INLINE
void LL_USART_DisableSCLKOutput(USART_TypeDef
*USARTx
)
801 CLEAR_BIT(USARTx
->CR2
, USART_CR2_CLKEN
);
805 * @brief Indicate if Clock output on SCLK pin is enabled
806 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
807 * Synchronous mode is supported by the USARTx instance.
808 * @rmtoll CR2 CLKEN LL_USART_IsEnabledSCLKOutput
809 * @param USARTx USART Instance
810 * @retval State of bit (1 or 0).
812 __STATIC_INLINE
uint32_t LL_USART_IsEnabledSCLKOutput(USART_TypeDef
*USARTx
)
814 return (READ_BIT(USARTx
->CR2
, USART_CR2_CLKEN
) == (USART_CR2_CLKEN
));
818 * @brief Set the length of the stop bits
819 * @rmtoll CR2 STOP LL_USART_SetStopBitsLength
820 * @param USARTx USART Instance
821 * @param StopBits This parameter can be one of the following values:
822 * @arg @ref LL_USART_STOPBITS_0_5
823 * @arg @ref LL_USART_STOPBITS_1
824 * @arg @ref LL_USART_STOPBITS_1_5
825 * @arg @ref LL_USART_STOPBITS_2
828 __STATIC_INLINE
void LL_USART_SetStopBitsLength(USART_TypeDef
*USARTx
, uint32_t StopBits
)
830 MODIFY_REG(USARTx
->CR2
, USART_CR2_STOP
, StopBits
);
834 * @brief Retrieve the length of the stop bits
835 * @rmtoll CR2 STOP LL_USART_GetStopBitsLength
836 * @param USARTx USART Instance
837 * @retval Returned value can be one of the following values:
838 * @arg @ref LL_USART_STOPBITS_0_5
839 * @arg @ref LL_USART_STOPBITS_1
840 * @arg @ref LL_USART_STOPBITS_1_5
841 * @arg @ref LL_USART_STOPBITS_2
843 __STATIC_INLINE
uint32_t LL_USART_GetStopBitsLength(USART_TypeDef
*USARTx
)
845 return (uint32_t)(READ_BIT(USARTx
->CR2
, USART_CR2_STOP
));
849 * @brief Configure Character frame format (Datawidth, Parity control, Stop Bits)
850 * @note Call of this function is equivalent to following function call sequence :
851 * - Data Width configuration using @ref LL_USART_SetDataWidth() function
852 * - Parity Control and mode configuration using @ref LL_USART_SetParity() function
853 * - Stop bits configuration using @ref LL_USART_SetStopBitsLength() function
854 * @rmtoll CR1 PS LL_USART_ConfigCharacter\n
855 * CR1 PCE LL_USART_ConfigCharacter\n
856 * CR1 M LL_USART_ConfigCharacter\n
857 * CR2 STOP LL_USART_ConfigCharacter
858 * @param USARTx USART Instance
859 * @param DataWidth This parameter can be one of the following values:
860 * @arg @ref LL_USART_DATAWIDTH_8B
861 * @arg @ref LL_USART_DATAWIDTH_9B
862 * @param Parity This parameter can be one of the following values:
863 * @arg @ref LL_USART_PARITY_NONE
864 * @arg @ref LL_USART_PARITY_EVEN
865 * @arg @ref LL_USART_PARITY_ODD
866 * @param StopBits This parameter can be one of the following values:
867 * @arg @ref LL_USART_STOPBITS_0_5
868 * @arg @ref LL_USART_STOPBITS_1
869 * @arg @ref LL_USART_STOPBITS_1_5
870 * @arg @ref LL_USART_STOPBITS_2
873 __STATIC_INLINE
void LL_USART_ConfigCharacter(USART_TypeDef
*USARTx
, uint32_t DataWidth
, uint32_t Parity
,
876 MODIFY_REG(USARTx
->CR1
, USART_CR1_PS
| USART_CR1_PCE
| USART_CR1_M
, Parity
| DataWidth
);
877 MODIFY_REG(USARTx
->CR2
, USART_CR2_STOP
, StopBits
);
881 * @brief Set Address of the USART node.
882 * @note This is used in multiprocessor communication during Mute mode or Stop mode,
883 * for wake up with address mark detection.
884 * @rmtoll CR2 ADD LL_USART_SetNodeAddress
885 * @param USARTx USART Instance
886 * @param NodeAddress 4 bit Address of the USART node.
889 __STATIC_INLINE
void LL_USART_SetNodeAddress(USART_TypeDef
*USARTx
, uint32_t NodeAddress
)
891 MODIFY_REG(USARTx
->CR2
, USART_CR2_ADD
, (NodeAddress
& USART_CR2_ADD
));
895 * @brief Return 4 bit Address of the USART node as set in ADD field of CR2.
896 * @note only 4bits (b3-b0) of returned value are relevant (b31-b4 are not relevant)
897 * @rmtoll CR2 ADD LL_USART_GetNodeAddress
898 * @param USARTx USART Instance
899 * @retval Address of the USART node (Value between Min_Data=0 and Max_Data=255)
901 __STATIC_INLINE
uint32_t LL_USART_GetNodeAddress(USART_TypeDef
*USARTx
)
903 return (uint32_t)(READ_BIT(USARTx
->CR2
, USART_CR2_ADD
));
907 * @brief Enable RTS HW Flow Control
908 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
909 * Hardware Flow control feature is supported by the USARTx instance.
910 * @rmtoll CR3 RTSE LL_USART_EnableRTSHWFlowCtrl
911 * @param USARTx USART Instance
914 __STATIC_INLINE
void LL_USART_EnableRTSHWFlowCtrl(USART_TypeDef
*USARTx
)
916 SET_BIT(USARTx
->CR3
, USART_CR3_RTSE
);
920 * @brief Disable RTS HW Flow Control
921 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
922 * Hardware Flow control feature is supported by the USARTx instance.
923 * @rmtoll CR3 RTSE LL_USART_DisableRTSHWFlowCtrl
924 * @param USARTx USART Instance
927 __STATIC_INLINE
void LL_USART_DisableRTSHWFlowCtrl(USART_TypeDef
*USARTx
)
929 CLEAR_BIT(USARTx
->CR3
, USART_CR3_RTSE
);
933 * @brief Enable CTS HW Flow Control
934 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
935 * Hardware Flow control feature is supported by the USARTx instance.
936 * @rmtoll CR3 CTSE LL_USART_EnableCTSHWFlowCtrl
937 * @param USARTx USART Instance
940 __STATIC_INLINE
void LL_USART_EnableCTSHWFlowCtrl(USART_TypeDef
*USARTx
)
942 SET_BIT(USARTx
->CR3
, USART_CR3_CTSE
);
946 * @brief Disable CTS HW Flow Control
947 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
948 * Hardware Flow control feature is supported by the USARTx instance.
949 * @rmtoll CR3 CTSE LL_USART_DisableCTSHWFlowCtrl
950 * @param USARTx USART Instance
953 __STATIC_INLINE
void LL_USART_DisableCTSHWFlowCtrl(USART_TypeDef
*USARTx
)
955 CLEAR_BIT(USARTx
->CR3
, USART_CR3_CTSE
);
959 * @brief Configure HW Flow Control mode (both CTS and RTS)
960 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
961 * Hardware Flow control feature is supported by the USARTx instance.
962 * @rmtoll CR3 RTSE LL_USART_SetHWFlowCtrl\n
963 * CR3 CTSE LL_USART_SetHWFlowCtrl
964 * @param USARTx USART Instance
965 * @param HardwareFlowControl This parameter can be one of the following values:
966 * @arg @ref LL_USART_HWCONTROL_NONE
967 * @arg @ref LL_USART_HWCONTROL_RTS
968 * @arg @ref LL_USART_HWCONTROL_CTS
969 * @arg @ref LL_USART_HWCONTROL_RTS_CTS
972 __STATIC_INLINE
void LL_USART_SetHWFlowCtrl(USART_TypeDef
*USARTx
, uint32_t HardwareFlowControl
)
974 MODIFY_REG(USARTx
->CR3
, USART_CR3_RTSE
| USART_CR3_CTSE
, HardwareFlowControl
);
978 * @brief Return HW Flow Control configuration (both CTS and RTS)
979 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
980 * Hardware Flow control feature is supported by the USARTx instance.
981 * @rmtoll CR3 RTSE LL_USART_GetHWFlowCtrl\n
982 * CR3 CTSE LL_USART_GetHWFlowCtrl
983 * @param USARTx USART Instance
984 * @retval Returned value can be one of the following values:
985 * @arg @ref LL_USART_HWCONTROL_NONE
986 * @arg @ref LL_USART_HWCONTROL_RTS
987 * @arg @ref LL_USART_HWCONTROL_CTS
988 * @arg @ref LL_USART_HWCONTROL_RTS_CTS
990 __STATIC_INLINE
uint32_t LL_USART_GetHWFlowCtrl(USART_TypeDef
*USARTx
)
992 return (uint32_t)(READ_BIT(USARTx
->CR3
, USART_CR3_RTSE
| USART_CR3_CTSE
));
995 #if defined(USART_CR3_ONEBIT)
997 * @brief Enable One bit sampling method
998 * @rmtoll CR3 ONEBIT LL_USART_EnableOneBitSamp
999 * @param USARTx USART Instance
1002 __STATIC_INLINE
void LL_USART_EnableOneBitSamp(USART_TypeDef
*USARTx
)
1004 SET_BIT(USARTx
->CR3
, USART_CR3_ONEBIT
);
1008 * @brief Disable One bit sampling method
1009 * @rmtoll CR3 ONEBIT LL_USART_DisableOneBitSamp
1010 * @param USARTx USART Instance
1013 __STATIC_INLINE
void LL_USART_DisableOneBitSamp(USART_TypeDef
*USARTx
)
1015 CLEAR_BIT(USARTx
->CR3
, USART_CR3_ONEBIT
);
1019 * @brief Indicate if One bit sampling method is enabled
1020 * @rmtoll CR3 ONEBIT LL_USART_IsEnabledOneBitSamp
1021 * @param USARTx USART Instance
1022 * @retval State of bit (1 or 0).
1024 __STATIC_INLINE
uint32_t LL_USART_IsEnabledOneBitSamp(USART_TypeDef
*USARTx
)
1026 return (READ_BIT(USARTx
->CR3
, USART_CR3_ONEBIT
) == (USART_CR3_ONEBIT
));
1028 #endif /* USART_OneBitSampling_Feature */
1030 #if defined(USART_CR1_OVER8)
1032 * @brief Configure USART BRR register for achieving expected Baud Rate value.
1033 * @note Compute and set USARTDIV value in BRR Register (full BRR content)
1034 * according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
1035 * @note Peripheral clock and Baud rate values provided as function parameters should be valid
1036 * (Baud rate value != 0)
1037 * @rmtoll BRR BRR LL_USART_SetBaudRate
1038 * @param USARTx USART Instance
1039 * @param PeriphClk Peripheral Clock
1040 * @param OverSampling This parameter can be one of the following values:
1041 * @arg @ref LL_USART_OVERSAMPLING_16
1042 * @arg @ref LL_USART_OVERSAMPLING_8
1043 * @param BaudRate Baud Rate
1046 __STATIC_INLINE
void LL_USART_SetBaudRate(USART_TypeDef
*USARTx
, uint32_t PeriphClk
, uint32_t OverSampling
,
1049 if (OverSampling
== LL_USART_OVERSAMPLING_8
)
1051 USARTx
->BRR
= (uint16_t)(__LL_USART_DIV_SAMPLING8(PeriphClk
, BaudRate
));
1055 USARTx
->BRR
= (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk
, BaudRate
));
1060 * @brief Return current Baud Rate value, according to USARTDIV present in BRR register
1061 * (full BRR content), and to used Peripheral Clock and Oversampling mode values
1062 * @note In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
1063 * @rmtoll BRR BRR LL_USART_GetBaudRate
1064 * @param USARTx USART Instance
1065 * @param PeriphClk Peripheral Clock
1066 * @param OverSampling This parameter can be one of the following values:
1067 * @arg @ref LL_USART_OVERSAMPLING_16
1068 * @arg @ref LL_USART_OVERSAMPLING_8
1071 __STATIC_INLINE
uint32_t LL_USART_GetBaudRate(USART_TypeDef
*USARTx
, uint32_t PeriphClk
, uint32_t OverSampling
)
1073 register uint32_t usartdiv
= 0x0U
;
1074 register uint32_t brrresult
= 0x0U
;
1076 usartdiv
= USARTx
->BRR
;
1078 if (OverSampling
== LL_USART_OVERSAMPLING_8
)
1080 if ((usartdiv
& 0xFFF7U
) != 0U)
1082 usartdiv
= (uint16_t)((usartdiv
& 0xFFF0U
) | ((usartdiv
& 0x0007U
) << 1U)) ;
1083 brrresult
= (PeriphClk
* 2U) / usartdiv
;
1088 if ((usartdiv
& 0xFFFFU
) != 0U)
1090 brrresult
= PeriphClk
/ usartdiv
;
1097 * @brief Configure USART BRR register for achieving expected Baud Rate value.
1098 * @note Compute and set USARTDIV value in BRR Register (full BRR content)
1099 * according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
1100 * @note Peripheral clock and Baud rate values provided as function parameters should be valid
1101 * (Baud rate value != 0)
1102 * @rmtoll BRR BRR LL_USART_SetBaudRate
1103 * @param USARTx USART Instance
1104 * @param PeriphClk Peripheral Clock
1105 * @param BaudRate Baud Rate
1108 __STATIC_INLINE
void LL_USART_SetBaudRate(USART_TypeDef
*USARTx
, uint32_t PeriphClk
, uint32_t BaudRate
)
1110 USARTx
->BRR
= (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk
, BaudRate
));
1114 * @brief Return current Baud Rate value, according to USARTDIV present in BRR register
1115 * (full BRR content), and to used Peripheral Clock and Oversampling mode values
1116 * @note In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
1117 * @rmtoll BRR BRR LL_USART_GetBaudRate
1118 * @param USARTx USART Instance
1119 * @param PeriphClk Peripheral Clock
1122 __STATIC_INLINE
uint32_t LL_USART_GetBaudRate(USART_TypeDef
*USARTx
, uint32_t PeriphClk
)
1124 register uint32_t usartdiv
= 0x0U
;
1125 register uint32_t brrresult
= 0x0U
;
1127 usartdiv
= USARTx
->BRR
;
1129 if ((usartdiv
& 0xFFFFU
) != 0U)
1131 brrresult
= PeriphClk
/ usartdiv
;
1135 #endif /* USART_OverSampling_Feature */
1141 /** @defgroup USART_LL_EF_Configuration_IRDA Configuration functions related to Irda feature
1146 * @brief Enable IrDA mode
1147 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1148 * IrDA feature is supported by the USARTx instance.
1149 * @rmtoll CR3 IREN LL_USART_EnableIrda
1150 * @param USARTx USART Instance
1153 __STATIC_INLINE
void LL_USART_EnableIrda(USART_TypeDef
*USARTx
)
1155 SET_BIT(USARTx
->CR3
, USART_CR3_IREN
);
1159 * @brief Disable IrDA mode
1160 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1161 * IrDA feature is supported by the USARTx instance.
1162 * @rmtoll CR3 IREN LL_USART_DisableIrda
1163 * @param USARTx USART Instance
1166 __STATIC_INLINE
void LL_USART_DisableIrda(USART_TypeDef
*USARTx
)
1168 CLEAR_BIT(USARTx
->CR3
, USART_CR3_IREN
);
1172 * @brief Indicate if IrDA mode is enabled
1173 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1174 * IrDA feature is supported by the USARTx instance.
1175 * @rmtoll CR3 IREN LL_USART_IsEnabledIrda
1176 * @param USARTx USART Instance
1177 * @retval State of bit (1 or 0).
1179 __STATIC_INLINE
uint32_t LL_USART_IsEnabledIrda(USART_TypeDef
*USARTx
)
1181 return (READ_BIT(USARTx
->CR3
, USART_CR3_IREN
) == (USART_CR3_IREN
));
1185 * @brief Configure IrDA Power Mode (Normal or Low Power)
1186 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1187 * IrDA feature is supported by the USARTx instance.
1188 * @rmtoll CR3 IRLP LL_USART_SetIrdaPowerMode
1189 * @param USARTx USART Instance
1190 * @param PowerMode This parameter can be one of the following values:
1191 * @arg @ref LL_USART_IRDA_POWER_NORMAL
1192 * @arg @ref LL_USART_IRDA_POWER_LOW
1195 __STATIC_INLINE
void LL_USART_SetIrdaPowerMode(USART_TypeDef
*USARTx
, uint32_t PowerMode
)
1197 MODIFY_REG(USARTx
->CR3
, USART_CR3_IRLP
, PowerMode
);
1201 * @brief Retrieve IrDA Power Mode configuration (Normal or Low Power)
1202 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1203 * IrDA feature is supported by the USARTx instance.
1204 * @rmtoll CR3 IRLP LL_USART_GetIrdaPowerMode
1205 * @param USARTx USART Instance
1206 * @retval Returned value can be one of the following values:
1207 * @arg @ref LL_USART_IRDA_POWER_NORMAL
1208 * @arg @ref LL_USART_PHASE_2EDGE
1210 __STATIC_INLINE
uint32_t LL_USART_GetIrdaPowerMode(USART_TypeDef
*USARTx
)
1212 return (uint32_t)(READ_BIT(USARTx
->CR3
, USART_CR3_IRLP
));
1216 * @brief Set Irda prescaler value, used for dividing the USART clock source
1217 * to achieve the Irda Low Power frequency (8 bits value)
1218 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1219 * IrDA feature is supported by the USARTx instance.
1220 * @rmtoll GTPR PSC LL_USART_SetIrdaPrescaler
1221 * @param USARTx USART Instance
1222 * @param PrescalerValue Value between Min_Data=0x00 and Max_Data=0xFF
1225 __STATIC_INLINE
void LL_USART_SetIrdaPrescaler(USART_TypeDef
*USARTx
, uint32_t PrescalerValue
)
1227 MODIFY_REG(USARTx
->GTPR
, USART_GTPR_PSC
, PrescalerValue
);
1231 * @brief Return Irda prescaler value, used for dividing the USART clock source
1232 * to achieve the Irda Low Power frequency (8 bits value)
1233 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1234 * IrDA feature is supported by the USARTx instance.
1235 * @rmtoll GTPR PSC LL_USART_GetIrdaPrescaler
1236 * @param USARTx USART Instance
1237 * @retval Irda prescaler value (Value between Min_Data=0x00 and Max_Data=0xFF)
1239 __STATIC_INLINE
uint32_t LL_USART_GetIrdaPrescaler(USART_TypeDef
*USARTx
)
1241 return (uint32_t)(READ_BIT(USARTx
->GTPR
, USART_GTPR_PSC
));
1248 /** @defgroup USART_LL_EF_Configuration_Smartcard Configuration functions related to Smartcard feature
1253 * @brief Enable Smartcard NACK transmission
1254 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1255 * Smartcard feature is supported by the USARTx instance.
1256 * @rmtoll CR3 NACK LL_USART_EnableSmartcardNACK
1257 * @param USARTx USART Instance
1260 __STATIC_INLINE
void LL_USART_EnableSmartcardNACK(USART_TypeDef
*USARTx
)
1262 SET_BIT(USARTx
->CR3
, USART_CR3_NACK
);
1266 * @brief Disable Smartcard NACK transmission
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 CR3 NACK LL_USART_DisableSmartcardNACK
1270 * @param USARTx USART Instance
1273 __STATIC_INLINE
void LL_USART_DisableSmartcardNACK(USART_TypeDef
*USARTx
)
1275 CLEAR_BIT(USARTx
->CR3
, USART_CR3_NACK
);
1279 * @brief Indicate if Smartcard NACK transmission is enabled
1280 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1281 * Smartcard feature is supported by the USARTx instance.
1282 * @rmtoll CR3 NACK LL_USART_IsEnabledSmartcardNACK
1283 * @param USARTx USART Instance
1284 * @retval State of bit (1 or 0).
1286 __STATIC_INLINE
uint32_t LL_USART_IsEnabledSmartcardNACK(USART_TypeDef
*USARTx
)
1288 return (READ_BIT(USARTx
->CR3
, USART_CR3_NACK
) == (USART_CR3_NACK
));
1292 * @brief Enable Smartcard mode
1293 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1294 * Smartcard feature is supported by the USARTx instance.
1295 * @rmtoll CR3 SCEN LL_USART_EnableSmartcard
1296 * @param USARTx USART Instance
1299 __STATIC_INLINE
void LL_USART_EnableSmartcard(USART_TypeDef
*USARTx
)
1301 SET_BIT(USARTx
->CR3
, USART_CR3_SCEN
);
1305 * @brief Disable Smartcard mode
1306 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1307 * Smartcard feature is supported by the USARTx instance.
1308 * @rmtoll CR3 SCEN LL_USART_DisableSmartcard
1309 * @param USARTx USART Instance
1312 __STATIC_INLINE
void LL_USART_DisableSmartcard(USART_TypeDef
*USARTx
)
1314 CLEAR_BIT(USARTx
->CR3
, USART_CR3_SCEN
);
1318 * @brief Indicate if Smartcard mode is enabled
1319 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1320 * Smartcard feature is supported by the USARTx instance.
1321 * @rmtoll CR3 SCEN LL_USART_IsEnabledSmartcard
1322 * @param USARTx USART Instance
1323 * @retval State of bit (1 or 0).
1325 __STATIC_INLINE
uint32_t LL_USART_IsEnabledSmartcard(USART_TypeDef
*USARTx
)
1327 return (READ_BIT(USARTx
->CR3
, USART_CR3_SCEN
) == (USART_CR3_SCEN
));
1331 * @brief Set Smartcard prescaler value, used for dividing the USART clock
1332 * source to provide the SMARTCARD Clock (5 bits value)
1333 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1334 * Smartcard feature is supported by the USARTx instance.
1335 * @rmtoll GTPR PSC LL_USART_SetSmartcardPrescaler
1336 * @param USARTx USART Instance
1337 * @param PrescalerValue Value between Min_Data=0 and Max_Data=31
1340 __STATIC_INLINE
void LL_USART_SetSmartcardPrescaler(USART_TypeDef
*USARTx
, uint32_t PrescalerValue
)
1342 MODIFY_REG(USARTx
->GTPR
, USART_GTPR_PSC
, PrescalerValue
);
1346 * @brief Return Smartcard prescaler value, used for dividing the USART clock
1347 * source to provide the SMARTCARD Clock (5 bits value)
1348 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1349 * Smartcard feature is supported by the USARTx instance.
1350 * @rmtoll GTPR PSC LL_USART_GetSmartcardPrescaler
1351 * @param USARTx USART Instance
1352 * @retval Smartcard prescaler value (Value between Min_Data=0 and Max_Data=31)
1354 __STATIC_INLINE
uint32_t LL_USART_GetSmartcardPrescaler(USART_TypeDef
*USARTx
)
1356 return (uint32_t)(READ_BIT(USARTx
->GTPR
, USART_GTPR_PSC
));
1360 * @brief Set Smartcard Guard time value, expressed in nb of baud clocks periods
1361 * (GT[7:0] bits : Guard time value)
1362 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1363 * Smartcard feature is supported by the USARTx instance.
1364 * @rmtoll GTPR GT LL_USART_SetSmartcardGuardTime
1365 * @param USARTx USART Instance
1366 * @param GuardTime Value between Min_Data=0x00 and Max_Data=0xFF
1369 __STATIC_INLINE
void LL_USART_SetSmartcardGuardTime(USART_TypeDef
*USARTx
, uint32_t GuardTime
)
1371 MODIFY_REG(USARTx
->GTPR
, USART_GTPR_GT
, GuardTime
<< USART_POSITION_GTPR_GT
);
1375 * @brief Return Smartcard Guard time value, expressed in nb of baud clocks periods
1376 * (GT[7:0] bits : Guard time value)
1377 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1378 * Smartcard feature is supported by the USARTx instance.
1379 * @rmtoll GTPR GT LL_USART_GetSmartcardGuardTime
1380 * @param USARTx USART Instance
1381 * @retval Smartcard Guard time value (Value between Min_Data=0x00 and Max_Data=0xFF)
1383 __STATIC_INLINE
uint32_t LL_USART_GetSmartcardGuardTime(USART_TypeDef
*USARTx
)
1385 return (uint32_t)(READ_BIT(USARTx
->GTPR
, USART_GTPR_GT
) >> USART_POSITION_GTPR_GT
);
1392 /** @defgroup USART_LL_EF_Configuration_HalfDuplex Configuration functions related to Half Duplex feature
1397 * @brief Enable Single Wire Half-Duplex mode
1398 * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
1399 * Half-Duplex mode is supported by the USARTx instance.
1400 * @rmtoll CR3 HDSEL LL_USART_EnableHalfDuplex
1401 * @param USARTx USART Instance
1404 __STATIC_INLINE
void LL_USART_EnableHalfDuplex(USART_TypeDef
*USARTx
)
1406 SET_BIT(USARTx
->CR3
, USART_CR3_HDSEL
);
1410 * @brief Disable Single Wire Half-Duplex mode
1411 * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
1412 * Half-Duplex mode is supported by the USARTx instance.
1413 * @rmtoll CR3 HDSEL LL_USART_DisableHalfDuplex
1414 * @param USARTx USART Instance
1417 __STATIC_INLINE
void LL_USART_DisableHalfDuplex(USART_TypeDef
*USARTx
)
1419 CLEAR_BIT(USARTx
->CR3
, USART_CR3_HDSEL
);
1423 * @brief Indicate if Single Wire Half-Duplex mode is enabled
1424 * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
1425 * Half-Duplex mode is supported by the USARTx instance.
1426 * @rmtoll CR3 HDSEL LL_USART_IsEnabledHalfDuplex
1427 * @param USARTx USART Instance
1428 * @retval State of bit (1 or 0).
1430 __STATIC_INLINE
uint32_t LL_USART_IsEnabledHalfDuplex(USART_TypeDef
*USARTx
)
1432 return (READ_BIT(USARTx
->CR3
, USART_CR3_HDSEL
) == (USART_CR3_HDSEL
));
1439 /** @defgroup USART_LL_EF_Configuration_LIN Configuration functions related to LIN feature
1444 * @brief Set LIN Break Detection Length
1445 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1446 * LIN feature is supported by the USARTx instance.
1447 * @rmtoll CR2 LBDL LL_USART_SetLINBrkDetectionLen
1448 * @param USARTx USART Instance
1449 * @param LINBDLength This parameter can be one of the following values:
1450 * @arg @ref LL_USART_LINBREAK_DETECT_10B
1451 * @arg @ref LL_USART_LINBREAK_DETECT_11B
1454 __STATIC_INLINE
void LL_USART_SetLINBrkDetectionLen(USART_TypeDef
*USARTx
, uint32_t LINBDLength
)
1456 MODIFY_REG(USARTx
->CR2
, USART_CR2_LBDL
, LINBDLength
);
1460 * @brief Return LIN Break Detection Length
1461 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1462 * LIN feature is supported by the USARTx instance.
1463 * @rmtoll CR2 LBDL LL_USART_GetLINBrkDetectionLen
1464 * @param USARTx USART Instance
1465 * @retval Returned value can be one of the following values:
1466 * @arg @ref LL_USART_LINBREAK_DETECT_10B
1467 * @arg @ref LL_USART_LINBREAK_DETECT_11B
1469 __STATIC_INLINE
uint32_t LL_USART_GetLINBrkDetectionLen(USART_TypeDef
*USARTx
)
1471 return (uint32_t)(READ_BIT(USARTx
->CR2
, USART_CR2_LBDL
));
1475 * @brief Enable LIN mode
1476 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1477 * LIN feature is supported by the USARTx instance.
1478 * @rmtoll CR2 LINEN LL_USART_EnableLIN
1479 * @param USARTx USART Instance
1482 __STATIC_INLINE
void LL_USART_EnableLIN(USART_TypeDef
*USARTx
)
1484 SET_BIT(USARTx
->CR2
, USART_CR2_LINEN
);
1488 * @brief Disable LIN mode
1489 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1490 * LIN feature is supported by the USARTx instance.
1491 * @rmtoll CR2 LINEN LL_USART_DisableLIN
1492 * @param USARTx USART Instance
1495 __STATIC_INLINE
void LL_USART_DisableLIN(USART_TypeDef
*USARTx
)
1497 CLEAR_BIT(USARTx
->CR2
, USART_CR2_LINEN
);
1501 * @brief Indicate if LIN mode is enabled
1502 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1503 * LIN feature is supported by the USARTx instance.
1504 * @rmtoll CR2 LINEN LL_USART_IsEnabledLIN
1505 * @param USARTx USART Instance
1506 * @retval State of bit (1 or 0).
1508 __STATIC_INLINE
uint32_t LL_USART_IsEnabledLIN(USART_TypeDef
*USARTx
)
1510 return (READ_BIT(USARTx
->CR2
, USART_CR2_LINEN
) == (USART_CR2_LINEN
));
1517 /** @defgroup USART_LL_EF_AdvancedConfiguration Advanced Configurations services
1522 * @brief Perform basic configuration of USART for enabling use in Asynchronous Mode (UART)
1523 * @note In UART mode, the following bits must be kept cleared:
1524 * - LINEN bit in the USART_CR2 register,
1525 * - CLKEN bit in the USART_CR2 register,
1526 * - SCEN bit in the USART_CR3 register,
1527 * - IREN bit in the USART_CR3 register,
1528 * - HDSEL bit in the USART_CR3 register.
1529 * @note Call of this function is equivalent to following function call sequence :
1530 * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1531 * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1532 * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1533 * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1534 * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1535 * @note Other remaining configurations items related to Asynchronous Mode
1536 * (as Baud Rate, Word length, Parity, ...) should be set using
1537 * dedicated functions
1538 * @rmtoll CR2 LINEN LL_USART_ConfigAsyncMode\n
1539 * CR2 CLKEN LL_USART_ConfigAsyncMode\n
1540 * CR3 SCEN LL_USART_ConfigAsyncMode\n
1541 * CR3 IREN LL_USART_ConfigAsyncMode\n
1542 * CR3 HDSEL LL_USART_ConfigAsyncMode
1543 * @param USARTx USART Instance
1546 __STATIC_INLINE
void LL_USART_ConfigAsyncMode(USART_TypeDef
*USARTx
)
1548 /* In Asynchronous mode, the following bits must be kept cleared:
1549 - LINEN, CLKEN bits in the USART_CR2 register,
1550 - SCEN, IREN and HDSEL bits in the USART_CR3 register.*/
1551 CLEAR_BIT(USARTx
->CR2
, (USART_CR2_LINEN
| USART_CR2_CLKEN
));
1552 CLEAR_BIT(USARTx
->CR3
, (USART_CR3_SCEN
| USART_CR3_IREN
| USART_CR3_HDSEL
));
1556 * @brief Perform basic configuration of USART for enabling use in Synchronous Mode
1557 * @note In Synchronous mode, the following bits must be kept cleared:
1558 * - LINEN bit in the USART_CR2 register,
1559 * - SCEN bit in the USART_CR3 register,
1560 * - IREN bit in the USART_CR3 register,
1561 * - HDSEL bit in the USART_CR3 register.
1562 * This function also sets the USART in Synchronous mode.
1563 * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
1564 * Synchronous mode is supported by the USARTx instance.
1565 * @note Call of this function is equivalent to following function call sequence :
1566 * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1567 * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1568 * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1569 * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1570 * - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
1571 * @note Other remaining configurations items related to Synchronous Mode
1572 * (as Baud Rate, Word length, Parity, Clock Polarity, ...) should be set using
1573 * dedicated functions
1574 * @rmtoll CR2 LINEN LL_USART_ConfigSyncMode\n
1575 * CR2 CLKEN LL_USART_ConfigSyncMode\n
1576 * CR3 SCEN LL_USART_ConfigSyncMode\n
1577 * CR3 IREN LL_USART_ConfigSyncMode\n
1578 * CR3 HDSEL LL_USART_ConfigSyncMode
1579 * @param USARTx USART Instance
1582 __STATIC_INLINE
void LL_USART_ConfigSyncMode(USART_TypeDef
*USARTx
)
1584 /* In Synchronous mode, the following bits must be kept cleared:
1585 - LINEN bit in the USART_CR2 register,
1586 - SCEN, IREN and HDSEL bits in the USART_CR3 register.*/
1587 CLEAR_BIT(USARTx
->CR2
, (USART_CR2_LINEN
));
1588 CLEAR_BIT(USARTx
->CR3
, (USART_CR3_SCEN
| USART_CR3_IREN
| USART_CR3_HDSEL
));
1589 /* set the UART/USART in Synchronous mode */
1590 SET_BIT(USARTx
->CR2
, USART_CR2_CLKEN
);
1594 * @brief Perform basic configuration of USART for enabling use in LIN Mode
1595 * @note In LIN mode, the following bits must be kept cleared:
1596 * - STOP and CLKEN bits in the USART_CR2 register,
1597 * - SCEN bit in the USART_CR3 register,
1598 * - IREN bit in the USART_CR3 register,
1599 * - HDSEL bit in the USART_CR3 register.
1600 * This function also set the UART/USART in LIN mode.
1601 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1602 * LIN feature is supported by the USARTx instance.
1603 * @note Call of this function is equivalent to following function call sequence :
1604 * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1605 * - Clear STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
1606 * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1607 * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1608 * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1609 * - Set LINEN in CR2 using @ref LL_USART_EnableLIN() function
1610 * @note Other remaining configurations items related to LIN Mode
1611 * (as Baud Rate, Word length, LIN Break Detection Length, ...) should be set using
1612 * dedicated functions
1613 * @rmtoll CR2 CLKEN LL_USART_ConfigLINMode\n
1614 * CR2 STOP LL_USART_ConfigLINMode\n
1615 * CR2 LINEN LL_USART_ConfigLINMode\n
1616 * CR3 IREN LL_USART_ConfigLINMode\n
1617 * CR3 SCEN LL_USART_ConfigLINMode\n
1618 * CR3 HDSEL LL_USART_ConfigLINMode
1619 * @param USARTx USART Instance
1622 __STATIC_INLINE
void LL_USART_ConfigLINMode(USART_TypeDef
*USARTx
)
1624 /* In LIN mode, the following bits must be kept cleared:
1625 - STOP and CLKEN bits in the USART_CR2 register,
1626 - IREN, SCEN and HDSEL bits in the USART_CR3 register.*/
1627 CLEAR_BIT(USARTx
->CR2
, (USART_CR2_CLKEN
| USART_CR2_STOP
));
1628 CLEAR_BIT(USARTx
->CR3
, (USART_CR3_IREN
| USART_CR3_SCEN
| USART_CR3_HDSEL
));
1629 /* Set the UART/USART in LIN mode */
1630 SET_BIT(USARTx
->CR2
, USART_CR2_LINEN
);
1634 * @brief Perform basic configuration of USART for enabling use in Half Duplex Mode
1635 * @note In Half Duplex mode, the following bits must be kept cleared:
1636 * - LINEN bit in the USART_CR2 register,
1637 * - CLKEN bit in the USART_CR2 register,
1638 * - SCEN bit in the USART_CR3 register,
1639 * - IREN bit in the USART_CR3 register,
1640 * This function also sets the UART/USART in Half Duplex mode.
1641 * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
1642 * Half-Duplex mode is supported by the USARTx instance.
1643 * @note Call of this function is equivalent to following function call sequence :
1644 * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1645 * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1646 * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1647 * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1648 * - Set HDSEL in CR3 using @ref LL_USART_EnableHalfDuplex() function
1649 * @note Other remaining configurations items related to Half Duplex Mode
1650 * (as Baud Rate, Word length, Parity, ...) should be set using
1651 * dedicated functions
1652 * @rmtoll CR2 LINEN LL_USART_ConfigHalfDuplexMode\n
1653 * CR2 CLKEN LL_USART_ConfigHalfDuplexMode\n
1654 * CR3 HDSEL LL_USART_ConfigHalfDuplexMode\n
1655 * CR3 SCEN LL_USART_ConfigHalfDuplexMode\n
1656 * CR3 IREN LL_USART_ConfigHalfDuplexMode
1657 * @param USARTx USART Instance
1660 __STATIC_INLINE
void LL_USART_ConfigHalfDuplexMode(USART_TypeDef
*USARTx
)
1662 /* In Half Duplex mode, the following bits must be kept cleared:
1663 - LINEN and CLKEN bits in the USART_CR2 register,
1664 - SCEN and IREN bits in the USART_CR3 register.*/
1665 CLEAR_BIT(USARTx
->CR2
, (USART_CR2_LINEN
| USART_CR2_CLKEN
));
1666 CLEAR_BIT(USARTx
->CR3
, (USART_CR3_SCEN
| USART_CR3_IREN
));
1667 /* set the UART/USART in Half Duplex mode */
1668 SET_BIT(USARTx
->CR3
, USART_CR3_HDSEL
);
1672 * @brief Perform basic configuration of USART for enabling use in Smartcard Mode
1673 * @note In Smartcard mode, the following bits must be kept cleared:
1674 * - LINEN bit in the USART_CR2 register,
1675 * - IREN bit in the USART_CR3 register,
1676 * - HDSEL bit in the USART_CR3 register.
1677 * This function also configures Stop bits to 1.5 bits and
1678 * sets the USART in Smartcard mode (SCEN bit).
1679 * Clock Output is also enabled (CLKEN).
1680 * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1681 * Smartcard feature is supported by the USARTx instance.
1682 * @note Call of this function is equivalent to following function call sequence :
1683 * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1684 * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1685 * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1686 * - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
1687 * - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
1688 * - Set SCEN in CR3 using @ref LL_USART_EnableSmartcard() function
1689 * @note Other remaining configurations items related to Smartcard Mode
1690 * (as Baud Rate, Word length, Parity, ...) should be set using
1691 * dedicated functions
1692 * @rmtoll CR2 LINEN LL_USART_ConfigSmartcardMode\n
1693 * CR2 STOP LL_USART_ConfigSmartcardMode\n
1694 * CR2 CLKEN LL_USART_ConfigSmartcardMode\n
1695 * CR3 HDSEL LL_USART_ConfigSmartcardMode\n
1696 * CR3 SCEN LL_USART_ConfigSmartcardMode
1697 * @param USARTx USART Instance
1700 __STATIC_INLINE
void LL_USART_ConfigSmartcardMode(USART_TypeDef
*USARTx
)
1702 /* In Smartcard mode, the following bits must be kept cleared:
1703 - LINEN bit in the USART_CR2 register,
1704 - IREN and HDSEL bits in the USART_CR3 register.*/
1705 CLEAR_BIT(USARTx
->CR2
, (USART_CR2_LINEN
));
1706 CLEAR_BIT(USARTx
->CR3
, (USART_CR3_IREN
| USART_CR3_HDSEL
));
1707 /* Configure Stop bits to 1.5 bits */
1708 /* Synchronous mode is activated by default */
1709 SET_BIT(USARTx
->CR2
, (USART_CR2_STOP_0
| USART_CR2_STOP_1
| USART_CR2_CLKEN
));
1710 /* set the UART/USART in Smartcard mode */
1711 SET_BIT(USARTx
->CR3
, USART_CR3_SCEN
);
1715 * @brief Perform basic configuration of USART for enabling use in Irda Mode
1716 * @note In IRDA mode, the following bits must be kept cleared:
1717 * - LINEN bit in the USART_CR2 register,
1718 * - STOP and CLKEN bits in the USART_CR2 register,
1719 * - SCEN bit in the USART_CR3 register,
1720 * - HDSEL bit in the USART_CR3 register.
1721 * This function also sets the UART/USART in IRDA mode (IREN bit).
1722 * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1723 * IrDA feature is supported by the USARTx instance.
1724 * @note Call of this function is equivalent to following function call sequence :
1725 * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1726 * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1727 * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1728 * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1729 * - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
1730 * - Set IREN in CR3 using @ref LL_USART_EnableIrda() function
1731 * @note Other remaining configurations items related to Irda Mode
1732 * (as Baud Rate, Word length, Power mode, ...) should be set using
1733 * dedicated functions
1734 * @rmtoll CR2 LINEN LL_USART_ConfigIrdaMode\n
1735 * CR2 CLKEN LL_USART_ConfigIrdaMode\n
1736 * CR2 STOP LL_USART_ConfigIrdaMode\n
1737 * CR3 SCEN LL_USART_ConfigIrdaMode\n
1738 * CR3 HDSEL LL_USART_ConfigIrdaMode\n
1739 * CR3 IREN LL_USART_ConfigIrdaMode
1740 * @param USARTx USART Instance
1743 __STATIC_INLINE
void LL_USART_ConfigIrdaMode(USART_TypeDef
*USARTx
)
1745 /* In IRDA mode, the following bits must be kept cleared:
1746 - LINEN, STOP and CLKEN bits in the USART_CR2 register,
1747 - SCEN and HDSEL bits in the USART_CR3 register.*/
1748 CLEAR_BIT(USARTx
->CR2
, (USART_CR2_LINEN
| USART_CR2_CLKEN
| USART_CR2_STOP
));
1749 CLEAR_BIT(USARTx
->CR3
, (USART_CR3_SCEN
| USART_CR3_HDSEL
));
1750 /* set the UART/USART in IRDA mode */
1751 SET_BIT(USARTx
->CR3
, USART_CR3_IREN
);
1755 * @brief Perform basic configuration of USART for enabling use in Multi processor Mode
1756 * (several USARTs connected in a network, one of the USARTs can be the master,
1757 * its TX output connected to the RX inputs of the other slaves USARTs).
1758 * @note In MultiProcessor mode, the following bits must be kept cleared:
1759 * - LINEN bit in the USART_CR2 register,
1760 * - CLKEN bit in the USART_CR2 register,
1761 * - SCEN bit in the USART_CR3 register,
1762 * - IREN bit in the USART_CR3 register,
1763 * - HDSEL bit in the USART_CR3 register.
1764 * @note Call of this function is equivalent to following function call sequence :
1765 * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1766 * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1767 * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1768 * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1769 * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1770 * @note Other remaining configurations items related to Multi processor Mode
1771 * (as Baud Rate, Wake Up Method, Node address, ...) should be set using
1772 * dedicated functions
1773 * @rmtoll CR2 LINEN LL_USART_ConfigMultiProcessMode\n
1774 * CR2 CLKEN LL_USART_ConfigMultiProcessMode\n
1775 * CR3 SCEN LL_USART_ConfigMultiProcessMode\n
1776 * CR3 HDSEL LL_USART_ConfigMultiProcessMode\n
1777 * CR3 IREN LL_USART_ConfigMultiProcessMode
1778 * @param USARTx USART Instance
1781 __STATIC_INLINE
void LL_USART_ConfigMultiProcessMode(USART_TypeDef
*USARTx
)
1783 /* In Multi Processor mode, the following bits must be kept cleared:
1784 - LINEN and CLKEN bits in the USART_CR2 register,
1785 - IREN, SCEN and HDSEL bits in the USART_CR3 register.*/
1786 CLEAR_BIT(USARTx
->CR2
, (USART_CR2_LINEN
| USART_CR2_CLKEN
));
1787 CLEAR_BIT(USARTx
->CR3
, (USART_CR3_SCEN
| USART_CR3_HDSEL
| USART_CR3_IREN
));
1794 /** @defgroup USART_LL_EF_FLAG_Management FLAG_Management
1799 * @brief Check if the USART Parity Error Flag is set or not
1800 * @rmtoll SR PE LL_USART_IsActiveFlag_PE
1801 * @param USARTx USART Instance
1802 * @retval State of bit (1 or 0).
1804 __STATIC_INLINE
uint32_t LL_USART_IsActiveFlag_PE(USART_TypeDef
*USARTx
)
1806 return (READ_BIT(USARTx
->SR
, USART_SR_PE
) == (USART_SR_PE
));
1810 * @brief Check if the USART Framing Error Flag is set or not
1811 * @rmtoll SR FE LL_USART_IsActiveFlag_FE
1812 * @param USARTx USART Instance
1813 * @retval State of bit (1 or 0).
1815 __STATIC_INLINE
uint32_t LL_USART_IsActiveFlag_FE(USART_TypeDef
*USARTx
)
1817 return (READ_BIT(USARTx
->SR
, USART_SR_FE
) == (USART_SR_FE
));
1821 * @brief Check if the USART Noise error detected Flag is set or not
1822 * @rmtoll SR NF LL_USART_IsActiveFlag_NE
1823 * @param USARTx USART Instance
1824 * @retval State of bit (1 or 0).
1826 __STATIC_INLINE
uint32_t LL_USART_IsActiveFlag_NE(USART_TypeDef
*USARTx
)
1828 return (READ_BIT(USARTx
->SR
, USART_SR_NE
) == (USART_SR_NE
));
1832 * @brief Check if the USART OverRun Error Flag is set or not
1833 * @rmtoll SR ORE LL_USART_IsActiveFlag_ORE
1834 * @param USARTx USART Instance
1835 * @retval State of bit (1 or 0).
1837 __STATIC_INLINE
uint32_t LL_USART_IsActiveFlag_ORE(USART_TypeDef
*USARTx
)
1839 return (READ_BIT(USARTx
->SR
, USART_SR_ORE
) == (USART_SR_ORE
));
1843 * @brief Check if the USART IDLE line detected Flag is set or not
1844 * @rmtoll SR IDLE LL_USART_IsActiveFlag_IDLE
1845 * @param USARTx USART Instance
1846 * @retval State of bit (1 or 0).
1848 __STATIC_INLINE
uint32_t LL_USART_IsActiveFlag_IDLE(USART_TypeDef
*USARTx
)
1850 return (READ_BIT(USARTx
->SR
, USART_SR_IDLE
) == (USART_SR_IDLE
));
1854 * @brief Check if the USART Read Data Register Not Empty Flag is set or not
1855 * @rmtoll SR RXNE LL_USART_IsActiveFlag_RXNE
1856 * @param USARTx USART Instance
1857 * @retval State of bit (1 or 0).
1859 __STATIC_INLINE
uint32_t LL_USART_IsActiveFlag_RXNE(USART_TypeDef
*USARTx
)
1861 return (READ_BIT(USARTx
->SR
, USART_SR_RXNE
) == (USART_SR_RXNE
));
1865 * @brief Check if the USART Transmission Complete Flag is set or not
1866 * @rmtoll SR TC LL_USART_IsActiveFlag_TC
1867 * @param USARTx USART Instance
1868 * @retval State of bit (1 or 0).
1870 __STATIC_INLINE
uint32_t LL_USART_IsActiveFlag_TC(USART_TypeDef
*USARTx
)
1872 return (READ_BIT(USARTx
->SR
, USART_SR_TC
) == (USART_SR_TC
));
1876 * @brief Check if the USART Transmit Data Register Empty Flag is set or not
1877 * @rmtoll SR TXE LL_USART_IsActiveFlag_TXE
1878 * @param USARTx USART Instance
1879 * @retval State of bit (1 or 0).
1881 __STATIC_INLINE
uint32_t LL_USART_IsActiveFlag_TXE(USART_TypeDef
*USARTx
)
1883 return (READ_BIT(USARTx
->SR
, USART_SR_TXE
) == (USART_SR_TXE
));
1887 * @brief Check if the USART LIN Break Detection Flag is set or not
1888 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1889 * LIN feature is supported by the USARTx instance.
1890 * @rmtoll SR LBD LL_USART_IsActiveFlag_LBD
1891 * @param USARTx USART Instance
1892 * @retval State of bit (1 or 0).
1894 __STATIC_INLINE
uint32_t LL_USART_IsActiveFlag_LBD(USART_TypeDef
*USARTx
)
1896 return (READ_BIT(USARTx
->SR
, USART_SR_LBD
) == (USART_SR_LBD
));
1900 * @brief Check if the USART CTS Flag is set or not
1901 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
1902 * Hardware Flow control feature is supported by the USARTx instance.
1903 * @rmtoll SR CTS LL_USART_IsActiveFlag_nCTS
1904 * @param USARTx USART Instance
1905 * @retval State of bit (1 or 0).
1907 __STATIC_INLINE
uint32_t LL_USART_IsActiveFlag_nCTS(USART_TypeDef
*USARTx
)
1909 return (READ_BIT(USARTx
->SR
, USART_SR_CTS
) == (USART_SR_CTS
));
1913 * @brief Check if the USART Send Break Flag is set or not
1914 * @rmtoll CR1 SBK LL_USART_IsActiveFlag_SBK
1915 * @param USARTx USART Instance
1916 * @retval State of bit (1 or 0).
1918 __STATIC_INLINE
uint32_t LL_USART_IsActiveFlag_SBK(USART_TypeDef
*USARTx
)
1920 return (READ_BIT(USARTx
->CR1
, USART_CR1_SBK
) == (USART_CR1_SBK
));
1924 * @brief Check if the USART Receive Wake Up from mute mode Flag is set or not
1925 * @rmtoll CR1 RWU LL_USART_IsActiveFlag_RWU
1926 * @param USARTx USART Instance
1927 * @retval State of bit (1 or 0).
1929 __STATIC_INLINE
uint32_t LL_USART_IsActiveFlag_RWU(USART_TypeDef
*USARTx
)
1931 return (READ_BIT(USARTx
->CR1
, USART_CR1_RWU
) == (USART_CR1_RWU
));
1935 * @brief Clear Parity Error Flag
1936 * @note Clearing this flag is done by a read access to the USARTx_SR
1937 * register followed by a read access to the USARTx_DR register.
1938 * @note Please also consider that when clearing this flag, other flags as
1939 * NE, FE, ORE, IDLE would also be cleared.
1940 * @rmtoll SR PE LL_USART_ClearFlag_PE
1941 * @param USARTx USART Instance
1944 __STATIC_INLINE
void LL_USART_ClearFlag_PE(USART_TypeDef
*USARTx
)
1946 __IO
uint32_t tmpreg
;
1947 tmpreg
= USARTx
->SR
;
1949 tmpreg
= USARTx
->DR
;
1954 * @brief Clear Framing Error Flag
1955 * @note Clearing this flag is done by a read access to the USARTx_SR
1956 * register followed by a read access to the USARTx_DR register.
1957 * @note Please also consider that when clearing this flag, other flags as
1958 * PE, NE, ORE, IDLE would also be cleared.
1959 * @rmtoll SR FE LL_USART_ClearFlag_FE
1960 * @param USARTx USART Instance
1963 __STATIC_INLINE
void LL_USART_ClearFlag_FE(USART_TypeDef
*USARTx
)
1965 __IO
uint32_t tmpreg
;
1966 tmpreg
= USARTx
->SR
;
1968 tmpreg
= USARTx
->DR
;
1973 * @brief Clear Noise detected Flag
1974 * @note Clearing this flag is done by a read access to the USARTx_SR
1975 * register followed by a read access to the USARTx_DR register.
1976 * @note Please also consider that when clearing this flag, other flags as
1977 * PE, FE, ORE, IDLE would also be cleared.
1978 * @rmtoll SR NF LL_USART_ClearFlag_NE
1979 * @param USARTx USART Instance
1982 __STATIC_INLINE
void LL_USART_ClearFlag_NE(USART_TypeDef
*USARTx
)
1984 __IO
uint32_t tmpreg
;
1985 tmpreg
= USARTx
->SR
;
1987 tmpreg
= USARTx
->DR
;
1992 * @brief Clear OverRun Error Flag
1993 * @note Clearing this flag is done by a read access to the USARTx_SR
1994 * register followed by a read access to the USARTx_DR register.
1995 * @note Please also consider that when clearing this flag, other flags as
1996 * PE, NE, FE, IDLE would also be cleared.
1997 * @rmtoll SR ORE LL_USART_ClearFlag_ORE
1998 * @param USARTx USART Instance
2001 __STATIC_INLINE
void LL_USART_ClearFlag_ORE(USART_TypeDef
*USARTx
)
2003 __IO
uint32_t tmpreg
;
2004 tmpreg
= USARTx
->SR
;
2006 tmpreg
= USARTx
->DR
;
2011 * @brief Clear IDLE line detected Flag
2012 * @note Clearing this flag is done by a read access to the USARTx_SR
2013 * register followed by a read access to the USARTx_DR register.
2014 * @note Please also consider that when clearing this flag, other flags as
2015 * PE, NE, FE, ORE would also be cleared.
2016 * @rmtoll SR IDLE LL_USART_ClearFlag_IDLE
2017 * @param USARTx USART Instance
2020 __STATIC_INLINE
void LL_USART_ClearFlag_IDLE(USART_TypeDef
*USARTx
)
2022 __IO
uint32_t tmpreg
;
2023 tmpreg
= USARTx
->SR
;
2025 tmpreg
= USARTx
->DR
;
2030 * @brief Clear Transmission Complete Flag
2031 * @rmtoll SR TC LL_USART_ClearFlag_TC
2032 * @param USARTx USART Instance
2035 __STATIC_INLINE
void LL_USART_ClearFlag_TC(USART_TypeDef
*USARTx
)
2037 WRITE_REG(USARTx
->SR
, ~(USART_SR_TC
));
2041 * @brief Clear RX Not Empty Flag
2042 * @rmtoll SR RXNE LL_USART_ClearFlag_RXNE
2043 * @param USARTx USART Instance
2046 __STATIC_INLINE
void LL_USART_ClearFlag_RXNE(USART_TypeDef
*USARTx
)
2048 WRITE_REG(USARTx
->SR
, ~(USART_SR_RXNE
));
2052 * @brief Clear LIN Break Detection Flag
2053 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2054 * LIN feature is supported by the USARTx instance.
2055 * @rmtoll SR LBD LL_USART_ClearFlag_LBD
2056 * @param USARTx USART Instance
2059 __STATIC_INLINE
void LL_USART_ClearFlag_LBD(USART_TypeDef
*USARTx
)
2061 WRITE_REG(USARTx
->SR
, ~(USART_SR_LBD
));
2065 * @brief Clear CTS Interrupt Flag
2066 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
2067 * Hardware Flow control feature is supported by the USARTx instance.
2068 * @rmtoll SR CTS LL_USART_ClearFlag_nCTS
2069 * @param USARTx USART Instance
2072 __STATIC_INLINE
void LL_USART_ClearFlag_nCTS(USART_TypeDef
*USARTx
)
2074 WRITE_REG(USARTx
->SR
, ~(USART_SR_CTS
));
2081 /** @defgroup USART_LL_EF_IT_Management IT_Management
2086 * @brief Enable IDLE Interrupt
2087 * @rmtoll CR1 IDLEIE LL_USART_EnableIT_IDLE
2088 * @param USARTx USART Instance
2091 __STATIC_INLINE
void LL_USART_EnableIT_IDLE(USART_TypeDef
*USARTx
)
2093 SET_BIT(USARTx
->CR1
, USART_CR1_IDLEIE
);
2097 * @brief Enable RX Not Empty Interrupt
2098 * @rmtoll CR1 RXNEIE LL_USART_EnableIT_RXNE
2099 * @param USARTx USART Instance
2102 __STATIC_INLINE
void LL_USART_EnableIT_RXNE(USART_TypeDef
*USARTx
)
2104 SET_BIT(USARTx
->CR1
, USART_CR1_RXNEIE
);
2108 * @brief Enable Transmission Complete Interrupt
2109 * @rmtoll CR1 TCIE LL_USART_EnableIT_TC
2110 * @param USARTx USART Instance
2113 __STATIC_INLINE
void LL_USART_EnableIT_TC(USART_TypeDef
*USARTx
)
2115 SET_BIT(USARTx
->CR1
, USART_CR1_TCIE
);
2119 * @brief Enable TX Empty Interrupt
2120 * @rmtoll CR1 TXEIE LL_USART_EnableIT_TXE
2121 * @param USARTx USART Instance
2124 __STATIC_INLINE
void LL_USART_EnableIT_TXE(USART_TypeDef
*USARTx
)
2126 SET_BIT(USARTx
->CR1
, USART_CR1_TXEIE
);
2130 * @brief Enable Parity Error Interrupt
2131 * @rmtoll CR1 PEIE LL_USART_EnableIT_PE
2132 * @param USARTx USART Instance
2135 __STATIC_INLINE
void LL_USART_EnableIT_PE(USART_TypeDef
*USARTx
)
2137 SET_BIT(USARTx
->CR1
, USART_CR1_PEIE
);
2141 * @brief Enable LIN Break Detection Interrupt
2142 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2143 * LIN feature is supported by the USARTx instance.
2144 * @rmtoll CR2 LBDIE LL_USART_EnableIT_LBD
2145 * @param USARTx USART Instance
2148 __STATIC_INLINE
void LL_USART_EnableIT_LBD(USART_TypeDef
*USARTx
)
2150 SET_BIT(USARTx
->CR2
, USART_CR2_LBDIE
);
2154 * @brief Enable Error Interrupt
2155 * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
2156 * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_SR register).
2157 * 0: Interrupt is inhibited
2158 * 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_SR register.
2159 * @rmtoll CR3 EIE LL_USART_EnableIT_ERROR
2160 * @param USARTx USART Instance
2163 __STATIC_INLINE
void LL_USART_EnableIT_ERROR(USART_TypeDef
*USARTx
)
2165 SET_BIT(USARTx
->CR3
, USART_CR3_EIE
);
2169 * @brief Enable CTS Interrupt
2170 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
2171 * Hardware Flow control feature is supported by the USARTx instance.
2172 * @rmtoll CR3 CTSIE LL_USART_EnableIT_CTS
2173 * @param USARTx USART Instance
2176 __STATIC_INLINE
void LL_USART_EnableIT_CTS(USART_TypeDef
*USARTx
)
2178 SET_BIT(USARTx
->CR3
, USART_CR3_CTSIE
);
2182 * @brief Disable IDLE Interrupt
2183 * @rmtoll CR1 IDLEIE LL_USART_DisableIT_IDLE
2184 * @param USARTx USART Instance
2187 __STATIC_INLINE
void LL_USART_DisableIT_IDLE(USART_TypeDef
*USARTx
)
2189 CLEAR_BIT(USARTx
->CR1
, USART_CR1_IDLEIE
);
2193 * @brief Disable RX Not Empty Interrupt
2194 * @rmtoll CR1 RXNEIE LL_USART_DisableIT_RXNE
2195 * @param USARTx USART Instance
2198 __STATIC_INLINE
void LL_USART_DisableIT_RXNE(USART_TypeDef
*USARTx
)
2200 CLEAR_BIT(USARTx
->CR1
, USART_CR1_RXNEIE
);
2204 * @brief Disable Transmission Complete Interrupt
2205 * @rmtoll CR1 TCIE LL_USART_DisableIT_TC
2206 * @param USARTx USART Instance
2209 __STATIC_INLINE
void LL_USART_DisableIT_TC(USART_TypeDef
*USARTx
)
2211 CLEAR_BIT(USARTx
->CR1
, USART_CR1_TCIE
);
2215 * @brief Disable TX Empty Interrupt
2216 * @rmtoll CR1 TXEIE LL_USART_DisableIT_TXE
2217 * @param USARTx USART Instance
2220 __STATIC_INLINE
void LL_USART_DisableIT_TXE(USART_TypeDef
*USARTx
)
2222 CLEAR_BIT(USARTx
->CR1
, USART_CR1_TXEIE
);
2226 * @brief Disable Parity Error Interrupt
2227 * @rmtoll CR1 PEIE LL_USART_DisableIT_PE
2228 * @param USARTx USART Instance
2231 __STATIC_INLINE
void LL_USART_DisableIT_PE(USART_TypeDef
*USARTx
)
2233 CLEAR_BIT(USARTx
->CR1
, USART_CR1_PEIE
);
2237 * @brief Disable LIN Break Detection Interrupt
2238 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2239 * LIN feature is supported by the USARTx instance.
2240 * @rmtoll CR2 LBDIE LL_USART_DisableIT_LBD
2241 * @param USARTx USART Instance
2244 __STATIC_INLINE
void LL_USART_DisableIT_LBD(USART_TypeDef
*USARTx
)
2246 CLEAR_BIT(USARTx
->CR2
, USART_CR2_LBDIE
);
2250 * @brief Disable Error Interrupt
2251 * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
2252 * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_SR register).
2253 * 0: Interrupt is inhibited
2254 * 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_SR register.
2255 * @rmtoll CR3 EIE LL_USART_DisableIT_ERROR
2256 * @param USARTx USART Instance
2259 __STATIC_INLINE
void LL_USART_DisableIT_ERROR(USART_TypeDef
*USARTx
)
2261 CLEAR_BIT(USARTx
->CR3
, USART_CR3_EIE
);
2265 * @brief Disable CTS Interrupt
2266 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
2267 * Hardware Flow control feature is supported by the USARTx instance.
2268 * @rmtoll CR3 CTSIE LL_USART_DisableIT_CTS
2269 * @param USARTx USART Instance
2272 __STATIC_INLINE
void LL_USART_DisableIT_CTS(USART_TypeDef
*USARTx
)
2274 CLEAR_BIT(USARTx
->CR3
, USART_CR3_CTSIE
);
2278 * @brief Check if the USART IDLE Interrupt source is enabled or disabled.
2279 * @rmtoll CR1 IDLEIE LL_USART_IsEnabledIT_IDLE
2280 * @param USARTx USART Instance
2281 * @retval State of bit (1 or 0).
2283 __STATIC_INLINE
uint32_t LL_USART_IsEnabledIT_IDLE(USART_TypeDef
*USARTx
)
2285 return (READ_BIT(USARTx
->CR1
, USART_CR1_IDLEIE
) == (USART_CR1_IDLEIE
));
2289 * @brief Check if the USART RX Not Empty Interrupt is enabled or disabled.
2290 * @rmtoll CR1 RXNEIE LL_USART_IsEnabledIT_RXNE
2291 * @param USARTx USART Instance
2292 * @retval State of bit (1 or 0).
2294 __STATIC_INLINE
uint32_t LL_USART_IsEnabledIT_RXNE(USART_TypeDef
*USARTx
)
2296 return (READ_BIT(USARTx
->CR1
, USART_CR1_RXNEIE
) == (USART_CR1_RXNEIE
));
2300 * @brief Check if the USART Transmission Complete Interrupt is enabled or disabled.
2301 * @rmtoll CR1 TCIE LL_USART_IsEnabledIT_TC
2302 * @param USARTx USART Instance
2303 * @retval State of bit (1 or 0).
2305 __STATIC_INLINE
uint32_t LL_USART_IsEnabledIT_TC(USART_TypeDef
*USARTx
)
2307 return (READ_BIT(USARTx
->CR1
, USART_CR1_TCIE
) == (USART_CR1_TCIE
));
2311 * @brief Check if the USART TX Empty Interrupt is enabled or disabled.
2312 * @rmtoll CR1 TXEIE LL_USART_IsEnabledIT_TXE
2313 * @param USARTx USART Instance
2314 * @retval State of bit (1 or 0).
2316 __STATIC_INLINE
uint32_t LL_USART_IsEnabledIT_TXE(USART_TypeDef
*USARTx
)
2318 return (READ_BIT(USARTx
->CR1
, USART_CR1_TXEIE
) == (USART_CR1_TXEIE
));
2322 * @brief Check if the USART Parity Error Interrupt is enabled or disabled.
2323 * @rmtoll CR1 PEIE LL_USART_IsEnabledIT_PE
2324 * @param USARTx USART Instance
2325 * @retval State of bit (1 or 0).
2327 __STATIC_INLINE
uint32_t LL_USART_IsEnabledIT_PE(USART_TypeDef
*USARTx
)
2329 return (READ_BIT(USARTx
->CR1
, USART_CR1_PEIE
) == (USART_CR1_PEIE
));
2333 * @brief Check if the USART LIN Break Detection Interrupt is enabled or disabled.
2334 * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2335 * LIN feature is supported by the USARTx instance.
2336 * @rmtoll CR2 LBDIE LL_USART_IsEnabledIT_LBD
2337 * @param USARTx USART Instance
2338 * @retval State of bit (1 or 0).
2340 __STATIC_INLINE
uint32_t LL_USART_IsEnabledIT_LBD(USART_TypeDef
*USARTx
)
2342 return (READ_BIT(USARTx
->CR2
, USART_CR2_LBDIE
) == (USART_CR2_LBDIE
));
2346 * @brief Check if the USART Error Interrupt is enabled or disabled.
2347 * @rmtoll CR3 EIE LL_USART_IsEnabledIT_ERROR
2348 * @param USARTx USART Instance
2349 * @retval State of bit (1 or 0).
2351 __STATIC_INLINE
uint32_t LL_USART_IsEnabledIT_ERROR(USART_TypeDef
*USARTx
)
2353 return (READ_BIT(USARTx
->CR3
, USART_CR3_EIE
) == (USART_CR3_EIE
));
2357 * @brief Check if the USART CTS Interrupt is enabled or disabled.
2358 * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
2359 * Hardware Flow control feature is supported by the USARTx instance.
2360 * @rmtoll CR3 CTSIE LL_USART_IsEnabledIT_CTS
2361 * @param USARTx USART Instance
2362 * @retval State of bit (1 or 0).
2364 __STATIC_INLINE
uint32_t LL_USART_IsEnabledIT_CTS(USART_TypeDef
*USARTx
)
2366 return (READ_BIT(USARTx
->CR3
, USART_CR3_CTSIE
) == (USART_CR3_CTSIE
));
2373 /** @defgroup USART_LL_EF_DMA_Management DMA_Management
2378 * @brief Enable DMA Mode for reception
2379 * @rmtoll CR3 DMAR LL_USART_EnableDMAReq_RX
2380 * @param USARTx USART Instance
2383 __STATIC_INLINE
void LL_USART_EnableDMAReq_RX(USART_TypeDef
*USARTx
)
2385 SET_BIT(USARTx
->CR3
, USART_CR3_DMAR
);
2389 * @brief Disable DMA Mode for reception
2390 * @rmtoll CR3 DMAR LL_USART_DisableDMAReq_RX
2391 * @param USARTx USART Instance
2394 __STATIC_INLINE
void LL_USART_DisableDMAReq_RX(USART_TypeDef
*USARTx
)
2396 CLEAR_BIT(USARTx
->CR3
, USART_CR3_DMAR
);
2400 * @brief Check if DMA Mode is enabled for reception
2401 * @rmtoll CR3 DMAR LL_USART_IsEnabledDMAReq_RX
2402 * @param USARTx USART Instance
2403 * @retval State of bit (1 or 0).
2405 __STATIC_INLINE
uint32_t LL_USART_IsEnabledDMAReq_RX(USART_TypeDef
*USARTx
)
2407 return (READ_BIT(USARTx
->CR3
, USART_CR3_DMAR
) == (USART_CR3_DMAR
));
2411 * @brief Enable DMA Mode for transmission
2412 * @rmtoll CR3 DMAT LL_USART_EnableDMAReq_TX
2413 * @param USARTx USART Instance
2416 __STATIC_INLINE
void LL_USART_EnableDMAReq_TX(USART_TypeDef
*USARTx
)
2418 SET_BIT(USARTx
->CR3
, USART_CR3_DMAT
);
2422 * @brief Disable DMA Mode for transmission
2423 * @rmtoll CR3 DMAT LL_USART_DisableDMAReq_TX
2424 * @param USARTx USART Instance
2427 __STATIC_INLINE
void LL_USART_DisableDMAReq_TX(USART_TypeDef
*USARTx
)
2429 CLEAR_BIT(USARTx
->CR3
, USART_CR3_DMAT
);
2433 * @brief Check if DMA Mode is enabled for transmission
2434 * @rmtoll CR3 DMAT LL_USART_IsEnabledDMAReq_TX
2435 * @param USARTx USART Instance
2436 * @retval State of bit (1 or 0).
2438 __STATIC_INLINE
uint32_t LL_USART_IsEnabledDMAReq_TX(USART_TypeDef
*USARTx
)
2440 return (READ_BIT(USARTx
->CR3
, USART_CR3_DMAT
) == (USART_CR3_DMAT
));
2444 * @brief Get the data register address used for DMA transfer
2445 * @rmtoll DR DR LL_USART_DMA_GetRegAddr
2446 * @note Address of Data Register is valid for both Transmit and Receive transfers.
2447 * @param USARTx USART Instance
2448 * @retval Address of data register
2450 __STATIC_INLINE
uint32_t LL_USART_DMA_GetRegAddr(USART_TypeDef
*USARTx
)
2452 /* return address of DR register */
2453 return ((uint32_t) &(USARTx
->DR
));
2460 /** @defgroup USART_LL_EF_Data_Management Data_Management
2465 * @brief Read Receiver Data register (Receive Data value, 8 bits)
2466 * @rmtoll DR DR LL_USART_ReceiveData8
2467 * @param USARTx USART Instance
2468 * @retval Value between Min_Data=0x00 and Max_Data=0xFF
2470 __STATIC_INLINE
uint8_t LL_USART_ReceiveData8(USART_TypeDef
*USARTx
)
2472 return (uint8_t)(READ_BIT(USARTx
->DR
, USART_DR_DR
));
2476 * @brief Read Receiver Data register (Receive Data value, 9 bits)
2477 * @rmtoll DR DR LL_USART_ReceiveData9
2478 * @param USARTx USART Instance
2479 * @retval Value between Min_Data=0x00 and Max_Data=0x1FF
2481 __STATIC_INLINE
uint16_t LL_USART_ReceiveData9(USART_TypeDef
*USARTx
)
2483 return (uint16_t)(READ_BIT(USARTx
->DR
, USART_DR_DR
));
2487 * @brief Write in Transmitter Data Register (Transmit Data value, 8 bits)
2488 * @rmtoll DR DR LL_USART_TransmitData8
2489 * @param USARTx USART Instance
2490 * @param Value between Min_Data=0x00 and Max_Data=0xFF
2493 __STATIC_INLINE
void LL_USART_TransmitData8(USART_TypeDef
*USARTx
, uint8_t Value
)
2499 * @brief Write in Transmitter Data Register (Transmit Data value, 9 bits)
2500 * @rmtoll DR DR LL_USART_TransmitData9
2501 * @param USARTx USART Instance
2502 * @param Value between Min_Data=0x00 and Max_Data=0x1FF
2505 __STATIC_INLINE
void LL_USART_TransmitData9(USART_TypeDef
*USARTx
, uint16_t Value
)
2507 USARTx
->DR
= Value
& 0x1FFU
;
2514 /** @defgroup USART_LL_EF_Execution Execution
2519 * @brief Request Break sending
2520 * @rmtoll CR1 SBK LL_USART_RequestBreakSending
2521 * @param USARTx USART Instance
2524 __STATIC_INLINE
void LL_USART_RequestBreakSending(USART_TypeDef
*USARTx
)
2526 SET_BIT(USARTx
->CR1
, USART_CR1_SBK
);
2530 * @brief Put USART in Mute mode
2531 * @rmtoll CR1 RWU LL_USART_RequestEnterMuteMode
2532 * @param USARTx USART Instance
2535 __STATIC_INLINE
void LL_USART_RequestEnterMuteMode(USART_TypeDef
*USARTx
)
2537 SET_BIT(USARTx
->CR1
, USART_CR1_RWU
);
2541 * @brief Put USART in Active mode
2542 * @rmtoll CR1 RWU LL_USART_RequestExitMuteMode
2543 * @param USARTx USART Instance
2546 __STATIC_INLINE
void LL_USART_RequestExitMuteMode(USART_TypeDef
*USARTx
)
2548 CLEAR_BIT(USARTx
->CR1
, USART_CR1_RWU
);
2555 #if defined(USE_FULL_LL_DRIVER)
2556 /** @defgroup USART_LL_EF_Init Initialization and de-initialization functions
2559 ErrorStatus
LL_USART_DeInit(USART_TypeDef
*USARTx
);
2560 ErrorStatus
LL_USART_Init(USART_TypeDef
*USARTx
, LL_USART_InitTypeDef
*USART_InitStruct
);
2561 void LL_USART_StructInit(LL_USART_InitTypeDef
*USART_InitStruct
);
2562 ErrorStatus
LL_USART_ClockInit(USART_TypeDef
*USARTx
, LL_USART_ClockInitTypeDef
*USART_ClockInitStruct
);
2563 void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef
*USART_ClockInitStruct
);
2567 #endif /* USE_FULL_LL_DRIVER */
2577 #endif /* USART1 || USART2 || USART3 || UART4 || UART5 */
2587 #endif /* __STM32F1xx_LL_USART_H */
2589 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/