You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

2524 lines
96 KiB

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