Subversion Repositories DashDisplay

Rev

Rev 56 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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