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.
 
 
 

4378 lines
170 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32wbxx_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) 2019 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 STM32WBxx_LL_USART_H
  21. #define STM32WBxx_LL_USART_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32wbxx.h"
  27. /** @addtogroup STM32WBxx_LL_Driver
  28. * @{
  29. */
  30. #if defined (USART1)
  31. /** @defgroup USART_LL USART
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /** @defgroup USART_LL_Private_Variables USART Private Variables
  37. * @{
  38. */
  39. /* Array used to get the USART prescaler division decimal values versus @ref USART_LL_EC_PRESCALER values */
  40. static const uint16_t USART_PRESCALER_TAB[] =
  41. {
  42. (uint16_t)1,
  43. (uint16_t)2,
  44. (uint16_t)4,
  45. (uint16_t)6,
  46. (uint16_t)8,
  47. (uint16_t)10,
  48. (uint16_t)12,
  49. (uint16_t)16,
  50. (uint16_t)32,
  51. (uint16_t)64,
  52. (uint16_t)128,
  53. (uint16_t)256
  54. };
  55. /**
  56. * @}
  57. */
  58. /* Private constants ---------------------------------------------------------*/
  59. /** @defgroup USART_LL_Private_Constants USART Private Constants
  60. * @{
  61. */
  62. /**
  63. * @}
  64. */
  65. /* Private macros ------------------------------------------------------------*/
  66. #if defined(USE_FULL_LL_DRIVER)
  67. /** @defgroup USART_LL_Private_Macros USART Private Macros
  68. * @{
  69. */
  70. /**
  71. * @}
  72. */
  73. #endif /*USE_FULL_LL_DRIVER*/
  74. /* Exported types ------------------------------------------------------------*/
  75. #if defined(USE_FULL_LL_DRIVER)
  76. /** @defgroup USART_LL_ES_INIT USART Exported Init structures
  77. * @{
  78. */
  79. /**
  80. * @brief LL USART Init Structure definition
  81. */
  82. typedef struct
  83. {
  84. uint32_t PrescalerValue; /*!< Specifies the Prescaler to compute the communication baud rate.
  85. This parameter can be a value of @ref USART_LL_EC_PRESCALER.
  86. This feature can be modified afterwards using unitary function @ref LL_USART_SetPrescaler().*/
  87. uint32_t BaudRate; /*!< This field defines expected Usart communication baud rate.
  88. This feature can be modified afterwards using unitary function @ref LL_USART_SetBaudRate().*/
  89. uint32_t DataWidth; /*!< Specifies the number of data bits transmitted or received in a frame.
  90. This parameter can be a value of @ref USART_LL_EC_DATAWIDTH.
  91. This feature can be modified afterwards using unitary function @ref LL_USART_SetDataWidth().*/
  92. uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
  93. This parameter can be a value of @ref USART_LL_EC_STOPBITS.
  94. This feature can be modified afterwards using unitary function @ref LL_USART_SetStopBitsLength().*/
  95. uint32_t Parity; /*!< Specifies the parity mode.
  96. This parameter can be a value of @ref USART_LL_EC_PARITY.
  97. This feature can be modified afterwards using unitary function @ref LL_USART_SetParity().*/
  98. uint32_t TransferDirection; /*!< Specifies whether the Receive and/or Transmit mode is enabled or disabled.
  99. This parameter can be a value of @ref USART_LL_EC_DIRECTION.
  100. This feature can be modified afterwards using unitary function @ref LL_USART_SetTransferDirection().*/
  101. uint32_t HardwareFlowControl; /*!< Specifies whether the hardware flow control mode is enabled or disabled.
  102. This parameter can be a value of @ref USART_LL_EC_HWCONTROL.
  103. This feature can be modified afterwards using unitary function @ref LL_USART_SetHWFlowCtrl().*/
  104. uint32_t OverSampling; /*!< Specifies whether USART oversampling mode is 16 or 8.
  105. This parameter can be a value of @ref USART_LL_EC_OVERSAMPLING.
  106. This feature can be modified afterwards using unitary function @ref LL_USART_SetOverSampling().*/
  107. } LL_USART_InitTypeDef;
  108. /**
  109. * @brief LL USART Clock Init Structure definition
  110. */
  111. typedef struct
  112. {
  113. uint32_t ClockOutput; /*!< Specifies whether the USART clock is enabled or disabled.
  114. This parameter can be a value of @ref USART_LL_EC_CLOCK.
  115. USART HW configuration can be modified afterwards using unitary functions
  116. @ref LL_USART_EnableSCLKOutput() or @ref LL_USART_DisableSCLKOutput().
  117. For more details, refer to description of this function. */
  118. uint32_t ClockPolarity; /*!< Specifies the steady state of the serial clock.
  119. This parameter can be a value of @ref USART_LL_EC_POLARITY.
  120. USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetClockPolarity().
  121. For more details, refer to description of this function. */
  122. uint32_t ClockPhase; /*!< Specifies the clock transition on which the bit capture is made.
  123. This parameter can be a value of @ref USART_LL_EC_PHASE.
  124. USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetClockPhase().
  125. For more details, refer to description of this function. */
  126. uint32_t LastBitClockPulse; /*!< Specifies whether the clock pulse corresponding to the last transmitted
  127. data bit (MSB) has to be output on the SCLK pin in synchronous mode.
  128. This parameter can be a value of @ref USART_LL_EC_LASTCLKPULSE.
  129. USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetLastClkPulseOutput().
  130. For more details, refer to description of this function. */
  131. } LL_USART_ClockInitTypeDef;
  132. /**
  133. * @}
  134. */
  135. #endif /* USE_FULL_LL_DRIVER */
  136. /* Exported constants --------------------------------------------------------*/
  137. /** @defgroup USART_LL_Exported_Constants USART Exported Constants
  138. * @{
  139. */
  140. /** @defgroup USART_LL_EC_CLEAR_FLAG Clear Flags Defines
  141. * @brief Flags defines which can be used with LL_USART_WriteReg function
  142. * @{
  143. */
  144. #define LL_USART_ICR_PECF USART_ICR_PECF /*!< Parity error flag */
  145. #define LL_USART_ICR_FECF USART_ICR_FECF /*!< Framing error flag */
  146. #define LL_USART_ICR_NECF USART_ICR_NECF /*!< Noise error detected flag */
  147. #define LL_USART_ICR_ORECF USART_ICR_ORECF /*!< Overrun error flag */
  148. #define LL_USART_ICR_IDLECF USART_ICR_IDLECF /*!< Idle line detected flag */
  149. #define LL_USART_ICR_TXFECF USART_ICR_TXFECF /*!< TX FIFO Empty Clear flag */
  150. #define LL_USART_ICR_TCCF USART_ICR_TCCF /*!< Transmission complete flag */
  151. #define LL_USART_ICR_TCBGTCF USART_ICR_TCBGTCF /*!< Transmission completed before guard time flag */
  152. #define LL_USART_ICR_LBDCF USART_ICR_LBDCF /*!< LIN break detection flag */
  153. #define LL_USART_ICR_CTSCF USART_ICR_CTSCF /*!< CTS flag */
  154. #define LL_USART_ICR_RTOCF USART_ICR_RTOCF /*!< Receiver timeout flag */
  155. #define LL_USART_ICR_EOBCF USART_ICR_EOBCF /*!< End of block flag */
  156. #define LL_USART_ICR_UDRCF USART_ICR_UDRCF /*!< SPI Slave Underrun Clear flag */
  157. #define LL_USART_ICR_CMCF USART_ICR_CMCF /*!< Character match flag */
  158. #define LL_USART_ICR_WUCF USART_ICR_WUCF /*!< Wakeup from Stop mode flag */
  159. /**
  160. * @}
  161. */
  162. /** @defgroup USART_LL_EC_GET_FLAG Get Flags Defines
  163. * @brief Flags defines which can be used with LL_USART_ReadReg function
  164. * @{
  165. */
  166. #define LL_USART_ISR_PE USART_ISR_PE /*!< Parity error flag */
  167. #define LL_USART_ISR_FE USART_ISR_FE /*!< Framing error flag */
  168. #define LL_USART_ISR_NE USART_ISR_NE /*!< Noise detected flag */
  169. #define LL_USART_ISR_ORE USART_ISR_ORE /*!< Overrun error flag */
  170. #define LL_USART_ISR_IDLE USART_ISR_IDLE /*!< Idle line detected flag */
  171. #define LL_USART_ISR_RXNE_RXFNE USART_ISR_RXNE_RXFNE /*!< Read data register or RX FIFO not empty flag */
  172. #define LL_USART_ISR_TC USART_ISR_TC /*!< Transmission complete flag */
  173. #define LL_USART_ISR_TXE_TXFNF USART_ISR_TXE_TXFNF /*!< Transmit data register empty or TX FIFO Not Full flag*/
  174. #define LL_USART_ISR_LBDF USART_ISR_LBDF /*!< LIN break detection flag */
  175. #define LL_USART_ISR_CTSIF USART_ISR_CTSIF /*!< CTS interrupt flag */
  176. #define LL_USART_ISR_CTS USART_ISR_CTS /*!< CTS flag */
  177. #define LL_USART_ISR_RTOF USART_ISR_RTOF /*!< Receiver timeout flag */
  178. #define LL_USART_ISR_EOBF USART_ISR_EOBF /*!< End of block flag */
  179. #define LL_USART_ISR_UDR USART_ISR_UDR /*!< SPI Slave underrun error flag */
  180. #define LL_USART_ISR_ABRE USART_ISR_ABRE /*!< Auto baud rate error flag */
  181. #define LL_USART_ISR_ABRF USART_ISR_ABRF /*!< Auto baud rate flag */
  182. #define LL_USART_ISR_BUSY USART_ISR_BUSY /*!< Busy flag */
  183. #define LL_USART_ISR_CMF USART_ISR_CMF /*!< Character match flag */
  184. #define LL_USART_ISR_SBKF USART_ISR_SBKF /*!< Send break flag */
  185. #define LL_USART_ISR_RWU USART_ISR_RWU /*!< Receiver wakeup from Mute mode flag */
  186. #define LL_USART_ISR_WUF USART_ISR_WUF /*!< Wakeup from Stop mode flag */
  187. #define LL_USART_ISR_TEACK USART_ISR_TEACK /*!< Transmit enable acknowledge flag */
  188. #define LL_USART_ISR_REACK USART_ISR_REACK /*!< Receive enable acknowledge flag */
  189. #define LL_USART_ISR_TXFE USART_ISR_TXFE /*!< TX FIFO empty flag */
  190. #define LL_USART_ISR_RXFF USART_ISR_RXFF /*!< RX FIFO full flag */
  191. #define LL_USART_ISR_TCBGT USART_ISR_TCBGT /*!< Transmission complete before guard time completion flag */
  192. #define LL_USART_ISR_RXFT USART_ISR_RXFT /*!< RX FIFO threshold flag */
  193. #define LL_USART_ISR_TXFT USART_ISR_TXFT /*!< TX FIFO threshold flag */
  194. /**
  195. * @}
  196. */
  197. /** @defgroup USART_LL_EC_IT IT Defines
  198. * @brief IT defines which can be used with LL_USART_ReadReg and LL_USART_WriteReg functions
  199. * @{
  200. */
  201. #define LL_USART_CR1_IDLEIE USART_CR1_IDLEIE /*!< IDLE interrupt enable */
  202. #define LL_USART_CR1_RXNEIE_RXFNEIE USART_CR1_RXNEIE_RXFNEIE /*!< Read data register and RXFIFO not empty interrupt enable */
  203. #define LL_USART_CR1_TCIE USART_CR1_TCIE /*!< Transmission complete interrupt enable */
  204. #define LL_USART_CR1_TXEIE_TXFNFIE USART_CR1_TXEIE_TXFNFIE /*!< Transmit data register empty and TX FIFO not full interrupt enable */
  205. #define LL_USART_CR1_PEIE USART_CR1_PEIE /*!< Parity error */
  206. #define LL_USART_CR1_CMIE USART_CR1_CMIE /*!< Character match interrupt enable */
  207. #define LL_USART_CR1_RTOIE USART_CR1_RTOIE /*!< Receiver timeout interrupt enable */
  208. #define LL_USART_CR1_EOBIE USART_CR1_EOBIE /*!< End of Block interrupt enable */
  209. #define LL_USART_CR1_TXFEIE USART_CR1_TXFEIE /*!< TX FIFO empty interrupt enable */
  210. #define LL_USART_CR1_RXFFIE USART_CR1_RXFFIE /*!< RX FIFO full interrupt enable */
  211. #define LL_USART_CR2_LBDIE USART_CR2_LBDIE /*!< LIN break detection interrupt enable */
  212. #define LL_USART_CR3_EIE USART_CR3_EIE /*!< Error interrupt enable */
  213. #define LL_USART_CR3_CTSIE USART_CR3_CTSIE /*!< CTS interrupt enable */
  214. #define LL_USART_CR3_WUFIE USART_CR3_WUFIE /*!< Wakeup from Stop mode interrupt enable */
  215. #define LL_USART_CR3_TXFTIE USART_CR3_TXFTIE /*!< TX FIFO threshold interrupt enable */
  216. #define LL_USART_CR3_TCBGTIE USART_CR3_TCBGTIE /*!< Transmission complete before guard time interrupt enable */
  217. #define LL_USART_CR3_RXFTIE USART_CR3_RXFTIE /*!< RX FIFO threshold interrupt enable */
  218. /**
  219. * @}
  220. */
  221. /** @defgroup USART_LL_EC_FIFOTHRESHOLD FIFO Threshold
  222. * @{
  223. */
  224. #define LL_USART_FIFOTHRESHOLD_1_8 0x00000000U /*!< FIFO reaches 1/8 of its depth */
  225. #define LL_USART_FIFOTHRESHOLD_1_4 0x00000001U /*!< FIFO reaches 1/4 of its depth */
  226. #define LL_USART_FIFOTHRESHOLD_1_2 0x00000002U /*!< FIFO reaches 1/2 of its depth */
  227. #define LL_USART_FIFOTHRESHOLD_3_4 0x00000003U /*!< FIFO reaches 3/4 of its depth */
  228. #define LL_USART_FIFOTHRESHOLD_7_8 0x00000004U /*!< FIFO reaches 7/8 of its depth */
  229. #define LL_USART_FIFOTHRESHOLD_8_8 0x00000005U /*!< FIFO becomes empty for TX and full for RX */
  230. /**
  231. * @}
  232. */
  233. /** @defgroup USART_LL_EC_DIRECTION Communication Direction
  234. * @{
  235. */
  236. #define LL_USART_DIRECTION_NONE 0x00000000U /*!< Transmitter and Receiver are disabled */
  237. #define LL_USART_DIRECTION_RX USART_CR1_RE /*!< Transmitter is disabled and Receiver is enabled */
  238. #define LL_USART_DIRECTION_TX USART_CR1_TE /*!< Transmitter is enabled and Receiver is disabled */
  239. #define LL_USART_DIRECTION_TX_RX (USART_CR1_TE |USART_CR1_RE) /*!< Transmitter and Receiver are enabled */
  240. /**
  241. * @}
  242. */
  243. /** @defgroup USART_LL_EC_PARITY Parity Control
  244. * @{
  245. */
  246. #define LL_USART_PARITY_NONE 0x00000000U /*!< Parity control disabled */
  247. #define LL_USART_PARITY_EVEN USART_CR1_PCE /*!< Parity control enabled and Even Parity is selected */
  248. #define LL_USART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS) /*!< Parity control enabled and Odd Parity is selected */
  249. /**
  250. * @}
  251. */
  252. /** @defgroup USART_LL_EC_WAKEUP Wakeup
  253. * @{
  254. */
  255. #define LL_USART_WAKEUP_IDLELINE 0x00000000U /*!< USART wake up from Mute mode on Idle Line */
  256. #define LL_USART_WAKEUP_ADDRESSMARK USART_CR1_WAKE /*!< USART wake up from Mute mode on Address Mark */
  257. /**
  258. * @}
  259. */
  260. /** @defgroup USART_LL_EC_DATAWIDTH Datawidth
  261. * @{
  262. */
  263. #define LL_USART_DATAWIDTH_7B USART_CR1_M1 /*!< 7 bits word length : Start bit, 7 data bits, n stop bits */
  264. #define LL_USART_DATAWIDTH_8B 0x00000000U /*!< 8 bits word length : Start bit, 8 data bits, n stop bits */
  265. #define LL_USART_DATAWIDTH_9B USART_CR1_M0 /*!< 9 bits word length : Start bit, 9 data bits, n stop bits */
  266. /**
  267. * @}
  268. */
  269. /** @defgroup USART_LL_EC_OVERSAMPLING Oversampling
  270. * @{
  271. */
  272. #define LL_USART_OVERSAMPLING_16 0x00000000U /*!< Oversampling by 16 */
  273. #define LL_USART_OVERSAMPLING_8 USART_CR1_OVER8 /*!< Oversampling by 8 */
  274. /**
  275. * @}
  276. */
  277. #if defined(USE_FULL_LL_DRIVER)
  278. /** @defgroup USART_LL_EC_CLOCK Clock Signal
  279. * @{
  280. */
  281. #define LL_USART_CLOCK_DISABLE 0x00000000U /*!< Clock signal not provided */
  282. #define LL_USART_CLOCK_ENABLE USART_CR2_CLKEN /*!< Clock signal provided */
  283. /**
  284. * @}
  285. */
  286. #endif /*USE_FULL_LL_DRIVER*/
  287. /** @defgroup USART_LL_EC_LASTCLKPULSE Last Clock Pulse
  288. * @{
  289. */
  290. #define LL_USART_LASTCLKPULSE_NO_OUTPUT 0x00000000U /*!< The clock pulse of the last data bit is not output to the SCLK pin */
  291. #define LL_USART_LASTCLKPULSE_OUTPUT USART_CR2_LBCL /*!< The clock pulse of the last data bit is output to the SCLK pin */
  292. /**
  293. * @}
  294. */
  295. /** @defgroup USART_LL_EC_PHASE Clock Phase
  296. * @{
  297. */
  298. #define LL_USART_PHASE_1EDGE 0x00000000U /*!< The first clock transition is the first data capture edge */
  299. #define LL_USART_PHASE_2EDGE USART_CR2_CPHA /*!< The second clock transition is the first data capture edge */
  300. /**
  301. * @}
  302. */
  303. /** @defgroup USART_LL_EC_POLARITY Clock Polarity
  304. * @{
  305. */
  306. #define LL_USART_POLARITY_LOW 0x00000000U /*!< Steady low value on SCLK pin outside transmission window*/
  307. #define LL_USART_POLARITY_HIGH USART_CR2_CPOL /*!< Steady high value on SCLK pin outside transmission window */
  308. /**
  309. * @}
  310. */
  311. /** @defgroup USART_LL_EC_PRESCALER Clock Source Prescaler
  312. * @{
  313. */
  314. #define LL_USART_PRESCALER_DIV1 0x00000000U /*!< Input clock not devided */
  315. #define LL_USART_PRESCALER_DIV2 (USART_PRESC_PRESCALER_0) /*!< Input clock devided by 2 */
  316. #define LL_USART_PRESCALER_DIV4 (USART_PRESC_PRESCALER_1) /*!< Input clock devided by 4 */
  317. #define LL_USART_PRESCALER_DIV6 (USART_PRESC_PRESCALER_1 | USART_PRESC_PRESCALER_0) /*!< Input clock devided by 6 */
  318. #define LL_USART_PRESCALER_DIV8 (USART_PRESC_PRESCALER_2) /*!< Input clock devided by 8 */
  319. #define LL_USART_PRESCALER_DIV10 (USART_PRESC_PRESCALER_2 | USART_PRESC_PRESCALER_0) /*!< Input clock devided by 10 */
  320. #define LL_USART_PRESCALER_DIV12 (USART_PRESC_PRESCALER_2 | USART_PRESC_PRESCALER_1) /*!< Input clock devided by 12 */
  321. #define LL_USART_PRESCALER_DIV16 (USART_PRESC_PRESCALER_2 | USART_PRESC_PRESCALER_1 | USART_PRESC_PRESCALER_0) /*!< Input clock devided by 16 */
  322. #define LL_USART_PRESCALER_DIV32 (USART_PRESC_PRESCALER_3) /*!< Input clock devided by 32 */
  323. #define LL_USART_PRESCALER_DIV64 (USART_PRESC_PRESCALER_3 | USART_PRESC_PRESCALER_0) /*!< Input clock devided by 64 */
  324. #define LL_USART_PRESCALER_DIV128 (USART_PRESC_PRESCALER_3 | USART_PRESC_PRESCALER_1) /*!< Input clock devided by 128 */
  325. #define LL_USART_PRESCALER_DIV256 (USART_PRESC_PRESCALER_3 | USART_PRESC_PRESCALER_1 | USART_PRESC_PRESCALER_0) /*!< Input clock devided by 256 */
  326. /**
  327. * @}
  328. */
  329. /** @defgroup USART_LL_EC_STOPBITS Stop Bits
  330. * @{
  331. */
  332. #define LL_USART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< 0.5 stop bit */
  333. #define LL_USART_STOPBITS_1 0x00000000U /*!< 1 stop bit */
  334. #define LL_USART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< 1.5 stop bits */
  335. #define LL_USART_STOPBITS_2 USART_CR2_STOP_1 /*!< 2 stop bits */
  336. /**
  337. * @}
  338. */
  339. /** @defgroup USART_LL_EC_TXRX TX RX Pins Swap
  340. * @{
  341. */
  342. #define LL_USART_TXRX_STANDARD 0x00000000U /*!< TX/RX pins are used as defined in standard pinout */
  343. #define LL_USART_TXRX_SWAPPED (USART_CR2_SWAP) /*!< TX and RX pins functions are swapped. */
  344. /**
  345. * @}
  346. */
  347. /** @defgroup USART_LL_EC_RXPIN_LEVEL RX Pin Active Level Inversion
  348. * @{
  349. */
  350. #define LL_USART_RXPIN_LEVEL_STANDARD 0x00000000U /*!< RX pin signal works using the standard logic levels */
  351. #define LL_USART_RXPIN_LEVEL_INVERTED (USART_CR2_RXINV) /*!< RX pin signal values are inverted. */
  352. /**
  353. * @}
  354. */
  355. /** @defgroup USART_LL_EC_TXPIN_LEVEL TX Pin Active Level Inversion
  356. * @{
  357. */
  358. #define LL_USART_TXPIN_LEVEL_STANDARD 0x00000000U /*!< TX pin signal works using the standard logic levels */
  359. #define LL_USART_TXPIN_LEVEL_INVERTED (USART_CR2_TXINV) /*!< TX pin signal values are inverted. */
  360. /**
  361. * @}
  362. */
  363. /** @defgroup USART_LL_EC_BINARY_LOGIC Binary Data Inversion
  364. * @{
  365. */
  366. #define LL_USART_BINARY_LOGIC_POSITIVE 0x00000000U /*!< Logical data from the data register are send/received in positive/direct logic. (1=H, 0=L) */
  367. #define LL_USART_BINARY_LOGIC_NEGATIVE USART_CR2_DATAINV /*!< Logical data from the data register are send/received in negative/inverse logic. (1=L, 0=H). The parity bit is also inverted. */
  368. /**
  369. * @}
  370. */
  371. /** @defgroup USART_LL_EC_BITORDER Bit Order
  372. * @{
  373. */
  374. #define LL_USART_BITORDER_LSBFIRST 0x00000000U /*!< data is transmitted/received with data bit 0 first, following the start bit */
  375. #define LL_USART_BITORDER_MSBFIRST USART_CR2_MSBFIRST /*!< data is transmitted/received with the MSB first, following the start bit */
  376. /**
  377. * @}
  378. */
  379. /** @defgroup USART_LL_EC_AUTOBAUD_DETECT_ON Autobaud Detection
  380. * @{
  381. */
  382. #define LL_USART_AUTOBAUD_DETECT_ON_STARTBIT 0x00000000U /*!< Measurement of the start bit is used to detect the baud rate */
  383. #define LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE USART_CR2_ABRMODE_0 /*!< Falling edge to falling edge measurement. Received frame must start with a single bit = 1 -> Frame = Start10xxxxxx */
  384. #define LL_USART_AUTOBAUD_DETECT_ON_7F_FRAME USART_CR2_ABRMODE_1 /*!< 0x7F frame detection */
  385. #define LL_USART_AUTOBAUD_DETECT_ON_55_FRAME (USART_CR2_ABRMODE_1 | USART_CR2_ABRMODE_0) /*!< 0x55 frame detection */
  386. /**
  387. * @}
  388. */
  389. /** @defgroup USART_LL_EC_ADDRESS_DETECT Address Length Detection
  390. * @{
  391. */
  392. #define LL_USART_ADDRESS_DETECT_4B 0x00000000U /*!< 4-bit address detection method selected */
  393. #define LL_USART_ADDRESS_DETECT_7B USART_CR2_ADDM7 /*!< 7-bit address detection (in 8-bit data mode) method selected */
  394. /**
  395. * @}
  396. */
  397. /** @defgroup USART_LL_EC_HWCONTROL Hardware Control
  398. * @{
  399. */
  400. #define LL_USART_HWCONTROL_NONE 0x00000000U /*!< CTS and RTS hardware flow control disabled */
  401. #define LL_USART_HWCONTROL_RTS USART_CR3_RTSE /*!< RTS output enabled, data is only requested when there is space in the receive buffer */
  402. #define LL_USART_HWCONTROL_CTS USART_CR3_CTSE /*!< CTS mode enabled, data is only transmitted when the nCTS input is asserted (tied to 0) */
  403. #define LL_USART_HWCONTROL_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE) /*!< CTS and RTS hardware flow control enabled */
  404. /**
  405. * @}
  406. */
  407. /** @defgroup USART_LL_EC_WAKEUP_ON Wakeup Activation
  408. * @{
  409. */
  410. #define LL_USART_WAKEUP_ON_ADDRESS 0x00000000U /*!< Wake up active on address match */
  411. #define LL_USART_WAKEUP_ON_STARTBIT USART_CR3_WUS_1 /*!< Wake up active on Start bit detection */
  412. #define LL_USART_WAKEUP_ON_RXNE (USART_CR3_WUS_0 | USART_CR3_WUS_1) /*!< Wake up active on RXNE */
  413. /**
  414. * @}
  415. */
  416. /** @defgroup USART_LL_EC_IRDA_POWER IrDA Power
  417. * @{
  418. */
  419. #define LL_USART_IRDA_POWER_NORMAL 0x00000000U /*!< IrDA normal power mode */
  420. #define LL_USART_IRDA_POWER_LOW USART_CR3_IRLP /*!< IrDA low power mode */
  421. /**
  422. * @}
  423. */
  424. /** @defgroup USART_LL_EC_LINBREAK_DETECT LIN Break Detection Length
  425. * @{
  426. */
  427. #define LL_USART_LINBREAK_DETECT_10B 0x00000000U /*!< 10-bit break detection method selected */
  428. #define LL_USART_LINBREAK_DETECT_11B USART_CR2_LBDL /*!< 11-bit break detection method selected */
  429. /**
  430. * @}
  431. */
  432. /** @defgroup USART_LL_EC_DE_POLARITY Driver Enable Polarity
  433. * @{
  434. */
  435. #define LL_USART_DE_POLARITY_HIGH 0x00000000U /*!< DE signal is active high */
  436. #define LL_USART_DE_POLARITY_LOW USART_CR3_DEP /*!< DE signal is active low */
  437. /**
  438. * @}
  439. */
  440. /** @defgroup USART_LL_EC_DMA_REG_DATA DMA Register Data
  441. * @{
  442. */
  443. #define LL_USART_DMA_REG_DATA_TRANSMIT 0x00000000U /*!< Get address of data register used for transmission */
  444. #define LL_USART_DMA_REG_DATA_RECEIVE 0x00000001U /*!< Get address of data register used for reception */
  445. /**
  446. * @}
  447. */
  448. /**
  449. * @}
  450. */
  451. /* Exported macro ------------------------------------------------------------*/
  452. /** @defgroup USART_LL_Exported_Macros USART Exported Macros
  453. * @{
  454. */
  455. /** @defgroup USART_LL_EM_WRITE_READ Common Write and read registers Macros
  456. * @{
  457. */
  458. /**
  459. * @brief Write a value in USART register
  460. * @param __INSTANCE__ USART Instance
  461. * @param __REG__ Register to be written
  462. * @param __VALUE__ Value to be written in the register
  463. * @retval None
  464. */
  465. #define LL_USART_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  466. /**
  467. * @brief Read a value in USART register
  468. * @param __INSTANCE__ USART Instance
  469. * @param __REG__ Register to be read
  470. * @retval Register value
  471. */
  472. #define LL_USART_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  473. /**
  474. * @}
  475. */
  476. /** @defgroup USART_LL_EM_Exported_Macros_Helper Exported_Macros_Helper
  477. * @{
  478. */
  479. /**
  480. * @brief Compute USARTDIV value according to Peripheral Clock and
  481. * expected Baud Rate in 8 bits sampling mode (32 bits value of USARTDIV is returned)
  482. * @param __PERIPHCLK__ Peripheral Clock frequency used for USART instance
  483. * @param __PRESCALER__ This parameter can be one of the following values:
  484. * @arg @ref LL_USART_PRESCALER_DIV1
  485. * @arg @ref LL_USART_PRESCALER_DIV2
  486. * @arg @ref LL_USART_PRESCALER_DIV4
  487. * @arg @ref LL_USART_PRESCALER_DIV6
  488. * @arg @ref LL_USART_PRESCALER_DIV8
  489. * @arg @ref LL_USART_PRESCALER_DIV10
  490. * @arg @ref LL_USART_PRESCALER_DIV12
  491. * @arg @ref LL_USART_PRESCALER_DIV16
  492. * @arg @ref LL_USART_PRESCALER_DIV32
  493. * @arg @ref LL_USART_PRESCALER_DIV64
  494. * @arg @ref LL_USART_PRESCALER_DIV128
  495. * @arg @ref LL_USART_PRESCALER_DIV256
  496. * @param __BAUDRATE__ Baud rate value to achieve
  497. * @retval USARTDIV value to be used for BRR register filling in OverSampling_8 case
  498. */
  499. #define __LL_USART_DIV_SAMPLING8(__PERIPHCLK__, __PRESCALER__, __BAUDRATE__) (((((__PERIPHCLK__)/(uint32_t)(USART_PRESCALER_TAB[(__PRESCALER__)]))*2U) + ((__BAUDRATE__)/2U))/(__BAUDRATE__))
  500. /**
  501. * @brief Compute USARTDIV value according to Peripheral Clock and
  502. * expected Baud Rate in 16 bits sampling mode (32 bits value of USARTDIV is returned)
  503. * @param __PERIPHCLK__ Peripheral Clock frequency used for USART instance
  504. * @param __PRESCALER__ This parameter can be one of the following values:
  505. * @arg @ref LL_USART_PRESCALER_DIV1
  506. * @arg @ref LL_USART_PRESCALER_DIV2
  507. * @arg @ref LL_USART_PRESCALER_DIV4
  508. * @arg @ref LL_USART_PRESCALER_DIV6
  509. * @arg @ref LL_USART_PRESCALER_DIV8
  510. * @arg @ref LL_USART_PRESCALER_DIV10
  511. * @arg @ref LL_USART_PRESCALER_DIV12
  512. * @arg @ref LL_USART_PRESCALER_DIV16
  513. * @arg @ref LL_USART_PRESCALER_DIV32
  514. * @arg @ref LL_USART_PRESCALER_DIV64
  515. * @arg @ref LL_USART_PRESCALER_DIV128
  516. * @arg @ref LL_USART_PRESCALER_DIV256
  517. * @param __BAUDRATE__ Baud rate value to achieve
  518. * @retval USARTDIV value to be used for BRR register filling in OverSampling_16 case
  519. */
  520. #define __LL_USART_DIV_SAMPLING16(__PERIPHCLK__, __PRESCALER__, __BAUDRATE__) ((((__PERIPHCLK__)/(uint32_t)(USART_PRESCALER_TAB[(__PRESCALER__)])) + ((__BAUDRATE__)/2U))/(__BAUDRATE__))
  521. /**
  522. * @}
  523. */
  524. /**
  525. * @}
  526. */
  527. /* Exported functions --------------------------------------------------------*/
  528. /** @defgroup USART_LL_Exported_Functions USART Exported Functions
  529. * @{
  530. */
  531. /** @defgroup USART_LL_EF_Configuration Configuration functions
  532. * @{
  533. */
  534. /**
  535. * @brief USART Enable
  536. * @rmtoll CR1 UE LL_USART_Enable
  537. * @param USARTx USART Instance
  538. * @retval None
  539. */
  540. __STATIC_INLINE void LL_USART_Enable(USART_TypeDef *USARTx)
  541. {
  542. SET_BIT(USARTx->CR1, USART_CR1_UE);
  543. }
  544. /**
  545. * @brief USART Disable (all USART prescalers and outputs are disabled)
  546. * @note When USART is disabled, USART prescalers and outputs are stopped immediately,
  547. * and current operations are discarded. The configuration of the USART is kept, but all the status
  548. * flags, in the USARTx_ISR are set to their default values.
  549. * @rmtoll CR1 UE LL_USART_Disable
  550. * @param USARTx USART Instance
  551. * @retval None
  552. */
  553. __STATIC_INLINE void LL_USART_Disable(USART_TypeDef *USARTx)
  554. {
  555. CLEAR_BIT(USARTx->CR1, USART_CR1_UE);
  556. }
  557. /**
  558. * @brief Indicate if USART is enabled
  559. * @rmtoll CR1 UE LL_USART_IsEnabled
  560. * @param USARTx USART Instance
  561. * @retval State of bit (1 or 0).
  562. */
  563. __STATIC_INLINE uint32_t LL_USART_IsEnabled(USART_TypeDef *USARTx)
  564. {
  565. return ((READ_BIT(USARTx->CR1, USART_CR1_UE) == (USART_CR1_UE)) ? 1U : 0U);
  566. }
  567. /**
  568. * @brief FIFO Mode Enable
  569. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  570. * FIFO mode feature is supported by the USARTx instance.
  571. * @rmtoll CR1 FIFOEN LL_USART_EnableFIFO
  572. * @param USARTx USART Instance
  573. * @retval None
  574. */
  575. __STATIC_INLINE void LL_USART_EnableFIFO(USART_TypeDef *USARTx)
  576. {
  577. SET_BIT(USARTx->CR1, USART_CR1_FIFOEN);
  578. }
  579. /**
  580. * @brief FIFO Mode Disable
  581. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  582. * FIFO mode feature is supported by the USARTx instance.
  583. * @rmtoll CR1 FIFOEN LL_USART_DisableFIFO
  584. * @param USARTx USART Instance
  585. * @retval None
  586. */
  587. __STATIC_INLINE void LL_USART_DisableFIFO(USART_TypeDef *USARTx)
  588. {
  589. CLEAR_BIT(USARTx->CR1, USART_CR1_FIFOEN);
  590. }
  591. /**
  592. * @brief Indicate if FIFO Mode is enabled
  593. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  594. * FIFO mode feature is supported by the USARTx instance.
  595. * @rmtoll CR1 FIFOEN LL_USART_IsEnabledFIFO
  596. * @param USARTx USART Instance
  597. * @retval State of bit (1 or 0).
  598. */
  599. __STATIC_INLINE uint32_t LL_USART_IsEnabledFIFO(USART_TypeDef *USARTx)
  600. {
  601. return ((READ_BIT(USARTx->CR1, USART_CR1_FIFOEN) == (USART_CR1_FIFOEN)) ? 1U : 0U);
  602. }
  603. /**
  604. * @brief Configure TX FIFO Threshold
  605. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  606. * FIFO mode feature is supported by the USARTx instance.
  607. * @rmtoll CR3 TXFTCFG LL_USART_SetTXFIFOThreshold
  608. * @param USARTx USART Instance
  609. * @param Threshold This parameter can be one of the following values:
  610. * @arg @ref LL_USART_FIFOTHRESHOLD_1_8
  611. * @arg @ref LL_USART_FIFOTHRESHOLD_1_4
  612. * @arg @ref LL_USART_FIFOTHRESHOLD_1_2
  613. * @arg @ref LL_USART_FIFOTHRESHOLD_3_4
  614. * @arg @ref LL_USART_FIFOTHRESHOLD_7_8
  615. * @arg @ref LL_USART_FIFOTHRESHOLD_8_8
  616. * @retval None
  617. */
  618. __STATIC_INLINE void LL_USART_SetTXFIFOThreshold(USART_TypeDef *USARTx, uint32_t Threshold)
  619. {
  620. MODIFY_REG(USARTx->CR3, USART_CR3_TXFTCFG, Threshold << USART_CR3_TXFTCFG_Pos);
  621. }
  622. /**
  623. * @brief Return TX FIFO Threshold Configuration
  624. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  625. * FIFO mode feature is supported by the USARTx instance.
  626. * @rmtoll CR3 TXFTCFG LL_USART_GetTXFIFOThreshold
  627. * @param USARTx USART Instance
  628. * @retval Returned value can be one of the following values:
  629. * @arg @ref LL_USART_FIFOTHRESHOLD_1_8
  630. * @arg @ref LL_USART_FIFOTHRESHOLD_1_4
  631. * @arg @ref LL_USART_FIFOTHRESHOLD_1_2
  632. * @arg @ref LL_USART_FIFOTHRESHOLD_3_4
  633. * @arg @ref LL_USART_FIFOTHRESHOLD_7_8
  634. * @arg @ref LL_USART_FIFOTHRESHOLD_8_8
  635. */
  636. __STATIC_INLINE uint32_t LL_USART_GetTXFIFOThreshold(USART_TypeDef *USARTx)
  637. {
  638. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_TXFTCFG) >> USART_CR3_TXFTCFG_Pos);
  639. }
  640. /**
  641. * @brief Configure RX FIFO Threshold
  642. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  643. * FIFO mode feature is supported by the USARTx instance.
  644. * @rmtoll CR3 RXFTCFG LL_USART_SetRXFIFOThreshold
  645. * @param USARTx USART Instance
  646. * @param Threshold This parameter can be one of the following values:
  647. * @arg @ref LL_USART_FIFOTHRESHOLD_1_8
  648. * @arg @ref LL_USART_FIFOTHRESHOLD_1_4
  649. * @arg @ref LL_USART_FIFOTHRESHOLD_1_2
  650. * @arg @ref LL_USART_FIFOTHRESHOLD_3_4
  651. * @arg @ref LL_USART_FIFOTHRESHOLD_7_8
  652. * @arg @ref LL_USART_FIFOTHRESHOLD_8_8
  653. * @retval None
  654. */
  655. __STATIC_INLINE void LL_USART_SetRXFIFOThreshold(USART_TypeDef *USARTx, uint32_t Threshold)
  656. {
  657. MODIFY_REG(USARTx->CR3, USART_CR3_RXFTCFG, Threshold << USART_CR3_RXFTCFG_Pos);
  658. }
  659. /**
  660. * @brief Return RX FIFO Threshold Configuration
  661. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  662. * FIFO mode feature is supported by the USARTx instance.
  663. * @rmtoll CR3 RXFTCFG LL_USART_GetRXFIFOThreshold
  664. * @param USARTx USART Instance
  665. * @retval Returned value can be one of the following values:
  666. * @arg @ref LL_USART_FIFOTHRESHOLD_1_8
  667. * @arg @ref LL_USART_FIFOTHRESHOLD_1_4
  668. * @arg @ref LL_USART_FIFOTHRESHOLD_1_2
  669. * @arg @ref LL_USART_FIFOTHRESHOLD_3_4
  670. * @arg @ref LL_USART_FIFOTHRESHOLD_7_8
  671. * @arg @ref LL_USART_FIFOTHRESHOLD_8_8
  672. */
  673. __STATIC_INLINE uint32_t LL_USART_GetRXFIFOThreshold(USART_TypeDef *USARTx)
  674. {
  675. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_RXFTCFG) >> USART_CR3_RXFTCFG_Pos);
  676. }
  677. /**
  678. * @brief Configure TX and RX FIFOs Threshold
  679. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  680. * FIFO mode feature is supported by the USARTx instance.
  681. * @rmtoll CR3 TXFTCFG LL_USART_ConfigFIFOsThreshold\n
  682. * CR3 RXFTCFG LL_USART_ConfigFIFOsThreshold
  683. * @param USARTx USART Instance
  684. * @param TXThreshold This parameter can be one of the following values:
  685. * @arg @ref LL_USART_FIFOTHRESHOLD_1_8
  686. * @arg @ref LL_USART_FIFOTHRESHOLD_1_4
  687. * @arg @ref LL_USART_FIFOTHRESHOLD_1_2
  688. * @arg @ref LL_USART_FIFOTHRESHOLD_3_4
  689. * @arg @ref LL_USART_FIFOTHRESHOLD_7_8
  690. * @arg @ref LL_USART_FIFOTHRESHOLD_8_8
  691. * @param RXThreshold This parameter can be one of the following values:
  692. * @arg @ref LL_USART_FIFOTHRESHOLD_1_8
  693. * @arg @ref LL_USART_FIFOTHRESHOLD_1_4
  694. * @arg @ref LL_USART_FIFOTHRESHOLD_1_2
  695. * @arg @ref LL_USART_FIFOTHRESHOLD_3_4
  696. * @arg @ref LL_USART_FIFOTHRESHOLD_7_8
  697. * @arg @ref LL_USART_FIFOTHRESHOLD_8_8
  698. * @retval None
  699. */
  700. __STATIC_INLINE void LL_USART_ConfigFIFOsThreshold(USART_TypeDef *USARTx, uint32_t TXThreshold, uint32_t RXThreshold)
  701. {
  702. MODIFY_REG(USARTx->CR3, USART_CR3_TXFTCFG | USART_CR3_RXFTCFG, (TXThreshold << USART_CR3_TXFTCFG_Pos) | (RXThreshold << USART_CR3_RXFTCFG_Pos));
  703. }
  704. /**
  705. * @brief USART enabled in STOP Mode.
  706. * @note When this function is enabled, USART is able to wake up the MCU from Stop mode, provided that
  707. * USART clock selection is HSI or LSE in RCC.
  708. * @note Macro @ref IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  709. * Wake-up from Stop mode feature is supported by the USARTx instance.
  710. * @rmtoll CR1 UESM LL_USART_EnableInStopMode
  711. * @param USARTx USART Instance
  712. * @retval None
  713. */
  714. __STATIC_INLINE void LL_USART_EnableInStopMode(USART_TypeDef *USARTx)
  715. {
  716. SET_BIT(USARTx->CR1, USART_CR1_UESM);
  717. }
  718. /**
  719. * @brief USART disabled in STOP Mode.
  720. * @note When this function is disabled, USART is not able to wake up the MCU from Stop mode
  721. * @note Macro @ref IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  722. * Wake-up from Stop mode feature is supported by the USARTx instance.
  723. * @rmtoll CR1 UESM LL_USART_DisableInStopMode
  724. * @param USARTx USART Instance
  725. * @retval None
  726. */
  727. __STATIC_INLINE void LL_USART_DisableInStopMode(USART_TypeDef *USARTx)
  728. {
  729. CLEAR_BIT(USARTx->CR1, USART_CR1_UESM);
  730. }
  731. /**
  732. * @brief Indicate if USART is enabled in STOP Mode (able to wake up MCU from Stop mode or not)
  733. * @note Macro @ref IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  734. * Wake-up from Stop mode feature is supported by the USARTx instance.
  735. * @rmtoll CR1 UESM LL_USART_IsEnabledInStopMode
  736. * @param USARTx USART Instance
  737. * @retval State of bit (1 or 0).
  738. */
  739. __STATIC_INLINE uint32_t LL_USART_IsEnabledInStopMode(USART_TypeDef *USARTx)
  740. {
  741. return ((READ_BIT(USARTx->CR1, USART_CR1_UESM) == (USART_CR1_UESM)) ? 1U : 0U);
  742. }
  743. /**
  744. * @brief Receiver Enable (Receiver is enabled and begins searching for a start bit)
  745. * @rmtoll CR1 RE LL_USART_EnableDirectionRx
  746. * @param USARTx USART Instance
  747. * @retval None
  748. */
  749. __STATIC_INLINE void LL_USART_EnableDirectionRx(USART_TypeDef *USARTx)
  750. {
  751. SET_BIT(USARTx->CR1, USART_CR1_RE);
  752. }
  753. /**
  754. * @brief Receiver Disable
  755. * @rmtoll CR1 RE LL_USART_DisableDirectionRx
  756. * @param USARTx USART Instance
  757. * @retval None
  758. */
  759. __STATIC_INLINE void LL_USART_DisableDirectionRx(USART_TypeDef *USARTx)
  760. {
  761. CLEAR_BIT(USARTx->CR1, USART_CR1_RE);
  762. }
  763. /**
  764. * @brief Transmitter Enable
  765. * @rmtoll CR1 TE LL_USART_EnableDirectionTx
  766. * @param USARTx USART Instance
  767. * @retval None
  768. */
  769. __STATIC_INLINE void LL_USART_EnableDirectionTx(USART_TypeDef *USARTx)
  770. {
  771. SET_BIT(USARTx->CR1, USART_CR1_TE);
  772. }
  773. /**
  774. * @brief Transmitter Disable
  775. * @rmtoll CR1 TE LL_USART_DisableDirectionTx
  776. * @param USARTx USART Instance
  777. * @retval None
  778. */
  779. __STATIC_INLINE void LL_USART_DisableDirectionTx(USART_TypeDef *USARTx)
  780. {
  781. CLEAR_BIT(USARTx->CR1, USART_CR1_TE);
  782. }
  783. /**
  784. * @brief Configure simultaneously enabled/disabled states
  785. * of Transmitter and Receiver
  786. * @rmtoll CR1 RE LL_USART_SetTransferDirection\n
  787. * CR1 TE LL_USART_SetTransferDirection
  788. * @param USARTx USART Instance
  789. * @param TransferDirection This parameter can be one of the following values:
  790. * @arg @ref LL_USART_DIRECTION_NONE
  791. * @arg @ref LL_USART_DIRECTION_RX
  792. * @arg @ref LL_USART_DIRECTION_TX
  793. * @arg @ref LL_USART_DIRECTION_TX_RX
  794. * @retval None
  795. */
  796. __STATIC_INLINE void LL_USART_SetTransferDirection(USART_TypeDef *USARTx, uint32_t TransferDirection)
  797. {
  798. MODIFY_REG(USARTx->CR1, USART_CR1_RE | USART_CR1_TE, TransferDirection);
  799. }
  800. /**
  801. * @brief Return enabled/disabled states of Transmitter and Receiver
  802. * @rmtoll CR1 RE LL_USART_GetTransferDirection\n
  803. * CR1 TE LL_USART_GetTransferDirection
  804. * @param USARTx USART Instance
  805. * @retval Returned value can be one of the following values:
  806. * @arg @ref LL_USART_DIRECTION_NONE
  807. * @arg @ref LL_USART_DIRECTION_RX
  808. * @arg @ref LL_USART_DIRECTION_TX
  809. * @arg @ref LL_USART_DIRECTION_TX_RX
  810. */
  811. __STATIC_INLINE uint32_t LL_USART_GetTransferDirection(USART_TypeDef *USARTx)
  812. {
  813. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_RE | USART_CR1_TE));
  814. }
  815. /**
  816. * @brief Configure Parity (enabled/disabled and parity mode if enabled).
  817. * @note This function selects if hardware parity control (generation and detection) is enabled or disabled.
  818. * When the parity control is enabled (Odd or Even), computed parity bit is inserted at the MSB position
  819. * (9th or 8th bit depending on data width) and parity is checked on the received data.
  820. * @rmtoll CR1 PS LL_USART_SetParity\n
  821. * CR1 PCE LL_USART_SetParity
  822. * @param USARTx USART Instance
  823. * @param Parity This parameter can be one of the following values:
  824. * @arg @ref LL_USART_PARITY_NONE
  825. * @arg @ref LL_USART_PARITY_EVEN
  826. * @arg @ref LL_USART_PARITY_ODD
  827. * @retval None
  828. */
  829. __STATIC_INLINE void LL_USART_SetParity(USART_TypeDef *USARTx, uint32_t Parity)
  830. {
  831. MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE, Parity);
  832. }
  833. /**
  834. * @brief Return Parity configuration (enabled/disabled and parity mode if enabled)
  835. * @rmtoll CR1 PS LL_USART_GetParity\n
  836. * CR1 PCE LL_USART_GetParity
  837. * @param USARTx USART Instance
  838. * @retval Returned value can be one of the following values:
  839. * @arg @ref LL_USART_PARITY_NONE
  840. * @arg @ref LL_USART_PARITY_EVEN
  841. * @arg @ref LL_USART_PARITY_ODD
  842. */
  843. __STATIC_INLINE uint32_t LL_USART_GetParity(USART_TypeDef *USARTx)
  844. {
  845. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE));
  846. }
  847. /**
  848. * @brief Set Receiver Wake Up method from Mute mode.
  849. * @rmtoll CR1 WAKE LL_USART_SetWakeUpMethod
  850. * @param USARTx USART Instance
  851. * @param Method This parameter can be one of the following values:
  852. * @arg @ref LL_USART_WAKEUP_IDLELINE
  853. * @arg @ref LL_USART_WAKEUP_ADDRESSMARK
  854. * @retval None
  855. */
  856. __STATIC_INLINE void LL_USART_SetWakeUpMethod(USART_TypeDef *USARTx, uint32_t Method)
  857. {
  858. MODIFY_REG(USARTx->CR1, USART_CR1_WAKE, Method);
  859. }
  860. /**
  861. * @brief Return Receiver Wake Up method from Mute mode
  862. * @rmtoll CR1 WAKE LL_USART_GetWakeUpMethod
  863. * @param USARTx USART Instance
  864. * @retval Returned value can be one of the following values:
  865. * @arg @ref LL_USART_WAKEUP_IDLELINE
  866. * @arg @ref LL_USART_WAKEUP_ADDRESSMARK
  867. */
  868. __STATIC_INLINE uint32_t LL_USART_GetWakeUpMethod(USART_TypeDef *USARTx)
  869. {
  870. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_WAKE));
  871. }
  872. /**
  873. * @brief Set Word length (i.e. nb of data bits, excluding start and stop bits)
  874. * @rmtoll CR1 M0 LL_USART_SetDataWidth\n
  875. * CR1 M1 LL_USART_SetDataWidth
  876. * @param USARTx USART Instance
  877. * @param DataWidth This parameter can be one of the following values:
  878. * @arg @ref LL_USART_DATAWIDTH_7B
  879. * @arg @ref LL_USART_DATAWIDTH_8B
  880. * @arg @ref LL_USART_DATAWIDTH_9B
  881. * @retval None
  882. */
  883. __STATIC_INLINE void LL_USART_SetDataWidth(USART_TypeDef *USARTx, uint32_t DataWidth)
  884. {
  885. MODIFY_REG(USARTx->CR1, USART_CR1_M, DataWidth);
  886. }
  887. /**
  888. * @brief Return Word length (i.e. nb of data bits, excluding start and stop bits)
  889. * @rmtoll CR1 M0 LL_USART_GetDataWidth\n
  890. * CR1 M1 LL_USART_GetDataWidth
  891. * @param USARTx USART Instance
  892. * @retval Returned value can be one of the following values:
  893. * @arg @ref LL_USART_DATAWIDTH_7B
  894. * @arg @ref LL_USART_DATAWIDTH_8B
  895. * @arg @ref LL_USART_DATAWIDTH_9B
  896. */
  897. __STATIC_INLINE uint32_t LL_USART_GetDataWidth(USART_TypeDef *USARTx)
  898. {
  899. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_M));
  900. }
  901. /**
  902. * @brief Allow switch between Mute Mode and Active mode
  903. * @rmtoll CR1 MME LL_USART_EnableMuteMode
  904. * @param USARTx USART Instance
  905. * @retval None
  906. */
  907. __STATIC_INLINE void LL_USART_EnableMuteMode(USART_TypeDef *USARTx)
  908. {
  909. SET_BIT(USARTx->CR1, USART_CR1_MME);
  910. }
  911. /**
  912. * @brief Prevent Mute Mode use. Set Receiver in active mode permanently.
  913. * @rmtoll CR1 MME LL_USART_DisableMuteMode
  914. * @param USARTx USART Instance
  915. * @retval None
  916. */
  917. __STATIC_INLINE void LL_USART_DisableMuteMode(USART_TypeDef *USARTx)
  918. {
  919. CLEAR_BIT(USARTx->CR1, USART_CR1_MME);
  920. }
  921. /**
  922. * @brief Indicate if switch between Mute Mode and Active mode is allowed
  923. * @rmtoll CR1 MME LL_USART_IsEnabledMuteMode
  924. * @param USARTx USART Instance
  925. * @retval State of bit (1 or 0).
  926. */
  927. __STATIC_INLINE uint32_t LL_USART_IsEnabledMuteMode(USART_TypeDef *USARTx)
  928. {
  929. return ((READ_BIT(USARTx->CR1, USART_CR1_MME) == (USART_CR1_MME)) ? 1U : 0U);
  930. }
  931. /**
  932. * @brief Set Oversampling to 8-bit or 16-bit mode
  933. * @rmtoll CR1 OVER8 LL_USART_SetOverSampling
  934. * @param USARTx USART Instance
  935. * @param OverSampling This parameter can be one of the following values:
  936. * @arg @ref LL_USART_OVERSAMPLING_16
  937. * @arg @ref LL_USART_OVERSAMPLING_8
  938. * @retval None
  939. */
  940. __STATIC_INLINE void LL_USART_SetOverSampling(USART_TypeDef *USARTx, uint32_t OverSampling)
  941. {
  942. MODIFY_REG(USARTx->CR1, USART_CR1_OVER8, OverSampling);
  943. }
  944. /**
  945. * @brief Return Oversampling mode
  946. * @rmtoll CR1 OVER8 LL_USART_GetOverSampling
  947. * @param USARTx USART Instance
  948. * @retval Returned value can be one of the following values:
  949. * @arg @ref LL_USART_OVERSAMPLING_16
  950. * @arg @ref LL_USART_OVERSAMPLING_8
  951. */
  952. __STATIC_INLINE uint32_t LL_USART_GetOverSampling(USART_TypeDef *USARTx)
  953. {
  954. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_OVER8));
  955. }
  956. /**
  957. * @brief Configure if Clock pulse of the last data bit is output to the SCLK pin or not
  958. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  959. * Synchronous mode is supported by the USARTx instance.
  960. * @rmtoll CR2 LBCL LL_USART_SetLastClkPulseOutput
  961. * @param USARTx USART Instance
  962. * @param LastBitClockPulse This parameter can be one of the following values:
  963. * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
  964. * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
  965. * @retval None
  966. */
  967. __STATIC_INLINE void LL_USART_SetLastClkPulseOutput(USART_TypeDef *USARTx, uint32_t LastBitClockPulse)
  968. {
  969. MODIFY_REG(USARTx->CR2, USART_CR2_LBCL, LastBitClockPulse);
  970. }
  971. /**
  972. * @brief Retrieve Clock pulse of the last data bit output configuration
  973. * (Last bit Clock pulse output to the SCLK pin or not)
  974. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  975. * Synchronous mode is supported by the USARTx instance.
  976. * @rmtoll CR2 LBCL LL_USART_GetLastClkPulseOutput
  977. * @param USARTx USART Instance
  978. * @retval Returned value can be one of the following values:
  979. * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
  980. * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
  981. */
  982. __STATIC_INLINE uint32_t LL_USART_GetLastClkPulseOutput(USART_TypeDef *USARTx)
  983. {
  984. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBCL));
  985. }
  986. /**
  987. * @brief Select the phase of the clock output on the SCLK pin in synchronous mode
  988. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  989. * Synchronous mode is supported by the USARTx instance.
  990. * @rmtoll CR2 CPHA LL_USART_SetClockPhase
  991. * @param USARTx USART Instance
  992. * @param ClockPhase This parameter can be one of the following values:
  993. * @arg @ref LL_USART_PHASE_1EDGE
  994. * @arg @ref LL_USART_PHASE_2EDGE
  995. * @retval None
  996. */
  997. __STATIC_INLINE void LL_USART_SetClockPhase(USART_TypeDef *USARTx, uint32_t ClockPhase)
  998. {
  999. MODIFY_REG(USARTx->CR2, USART_CR2_CPHA, ClockPhase);
  1000. }
  1001. /**
  1002. * @brief Return phase of the clock output on the SCLK pin in synchronous mode
  1003. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  1004. * Synchronous mode is supported by the USARTx instance.
  1005. * @rmtoll CR2 CPHA LL_USART_GetClockPhase
  1006. * @param USARTx USART Instance
  1007. * @retval Returned value can be one of the following values:
  1008. * @arg @ref LL_USART_PHASE_1EDGE
  1009. * @arg @ref LL_USART_PHASE_2EDGE
  1010. */
  1011. __STATIC_INLINE uint32_t LL_USART_GetClockPhase(USART_TypeDef *USARTx)
  1012. {
  1013. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPHA));
  1014. }
  1015. /**
  1016. * @brief Select the polarity of the clock output on the SCLK pin in synchronous mode
  1017. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  1018. * Synchronous mode is supported by the USARTx instance.
  1019. * @rmtoll CR2 CPOL LL_USART_SetClockPolarity
  1020. * @param USARTx USART Instance
  1021. * @param ClockPolarity This parameter can be one of the following values:
  1022. * @arg @ref LL_USART_POLARITY_LOW
  1023. * @arg @ref LL_USART_POLARITY_HIGH
  1024. * @retval None
  1025. */
  1026. __STATIC_INLINE void LL_USART_SetClockPolarity(USART_TypeDef *USARTx, uint32_t ClockPolarity)
  1027. {
  1028. MODIFY_REG(USARTx->CR2, USART_CR2_CPOL, ClockPolarity);
  1029. }
  1030. /**
  1031. * @brief Return polarity of the clock output on the SCLK pin in synchronous mode
  1032. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  1033. * Synchronous mode is supported by the USARTx instance.
  1034. * @rmtoll CR2 CPOL LL_USART_GetClockPolarity
  1035. * @param USARTx USART Instance
  1036. * @retval Returned value can be one of the following values:
  1037. * @arg @ref LL_USART_POLARITY_LOW
  1038. * @arg @ref LL_USART_POLARITY_HIGH
  1039. */
  1040. __STATIC_INLINE uint32_t LL_USART_GetClockPolarity(USART_TypeDef *USARTx)
  1041. {
  1042. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPOL));
  1043. }
  1044. /**
  1045. * @brief Configure Clock signal format (Phase Polarity and choice about output of last bit clock pulse)
  1046. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  1047. * Synchronous mode is supported by the USARTx instance.
  1048. * @note Call of this function is equivalent to following function call sequence :
  1049. * - Clock Phase configuration using @ref LL_USART_SetClockPhase() function
  1050. * - Clock Polarity configuration using @ref LL_USART_SetClockPolarity() function
  1051. * - Output of Last bit Clock pulse configuration using @ref LL_USART_SetLastClkPulseOutput() function
  1052. * @rmtoll CR2 CPHA LL_USART_ConfigClock\n
  1053. * CR2 CPOL LL_USART_ConfigClock\n
  1054. * CR2 LBCL LL_USART_ConfigClock
  1055. * @param USARTx USART Instance
  1056. * @param Phase This parameter can be one of the following values:
  1057. * @arg @ref LL_USART_PHASE_1EDGE
  1058. * @arg @ref LL_USART_PHASE_2EDGE
  1059. * @param Polarity This parameter can be one of the following values:
  1060. * @arg @ref LL_USART_POLARITY_LOW
  1061. * @arg @ref LL_USART_POLARITY_HIGH
  1062. * @param LBCPOutput This parameter can be one of the following values:
  1063. * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
  1064. * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
  1065. * @retval None
  1066. */
  1067. __STATIC_INLINE void LL_USART_ConfigClock(USART_TypeDef *USARTx, uint32_t Phase, uint32_t Polarity, uint32_t LBCPOutput)
  1068. {
  1069. MODIFY_REG(USARTx->CR2, USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL, Phase | Polarity | LBCPOutput);
  1070. }
  1071. /**
  1072. * @brief Configure Clock source prescaler for baudrate generator and oversampling
  1073. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  1074. * FIFO mode feature is supported by the USARTx instance.
  1075. * @rmtoll PRESC PRESCALER LL_USART_SetPrescaler
  1076. * @param USARTx USART Instance
  1077. * @param PrescalerValue This parameter can be one of the following values:
  1078. * @arg @ref LL_USART_PRESCALER_DIV1
  1079. * @arg @ref LL_USART_PRESCALER_DIV2
  1080. * @arg @ref LL_USART_PRESCALER_DIV4
  1081. * @arg @ref LL_USART_PRESCALER_DIV6
  1082. * @arg @ref LL_USART_PRESCALER_DIV8
  1083. * @arg @ref LL_USART_PRESCALER_DIV10
  1084. * @arg @ref LL_USART_PRESCALER_DIV12
  1085. * @arg @ref LL_USART_PRESCALER_DIV16
  1086. * @arg @ref LL_USART_PRESCALER_DIV32
  1087. * @arg @ref LL_USART_PRESCALER_DIV64
  1088. * @arg @ref LL_USART_PRESCALER_DIV128
  1089. * @arg @ref LL_USART_PRESCALER_DIV256
  1090. * @retval None
  1091. */
  1092. __STATIC_INLINE void LL_USART_SetPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
  1093. {
  1094. MODIFY_REG(USARTx->PRESC, USART_PRESC_PRESCALER, (uint16_t)PrescalerValue);
  1095. }
  1096. /**
  1097. * @brief Retrieve the Clock source prescaler for baudrate generator and oversampling
  1098. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  1099. * FIFO mode feature is supported by the USARTx instance.
  1100. * @rmtoll PRESC PRESCALER LL_USART_GetPrescaler
  1101. * @param USARTx USART Instance
  1102. * @retval Returned value can be one of the following values:
  1103. * @arg @ref LL_USART_PRESCALER_DIV1
  1104. * @arg @ref LL_USART_PRESCALER_DIV2
  1105. * @arg @ref LL_USART_PRESCALER_DIV4
  1106. * @arg @ref LL_USART_PRESCALER_DIV6
  1107. * @arg @ref LL_USART_PRESCALER_DIV8
  1108. * @arg @ref LL_USART_PRESCALER_DIV10
  1109. * @arg @ref LL_USART_PRESCALER_DIV12
  1110. * @arg @ref LL_USART_PRESCALER_DIV16
  1111. * @arg @ref LL_USART_PRESCALER_DIV32
  1112. * @arg @ref LL_USART_PRESCALER_DIV64
  1113. * @arg @ref LL_USART_PRESCALER_DIV128
  1114. * @arg @ref LL_USART_PRESCALER_DIV256
  1115. */
  1116. __STATIC_INLINE uint32_t LL_USART_GetPrescaler(USART_TypeDef *USARTx)
  1117. {
  1118. return (uint32_t)(READ_BIT(USARTx->PRESC, USART_PRESC_PRESCALER));
  1119. }
  1120. /**
  1121. * @brief Enable Clock output on SCLK pin
  1122. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  1123. * Synchronous mode is supported by the USARTx instance.
  1124. * @rmtoll CR2 CLKEN LL_USART_EnableSCLKOutput
  1125. * @param USARTx USART Instance
  1126. * @retval None
  1127. */
  1128. __STATIC_INLINE void LL_USART_EnableSCLKOutput(USART_TypeDef *USARTx)
  1129. {
  1130. SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
  1131. }
  1132. /**
  1133. * @brief Disable Clock output on SCLK pin
  1134. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  1135. * Synchronous mode is supported by the USARTx instance.
  1136. * @rmtoll CR2 CLKEN LL_USART_DisableSCLKOutput
  1137. * @param USARTx USART Instance
  1138. * @retval None
  1139. */
  1140. __STATIC_INLINE void LL_USART_DisableSCLKOutput(USART_TypeDef *USARTx)
  1141. {
  1142. CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
  1143. }
  1144. /**
  1145. * @brief Indicate if Clock output on SCLK pin is enabled
  1146. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  1147. * Synchronous mode is supported by the USARTx instance.
  1148. * @rmtoll CR2 CLKEN LL_USART_IsEnabledSCLKOutput
  1149. * @param USARTx USART Instance
  1150. * @retval State of bit (1 or 0).
  1151. */
  1152. __STATIC_INLINE uint32_t LL_USART_IsEnabledSCLKOutput(USART_TypeDef *USARTx)
  1153. {
  1154. return ((READ_BIT(USARTx->CR2, USART_CR2_CLKEN) == (USART_CR2_CLKEN)) ? 1U : 0U);
  1155. }
  1156. /**
  1157. * @brief Set the length of the stop bits
  1158. * @rmtoll CR2 STOP LL_USART_SetStopBitsLength
  1159. * @param USARTx USART Instance
  1160. * @param StopBits This parameter can be one of the following values:
  1161. * @arg @ref LL_USART_STOPBITS_0_5
  1162. * @arg @ref LL_USART_STOPBITS_1
  1163. * @arg @ref LL_USART_STOPBITS_1_5
  1164. * @arg @ref LL_USART_STOPBITS_2
  1165. * @retval None
  1166. */
  1167. __STATIC_INLINE void LL_USART_SetStopBitsLength(USART_TypeDef *USARTx, uint32_t StopBits)
  1168. {
  1169. MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
  1170. }
  1171. /**
  1172. * @brief Retrieve the length of the stop bits
  1173. * @rmtoll CR2 STOP LL_USART_GetStopBitsLength
  1174. * @param USARTx USART Instance
  1175. * @retval Returned value can be one of the following values:
  1176. * @arg @ref LL_USART_STOPBITS_0_5
  1177. * @arg @ref LL_USART_STOPBITS_1
  1178. * @arg @ref LL_USART_STOPBITS_1_5
  1179. * @arg @ref LL_USART_STOPBITS_2
  1180. */
  1181. __STATIC_INLINE uint32_t LL_USART_GetStopBitsLength(USART_TypeDef *USARTx)
  1182. {
  1183. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_STOP));
  1184. }
  1185. /**
  1186. * @brief Configure Character frame format (Datawidth, Parity control, Stop Bits)
  1187. * @note Call of this function is equivalent to following function call sequence :
  1188. * - Data Width configuration using @ref LL_USART_SetDataWidth() function
  1189. * - Parity Control and mode configuration using @ref LL_USART_SetParity() function
  1190. * - Stop bits configuration using @ref LL_USART_SetStopBitsLength() function
  1191. * @rmtoll CR1 PS LL_USART_ConfigCharacter\n
  1192. * CR1 PCE LL_USART_ConfigCharacter\n
  1193. * CR1 M0 LL_USART_ConfigCharacter\n
  1194. * CR1 M1 LL_USART_ConfigCharacter\n
  1195. * CR2 STOP LL_USART_ConfigCharacter
  1196. * @param USARTx USART Instance
  1197. * @param DataWidth This parameter can be one of the following values:
  1198. * @arg @ref LL_USART_DATAWIDTH_7B
  1199. * @arg @ref LL_USART_DATAWIDTH_8B
  1200. * @arg @ref LL_USART_DATAWIDTH_9B
  1201. * @param Parity This parameter can be one of the following values:
  1202. * @arg @ref LL_USART_PARITY_NONE
  1203. * @arg @ref LL_USART_PARITY_EVEN
  1204. * @arg @ref LL_USART_PARITY_ODD
  1205. * @param StopBits This parameter can be one of the following values:
  1206. * @arg @ref LL_USART_STOPBITS_0_5
  1207. * @arg @ref LL_USART_STOPBITS_1
  1208. * @arg @ref LL_USART_STOPBITS_1_5
  1209. * @arg @ref LL_USART_STOPBITS_2
  1210. * @retval None
  1211. */
  1212. __STATIC_INLINE void LL_USART_ConfigCharacter(USART_TypeDef *USARTx, uint32_t DataWidth, uint32_t Parity,
  1213. uint32_t StopBits)
  1214. {
  1215. MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE | USART_CR1_M, Parity | DataWidth);
  1216. MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
  1217. }
  1218. /**
  1219. * @brief Configure TX/RX pins swapping setting.
  1220. * @rmtoll CR2 SWAP LL_USART_SetTXRXSwap
  1221. * @param USARTx USART Instance
  1222. * @param SwapConfig This parameter can be one of the following values:
  1223. * @arg @ref LL_USART_TXRX_STANDARD
  1224. * @arg @ref LL_USART_TXRX_SWAPPED
  1225. * @retval None
  1226. */
  1227. __STATIC_INLINE void LL_USART_SetTXRXSwap(USART_TypeDef *USARTx, uint32_t SwapConfig)
  1228. {
  1229. MODIFY_REG(USARTx->CR2, USART_CR2_SWAP, SwapConfig);
  1230. }
  1231. /**
  1232. * @brief Retrieve TX/RX pins swapping configuration.
  1233. * @rmtoll CR2 SWAP LL_USART_GetTXRXSwap
  1234. * @param USARTx USART Instance
  1235. * @retval Returned value can be one of the following values:
  1236. * @arg @ref LL_USART_TXRX_STANDARD
  1237. * @arg @ref LL_USART_TXRX_SWAPPED
  1238. */
  1239. __STATIC_INLINE uint32_t LL_USART_GetTXRXSwap(USART_TypeDef *USARTx)
  1240. {
  1241. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_SWAP));
  1242. }
  1243. /**
  1244. * @brief Configure RX pin active level logic
  1245. * @rmtoll CR2 RXINV LL_USART_SetRXPinLevel
  1246. * @param USARTx USART Instance
  1247. * @param PinInvMethod This parameter can be one of the following values:
  1248. * @arg @ref LL_USART_RXPIN_LEVEL_STANDARD
  1249. * @arg @ref LL_USART_RXPIN_LEVEL_INVERTED
  1250. * @retval None
  1251. */
  1252. __STATIC_INLINE void LL_USART_SetRXPinLevel(USART_TypeDef *USARTx, uint32_t PinInvMethod)
  1253. {
  1254. MODIFY_REG(USARTx->CR2, USART_CR2_RXINV, PinInvMethod);
  1255. }
  1256. /**
  1257. * @brief Retrieve RX pin active level logic configuration
  1258. * @rmtoll CR2 RXINV LL_USART_GetRXPinLevel
  1259. * @param USARTx USART Instance
  1260. * @retval Returned value can be one of the following values:
  1261. * @arg @ref LL_USART_RXPIN_LEVEL_STANDARD
  1262. * @arg @ref LL_USART_RXPIN_LEVEL_INVERTED
  1263. */
  1264. __STATIC_INLINE uint32_t LL_USART_GetRXPinLevel(USART_TypeDef *USARTx)
  1265. {
  1266. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_RXINV));
  1267. }
  1268. /**
  1269. * @brief Configure TX pin active level logic
  1270. * @rmtoll CR2 TXINV LL_USART_SetTXPinLevel
  1271. * @param USARTx USART Instance
  1272. * @param PinInvMethod This parameter can be one of the following values:
  1273. * @arg @ref LL_USART_TXPIN_LEVEL_STANDARD
  1274. * @arg @ref LL_USART_TXPIN_LEVEL_INVERTED
  1275. * @retval None
  1276. */
  1277. __STATIC_INLINE void LL_USART_SetTXPinLevel(USART_TypeDef *USARTx, uint32_t PinInvMethod)
  1278. {
  1279. MODIFY_REG(USARTx->CR2, USART_CR2_TXINV, PinInvMethod);
  1280. }
  1281. /**
  1282. * @brief Retrieve TX pin active level logic configuration
  1283. * @rmtoll CR2 TXINV LL_USART_GetTXPinLevel
  1284. * @param USARTx USART Instance
  1285. * @retval Returned value can be one of the following values:
  1286. * @arg @ref LL_USART_TXPIN_LEVEL_STANDARD
  1287. * @arg @ref LL_USART_TXPIN_LEVEL_INVERTED
  1288. */
  1289. __STATIC_INLINE uint32_t LL_USART_GetTXPinLevel(USART_TypeDef *USARTx)
  1290. {
  1291. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_TXINV));
  1292. }
  1293. /**
  1294. * @brief Configure Binary data logic.
  1295. * @note Allow to define how Logical data from the data register are send/received :
  1296. * either in positive/direct logic (1=H, 0=L) or in negative/inverse logic (1=L, 0=H)
  1297. * @rmtoll CR2 DATAINV LL_USART_SetBinaryDataLogic
  1298. * @param USARTx USART Instance
  1299. * @param DataLogic This parameter can be one of the following values:
  1300. * @arg @ref LL_USART_BINARY_LOGIC_POSITIVE
  1301. * @arg @ref LL_USART_BINARY_LOGIC_NEGATIVE
  1302. * @retval None
  1303. */
  1304. __STATIC_INLINE void LL_USART_SetBinaryDataLogic(USART_TypeDef *USARTx, uint32_t DataLogic)
  1305. {
  1306. MODIFY_REG(USARTx->CR2, USART_CR2_DATAINV, DataLogic);
  1307. }
  1308. /**
  1309. * @brief Retrieve Binary data configuration
  1310. * @rmtoll CR2 DATAINV LL_USART_GetBinaryDataLogic
  1311. * @param USARTx USART Instance
  1312. * @retval Returned value can be one of the following values:
  1313. * @arg @ref LL_USART_BINARY_LOGIC_POSITIVE
  1314. * @arg @ref LL_USART_BINARY_LOGIC_NEGATIVE
  1315. */
  1316. __STATIC_INLINE uint32_t LL_USART_GetBinaryDataLogic(USART_TypeDef *USARTx)
  1317. {
  1318. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_DATAINV));
  1319. }
  1320. /**
  1321. * @brief Configure transfer bit order (either Less or Most Significant Bit First)
  1322. * @note MSB First means data is transmitted/received with the MSB first, following the start bit.
  1323. * LSB First means data is transmitted/received with data bit 0 first, following the start bit.
  1324. * @rmtoll CR2 MSBFIRST LL_USART_SetTransferBitOrder
  1325. * @param USARTx USART Instance
  1326. * @param BitOrder This parameter can be one of the following values:
  1327. * @arg @ref LL_USART_BITORDER_LSBFIRST
  1328. * @arg @ref LL_USART_BITORDER_MSBFIRST
  1329. * @retval None
  1330. */
  1331. __STATIC_INLINE void LL_USART_SetTransferBitOrder(USART_TypeDef *USARTx, uint32_t BitOrder)
  1332. {
  1333. MODIFY_REG(USARTx->CR2, USART_CR2_MSBFIRST, BitOrder);
  1334. }
  1335. /**
  1336. * @brief Return transfer bit order (either Less or Most Significant Bit First)
  1337. * @note MSB First means data is transmitted/received with the MSB first, following the start bit.
  1338. * LSB First means data is transmitted/received with data bit 0 first, following the start bit.
  1339. * @rmtoll CR2 MSBFIRST LL_USART_GetTransferBitOrder
  1340. * @param USARTx USART Instance
  1341. * @retval Returned value can be one of the following values:
  1342. * @arg @ref LL_USART_BITORDER_LSBFIRST
  1343. * @arg @ref LL_USART_BITORDER_MSBFIRST
  1344. */
  1345. __STATIC_INLINE uint32_t LL_USART_GetTransferBitOrder(USART_TypeDef *USARTx)
  1346. {
  1347. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_MSBFIRST));
  1348. }
  1349. /**
  1350. * @brief Enable Auto Baud-Rate Detection
  1351. * @note Macro @ref IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  1352. * Auto Baud Rate detection feature is supported by the USARTx instance.
  1353. * @rmtoll CR2 ABREN LL_USART_EnableAutoBaudRate
  1354. * @param USARTx USART Instance
  1355. * @retval None
  1356. */
  1357. __STATIC_INLINE void LL_USART_EnableAutoBaudRate(USART_TypeDef *USARTx)
  1358. {
  1359. SET_BIT(USARTx->CR2, USART_CR2_ABREN);
  1360. }
  1361. /**
  1362. * @brief Disable Auto Baud-Rate Detection
  1363. * @note Macro @ref IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  1364. * Auto Baud Rate detection feature is supported by the USARTx instance.
  1365. * @rmtoll CR2 ABREN LL_USART_DisableAutoBaudRate
  1366. * @param USARTx USART Instance
  1367. * @retval None
  1368. */
  1369. __STATIC_INLINE void LL_USART_DisableAutoBaudRate(USART_TypeDef *USARTx)
  1370. {
  1371. CLEAR_BIT(USARTx->CR2, USART_CR2_ABREN);
  1372. }
  1373. /**
  1374. * @brief Indicate if Auto Baud-Rate Detection mechanism is enabled
  1375. * @note Macro @ref IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  1376. * Auto Baud Rate detection feature is supported by the USARTx instance.
  1377. * @rmtoll CR2 ABREN LL_USART_IsEnabledAutoBaud
  1378. * @param USARTx USART Instance
  1379. * @retval State of bit (1 or 0).
  1380. */
  1381. __STATIC_INLINE uint32_t LL_USART_IsEnabledAutoBaud(USART_TypeDef *USARTx)
  1382. {
  1383. return ((READ_BIT(USARTx->CR2, USART_CR2_ABREN) == (USART_CR2_ABREN)) ? 1U : 0U);
  1384. }
  1385. /**
  1386. * @brief Set Auto Baud-Rate mode bits
  1387. * @note Macro @ref IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  1388. * Auto Baud Rate detection feature is supported by the USARTx instance.
  1389. * @rmtoll CR2 ABRMODE LL_USART_SetAutoBaudRateMode
  1390. * @param USARTx USART Instance
  1391. * @param AutoBaudRateMode This parameter can be one of the following values:
  1392. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_STARTBIT
  1393. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE
  1394. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_7F_FRAME
  1395. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_55_FRAME
  1396. * @retval None
  1397. */
  1398. __STATIC_INLINE void LL_USART_SetAutoBaudRateMode(USART_TypeDef *USARTx, uint32_t AutoBaudRateMode)
  1399. {
  1400. MODIFY_REG(USARTx->CR2, USART_CR2_ABRMODE, AutoBaudRateMode);
  1401. }
  1402. /**
  1403. * @brief Return Auto Baud-Rate mode
  1404. * @note Macro @ref IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  1405. * Auto Baud Rate detection feature is supported by the USARTx instance.
  1406. * @rmtoll CR2 ABRMODE LL_USART_GetAutoBaudRateMode
  1407. * @param USARTx USART Instance
  1408. * @retval Returned value can be one of the following values:
  1409. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_STARTBIT
  1410. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE
  1411. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_7F_FRAME
  1412. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_55_FRAME
  1413. */
  1414. __STATIC_INLINE uint32_t LL_USART_GetAutoBaudRateMode(USART_TypeDef *USARTx)
  1415. {
  1416. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ABRMODE));
  1417. }
  1418. /**
  1419. * @brief Enable Receiver Timeout
  1420. * @rmtoll CR2 RTOEN LL_USART_EnableRxTimeout
  1421. * @param USARTx USART Instance
  1422. * @retval None
  1423. */
  1424. __STATIC_INLINE void LL_USART_EnableRxTimeout(USART_TypeDef *USARTx)
  1425. {
  1426. SET_BIT(USARTx->CR2, USART_CR2_RTOEN);
  1427. }
  1428. /**
  1429. * @brief Disable Receiver Timeout
  1430. * @rmtoll CR2 RTOEN LL_USART_DisableRxTimeout
  1431. * @param USARTx USART Instance
  1432. * @retval None
  1433. */
  1434. __STATIC_INLINE void LL_USART_DisableRxTimeout(USART_TypeDef *USARTx)
  1435. {
  1436. CLEAR_BIT(USARTx->CR2, USART_CR2_RTOEN);
  1437. }
  1438. /**
  1439. * @brief Indicate if Receiver Timeout feature is enabled
  1440. * @rmtoll CR2 RTOEN LL_USART_IsEnabledRxTimeout
  1441. * @param USARTx USART Instance
  1442. * @retval State of bit (1 or 0).
  1443. */
  1444. __STATIC_INLINE uint32_t LL_USART_IsEnabledRxTimeout(USART_TypeDef *USARTx)
  1445. {
  1446. return ((READ_BIT(USARTx->CR2, USART_CR2_RTOEN) == (USART_CR2_RTOEN)) ? 1U : 0U);
  1447. }
  1448. /**
  1449. * @brief Set Address of the USART node.
  1450. * @note This is used in multiprocessor communication during Mute mode or Stop mode,
  1451. * for wake up with address mark detection.
  1452. * @note 4bits address node is used when 4-bit Address Detection is selected in ADDM7.
  1453. * (b7-b4 should be set to 0)
  1454. * 8bits address node is used when 7-bit Address Detection is selected in ADDM7.
  1455. * (This is used in multiprocessor communication during Mute mode or Stop mode,
  1456. * for wake up with 7-bit address mark detection.
  1457. * The MSB of the character sent by the transmitter should be equal to 1.
  1458. * It may also be used for character detection during normal reception,
  1459. * Mute mode inactive (for example, end of block detection in ModBus protocol).
  1460. * In this case, the whole received character (8-bit) is compared to the ADD[7:0]
  1461. * value and CMF flag is set on match)
  1462. * @rmtoll CR2 ADD LL_USART_ConfigNodeAddress\n
  1463. * CR2 ADDM7 LL_USART_ConfigNodeAddress
  1464. * @param USARTx USART Instance
  1465. * @param AddressLen This parameter can be one of the following values:
  1466. * @arg @ref LL_USART_ADDRESS_DETECT_4B
  1467. * @arg @ref LL_USART_ADDRESS_DETECT_7B
  1468. * @param NodeAddress 4 or 7 bit Address of the USART node.
  1469. * @retval None
  1470. */
  1471. __STATIC_INLINE void LL_USART_ConfigNodeAddress(USART_TypeDef *USARTx, uint32_t AddressLen, uint32_t NodeAddress)
  1472. {
  1473. MODIFY_REG(USARTx->CR2, USART_CR2_ADD | USART_CR2_ADDM7,
  1474. (uint32_t)(AddressLen | (NodeAddress << USART_CR2_ADD_Pos)));
  1475. }
  1476. /**
  1477. * @brief Return 8 bit Address of the USART node as set in ADD field of CR2.
  1478. * @note If 4-bit Address Detection is selected in ADDM7,
  1479. * only 4bits (b3-b0) of returned value are relevant (b31-b4 are not relevant)
  1480. * If 7-bit Address Detection is selected in ADDM7,
  1481. * only 8bits (b7-b0) of returned value are relevant (b31-b8 are not relevant)
  1482. * @rmtoll CR2 ADD LL_USART_GetNodeAddress
  1483. * @param USARTx USART Instance
  1484. * @retval Address of the USART node (Value between Min_Data=0 and Max_Data=255)
  1485. */
  1486. __STATIC_INLINE uint32_t LL_USART_GetNodeAddress(USART_TypeDef *USARTx)
  1487. {
  1488. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ADD) >> USART_CR2_ADD_Pos);
  1489. }
  1490. /**
  1491. * @brief Return Length of Node Address used in Address Detection mode (7-bit or 4-bit)
  1492. * @rmtoll CR2 ADDM7 LL_USART_GetNodeAddressLen
  1493. * @param USARTx USART Instance
  1494. * @retval Returned value can be one of the following values:
  1495. * @arg @ref LL_USART_ADDRESS_DETECT_4B
  1496. * @arg @ref LL_USART_ADDRESS_DETECT_7B
  1497. */
  1498. __STATIC_INLINE uint32_t LL_USART_GetNodeAddressLen(USART_TypeDef *USARTx)
  1499. {
  1500. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ADDM7));
  1501. }
  1502. /**
  1503. * @brief Enable RTS HW Flow Control
  1504. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1505. * Hardware Flow control feature is supported by the USARTx instance.
  1506. * @rmtoll CR3 RTSE LL_USART_EnableRTSHWFlowCtrl
  1507. * @param USARTx USART Instance
  1508. * @retval None
  1509. */
  1510. __STATIC_INLINE void LL_USART_EnableRTSHWFlowCtrl(USART_TypeDef *USARTx)
  1511. {
  1512. SET_BIT(USARTx->CR3, USART_CR3_RTSE);
  1513. }
  1514. /**
  1515. * @brief Disable RTS HW Flow Control
  1516. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1517. * Hardware Flow control feature is supported by the USARTx instance.
  1518. * @rmtoll CR3 RTSE LL_USART_DisableRTSHWFlowCtrl
  1519. * @param USARTx USART Instance
  1520. * @retval None
  1521. */
  1522. __STATIC_INLINE void LL_USART_DisableRTSHWFlowCtrl(USART_TypeDef *USARTx)
  1523. {
  1524. CLEAR_BIT(USARTx->CR3, USART_CR3_RTSE);
  1525. }
  1526. /**
  1527. * @brief Enable CTS HW Flow Control
  1528. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1529. * Hardware Flow control feature is supported by the USARTx instance.
  1530. * @rmtoll CR3 CTSE LL_USART_EnableCTSHWFlowCtrl
  1531. * @param USARTx USART Instance
  1532. * @retval None
  1533. */
  1534. __STATIC_INLINE void LL_USART_EnableCTSHWFlowCtrl(USART_TypeDef *USARTx)
  1535. {
  1536. SET_BIT(USARTx->CR3, USART_CR3_CTSE);
  1537. }
  1538. /**
  1539. * @brief Disable CTS HW Flow Control
  1540. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1541. * Hardware Flow control feature is supported by the USARTx instance.
  1542. * @rmtoll CR3 CTSE LL_USART_DisableCTSHWFlowCtrl
  1543. * @param USARTx USART Instance
  1544. * @retval None
  1545. */
  1546. __STATIC_INLINE void LL_USART_DisableCTSHWFlowCtrl(USART_TypeDef *USARTx)
  1547. {
  1548. CLEAR_BIT(USARTx->CR3, USART_CR3_CTSE);
  1549. }
  1550. /**
  1551. * @brief Configure HW Flow Control mode (both CTS and RTS)
  1552. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1553. * Hardware Flow control feature is supported by the USARTx instance.
  1554. * @rmtoll CR3 RTSE LL_USART_SetHWFlowCtrl\n
  1555. * CR3 CTSE LL_USART_SetHWFlowCtrl
  1556. * @param USARTx USART Instance
  1557. * @param HardwareFlowControl This parameter can be one of the following values:
  1558. * @arg @ref LL_USART_HWCONTROL_NONE
  1559. * @arg @ref LL_USART_HWCONTROL_RTS
  1560. * @arg @ref LL_USART_HWCONTROL_CTS
  1561. * @arg @ref LL_USART_HWCONTROL_RTS_CTS
  1562. * @retval None
  1563. */
  1564. __STATIC_INLINE void LL_USART_SetHWFlowCtrl(USART_TypeDef *USARTx, uint32_t HardwareFlowControl)
  1565. {
  1566. MODIFY_REG(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE, HardwareFlowControl);
  1567. }
  1568. /**
  1569. * @brief Return HW Flow Control configuration (both CTS and RTS)
  1570. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1571. * Hardware Flow control feature is supported by the USARTx instance.
  1572. * @rmtoll CR3 RTSE LL_USART_GetHWFlowCtrl\n
  1573. * CR3 CTSE LL_USART_GetHWFlowCtrl
  1574. * @param USARTx USART Instance
  1575. * @retval Returned value can be one of the following values:
  1576. * @arg @ref LL_USART_HWCONTROL_NONE
  1577. * @arg @ref LL_USART_HWCONTROL_RTS
  1578. * @arg @ref LL_USART_HWCONTROL_CTS
  1579. * @arg @ref LL_USART_HWCONTROL_RTS_CTS
  1580. */
  1581. __STATIC_INLINE uint32_t LL_USART_GetHWFlowCtrl(USART_TypeDef *USARTx)
  1582. {
  1583. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE));
  1584. }
  1585. /**
  1586. * @brief Enable One bit sampling method
  1587. * @rmtoll CR3 ONEBIT LL_USART_EnableOneBitSamp
  1588. * @param USARTx USART Instance
  1589. * @retval None
  1590. */
  1591. __STATIC_INLINE void LL_USART_EnableOneBitSamp(USART_TypeDef *USARTx)
  1592. {
  1593. SET_BIT(USARTx->CR3, USART_CR3_ONEBIT);
  1594. }
  1595. /**
  1596. * @brief Disable One bit sampling method
  1597. * @rmtoll CR3 ONEBIT LL_USART_DisableOneBitSamp
  1598. * @param USARTx USART Instance
  1599. * @retval None
  1600. */
  1601. __STATIC_INLINE void LL_USART_DisableOneBitSamp(USART_TypeDef *USARTx)
  1602. {
  1603. CLEAR_BIT(USARTx->CR3, USART_CR3_ONEBIT);
  1604. }
  1605. /**
  1606. * @brief Indicate if One bit sampling method is enabled
  1607. * @rmtoll CR3 ONEBIT LL_USART_IsEnabledOneBitSamp
  1608. * @param USARTx USART Instance
  1609. * @retval State of bit (1 or 0).
  1610. */
  1611. __STATIC_INLINE uint32_t LL_USART_IsEnabledOneBitSamp(USART_TypeDef *USARTx)
  1612. {
  1613. return ((READ_BIT(USARTx->CR3, USART_CR3_ONEBIT) == (USART_CR3_ONEBIT)) ? 1U : 0U);
  1614. }
  1615. /**
  1616. * @brief Enable Overrun detection
  1617. * @rmtoll CR3 OVRDIS LL_USART_EnableOverrunDetect
  1618. * @param USARTx USART Instance
  1619. * @retval None
  1620. */
  1621. __STATIC_INLINE void LL_USART_EnableOverrunDetect(USART_TypeDef *USARTx)
  1622. {
  1623. CLEAR_BIT(USARTx->CR3, USART_CR3_OVRDIS);
  1624. }
  1625. /**
  1626. * @brief Disable Overrun detection
  1627. * @rmtoll CR3 OVRDIS LL_USART_DisableOverrunDetect
  1628. * @param USARTx USART Instance
  1629. * @retval None
  1630. */
  1631. __STATIC_INLINE void LL_USART_DisableOverrunDetect(USART_TypeDef *USARTx)
  1632. {
  1633. SET_BIT(USARTx->CR3, USART_CR3_OVRDIS);
  1634. }
  1635. /**
  1636. * @brief Indicate if Overrun detection is enabled
  1637. * @rmtoll CR3 OVRDIS LL_USART_IsEnabledOverrunDetect
  1638. * @param USARTx USART Instance
  1639. * @retval State of bit (1 or 0).
  1640. */
  1641. __STATIC_INLINE uint32_t LL_USART_IsEnabledOverrunDetect(USART_TypeDef *USARTx)
  1642. {
  1643. return ((READ_BIT(USARTx->CR3, USART_CR3_OVRDIS) != USART_CR3_OVRDIS) ? 1U : 0U);
  1644. }
  1645. /**
  1646. * @brief Select event type for Wake UP Interrupt Flag (WUS[1:0] bits)
  1647. * @note Macro @ref IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  1648. * Wake-up from Stop mode feature is supported by the USARTx instance.
  1649. * @rmtoll CR3 WUS LL_USART_SetWKUPType
  1650. * @param USARTx USART Instance
  1651. * @param Type This parameter can be one of the following values:
  1652. * @arg @ref LL_USART_WAKEUP_ON_ADDRESS
  1653. * @arg @ref LL_USART_WAKEUP_ON_STARTBIT
  1654. * @arg @ref LL_USART_WAKEUP_ON_RXNE
  1655. * @retval None
  1656. */
  1657. __STATIC_INLINE void LL_USART_SetWKUPType(USART_TypeDef *USARTx, uint32_t Type)
  1658. {
  1659. MODIFY_REG(USARTx->CR3, USART_CR3_WUS, Type);
  1660. }
  1661. /**
  1662. * @brief Return event type for Wake UP Interrupt Flag (WUS[1:0] bits)
  1663. * @note Macro @ref IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  1664. * Wake-up from Stop mode feature is supported by the USARTx instance.
  1665. * @rmtoll CR3 WUS LL_USART_GetWKUPType
  1666. * @param USARTx USART Instance
  1667. * @retval Returned value can be one of the following values:
  1668. * @arg @ref LL_USART_WAKEUP_ON_ADDRESS
  1669. * @arg @ref LL_USART_WAKEUP_ON_STARTBIT
  1670. * @arg @ref LL_USART_WAKEUP_ON_RXNE
  1671. */
  1672. __STATIC_INLINE uint32_t LL_USART_GetWKUPType(USART_TypeDef *USARTx)
  1673. {
  1674. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_WUS));
  1675. }
  1676. /**
  1677. * @brief Configure USART BRR register for achieving expected Baud Rate value.
  1678. * @note Compute and set USARTDIV value in BRR Register (full BRR content)
  1679. * according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
  1680. * @note Peripheral clock and Baud rate values provided as function parameters should be valid
  1681. * (Baud rate value != 0)
  1682. * @note In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d.
  1683. * @rmtoll BRR BRR LL_USART_SetBaudRate
  1684. * @param USARTx USART Instance
  1685. * @param PeriphClk Peripheral Clock
  1686. * @param PrescalerValue This parameter can be one of the following values:
  1687. * @arg @ref LL_USART_PRESCALER_DIV1
  1688. * @arg @ref LL_USART_PRESCALER_DIV2
  1689. * @arg @ref LL_USART_PRESCALER_DIV4
  1690. * @arg @ref LL_USART_PRESCALER_DIV6
  1691. * @arg @ref LL_USART_PRESCALER_DIV8
  1692. * @arg @ref LL_USART_PRESCALER_DIV10
  1693. * @arg @ref LL_USART_PRESCALER_DIV12
  1694. * @arg @ref LL_USART_PRESCALER_DIV16
  1695. * @arg @ref LL_USART_PRESCALER_DIV32
  1696. * @arg @ref LL_USART_PRESCALER_DIV64
  1697. * @arg @ref LL_USART_PRESCALER_DIV128
  1698. * @arg @ref LL_USART_PRESCALER_DIV256
  1699. * @param OverSampling This parameter can be one of the following values:
  1700. * @arg @ref LL_USART_OVERSAMPLING_16
  1701. * @arg @ref LL_USART_OVERSAMPLING_8
  1702. * @param BaudRate Baud Rate
  1703. * @retval None
  1704. */
  1705. __STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t PrescalerValue, uint32_t OverSampling,
  1706. uint32_t BaudRate)
  1707. {
  1708. uint32_t usartdiv;
  1709. uint32_t brrtemp;
  1710. if (OverSampling == LL_USART_OVERSAMPLING_8)
  1711. {
  1712. usartdiv = (uint16_t)(__LL_USART_DIV_SAMPLING8(PeriphClk, (uint16_t)PrescalerValue, BaudRate));
  1713. brrtemp = usartdiv & 0xFFF0U;
  1714. brrtemp |= (uint16_t)((usartdiv & (uint16_t)0x000FU) >> 1U);
  1715. USARTx->BRR = brrtemp;
  1716. }
  1717. else
  1718. {
  1719. USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk, (uint16_t)PrescalerValue, BaudRate));
  1720. }
  1721. }
  1722. /**
  1723. * @brief Return current Baud Rate value, according to USARTDIV present in BRR register
  1724. * (full BRR content), and to used Peripheral Clock and Oversampling mode values
  1725. * @note In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
  1726. * @note In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d.
  1727. * @rmtoll BRR BRR LL_USART_GetBaudRate
  1728. * @param USARTx USART Instance
  1729. * @param PeriphClk Peripheral Clock
  1730. * @param PrescalerValue This parameter can be one of the following values:
  1731. * @arg @ref LL_USART_PRESCALER_DIV1
  1732. * @arg @ref LL_USART_PRESCALER_DIV2
  1733. * @arg @ref LL_USART_PRESCALER_DIV4
  1734. * @arg @ref LL_USART_PRESCALER_DIV6
  1735. * @arg @ref LL_USART_PRESCALER_DIV8
  1736. * @arg @ref LL_USART_PRESCALER_DIV10
  1737. * @arg @ref LL_USART_PRESCALER_DIV12
  1738. * @arg @ref LL_USART_PRESCALER_DIV16
  1739. * @arg @ref LL_USART_PRESCALER_DIV32
  1740. * @arg @ref LL_USART_PRESCALER_DIV64
  1741. * @arg @ref LL_USART_PRESCALER_DIV128
  1742. * @arg @ref LL_USART_PRESCALER_DIV256
  1743. * @param OverSampling This parameter can be one of the following values:
  1744. * @arg @ref LL_USART_OVERSAMPLING_16
  1745. * @arg @ref LL_USART_OVERSAMPLING_8
  1746. * @retval Baud Rate
  1747. */
  1748. __STATIC_INLINE uint32_t LL_USART_GetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t PrescalerValue, uint32_t OverSampling)
  1749. {
  1750. uint32_t usartdiv;
  1751. uint32_t brrresult = 0x0U;
  1752. uint32_t periphclkpresc = (uint32_t)(PeriphClk / (uint32_t)(USART_PRESCALER_TAB[(uint16_t)PrescalerValue]));
  1753. usartdiv = USARTx->BRR;
  1754. if(usartdiv == 0U)
  1755. {
  1756. /* Do not perform a division by 0 */
  1757. }
  1758. else if (OverSampling == LL_USART_OVERSAMPLING_8)
  1759. {
  1760. usartdiv = (uint16_t)((usartdiv & 0xFFF0U) | ((usartdiv & 0x0007U) << 1U)) ;
  1761. if(usartdiv != 0U)
  1762. {
  1763. brrresult = (periphclkpresc * 2U) / usartdiv;
  1764. }
  1765. }
  1766. else
  1767. {
  1768. if ((usartdiv & 0xFFFFU) != 0U)
  1769. {
  1770. brrresult = periphclkpresc / usartdiv;
  1771. }
  1772. }
  1773. return (brrresult);
  1774. }
  1775. /**
  1776. * @brief Set Receiver Time Out Value (expressed in nb of bits duration)
  1777. * @rmtoll RTOR RTO LL_USART_SetRxTimeout
  1778. * @param USARTx USART Instance
  1779. * @param Timeout Value between Min_Data=0x00 and Max_Data=0x00FFFFFF
  1780. * @retval None
  1781. */
  1782. __STATIC_INLINE void LL_USART_SetRxTimeout(USART_TypeDef *USARTx, uint32_t Timeout)
  1783. {
  1784. MODIFY_REG(USARTx->RTOR, USART_RTOR_RTO, Timeout);
  1785. }
  1786. /**
  1787. * @brief Get Receiver Time Out Value (expressed in nb of bits duration)
  1788. * @rmtoll RTOR RTO LL_USART_GetRxTimeout
  1789. * @param USARTx USART Instance
  1790. * @retval Value between Min_Data=0x00 and Max_Data=0x00FFFFFF
  1791. */
  1792. __STATIC_INLINE uint32_t LL_USART_GetRxTimeout(USART_TypeDef *USARTx)
  1793. {
  1794. return (uint32_t)(READ_BIT(USARTx->RTOR, USART_RTOR_RTO));
  1795. }
  1796. /**
  1797. * @brief Set Block Length value in reception
  1798. * @rmtoll RTOR BLEN LL_USART_SetBlockLength
  1799. * @param USARTx USART Instance
  1800. * @param BlockLength Value between Min_Data=0x00 and Max_Data=0xFF
  1801. * @retval None
  1802. */
  1803. __STATIC_INLINE void LL_USART_SetBlockLength(USART_TypeDef *USARTx, uint32_t BlockLength)
  1804. {
  1805. MODIFY_REG(USARTx->RTOR, USART_RTOR_BLEN, BlockLength << USART_RTOR_BLEN_Pos);
  1806. }
  1807. /**
  1808. * @brief Get Block Length value in reception
  1809. * @rmtoll RTOR BLEN LL_USART_GetBlockLength
  1810. * @param USARTx USART Instance
  1811. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  1812. */
  1813. __STATIC_INLINE uint32_t LL_USART_GetBlockLength(USART_TypeDef *USARTx)
  1814. {
  1815. return (uint32_t)(READ_BIT(USARTx->RTOR, USART_RTOR_BLEN) >> USART_RTOR_BLEN_Pos);
  1816. }
  1817. /**
  1818. * @}
  1819. */
  1820. /** @defgroup USART_LL_EF_Configuration_IRDA Configuration functions related to Irda feature
  1821. * @{
  1822. */
  1823. /**
  1824. * @brief Enable IrDA mode
  1825. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1826. * IrDA feature is supported by the USARTx instance.
  1827. * @rmtoll CR3 IREN LL_USART_EnableIrda
  1828. * @param USARTx USART Instance
  1829. * @retval None
  1830. */
  1831. __STATIC_INLINE void LL_USART_EnableIrda(USART_TypeDef *USARTx)
  1832. {
  1833. SET_BIT(USARTx->CR3, USART_CR3_IREN);
  1834. }
  1835. /**
  1836. * @brief Disable IrDA mode
  1837. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1838. * IrDA feature is supported by the USARTx instance.
  1839. * @rmtoll CR3 IREN LL_USART_DisableIrda
  1840. * @param USARTx USART Instance
  1841. * @retval None
  1842. */
  1843. __STATIC_INLINE void LL_USART_DisableIrda(USART_TypeDef *USARTx)
  1844. {
  1845. CLEAR_BIT(USARTx->CR3, USART_CR3_IREN);
  1846. }
  1847. /**
  1848. * @brief Indicate if IrDA mode is enabled
  1849. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1850. * IrDA feature is supported by the USARTx instance.
  1851. * @rmtoll CR3 IREN LL_USART_IsEnabledIrda
  1852. * @param USARTx USART Instance
  1853. * @retval State of bit (1 or 0).
  1854. */
  1855. __STATIC_INLINE uint32_t LL_USART_IsEnabledIrda(USART_TypeDef *USARTx)
  1856. {
  1857. return ((READ_BIT(USARTx->CR3, USART_CR3_IREN) == (USART_CR3_IREN)) ? 1U : 0U);
  1858. }
  1859. /**
  1860. * @brief Configure IrDA Power Mode (Normal or Low Power)
  1861. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1862. * IrDA feature is supported by the USARTx instance.
  1863. * @rmtoll CR3 IRLP LL_USART_SetIrdaPowerMode
  1864. * @param USARTx USART Instance
  1865. * @param PowerMode This parameter can be one of the following values:
  1866. * @arg @ref LL_USART_IRDA_POWER_NORMAL
  1867. * @arg @ref LL_USART_IRDA_POWER_LOW
  1868. * @retval None
  1869. */
  1870. __STATIC_INLINE void LL_USART_SetIrdaPowerMode(USART_TypeDef *USARTx, uint32_t PowerMode)
  1871. {
  1872. MODIFY_REG(USARTx->CR3, USART_CR3_IRLP, PowerMode);
  1873. }
  1874. /**
  1875. * @brief Retrieve IrDA Power Mode configuration (Normal or Low Power)
  1876. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1877. * IrDA feature is supported by the USARTx instance.
  1878. * @rmtoll CR3 IRLP LL_USART_GetIrdaPowerMode
  1879. * @param USARTx USART Instance
  1880. * @retval Returned value can be one of the following values:
  1881. * @arg @ref LL_USART_IRDA_POWER_NORMAL
  1882. * @arg @ref LL_USART_PHASE_2EDGE
  1883. */
  1884. __STATIC_INLINE uint32_t LL_USART_GetIrdaPowerMode(USART_TypeDef *USARTx)
  1885. {
  1886. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_IRLP));
  1887. }
  1888. /**
  1889. * @brief Set Irda prescaler value, used for dividing the USART clock source
  1890. * to achieve the Irda Low Power frequency (8 bits value)
  1891. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1892. * IrDA feature is supported by the USARTx instance.
  1893. * @rmtoll GTPR PSC LL_USART_SetIrdaPrescaler
  1894. * @param USARTx USART Instance
  1895. * @param PrescalerValue Value between Min_Data=0x00 and Max_Data=0xFF
  1896. * @retval None
  1897. */
  1898. __STATIC_INLINE void LL_USART_SetIrdaPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
  1899. {
  1900. MODIFY_REG(USARTx->GTPR, USART_GTPR_PSC, (uint16_t)PrescalerValue);
  1901. }
  1902. /**
  1903. * @brief Return Irda prescaler value, used for dividing the USART clock source
  1904. * to achieve the Irda Low Power frequency (8 bits value)
  1905. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1906. * IrDA feature is supported by the USARTx instance.
  1907. * @rmtoll GTPR PSC LL_USART_GetIrdaPrescaler
  1908. * @param USARTx USART Instance
  1909. * @retval Irda prescaler value (Value between Min_Data=0x00 and Max_Data=0xFF)
  1910. */
  1911. __STATIC_INLINE uint32_t LL_USART_GetIrdaPrescaler(USART_TypeDef *USARTx)
  1912. {
  1913. return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_PSC));
  1914. }
  1915. /**
  1916. * @}
  1917. */
  1918. /** @defgroup USART_LL_EF_Configuration_Smartcard Configuration functions related to Smartcard feature
  1919. * @{
  1920. */
  1921. /**
  1922. * @brief Enable Smartcard NACK transmission
  1923. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1924. * Smartcard feature is supported by the USARTx instance.
  1925. * @rmtoll CR3 NACK LL_USART_EnableSmartcardNACK
  1926. * @param USARTx USART Instance
  1927. * @retval None
  1928. */
  1929. __STATIC_INLINE void LL_USART_EnableSmartcardNACK(USART_TypeDef *USARTx)
  1930. {
  1931. SET_BIT(USARTx->CR3, USART_CR3_NACK);
  1932. }
  1933. /**
  1934. * @brief Disable Smartcard NACK transmission
  1935. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1936. * Smartcard feature is supported by the USARTx instance.
  1937. * @rmtoll CR3 NACK LL_USART_DisableSmartcardNACK
  1938. * @param USARTx USART Instance
  1939. * @retval None
  1940. */
  1941. __STATIC_INLINE void LL_USART_DisableSmartcardNACK(USART_TypeDef *USARTx)
  1942. {
  1943. CLEAR_BIT(USARTx->CR3, USART_CR3_NACK);
  1944. }
  1945. /**
  1946. * @brief Indicate if Smartcard NACK transmission is enabled
  1947. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1948. * Smartcard feature is supported by the USARTx instance.
  1949. * @rmtoll CR3 NACK LL_USART_IsEnabledSmartcardNACK
  1950. * @param USARTx USART Instance
  1951. * @retval State of bit (1 or 0).
  1952. */
  1953. __STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcardNACK(USART_TypeDef *USARTx)
  1954. {
  1955. return ((READ_BIT(USARTx->CR3, USART_CR3_NACK) == (USART_CR3_NACK)) ? 1U : 0U);
  1956. }
  1957. /**
  1958. * @brief Enable Smartcard mode
  1959. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1960. * Smartcard feature is supported by the USARTx instance.
  1961. * @rmtoll CR3 SCEN LL_USART_EnableSmartcard
  1962. * @param USARTx USART Instance
  1963. * @retval None
  1964. */
  1965. __STATIC_INLINE void LL_USART_EnableSmartcard(USART_TypeDef *USARTx)
  1966. {
  1967. SET_BIT(USARTx->CR3, USART_CR3_SCEN);
  1968. }
  1969. /**
  1970. * @brief Disable Smartcard mode
  1971. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1972. * Smartcard feature is supported by the USARTx instance.
  1973. * @rmtoll CR3 SCEN LL_USART_DisableSmartcard
  1974. * @param USARTx USART Instance
  1975. * @retval None
  1976. */
  1977. __STATIC_INLINE void LL_USART_DisableSmartcard(USART_TypeDef *USARTx)
  1978. {
  1979. CLEAR_BIT(USARTx->CR3, USART_CR3_SCEN);
  1980. }
  1981. /**
  1982. * @brief Indicate if Smartcard mode is enabled
  1983. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1984. * Smartcard feature is supported by the USARTx instance.
  1985. * @rmtoll CR3 SCEN LL_USART_IsEnabledSmartcard
  1986. * @param USARTx USART Instance
  1987. * @retval State of bit (1 or 0).
  1988. */
  1989. __STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcard(USART_TypeDef *USARTx)
  1990. {
  1991. return ((READ_BIT(USARTx->CR3, USART_CR3_SCEN) == (USART_CR3_SCEN)) ? 1U : 0U);
  1992. }
  1993. /**
  1994. * @brief Set Smartcard Auto-Retry Count value (SCARCNT[2:0] bits)
  1995. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1996. * Smartcard feature is supported by the USARTx instance.
  1997. * @note This bit-field specifies the number of retries in transmit and receive, in Smartcard mode.
  1998. * In transmission mode, it specifies the number of automatic retransmission retries, before
  1999. * generating a transmission error (FE bit set).
  2000. * In reception mode, it specifies the number or erroneous reception trials, before generating a
  2001. * reception error (RXNE and PE bits set)
  2002. * @rmtoll CR3 SCARCNT LL_USART_SetSmartcardAutoRetryCount
  2003. * @param USARTx USART Instance
  2004. * @param AutoRetryCount Value between Min_Data=0 and Max_Data=7
  2005. * @retval None
  2006. */
  2007. __STATIC_INLINE void LL_USART_SetSmartcardAutoRetryCount(USART_TypeDef *USARTx, uint32_t AutoRetryCount)
  2008. {
  2009. MODIFY_REG(USARTx->CR3, USART_CR3_SCARCNT, AutoRetryCount << USART_CR3_SCARCNT_Pos);
  2010. }
  2011. /**
  2012. * @brief Return Smartcard Auto-Retry Count value (SCARCNT[2:0] bits)
  2013. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  2014. * Smartcard feature is supported by the USARTx instance.
  2015. * @rmtoll CR3 SCARCNT LL_USART_GetSmartcardAutoRetryCount
  2016. * @param USARTx USART Instance
  2017. * @retval Smartcard Auto-Retry Count value (Value between Min_Data=0 and Max_Data=7)
  2018. */
  2019. __STATIC_INLINE uint32_t LL_USART_GetSmartcardAutoRetryCount(USART_TypeDef *USARTx)
  2020. {
  2021. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_SCARCNT) >> USART_CR3_SCARCNT_Pos);
  2022. }
  2023. /**
  2024. * @brief Set Smartcard prescaler value, used for dividing the USART clock
  2025. * source to provide the SMARTCARD Clock (5 bits value)
  2026. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  2027. * Smartcard feature is supported by the USARTx instance.
  2028. * @rmtoll GTPR PSC LL_USART_SetSmartcardPrescaler
  2029. * @param USARTx USART Instance
  2030. * @param PrescalerValue Value between Min_Data=0 and Max_Data=31
  2031. * @retval None
  2032. */
  2033. __STATIC_INLINE void LL_USART_SetSmartcardPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
  2034. {
  2035. MODIFY_REG(USARTx->GTPR, USART_GTPR_PSC, (uint16_t)PrescalerValue);
  2036. }
  2037. /**
  2038. * @brief Return Smartcard prescaler value, used for dividing the USART clock
  2039. * source to provide the SMARTCARD Clock (5 bits value)
  2040. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  2041. * Smartcard feature is supported by the USARTx instance.
  2042. * @rmtoll GTPR PSC LL_USART_GetSmartcardPrescaler
  2043. * @param USARTx USART Instance
  2044. * @retval Smartcard prescaler value (Value between Min_Data=0 and Max_Data=31)
  2045. */
  2046. __STATIC_INLINE uint32_t LL_USART_GetSmartcardPrescaler(USART_TypeDef *USARTx)
  2047. {
  2048. return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_PSC));
  2049. }
  2050. /**
  2051. * @brief Set Smartcard Guard time value, expressed in nb of baud clocks periods
  2052. * (GT[7:0] bits : Guard time value)
  2053. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  2054. * Smartcard feature is supported by the USARTx instance.
  2055. * @rmtoll GTPR GT LL_USART_SetSmartcardGuardTime
  2056. * @param USARTx USART Instance
  2057. * @param GuardTime Value between Min_Data=0x00 and Max_Data=0xFF
  2058. * @retval None
  2059. */
  2060. __STATIC_INLINE void LL_USART_SetSmartcardGuardTime(USART_TypeDef *USARTx, uint32_t GuardTime)
  2061. {
  2062. MODIFY_REG(USARTx->GTPR, USART_GTPR_GT, GuardTime << USART_GTPR_GT_Pos);
  2063. }
  2064. /**
  2065. * @brief Return Smartcard Guard time value, expressed in nb of baud clocks periods
  2066. * (GT[7:0] bits : Guard time value)
  2067. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  2068. * Smartcard feature is supported by the USARTx instance.
  2069. * @rmtoll GTPR GT LL_USART_GetSmartcardGuardTime
  2070. * @param USARTx USART Instance
  2071. * @retval Smartcard Guard time value (Value between Min_Data=0x00 and Max_Data=0xFF)
  2072. */
  2073. __STATIC_INLINE uint32_t LL_USART_GetSmartcardGuardTime(USART_TypeDef *USARTx)
  2074. {
  2075. return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_GT) >> USART_GTPR_GT_Pos);
  2076. }
  2077. /**
  2078. * @}
  2079. */
  2080. /** @defgroup USART_LL_EF_Configuration_HalfDuplex Configuration functions related to Half Duplex feature
  2081. * @{
  2082. */
  2083. /**
  2084. * @brief Enable Single Wire Half-Duplex mode
  2085. * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  2086. * Half-Duplex mode is supported by the USARTx instance.
  2087. * @rmtoll CR3 HDSEL LL_USART_EnableHalfDuplex
  2088. * @param USARTx USART Instance
  2089. * @retval None
  2090. */
  2091. __STATIC_INLINE void LL_USART_EnableHalfDuplex(USART_TypeDef *USARTx)
  2092. {
  2093. SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
  2094. }
  2095. /**
  2096. * @brief Disable Single Wire Half-Duplex mode
  2097. * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  2098. * Half-Duplex mode is supported by the USARTx instance.
  2099. * @rmtoll CR3 HDSEL LL_USART_DisableHalfDuplex
  2100. * @param USARTx USART Instance
  2101. * @retval None
  2102. */
  2103. __STATIC_INLINE void LL_USART_DisableHalfDuplex(USART_TypeDef *USARTx)
  2104. {
  2105. CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
  2106. }
  2107. /**
  2108. * @brief Indicate if Single Wire Half-Duplex mode is enabled
  2109. * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  2110. * Half-Duplex mode is supported by the USARTx instance.
  2111. * @rmtoll CR3 HDSEL LL_USART_IsEnabledHalfDuplex
  2112. * @param USARTx USART Instance
  2113. * @retval State of bit (1 or 0).
  2114. */
  2115. __STATIC_INLINE uint32_t LL_USART_IsEnabledHalfDuplex(USART_TypeDef *USARTx)
  2116. {
  2117. return ((READ_BIT(USARTx->CR3, USART_CR3_HDSEL) == (USART_CR3_HDSEL)) ? 1U : 0U);
  2118. }
  2119. /**
  2120. * @}
  2121. */
  2122. /** @defgroup USART_LL_EF_Configuration_SPI_SLAVE Configuration functions related to SPI Slave feature
  2123. * @{
  2124. */
  2125. /**
  2126. * @brief Enable SPI Synchronous Slave mode
  2127. * @note Macro @ref IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
  2128. * SPI Slave mode feature is supported by the USARTx instance.
  2129. * @rmtoll CR2 SLVEN LL_USART_EnableSPISlave
  2130. * @param USARTx USART Instance
  2131. * @retval None
  2132. */
  2133. __STATIC_INLINE void LL_USART_EnableSPISlave(USART_TypeDef *USARTx)
  2134. {
  2135. SET_BIT(USARTx->CR2, USART_CR2_SLVEN);
  2136. }
  2137. /**
  2138. * @brief Disable SPI Synchronous Slave mode
  2139. * @note Macro @ref IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
  2140. * SPI Slave mode feature is supported by the USARTx instance.
  2141. * @rmtoll CR2 SLVEN LL_USART_DisableSPISlave
  2142. * @param USARTx USART Instance
  2143. * @retval None
  2144. */
  2145. __STATIC_INLINE void LL_USART_DisableSPISlave(USART_TypeDef *USARTx)
  2146. {
  2147. CLEAR_BIT(USARTx->CR2, USART_CR2_SLVEN);
  2148. }
  2149. /**
  2150. * @brief Indicate if SPI Synchronous Slave mode is enabled
  2151. * @note Macro @ref IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
  2152. * SPI Slave mode feature is supported by the USARTx instance.
  2153. * @rmtoll CR2 SLVEN LL_USART_IsEnabledSPISlave
  2154. * @param USARTx USART Instance
  2155. * @retval State of bit (1 or 0).
  2156. */
  2157. __STATIC_INLINE uint32_t LL_USART_IsEnabledSPISlave(USART_TypeDef *USARTx)
  2158. {
  2159. return ((READ_BIT(USARTx->CR2, USART_CR2_SLVEN) == (USART_CR2_SLVEN)) ? 1U : 0U);
  2160. }
  2161. /**
  2162. * @brief Enable SPI Slave Selection using NSS input pin
  2163. * @note Macro @ref IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
  2164. * SPI Slave mode feature is supported by the USARTx instance.
  2165. * @note SPI Slave Selection depends on NSS input pin
  2166. * (The slave is selected when NSS is low and deselected when NSS is high).
  2167. * @rmtoll CR2 DIS_NSS LL_USART_EnableSPISlaveSelect
  2168. * @param USARTx USART Instance
  2169. * @retval None
  2170. */
  2171. __STATIC_INLINE void LL_USART_EnableSPISlaveSelect(USART_TypeDef *USARTx)
  2172. {
  2173. CLEAR_BIT(USARTx->CR2, USART_CR2_DIS_NSS);
  2174. }
  2175. /**
  2176. * @brief Disable SPI Slave Selection using NSS input pin
  2177. * @note Macro @ref IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
  2178. * SPI Slave mode feature is supported by the USARTx instance.
  2179. * @note SPI Slave will be always selected and NSS input pin will be ignored.
  2180. * @rmtoll CR2 DIS_NSS LL_USART_DisableSPISlaveSelect
  2181. * @param USARTx USART Instance
  2182. * @retval None
  2183. */
  2184. __STATIC_INLINE void LL_USART_DisableSPISlaveSelect(USART_TypeDef *USARTx)
  2185. {
  2186. SET_BIT(USARTx->CR2, USART_CR2_DIS_NSS);
  2187. }
  2188. /**
  2189. * @brief Indicate if SPI Slave Selection depends on NSS input pin
  2190. * @note Macro @ref IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
  2191. * SPI Slave mode feature is supported by the USARTx instance.
  2192. * @rmtoll CR2 DIS_NSS LL_USART_IsEnabledSPISlaveSelect
  2193. * @param USARTx USART Instance
  2194. * @retval State of bit (1 or 0).
  2195. */
  2196. __STATIC_INLINE uint32_t LL_USART_IsEnabledSPISlaveSelect(USART_TypeDef *USARTx)
  2197. {
  2198. return ((READ_BIT(USARTx->CR2, USART_CR2_DIS_NSS) != (USART_CR2_DIS_NSS)) ? 1U : 0U);
  2199. }
  2200. /**
  2201. * @}
  2202. */
  2203. /** @defgroup USART_LL_EF_Configuration_LIN Configuration functions related to LIN feature
  2204. * @{
  2205. */
  2206. /**
  2207. * @brief Set LIN Break Detection Length
  2208. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2209. * LIN feature is supported by the USARTx instance.
  2210. * @rmtoll CR2 LBDL LL_USART_SetLINBrkDetectionLen
  2211. * @param USARTx USART Instance
  2212. * @param LINBDLength This parameter can be one of the following values:
  2213. * @arg @ref LL_USART_LINBREAK_DETECT_10B
  2214. * @arg @ref LL_USART_LINBREAK_DETECT_11B
  2215. * @retval None
  2216. */
  2217. __STATIC_INLINE void LL_USART_SetLINBrkDetectionLen(USART_TypeDef *USARTx, uint32_t LINBDLength)
  2218. {
  2219. MODIFY_REG(USARTx->CR2, USART_CR2_LBDL, LINBDLength);
  2220. }
  2221. /**
  2222. * @brief Return LIN Break Detection Length
  2223. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2224. * LIN feature is supported by the USARTx instance.
  2225. * @rmtoll CR2 LBDL LL_USART_GetLINBrkDetectionLen
  2226. * @param USARTx USART Instance
  2227. * @retval Returned value can be one of the following values:
  2228. * @arg @ref LL_USART_LINBREAK_DETECT_10B
  2229. * @arg @ref LL_USART_LINBREAK_DETECT_11B
  2230. */
  2231. __STATIC_INLINE uint32_t LL_USART_GetLINBrkDetectionLen(USART_TypeDef *USARTx)
  2232. {
  2233. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBDL));
  2234. }
  2235. /**
  2236. * @brief Enable LIN mode
  2237. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2238. * LIN feature is supported by the USARTx instance.
  2239. * @rmtoll CR2 LINEN LL_USART_EnableLIN
  2240. * @param USARTx USART Instance
  2241. * @retval None
  2242. */
  2243. __STATIC_INLINE void LL_USART_EnableLIN(USART_TypeDef *USARTx)
  2244. {
  2245. SET_BIT(USARTx->CR2, USART_CR2_LINEN);
  2246. }
  2247. /**
  2248. * @brief Disable LIN mode
  2249. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2250. * LIN feature is supported by the USARTx instance.
  2251. * @rmtoll CR2 LINEN LL_USART_DisableLIN
  2252. * @param USARTx USART Instance
  2253. * @retval None
  2254. */
  2255. __STATIC_INLINE void LL_USART_DisableLIN(USART_TypeDef *USARTx)
  2256. {
  2257. CLEAR_BIT(USARTx->CR2, USART_CR2_LINEN);
  2258. }
  2259. /**
  2260. * @brief Indicate if LIN mode is enabled
  2261. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2262. * LIN feature is supported by the USARTx instance.
  2263. * @rmtoll CR2 LINEN LL_USART_IsEnabledLIN
  2264. * @param USARTx USART Instance
  2265. * @retval State of bit (1 or 0).
  2266. */
  2267. __STATIC_INLINE uint32_t LL_USART_IsEnabledLIN(USART_TypeDef *USARTx)
  2268. {
  2269. return ((READ_BIT(USARTx->CR2, USART_CR2_LINEN) == (USART_CR2_LINEN)) ? 1U : 0U);
  2270. }
  2271. /**
  2272. * @}
  2273. */
  2274. /** @defgroup USART_LL_EF_Configuration_DE Configuration functions related to Driver Enable feature
  2275. * @{
  2276. */
  2277. /**
  2278. * @brief Set DEDT (Driver Enable De-Assertion Time), Time value expressed on 5 bits ([4:0] bits).
  2279. * @note Macro @ref IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2280. * Driver Enable feature is supported by the USARTx instance.
  2281. * @rmtoll CR1 DEDT LL_USART_SetDEDeassertionTime
  2282. * @param USARTx USART Instance
  2283. * @param Time Value between Min_Data=0 and Max_Data=31
  2284. * @retval None
  2285. */
  2286. __STATIC_INLINE void LL_USART_SetDEDeassertionTime(USART_TypeDef *USARTx, uint32_t Time)
  2287. {
  2288. MODIFY_REG(USARTx->CR1, USART_CR1_DEDT, Time << USART_CR1_DEDT_Pos);
  2289. }
  2290. /**
  2291. * @brief Return DEDT (Driver Enable De-Assertion Time)
  2292. * @note Macro @ref IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2293. * Driver Enable feature is supported by the USARTx instance.
  2294. * @rmtoll CR1 DEDT LL_USART_GetDEDeassertionTime
  2295. * @param USARTx USART Instance
  2296. * @retval Time value expressed on 5 bits ([4:0] bits) : Value between Min_Data=0 and Max_Data=31
  2297. */
  2298. __STATIC_INLINE uint32_t LL_USART_GetDEDeassertionTime(USART_TypeDef *USARTx)
  2299. {
  2300. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_DEDT) >> USART_CR1_DEDT_Pos);
  2301. }
  2302. /**
  2303. * @brief Set DEAT (Driver Enable Assertion Time), Time value expressed on 5 bits ([4:0] bits).
  2304. * @note Macro @ref IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2305. * Driver Enable feature is supported by the USARTx instance.
  2306. * @rmtoll CR1 DEAT LL_USART_SetDEAssertionTime
  2307. * @param USARTx USART Instance
  2308. * @param Time Value between Min_Data=0 and Max_Data=31
  2309. * @retval None
  2310. */
  2311. __STATIC_INLINE void LL_USART_SetDEAssertionTime(USART_TypeDef *USARTx, uint32_t Time)
  2312. {
  2313. MODIFY_REG(USARTx->CR1, USART_CR1_DEAT, Time << USART_CR1_DEAT_Pos);
  2314. }
  2315. /**
  2316. * @brief Return DEAT (Driver Enable Assertion Time)
  2317. * @note Macro @ref IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2318. * Driver Enable feature is supported by the USARTx instance.
  2319. * @rmtoll CR1 DEAT LL_USART_GetDEAssertionTime
  2320. * @param USARTx USART Instance
  2321. * @retval Time value expressed on 5 bits ([4:0] bits) : Value between Min_Data=0 and Max_Data=31
  2322. */
  2323. __STATIC_INLINE uint32_t LL_USART_GetDEAssertionTime(USART_TypeDef *USARTx)
  2324. {
  2325. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_DEAT) >> USART_CR1_DEAT_Pos);
  2326. }
  2327. /**
  2328. * @brief Enable Driver Enable (DE) Mode
  2329. * @note Macro @ref IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2330. * Driver Enable feature is supported by the USARTx instance.
  2331. * @rmtoll CR3 DEM LL_USART_EnableDEMode
  2332. * @param USARTx USART Instance
  2333. * @retval None
  2334. */
  2335. __STATIC_INLINE void LL_USART_EnableDEMode(USART_TypeDef *USARTx)
  2336. {
  2337. SET_BIT(USARTx->CR3, USART_CR3_DEM);
  2338. }
  2339. /**
  2340. * @brief Disable Driver Enable (DE) Mode
  2341. * @note Macro @ref IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2342. * Driver Enable feature is supported by the USARTx instance.
  2343. * @rmtoll CR3 DEM LL_USART_DisableDEMode
  2344. * @param USARTx USART Instance
  2345. * @retval None
  2346. */
  2347. __STATIC_INLINE void LL_USART_DisableDEMode(USART_TypeDef *USARTx)
  2348. {
  2349. CLEAR_BIT(USARTx->CR3, USART_CR3_DEM);
  2350. }
  2351. /**
  2352. * @brief Indicate if Driver Enable (DE) Mode is enabled
  2353. * @note Macro @ref IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2354. * Driver Enable feature is supported by the USARTx instance.
  2355. * @rmtoll CR3 DEM LL_USART_IsEnabledDEMode
  2356. * @param USARTx USART Instance
  2357. * @retval State of bit (1 or 0).
  2358. */
  2359. __STATIC_INLINE uint32_t LL_USART_IsEnabledDEMode(USART_TypeDef *USARTx)
  2360. {
  2361. return ((READ_BIT(USARTx->CR3, USART_CR3_DEM) == (USART_CR3_DEM)) ? 1U : 0U);
  2362. }
  2363. /**
  2364. * @brief Select Driver Enable Polarity
  2365. * @note Macro @ref IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2366. * Driver Enable feature is supported by the USARTx instance.
  2367. * @rmtoll CR3 DEP LL_USART_SetDESignalPolarity
  2368. * @param USARTx USART Instance
  2369. * @param Polarity This parameter can be one of the following values:
  2370. * @arg @ref LL_USART_DE_POLARITY_HIGH
  2371. * @arg @ref LL_USART_DE_POLARITY_LOW
  2372. * @retval None
  2373. */
  2374. __STATIC_INLINE void LL_USART_SetDESignalPolarity(USART_TypeDef *USARTx, uint32_t Polarity)
  2375. {
  2376. MODIFY_REG(USARTx->CR3, USART_CR3_DEP, Polarity);
  2377. }
  2378. /**
  2379. * @brief Return Driver Enable Polarity
  2380. * @note Macro @ref IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2381. * Driver Enable feature is supported by the USARTx instance.
  2382. * @rmtoll CR3 DEP LL_USART_GetDESignalPolarity
  2383. * @param USARTx USART Instance
  2384. * @retval Returned value can be one of the following values:
  2385. * @arg @ref LL_USART_DE_POLARITY_HIGH
  2386. * @arg @ref LL_USART_DE_POLARITY_LOW
  2387. */
  2388. __STATIC_INLINE uint32_t LL_USART_GetDESignalPolarity(USART_TypeDef *USARTx)
  2389. {
  2390. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_DEP));
  2391. }
  2392. /**
  2393. * @}
  2394. */
  2395. /** @defgroup USART_LL_EF_AdvancedConfiguration Advanced Configurations services
  2396. * @{
  2397. */
  2398. /**
  2399. * @brief Perform basic configuration of USART for enabling use in Asynchronous Mode (UART)
  2400. * @note In UART mode, the following bits must be kept cleared:
  2401. * - LINEN bit in the USART_CR2 register,
  2402. * - CLKEN bit in the USART_CR2 register,
  2403. * - SCEN bit in the USART_CR3 register,
  2404. * - IREN bit in the USART_CR3 register,
  2405. * - HDSEL bit in the USART_CR3 register.
  2406. * @note Call of this function is equivalent to following function call sequence :
  2407. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
  2408. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  2409. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
  2410. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
  2411. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  2412. * @note Other remaining configurations items related to Asynchronous Mode
  2413. * (as Baud Rate, Word length, Parity, ...) should be set using
  2414. * dedicated functions
  2415. * @rmtoll CR2 LINEN LL_USART_ConfigAsyncMode\n
  2416. * CR2 CLKEN LL_USART_ConfigAsyncMode\n
  2417. * CR3 SCEN LL_USART_ConfigAsyncMode\n
  2418. * CR3 IREN LL_USART_ConfigAsyncMode\n
  2419. * CR3 HDSEL LL_USART_ConfigAsyncMode
  2420. * @param USARTx USART Instance
  2421. * @retval None
  2422. */
  2423. __STATIC_INLINE void LL_USART_ConfigAsyncMode(USART_TypeDef *USARTx)
  2424. {
  2425. /* In Asynchronous mode, the following bits must be kept cleared:
  2426. - LINEN, CLKEN bits in the USART_CR2 register,
  2427. - SCEN, IREN and HDSEL bits in the USART_CR3 register.*/
  2428. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
  2429. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN | USART_CR3_HDSEL));
  2430. }
  2431. /**
  2432. * @brief Perform basic configuration of USART for enabling use in Synchronous Mode
  2433. * @note In Synchronous mode, the following bits must be kept cleared:
  2434. * - LINEN bit in the USART_CR2 register,
  2435. * - SCEN bit in the USART_CR3 register,
  2436. * - IREN bit in the USART_CR3 register,
  2437. * - HDSEL bit in the USART_CR3 register.
  2438. * This function also sets the USART in Synchronous mode.
  2439. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  2440. * Synchronous mode is supported by the USARTx instance.
  2441. * @note Call of this function is equivalent to following function call sequence :
  2442. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
  2443. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
  2444. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
  2445. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  2446. * - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
  2447. * @note Other remaining configurations items related to Synchronous Mode
  2448. * (as Baud Rate, Word length, Parity, Clock Polarity, ...) should be set using
  2449. * dedicated functions
  2450. * @rmtoll CR2 LINEN LL_USART_ConfigSyncMode\n
  2451. * CR2 CLKEN LL_USART_ConfigSyncMode\n
  2452. * CR3 SCEN LL_USART_ConfigSyncMode\n
  2453. * CR3 IREN LL_USART_ConfigSyncMode\n
  2454. * CR3 HDSEL LL_USART_ConfigSyncMode
  2455. * @param USARTx USART Instance
  2456. * @retval None
  2457. */
  2458. __STATIC_INLINE void LL_USART_ConfigSyncMode(USART_TypeDef *USARTx)
  2459. {
  2460. /* In Synchronous mode, the following bits must be kept cleared:
  2461. - LINEN bit in the USART_CR2 register,
  2462. - SCEN, IREN and HDSEL bits in the USART_CR3 register.*/
  2463. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN));
  2464. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN | USART_CR3_HDSEL));
  2465. /* set the UART/USART in Synchronous mode */
  2466. SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
  2467. }
  2468. /**
  2469. * @brief Perform basic configuration of USART for enabling use in LIN Mode
  2470. * @note In LIN mode, the following bits must be kept cleared:
  2471. * - STOP and CLKEN bits in the USART_CR2 register,
  2472. * - SCEN bit in the USART_CR3 register,
  2473. * - IREN bit in the USART_CR3 register,
  2474. * - HDSEL bit in the USART_CR3 register.
  2475. * This function also set the UART/USART in LIN mode.
  2476. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2477. * LIN feature is supported by the USARTx instance.
  2478. * @note Call of this function is equivalent to following function call sequence :
  2479. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  2480. * - Clear STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
  2481. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
  2482. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
  2483. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  2484. * - Set LINEN in CR2 using @ref LL_USART_EnableLIN() function
  2485. * @note Other remaining configurations items related to LIN Mode
  2486. * (as Baud Rate, Word length, LIN Break Detection Length, ...) should be set using
  2487. * dedicated functions
  2488. * @rmtoll CR2 CLKEN LL_USART_ConfigLINMode\n
  2489. * CR2 STOP LL_USART_ConfigLINMode\n
  2490. * CR2 LINEN LL_USART_ConfigLINMode\n
  2491. * CR3 IREN LL_USART_ConfigLINMode\n
  2492. * CR3 SCEN LL_USART_ConfigLINMode\n
  2493. * CR3 HDSEL LL_USART_ConfigLINMode
  2494. * @param USARTx USART Instance
  2495. * @retval None
  2496. */
  2497. __STATIC_INLINE void LL_USART_ConfigLINMode(USART_TypeDef *USARTx)
  2498. {
  2499. /* In LIN mode, the following bits must be kept cleared:
  2500. - STOP and CLKEN bits in the USART_CR2 register,
  2501. - IREN, SCEN and HDSEL bits in the USART_CR3 register.*/
  2502. CLEAR_BIT(USARTx->CR2, (USART_CR2_CLKEN | USART_CR2_STOP));
  2503. CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_SCEN | USART_CR3_HDSEL));
  2504. /* Set the UART/USART in LIN mode */
  2505. SET_BIT(USARTx->CR2, USART_CR2_LINEN);
  2506. }
  2507. /**
  2508. * @brief Perform basic configuration of USART for enabling use in Half Duplex Mode
  2509. * @note In Half Duplex mode, the following bits must be kept cleared:
  2510. * - LINEN bit in the USART_CR2 register,
  2511. * - CLKEN bit in the USART_CR2 register,
  2512. * - SCEN bit in the USART_CR3 register,
  2513. * - IREN bit in the USART_CR3 register,
  2514. * This function also sets the UART/USART in Half Duplex mode.
  2515. * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  2516. * Half-Duplex mode is supported by the USARTx instance.
  2517. * @note Call of this function is equivalent to following function call sequence :
  2518. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
  2519. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  2520. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
  2521. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
  2522. * - Set HDSEL in CR3 using @ref LL_USART_EnableHalfDuplex() function
  2523. * @note Other remaining configurations items related to Half Duplex Mode
  2524. * (as Baud Rate, Word length, Parity, ...) should be set using
  2525. * dedicated functions
  2526. * @rmtoll CR2 LINEN LL_USART_ConfigHalfDuplexMode\n
  2527. * CR2 CLKEN LL_USART_ConfigHalfDuplexMode\n
  2528. * CR3 HDSEL LL_USART_ConfigHalfDuplexMode\n
  2529. * CR3 SCEN LL_USART_ConfigHalfDuplexMode\n
  2530. * CR3 IREN LL_USART_ConfigHalfDuplexMode
  2531. * @param USARTx USART Instance
  2532. * @retval None
  2533. */
  2534. __STATIC_INLINE void LL_USART_ConfigHalfDuplexMode(USART_TypeDef *USARTx)
  2535. {
  2536. /* In Half Duplex mode, the following bits must be kept cleared:
  2537. - LINEN and CLKEN bits in the USART_CR2 register,
  2538. - SCEN and IREN bits in the USART_CR3 register.*/
  2539. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
  2540. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN));
  2541. /* set the UART/USART in Half Duplex mode */
  2542. SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
  2543. }
  2544. /**
  2545. * @brief Perform basic configuration of USART for enabling use in Smartcard Mode
  2546. * @note In Smartcard mode, the following bits must be kept cleared:
  2547. * - LINEN bit in the USART_CR2 register,
  2548. * - IREN bit in the USART_CR3 register,
  2549. * - HDSEL bit in the USART_CR3 register.
  2550. * This function also configures Stop bits to 1.5 bits and
  2551. * sets the USART in Smartcard mode (SCEN bit).
  2552. * Clock Output is also enabled (CLKEN).
  2553. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  2554. * Smartcard feature is supported by the USARTx instance.
  2555. * @note Call of this function is equivalent to following function call sequence :
  2556. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
  2557. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
  2558. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  2559. * - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
  2560. * - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
  2561. * - Set SCEN in CR3 using @ref LL_USART_EnableSmartcard() function
  2562. * @note Other remaining configurations items related to Smartcard Mode
  2563. * (as Baud Rate, Word length, Parity, ...) should be set using
  2564. * dedicated functions
  2565. * @rmtoll CR2 LINEN LL_USART_ConfigSmartcardMode\n
  2566. * CR2 STOP LL_USART_ConfigSmartcardMode\n
  2567. * CR2 CLKEN LL_USART_ConfigSmartcardMode\n
  2568. * CR3 HDSEL LL_USART_ConfigSmartcardMode\n
  2569. * CR3 SCEN LL_USART_ConfigSmartcardMode
  2570. * @param USARTx USART Instance
  2571. * @retval None
  2572. */
  2573. __STATIC_INLINE void LL_USART_ConfigSmartcardMode(USART_TypeDef *USARTx)
  2574. {
  2575. /* In Smartcard mode, the following bits must be kept cleared:
  2576. - LINEN bit in the USART_CR2 register,
  2577. - IREN and HDSEL bits in the USART_CR3 register.*/
  2578. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN));
  2579. CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_HDSEL));
  2580. /* Configure Stop bits to 1.5 bits */
  2581. /* Synchronous mode is activated by default */
  2582. SET_BIT(USARTx->CR2, (USART_CR2_STOP_0 | USART_CR2_STOP_1 | USART_CR2_CLKEN));
  2583. /* set the UART/USART in Smartcard mode */
  2584. SET_BIT(USARTx->CR3, USART_CR3_SCEN);
  2585. }
  2586. /**
  2587. * @brief Perform basic configuration of USART for enabling use in Irda Mode
  2588. * @note In IRDA mode, the following bits must be kept cleared:
  2589. * - LINEN bit in the USART_CR2 register,
  2590. * - STOP and CLKEN bits in the USART_CR2 register,
  2591. * - SCEN bit in the USART_CR3 register,
  2592. * - HDSEL bit in the USART_CR3 register.
  2593. * This function also sets the UART/USART in IRDA mode (IREN bit).
  2594. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  2595. * IrDA feature is supported by the USARTx instance.
  2596. * @note Call of this function is equivalent to following function call sequence :
  2597. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
  2598. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  2599. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
  2600. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  2601. * - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
  2602. * - Set IREN in CR3 using @ref LL_USART_EnableIrda() function
  2603. * @note Other remaining configurations items related to Irda Mode
  2604. * (as Baud Rate, Word length, Power mode, ...) should be set using
  2605. * dedicated functions
  2606. * @rmtoll CR2 LINEN LL_USART_ConfigIrdaMode\n
  2607. * CR2 CLKEN LL_USART_ConfigIrdaMode\n
  2608. * CR2 STOP LL_USART_ConfigIrdaMode\n
  2609. * CR3 SCEN LL_USART_ConfigIrdaMode\n
  2610. * CR3 HDSEL LL_USART_ConfigIrdaMode\n
  2611. * CR3 IREN LL_USART_ConfigIrdaMode
  2612. * @param USARTx USART Instance
  2613. * @retval None
  2614. */
  2615. __STATIC_INLINE void LL_USART_ConfigIrdaMode(USART_TypeDef *USARTx)
  2616. {
  2617. /* In IRDA mode, the following bits must be kept cleared:
  2618. - LINEN, STOP and CLKEN bits in the USART_CR2 register,
  2619. - SCEN and HDSEL bits in the USART_CR3 register.*/
  2620. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP));
  2621. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
  2622. /* set the UART/USART in IRDA mode */
  2623. SET_BIT(USARTx->CR3, USART_CR3_IREN);
  2624. }
  2625. /**
  2626. * @brief Perform basic configuration of USART for enabling use in Multi processor Mode
  2627. * (several USARTs connected in a network, one of the USARTs can be the master,
  2628. * its TX output connected to the RX inputs of the other slaves USARTs).
  2629. * @note In MultiProcessor mode, the following bits must be kept cleared:
  2630. * - LINEN bit in the USART_CR2 register,
  2631. * - CLKEN bit in the USART_CR2 register,
  2632. * - SCEN bit in the USART_CR3 register,
  2633. * - IREN bit in the USART_CR3 register,
  2634. * - HDSEL bit in the USART_CR3 register.
  2635. * @note Call of this function is equivalent to following function call sequence :
  2636. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
  2637. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  2638. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
  2639. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
  2640. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  2641. * @note Other remaining configurations items related to Multi processor Mode
  2642. * (as Baud Rate, Wake Up Method, Node address, ...) should be set using
  2643. * dedicated functions
  2644. * @rmtoll CR2 LINEN LL_USART_ConfigMultiProcessMode\n
  2645. * CR2 CLKEN LL_USART_ConfigMultiProcessMode\n
  2646. * CR3 SCEN LL_USART_ConfigMultiProcessMode\n
  2647. * CR3 HDSEL LL_USART_ConfigMultiProcessMode\n
  2648. * CR3 IREN LL_USART_ConfigMultiProcessMode
  2649. * @param USARTx USART Instance
  2650. * @retval None
  2651. */
  2652. __STATIC_INLINE void LL_USART_ConfigMultiProcessMode(USART_TypeDef *USARTx)
  2653. {
  2654. /* In Multi Processor mode, the following bits must be kept cleared:
  2655. - LINEN and CLKEN bits in the USART_CR2 register,
  2656. - IREN, SCEN and HDSEL bits in the USART_CR3 register.*/
  2657. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
  2658. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
  2659. }
  2660. /**
  2661. * @}
  2662. */
  2663. /** @defgroup USART_LL_EF_FLAG_Management FLAG_Management
  2664. * @{
  2665. */
  2666. /**
  2667. * @brief Check if the USART Parity Error Flag is set or not
  2668. * @rmtoll ISR PE LL_USART_IsActiveFlag_PE
  2669. * @param USARTx USART Instance
  2670. * @retval State of bit (1 or 0).
  2671. */
  2672. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_PE(USART_TypeDef *USARTx)
  2673. {
  2674. return ((READ_BIT(USARTx->ISR, USART_ISR_PE) == (USART_ISR_PE)) ? 1U : 0U);
  2675. }
  2676. /**
  2677. * @brief Check if the USART Framing Error Flag is set or not
  2678. * @rmtoll ISR FE LL_USART_IsActiveFlag_FE
  2679. * @param USARTx USART Instance
  2680. * @retval State of bit (1 or 0).
  2681. */
  2682. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_FE(USART_TypeDef *USARTx)
  2683. {
  2684. return ((READ_BIT(USARTx->ISR, USART_ISR_FE) == (USART_ISR_FE)) ? 1U : 0U);
  2685. }
  2686. /**
  2687. * @brief Check if the USART Noise error detected Flag is set or not
  2688. * @rmtoll ISR NE LL_USART_IsActiveFlag_NE
  2689. * @param USARTx USART Instance
  2690. * @retval State of bit (1 or 0).
  2691. */
  2692. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_NE(USART_TypeDef *USARTx)
  2693. {
  2694. return ((READ_BIT(USARTx->ISR, USART_ISR_NE) == (USART_ISR_NE)) ? 1U : 0U);
  2695. }
  2696. /**
  2697. * @brief Check if the USART OverRun Error Flag is set or not
  2698. * @rmtoll ISR ORE LL_USART_IsActiveFlag_ORE
  2699. * @param USARTx USART Instance
  2700. * @retval State of bit (1 or 0).
  2701. */
  2702. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ORE(USART_TypeDef *USARTx)
  2703. {
  2704. return ((READ_BIT(USARTx->ISR, USART_ISR_ORE) == (USART_ISR_ORE)) ? 1U : 0U);
  2705. }
  2706. /**
  2707. * @brief Check if the USART IDLE line detected Flag is set or not
  2708. * @rmtoll ISR IDLE LL_USART_IsActiveFlag_IDLE
  2709. * @param USARTx USART Instance
  2710. * @retval State of bit (1 or 0).
  2711. */
  2712. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_IDLE(USART_TypeDef *USARTx)
  2713. {
  2714. return ((READ_BIT(USARTx->ISR, USART_ISR_IDLE) == (USART_ISR_IDLE)) ? 1U : 0U);
  2715. }
  2716. /* Legacy define */
  2717. #define LL_USART_IsActiveFlag_RXNE LL_USART_IsActiveFlag_RXNE_RXFNE
  2718. /**
  2719. * @brief Check if the USART Read Data Register or USART RX FIFO Not Empty Flag is set or not
  2720. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  2721. * FIFO mode feature is supported by the USARTx instance.
  2722. * @rmtoll ISR RXNE_RXFNE LL_USART_IsActiveFlag_RXNE_RXFNE
  2723. * @param USARTx USART Instance
  2724. * @retval State of bit (1 or 0).
  2725. */
  2726. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RXNE_RXFNE(USART_TypeDef *USARTx)
  2727. {
  2728. return ((READ_BIT(USARTx->ISR, USART_ISR_RXNE_RXFNE) == (USART_ISR_RXNE_RXFNE)) ? 1U : 0U);
  2729. }
  2730. /**
  2731. * @brief Check if the USART Transmission Complete Flag is set or not
  2732. * @rmtoll ISR TC LL_USART_IsActiveFlag_TC
  2733. * @param USARTx USART Instance
  2734. * @retval State of bit (1 or 0).
  2735. */
  2736. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TC(USART_TypeDef *USARTx)
  2737. {
  2738. return ((READ_BIT(USARTx->ISR, USART_ISR_TC) == (USART_ISR_TC)) ? 1U : 0U);
  2739. }
  2740. /* Legacy define */
  2741. #define LL_USART_IsActiveFlag_TXE LL_USART_IsActiveFlag_TXE_TXFNF
  2742. /**
  2743. * @brief Check if the USART Transmit Data Register Empty or USART TX FIFO Not Full Flag is set or not
  2744. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  2745. * FIFO mode feature is supported by the USARTx instance.
  2746. * @rmtoll ISR TXE_TXFNF LL_USART_IsActiveFlag_TXE_TXFNF
  2747. * @param USARTx USART Instance
  2748. * @retval State of bit (1 or 0).
  2749. */
  2750. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXE_TXFNF(USART_TypeDef *USARTx)
  2751. {
  2752. return ((READ_BIT(USARTx->ISR, USART_ISR_TXE_TXFNF) == (USART_ISR_TXE_TXFNF)) ? 1U : 0U);
  2753. }
  2754. /**
  2755. * @brief Check if the USART LIN Break Detection Flag is set or not
  2756. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2757. * LIN feature is supported by the USARTx instance.
  2758. * @rmtoll ISR LBDF LL_USART_IsActiveFlag_LBD
  2759. * @param USARTx USART Instance
  2760. * @retval State of bit (1 or 0).
  2761. */
  2762. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_LBD(USART_TypeDef *USARTx)
  2763. {
  2764. return ((READ_BIT(USARTx->ISR, USART_ISR_LBDF) == (USART_ISR_LBDF)) ? 1U : 0U);
  2765. }
  2766. /**
  2767. * @brief Check if the USART CTS interrupt Flag is set or not
  2768. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  2769. * Hardware Flow control feature is supported by the USARTx instance.
  2770. * @rmtoll ISR CTSIF LL_USART_IsActiveFlag_nCTS
  2771. * @param USARTx USART Instance
  2772. * @retval State of bit (1 or 0).
  2773. */
  2774. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_nCTS(USART_TypeDef *USARTx)
  2775. {
  2776. return ((READ_BIT(USARTx->ISR, USART_ISR_CTSIF) == (USART_ISR_CTSIF)) ? 1U : 0U);
  2777. }
  2778. /**
  2779. * @brief Check if the USART CTS Flag is set or not
  2780. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  2781. * Hardware Flow control feature is supported by the USARTx instance.
  2782. * @rmtoll ISR CTS LL_USART_IsActiveFlag_CTS
  2783. * @param USARTx USART Instance
  2784. * @retval State of bit (1 or 0).
  2785. */
  2786. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_CTS(USART_TypeDef *USARTx)
  2787. {
  2788. return ((READ_BIT(USARTx->ISR, USART_ISR_CTS) == (USART_ISR_CTS)) ? 1U : 0U);
  2789. }
  2790. /**
  2791. * @brief Check if the USART Receiver Time Out Flag is set or not
  2792. * @rmtoll ISR RTOF LL_USART_IsActiveFlag_RTO
  2793. * @param USARTx USART Instance
  2794. * @retval State of bit (1 or 0).
  2795. */
  2796. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RTO(USART_TypeDef *USARTx)
  2797. {
  2798. return ((READ_BIT(USARTx->ISR, USART_ISR_RTOF) == (USART_ISR_RTOF)) ? 1U : 0U);
  2799. }
  2800. /**
  2801. * @brief Check if the USART End Of Block Flag is set or not
  2802. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  2803. * Smartcard feature is supported by the USARTx instance.
  2804. * @rmtoll ISR EOBF LL_USART_IsActiveFlag_EOB
  2805. * @param USARTx USART Instance
  2806. * @retval State of bit (1 or 0).
  2807. */
  2808. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_EOB(USART_TypeDef *USARTx)
  2809. {
  2810. return ((READ_BIT(USARTx->ISR, USART_ISR_EOBF) == (USART_ISR_EOBF)) ? 1U : 0U);
  2811. }
  2812. /**
  2813. * @brief Check if the SPI Slave Underrun error flag is set or not
  2814. * @note Macro @ref IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
  2815. * SPI Slave mode feature is supported by the USARTx instance.
  2816. * @rmtoll ISR UDR LL_USART_IsActiveFlag_UDR
  2817. * @param USARTx USART Instance
  2818. * @retval State of bit (1 or 0).
  2819. */
  2820. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_UDR(USART_TypeDef *USARTx)
  2821. {
  2822. return ((READ_BIT(USARTx->ISR, USART_ISR_UDR) == (USART_ISR_UDR)) ? 1U : 0U);
  2823. }
  2824. /**
  2825. * @brief Check if the USART Auto-Baud Rate Error Flag is set or not
  2826. * @note Macro @ref IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  2827. * Auto Baud Rate detection feature is supported by the USARTx instance.
  2828. * @rmtoll ISR ABRE LL_USART_IsActiveFlag_ABRE
  2829. * @param USARTx USART Instance
  2830. * @retval State of bit (1 or 0).
  2831. */
  2832. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ABRE(USART_TypeDef *USARTx)
  2833. {
  2834. return ((READ_BIT(USARTx->ISR, USART_ISR_ABRE) == (USART_ISR_ABRE)) ? 1U : 0U);
  2835. }
  2836. /**
  2837. * @brief Check if the USART Auto-Baud Rate Flag is set or not
  2838. * @note Macro @ref IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  2839. * Auto Baud Rate detection feature is supported by the USARTx instance.
  2840. * @rmtoll ISR ABRF LL_USART_IsActiveFlag_ABR
  2841. * @param USARTx USART Instance
  2842. * @retval State of bit (1 or 0).
  2843. */
  2844. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ABR(USART_TypeDef *USARTx)
  2845. {
  2846. return ((READ_BIT(USARTx->ISR, USART_ISR_ABRF) == (USART_ISR_ABRF)) ? 1U : 0U);
  2847. }
  2848. /**
  2849. * @brief Check if the USART Busy Flag is set or not
  2850. * @rmtoll ISR BUSY LL_USART_IsActiveFlag_BUSY
  2851. * @param USARTx USART Instance
  2852. * @retval State of bit (1 or 0).
  2853. */
  2854. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_BUSY(USART_TypeDef *USARTx)
  2855. {
  2856. return ((READ_BIT(USARTx->ISR, USART_ISR_BUSY) == (USART_ISR_BUSY)) ? 1U : 0U);
  2857. }
  2858. /**
  2859. * @brief Check if the USART Character Match Flag is set or not
  2860. * @rmtoll ISR CMF LL_USART_IsActiveFlag_CM
  2861. * @param USARTx USART Instance
  2862. * @retval State of bit (1 or 0).
  2863. */
  2864. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_CM(USART_TypeDef *USARTx)
  2865. {
  2866. return ((READ_BIT(USARTx->ISR, USART_ISR_CMF) == (USART_ISR_CMF)) ? 1U : 0U);
  2867. }
  2868. /**
  2869. * @brief Check if the USART Send Break Flag is set or not
  2870. * @rmtoll ISR SBKF LL_USART_IsActiveFlag_SBK
  2871. * @param USARTx USART Instance
  2872. * @retval State of bit (1 or 0).
  2873. */
  2874. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_SBK(USART_TypeDef *USARTx)
  2875. {
  2876. return ((READ_BIT(USARTx->ISR, USART_ISR_SBKF) == (USART_ISR_SBKF)) ? 1U : 0U);
  2877. }
  2878. /**
  2879. * @brief Check if the USART Receive Wake Up from mute mode Flag is set or not
  2880. * @rmtoll ISR RWU LL_USART_IsActiveFlag_RWU
  2881. * @param USARTx USART Instance
  2882. * @retval State of bit (1 or 0).
  2883. */
  2884. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RWU(USART_TypeDef *USARTx)
  2885. {
  2886. return ((READ_BIT(USARTx->ISR, USART_ISR_RWU) == (USART_ISR_RWU)) ? 1U : 0U);
  2887. }
  2888. /**
  2889. * @brief Check if the USART Wake Up from stop mode Flag is set or not
  2890. * @note Macro @ref IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  2891. * Wake-up from Stop mode feature is supported by the USARTx instance.
  2892. * @rmtoll ISR WUF LL_USART_IsActiveFlag_WKUP
  2893. * @param USARTx USART Instance
  2894. * @retval State of bit (1 or 0).
  2895. */
  2896. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_WKUP(USART_TypeDef *USARTx)
  2897. {
  2898. return ((READ_BIT(USARTx->ISR, USART_ISR_WUF) == (USART_ISR_WUF)) ? 1U : 0U);
  2899. }
  2900. /**
  2901. * @brief Check if the USART Transmit Enable Acknowledge Flag is set or not
  2902. * @rmtoll ISR TEACK LL_USART_IsActiveFlag_TEACK
  2903. * @param USARTx USART Instance
  2904. * @retval State of bit (1 or 0).
  2905. */
  2906. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TEACK(USART_TypeDef *USARTx)
  2907. {
  2908. return ((READ_BIT(USARTx->ISR, USART_ISR_TEACK) == (USART_ISR_TEACK)) ? 1U : 0U);
  2909. }
  2910. /**
  2911. * @brief Check if the USART Receive Enable Acknowledge Flag is set or not
  2912. * @rmtoll ISR REACK LL_USART_IsActiveFlag_REACK
  2913. * @param USARTx USART Instance
  2914. * @retval State of bit (1 or 0).
  2915. */
  2916. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_REACK(USART_TypeDef *USARTx)
  2917. {
  2918. return ((READ_BIT(USARTx->ISR, USART_ISR_REACK) == (USART_ISR_REACK)) ? 1U : 0U);
  2919. }
  2920. /**
  2921. * @brief Check if the USART TX FIFO Empty Flag is set or not
  2922. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  2923. * FIFO mode feature is supported by the USARTx instance.
  2924. * @rmtoll ISR TXFE LL_USART_IsActiveFlag_TXFE
  2925. * @param USARTx USART Instance
  2926. * @retval State of bit (1 or 0).
  2927. */
  2928. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXFE(USART_TypeDef *USARTx)
  2929. {
  2930. return ((READ_BIT(USARTx->ISR, USART_ISR_TXFE) == (USART_ISR_TXFE)) ? 1U : 0U);
  2931. }
  2932. /**
  2933. * @brief Check if the USART RX FIFO Full Flag is set or not
  2934. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  2935. * FIFO mode feature is supported by the USARTx instance.
  2936. * @rmtoll ISR RXFF LL_USART_IsActiveFlag_RXFF
  2937. * @param USARTx USART Instance
  2938. * @retval State of bit (1 or 0).
  2939. */
  2940. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RXFF(USART_TypeDef *USARTx)
  2941. {
  2942. return ((READ_BIT(USARTx->ISR, USART_ISR_RXFF) == (USART_ISR_RXFF)) ? 1U : 0U);
  2943. }
  2944. /**
  2945. * @brief Check if the Smartcard Transmission Complete Before Guard Time Flag is set or not
  2946. * @rmtoll ISR TCBGT LL_USART_IsActiveFlag_TCBGT
  2947. * @param USARTx USART Instance
  2948. * @retval State of bit (1 or 0).
  2949. */
  2950. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TCBGT(USART_TypeDef *USARTx)
  2951. {
  2952. return ((READ_BIT(USARTx->ISR, USART_ISR_TCBGT) == (USART_ISR_TCBGT)) ? 1U : 0U);
  2953. }
  2954. /**
  2955. * @brief Check if the USART TX FIFO Threshold Flag is set or not
  2956. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  2957. * FIFO mode feature is supported by the USARTx instance.
  2958. * @rmtoll ISR TXFT LL_USART_IsActiveFlag_TXFT
  2959. * @param USARTx USART Instance
  2960. * @retval State of bit (1 or 0).
  2961. */
  2962. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXFT(USART_TypeDef *USARTx)
  2963. {
  2964. return ((READ_BIT(USARTx->ISR, USART_ISR_TXFT) == (USART_ISR_TXFT)) ? 1U : 0U);
  2965. }
  2966. /**
  2967. * @brief Check if the USART RX FIFO Threshold Flag is set or not
  2968. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  2969. * FIFO mode feature is supported by the USARTx instance.
  2970. * @rmtoll ISR RXFT LL_USART_IsActiveFlag_RXFT
  2971. * @param USARTx USART Instance
  2972. * @retval State of bit (1 or 0).
  2973. */
  2974. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RXFT(USART_TypeDef *USARTx)
  2975. {
  2976. return ((READ_BIT(USARTx->ISR, USART_ISR_RXFT) == (USART_ISR_RXFT)) ? 1U : 0U);
  2977. }
  2978. /**
  2979. * @brief Clear Parity Error Flag
  2980. * @rmtoll ICR PECF LL_USART_ClearFlag_PE
  2981. * @param USARTx USART Instance
  2982. * @retval None
  2983. */
  2984. __STATIC_INLINE void LL_USART_ClearFlag_PE(USART_TypeDef *USARTx)
  2985. {
  2986. WRITE_REG(USARTx->ICR, USART_ICR_PECF);
  2987. }
  2988. /**
  2989. * @brief Clear Framing Error Flag
  2990. * @rmtoll ICR FECF LL_USART_ClearFlag_FE
  2991. * @param USARTx USART Instance
  2992. * @retval None
  2993. */
  2994. __STATIC_INLINE void LL_USART_ClearFlag_FE(USART_TypeDef *USARTx)
  2995. {
  2996. WRITE_REG(USARTx->ICR, USART_ICR_FECF);
  2997. }
  2998. /**
  2999. * @brief Clear Noise Error detected Flag
  3000. * @rmtoll ICR NECF LL_USART_ClearFlag_NE
  3001. * @param USARTx USART Instance
  3002. * @retval None
  3003. */
  3004. __STATIC_INLINE void LL_USART_ClearFlag_NE(USART_TypeDef *USARTx)
  3005. {
  3006. WRITE_REG(USARTx->ICR, USART_ICR_NECF);
  3007. }
  3008. /**
  3009. * @brief Clear OverRun Error Flag
  3010. * @rmtoll ICR ORECF LL_USART_ClearFlag_ORE
  3011. * @param USARTx USART Instance
  3012. * @retval None
  3013. */
  3014. __STATIC_INLINE void LL_USART_ClearFlag_ORE(USART_TypeDef *USARTx)
  3015. {
  3016. WRITE_REG(USARTx->ICR, USART_ICR_ORECF);
  3017. }
  3018. /**
  3019. * @brief Clear IDLE line detected Flag
  3020. * @rmtoll ICR IDLECF LL_USART_ClearFlag_IDLE
  3021. * @param USARTx USART Instance
  3022. * @retval None
  3023. */
  3024. __STATIC_INLINE void LL_USART_ClearFlag_IDLE(USART_TypeDef *USARTx)
  3025. {
  3026. WRITE_REG(USARTx->ICR, USART_ICR_IDLECF);
  3027. }
  3028. /**
  3029. * @brief Clear TX FIFO Empty Flag
  3030. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3031. * FIFO mode feature is supported by the USARTx instance.
  3032. * @rmtoll ICR TXFECF LL_USART_ClearFlag_TXFE
  3033. * @param USARTx USART Instance
  3034. * @retval None
  3035. */
  3036. __STATIC_INLINE void LL_USART_ClearFlag_TXFE(USART_TypeDef *USARTx)
  3037. {
  3038. WRITE_REG(USARTx->ICR, USART_ICR_TXFECF);
  3039. }
  3040. /**
  3041. * @brief Clear Transmission Complete Flag
  3042. * @rmtoll ICR TCCF LL_USART_ClearFlag_TC
  3043. * @param USARTx USART Instance
  3044. * @retval None
  3045. */
  3046. __STATIC_INLINE void LL_USART_ClearFlag_TC(USART_TypeDef *USARTx)
  3047. {
  3048. WRITE_REG(USARTx->ICR, USART_ICR_TCCF);
  3049. }
  3050. /**
  3051. * @brief Clear Smartcard Transmission Complete Before Guard Time Flag
  3052. * @rmtoll ICR TCBGTCF LL_USART_ClearFlag_TCBGT
  3053. * @param USARTx USART Instance
  3054. * @retval None
  3055. */
  3056. __STATIC_INLINE void LL_USART_ClearFlag_TCBGT(USART_TypeDef *USARTx)
  3057. {
  3058. WRITE_REG(USARTx->ICR, USART_ICR_TCBGTCF);
  3059. }
  3060. /**
  3061. * @brief Clear LIN Break Detection Flag
  3062. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  3063. * LIN feature is supported by the USARTx instance.
  3064. * @rmtoll ICR LBDCF LL_USART_ClearFlag_LBD
  3065. * @param USARTx USART Instance
  3066. * @retval None
  3067. */
  3068. __STATIC_INLINE void LL_USART_ClearFlag_LBD(USART_TypeDef *USARTx)
  3069. {
  3070. WRITE_REG(USARTx->ICR, USART_ICR_LBDCF);
  3071. }
  3072. /**
  3073. * @brief Clear CTS Interrupt Flag
  3074. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  3075. * Hardware Flow control feature is supported by the USARTx instance.
  3076. * @rmtoll ICR CTSCF LL_USART_ClearFlag_nCTS
  3077. * @param USARTx USART Instance
  3078. * @retval None
  3079. */
  3080. __STATIC_INLINE void LL_USART_ClearFlag_nCTS(USART_TypeDef *USARTx)
  3081. {
  3082. WRITE_REG(USARTx->ICR, USART_ICR_CTSCF);
  3083. }
  3084. /**
  3085. * @brief Clear Receiver Time Out Flag
  3086. * @rmtoll ICR RTOCF LL_USART_ClearFlag_RTO
  3087. * @param USARTx USART Instance
  3088. * @retval None
  3089. */
  3090. __STATIC_INLINE void LL_USART_ClearFlag_RTO(USART_TypeDef *USARTx)
  3091. {
  3092. WRITE_REG(USARTx->ICR, USART_ICR_RTOCF);
  3093. }
  3094. /**
  3095. * @brief Clear End Of Block Flag
  3096. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  3097. * Smartcard feature is supported by the USARTx instance.
  3098. * @rmtoll ICR EOBCF LL_USART_ClearFlag_EOB
  3099. * @param USARTx USART Instance
  3100. * @retval None
  3101. */
  3102. __STATIC_INLINE void LL_USART_ClearFlag_EOB(USART_TypeDef *USARTx)
  3103. {
  3104. WRITE_REG(USARTx->ICR, USART_ICR_EOBCF);
  3105. }
  3106. /**
  3107. * @brief Clear SPI Slave Underrun Flag
  3108. * @note Macro @ref IS_UART_SPI_SLAVE_INSTANCE(USARTx) can be used to check whether or not
  3109. * SPI Slave mode feature is supported by the USARTx instance.
  3110. * @rmtoll ICR UDRCF LL_USART_ClearFlag_UDR
  3111. * @param USARTx USART Instance
  3112. * @retval None
  3113. */
  3114. __STATIC_INLINE void LL_USART_ClearFlag_UDR(USART_TypeDef *USARTx)
  3115. {
  3116. WRITE_REG(USARTx->ICR, USART_ICR_UDRCF);
  3117. }
  3118. /**
  3119. * @brief Clear Character Match Flag
  3120. * @rmtoll ICR CMCF LL_USART_ClearFlag_CM
  3121. * @param USARTx USART Instance
  3122. * @retval None
  3123. */
  3124. __STATIC_INLINE void LL_USART_ClearFlag_CM(USART_TypeDef *USARTx)
  3125. {
  3126. WRITE_REG(USARTx->ICR, USART_ICR_CMCF);
  3127. }
  3128. /**
  3129. * @brief Clear Wake Up from stop mode Flag
  3130. * @note Macro @ref IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  3131. * Wake-up from Stop mode feature is supported by the USARTx instance.
  3132. * @rmtoll ICR WUCF LL_USART_ClearFlag_WKUP
  3133. * @param USARTx USART Instance
  3134. * @retval None
  3135. */
  3136. __STATIC_INLINE void LL_USART_ClearFlag_WKUP(USART_TypeDef *USARTx)
  3137. {
  3138. WRITE_REG(USARTx->ICR, USART_ICR_WUCF);
  3139. }
  3140. /**
  3141. * @}
  3142. */
  3143. /** @defgroup USART_LL_EF_IT_Management IT_Management
  3144. * @{
  3145. */
  3146. /**
  3147. * @brief Enable IDLE Interrupt
  3148. * @rmtoll CR1 IDLEIE LL_USART_EnableIT_IDLE
  3149. * @param USARTx USART Instance
  3150. * @retval None
  3151. */
  3152. __STATIC_INLINE void LL_USART_EnableIT_IDLE(USART_TypeDef *USARTx)
  3153. {
  3154. SET_BIT(USARTx->CR1, USART_CR1_IDLEIE);
  3155. }
  3156. /* Legacy define */
  3157. #define LL_USART_EnableIT_RXNE LL_USART_EnableIT_RXNE_RXFNE
  3158. /**
  3159. * @brief Enable RX Not Empty and RX FIFO Not Empty Interrupt
  3160. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3161. * FIFO mode feature is supported by the USARTx instance.
  3162. * @rmtoll CR1 RXNEIE_RXFNEIE LL_USART_EnableIT_RXNE_RXFNE
  3163. * @param USARTx USART Instance
  3164. * @retval None
  3165. */
  3166. __STATIC_INLINE void LL_USART_EnableIT_RXNE_RXFNE(USART_TypeDef *USARTx)
  3167. {
  3168. SET_BIT(USARTx->CR1, USART_CR1_RXNEIE_RXFNEIE);
  3169. }
  3170. /**
  3171. * @brief Enable Transmission Complete Interrupt
  3172. * @rmtoll CR1 TCIE LL_USART_EnableIT_TC
  3173. * @param USARTx USART Instance
  3174. * @retval None
  3175. */
  3176. __STATIC_INLINE void LL_USART_EnableIT_TC(USART_TypeDef *USARTx)
  3177. {
  3178. SET_BIT(USARTx->CR1, USART_CR1_TCIE);
  3179. }
  3180. /* Legacy define */
  3181. #define LL_USART_EnableIT_TXE LL_USART_EnableIT_TXE_TXFNF
  3182. /**
  3183. * @brief Enable TX Empty and TX FIFO Not Full Interrupt
  3184. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3185. * FIFO mode feature is supported by the USARTx instance.
  3186. * @rmtoll CR1 TXEIE_TXFNFIE LL_USART_EnableIT_TXE_TXFNF
  3187. * @param USARTx USART Instance
  3188. * @retval None
  3189. */
  3190. __STATIC_INLINE void LL_USART_EnableIT_TXE_TXFNF(USART_TypeDef *USARTx)
  3191. {
  3192. SET_BIT(USARTx->CR1, USART_CR1_TXEIE_TXFNFIE);
  3193. }
  3194. /**
  3195. * @brief Enable Parity Error Interrupt
  3196. * @rmtoll CR1 PEIE LL_USART_EnableIT_PE
  3197. * @param USARTx USART Instance
  3198. * @retval None
  3199. */
  3200. __STATIC_INLINE void LL_USART_EnableIT_PE(USART_TypeDef *USARTx)
  3201. {
  3202. SET_BIT(USARTx->CR1, USART_CR1_PEIE);
  3203. }
  3204. /**
  3205. * @brief Enable Character Match Interrupt
  3206. * @rmtoll CR1 CMIE LL_USART_EnableIT_CM
  3207. * @param USARTx USART Instance
  3208. * @retval None
  3209. */
  3210. __STATIC_INLINE void LL_USART_EnableIT_CM(USART_TypeDef *USARTx)
  3211. {
  3212. SET_BIT(USARTx->CR1, USART_CR1_CMIE);
  3213. }
  3214. /**
  3215. * @brief Enable Receiver Timeout Interrupt
  3216. * @rmtoll CR1 RTOIE LL_USART_EnableIT_RTO
  3217. * @param USARTx USART Instance
  3218. * @retval None
  3219. */
  3220. __STATIC_INLINE void LL_USART_EnableIT_RTO(USART_TypeDef *USARTx)
  3221. {
  3222. SET_BIT(USARTx->CR1, USART_CR1_RTOIE);
  3223. }
  3224. /**
  3225. * @brief Enable End Of Block Interrupt
  3226. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  3227. * Smartcard feature is supported by the USARTx instance.
  3228. * @rmtoll CR1 EOBIE LL_USART_EnableIT_EOB
  3229. * @param USARTx USART Instance
  3230. * @retval None
  3231. */
  3232. __STATIC_INLINE void LL_USART_EnableIT_EOB(USART_TypeDef *USARTx)
  3233. {
  3234. SET_BIT(USARTx->CR1, USART_CR1_EOBIE);
  3235. }
  3236. /**
  3237. * @brief Enable TX FIFO Empty Interrupt
  3238. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3239. * FIFO mode feature is supported by the USARTx instance.
  3240. * @rmtoll CR1 TXFEIE LL_USART_EnableIT_TXFE
  3241. * @param USARTx USART Instance
  3242. * @retval None
  3243. */
  3244. __STATIC_INLINE void LL_USART_EnableIT_TXFE(USART_TypeDef *USARTx)
  3245. {
  3246. SET_BIT(USARTx->CR1, USART_CR1_TXFEIE);
  3247. }
  3248. /**
  3249. * @brief Enable RX FIFO Full Interrupt
  3250. * @rmtoll CR1 RXFFIE LL_USART_EnableIT_RXFF
  3251. * @param USARTx USART Instance
  3252. * @retval None
  3253. */
  3254. __STATIC_INLINE void LL_USART_EnableIT_RXFF(USART_TypeDef *USARTx)
  3255. {
  3256. SET_BIT(USARTx->CR1, USART_CR1_RXFFIE);
  3257. }
  3258. /**
  3259. * @brief Enable LIN Break Detection Interrupt
  3260. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  3261. * LIN feature is supported by the USARTx instance.
  3262. * @rmtoll CR2 LBDIE LL_USART_EnableIT_LBD
  3263. * @param USARTx USART Instance
  3264. * @retval None
  3265. */
  3266. __STATIC_INLINE void LL_USART_EnableIT_LBD(USART_TypeDef *USARTx)
  3267. {
  3268. SET_BIT(USARTx->CR2, USART_CR2_LBDIE);
  3269. }
  3270. /**
  3271. * @brief Enable Error Interrupt
  3272. * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
  3273. * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_ISR register).
  3274. * 0: Interrupt is inhibited
  3275. * 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_ISR register.
  3276. * @rmtoll CR3 EIE LL_USART_EnableIT_ERROR
  3277. * @param USARTx USART Instance
  3278. * @retval None
  3279. */
  3280. __STATIC_INLINE void LL_USART_EnableIT_ERROR(USART_TypeDef *USARTx)
  3281. {
  3282. SET_BIT(USARTx->CR3, USART_CR3_EIE);
  3283. }
  3284. /**
  3285. * @brief Enable CTS Interrupt
  3286. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  3287. * Hardware Flow control feature is supported by the USARTx instance.
  3288. * @rmtoll CR3 CTSIE LL_USART_EnableIT_CTS
  3289. * @param USARTx USART Instance
  3290. * @retval None
  3291. */
  3292. __STATIC_INLINE void LL_USART_EnableIT_CTS(USART_TypeDef *USARTx)
  3293. {
  3294. SET_BIT(USARTx->CR3, USART_CR3_CTSIE);
  3295. }
  3296. /**
  3297. * @brief Enable Wake Up from Stop Mode Interrupt
  3298. * @note Macro @ref IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  3299. * Wake-up from Stop mode feature is supported by the USARTx instance.
  3300. * @rmtoll CR3 WUFIE LL_USART_EnableIT_WKUP
  3301. * @param USARTx USART Instance
  3302. * @retval None
  3303. */
  3304. __STATIC_INLINE void LL_USART_EnableIT_WKUP(USART_TypeDef *USARTx)
  3305. {
  3306. SET_BIT(USARTx->CR3, USART_CR3_WUFIE);
  3307. }
  3308. /**
  3309. * @brief Enable TX FIFO Threshold Interrupt
  3310. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3311. * FIFO mode feature is supported by the USARTx instance.
  3312. * @rmtoll CR3 TXFTIE LL_USART_EnableIT_TXFT
  3313. * @param USARTx USART Instance
  3314. * @retval None
  3315. */
  3316. __STATIC_INLINE void LL_USART_EnableIT_TXFT(USART_TypeDef *USARTx)
  3317. {
  3318. SET_BIT(USARTx->CR3, USART_CR3_TXFTIE);
  3319. }
  3320. /**
  3321. * @brief Enable Smartcard Transmission Complete Before Guard Time Interrupt
  3322. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  3323. * Smartcard feature is supported by the USARTx instance.
  3324. * @rmtoll CR3 TCBGTIE LL_USART_EnableIT_TCBGT
  3325. * @param USARTx USART Instance
  3326. * @retval None
  3327. */
  3328. __STATIC_INLINE void LL_USART_EnableIT_TCBGT(USART_TypeDef *USARTx)
  3329. {
  3330. SET_BIT(USARTx->CR3, USART_CR3_TCBGTIE);
  3331. }
  3332. /**
  3333. * @brief Enable RX FIFO Threshold Interrupt
  3334. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3335. * FIFO mode feature is supported by the USARTx instance.
  3336. * @rmtoll CR3 RXFTIE LL_USART_EnableIT_RXFT
  3337. * @param USARTx USART Instance
  3338. * @retval None
  3339. */
  3340. __STATIC_INLINE void LL_USART_EnableIT_RXFT(USART_TypeDef *USARTx)
  3341. {
  3342. SET_BIT(USARTx->CR3, USART_CR3_RXFTIE);
  3343. }
  3344. /**
  3345. * @brief Disable IDLE Interrupt
  3346. * @rmtoll CR1 IDLEIE LL_USART_DisableIT_IDLE
  3347. * @param USARTx USART Instance
  3348. * @retval None
  3349. */
  3350. __STATIC_INLINE void LL_USART_DisableIT_IDLE(USART_TypeDef *USARTx)
  3351. {
  3352. CLEAR_BIT(USARTx->CR1, USART_CR1_IDLEIE);
  3353. }
  3354. /* Legacy define */
  3355. #define LL_USART_DisableIT_RXNE LL_USART_DisableIT_RXNE_RXFNE
  3356. /**
  3357. * @brief Disable RX Not Empty and RX FIFO Not Empty Interrupt
  3358. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3359. * FIFO mode feature is supported by the USARTx instance.
  3360. * @rmtoll CR1 RXNEIE_RXFNEIE LL_USART_DisableIT_RXNE_RXFNE
  3361. * @param USARTx USART Instance
  3362. * @retval None
  3363. */
  3364. __STATIC_INLINE void LL_USART_DisableIT_RXNE_RXFNE(USART_TypeDef *USARTx)
  3365. {
  3366. CLEAR_BIT(USARTx->CR1, USART_CR1_RXNEIE_RXFNEIE);
  3367. }
  3368. /**
  3369. * @brief Disable Transmission Complete Interrupt
  3370. * @rmtoll CR1 TCIE LL_USART_DisableIT_TC
  3371. * @param USARTx USART Instance
  3372. * @retval None
  3373. */
  3374. __STATIC_INLINE void LL_USART_DisableIT_TC(USART_TypeDef *USARTx)
  3375. {
  3376. CLEAR_BIT(USARTx->CR1, USART_CR1_TCIE);
  3377. }
  3378. /* Legacy define */
  3379. #define LL_USART_DisableIT_TXE LL_USART_DisableIT_TXE_TXFNF
  3380. /**
  3381. * @brief Disable TX Empty and TX FIFO Not Full Interrupt
  3382. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3383. * FIFO mode feature is supported by the USARTx instance.
  3384. * @rmtoll CR1 TXEIE_TXFNFIE LL_USART_DisableIT_TXE_TXFNF
  3385. * @param USARTx USART Instance
  3386. * @retval None
  3387. */
  3388. __STATIC_INLINE void LL_USART_DisableIT_TXE_TXFNF(USART_TypeDef *USARTx)
  3389. {
  3390. CLEAR_BIT(USARTx->CR1, USART_CR1_TXEIE_TXFNFIE);
  3391. }
  3392. /**
  3393. * @brief Disable Parity Error Interrupt
  3394. * @rmtoll CR1 PEIE LL_USART_DisableIT_PE
  3395. * @param USARTx USART Instance
  3396. * @retval None
  3397. */
  3398. __STATIC_INLINE void LL_USART_DisableIT_PE(USART_TypeDef *USARTx)
  3399. {
  3400. CLEAR_BIT(USARTx->CR1, USART_CR1_PEIE);
  3401. }
  3402. /**
  3403. * @brief Disable Character Match Interrupt
  3404. * @rmtoll CR1 CMIE LL_USART_DisableIT_CM
  3405. * @param USARTx USART Instance
  3406. * @retval None
  3407. */
  3408. __STATIC_INLINE void LL_USART_DisableIT_CM(USART_TypeDef *USARTx)
  3409. {
  3410. CLEAR_BIT(USARTx->CR1, USART_CR1_CMIE);
  3411. }
  3412. /**
  3413. * @brief Disable Receiver Timeout Interrupt
  3414. * @rmtoll CR1 RTOIE LL_USART_DisableIT_RTO
  3415. * @param USARTx USART Instance
  3416. * @retval None
  3417. */
  3418. __STATIC_INLINE void LL_USART_DisableIT_RTO(USART_TypeDef *USARTx)
  3419. {
  3420. CLEAR_BIT(USARTx->CR1, USART_CR1_RTOIE);
  3421. }
  3422. /**
  3423. * @brief Disable End Of Block Interrupt
  3424. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  3425. * Smartcard feature is supported by the USARTx instance.
  3426. * @rmtoll CR1 EOBIE LL_USART_DisableIT_EOB
  3427. * @param USARTx USART Instance
  3428. * @retval None
  3429. */
  3430. __STATIC_INLINE void LL_USART_DisableIT_EOB(USART_TypeDef *USARTx)
  3431. {
  3432. CLEAR_BIT(USARTx->CR1, USART_CR1_EOBIE);
  3433. }
  3434. /**
  3435. * @brief Disable TX FIFO Empty Interrupt
  3436. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3437. * FIFO mode feature is supported by the USARTx instance.
  3438. * @rmtoll CR1 TXFEIE LL_USART_DisableIT_TXFE
  3439. * @param USARTx USART Instance
  3440. * @retval None
  3441. */
  3442. __STATIC_INLINE void LL_USART_DisableIT_TXFE(USART_TypeDef *USARTx)
  3443. {
  3444. CLEAR_BIT(USARTx->CR1, USART_CR1_TXFEIE);
  3445. }
  3446. /**
  3447. * @brief Disable RX FIFO Full Interrupt
  3448. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3449. * FIFO mode feature is supported by the USARTx instance.
  3450. * @rmtoll CR1 RXFFIE LL_USART_DisableIT_RXFF
  3451. * @param USARTx USART Instance
  3452. * @retval None
  3453. */
  3454. __STATIC_INLINE void LL_USART_DisableIT_RXFF(USART_TypeDef *USARTx)
  3455. {
  3456. CLEAR_BIT(USARTx->CR1, USART_CR1_RXFFIE);
  3457. }
  3458. /**
  3459. * @brief Disable LIN Break Detection Interrupt
  3460. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  3461. * LIN feature is supported by the USARTx instance.
  3462. * @rmtoll CR2 LBDIE LL_USART_DisableIT_LBD
  3463. * @param USARTx USART Instance
  3464. * @retval None
  3465. */
  3466. __STATIC_INLINE void LL_USART_DisableIT_LBD(USART_TypeDef *USARTx)
  3467. {
  3468. CLEAR_BIT(USARTx->CR2, USART_CR2_LBDIE);
  3469. }
  3470. /**
  3471. * @brief Disable Error Interrupt
  3472. * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
  3473. * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_ISR register).
  3474. * 0: Interrupt is inhibited
  3475. * 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_ISR register.
  3476. * @rmtoll CR3 EIE LL_USART_DisableIT_ERROR
  3477. * @param USARTx USART Instance
  3478. * @retval None
  3479. */
  3480. __STATIC_INLINE void LL_USART_DisableIT_ERROR(USART_TypeDef *USARTx)
  3481. {
  3482. CLEAR_BIT(USARTx->CR3, USART_CR3_EIE);
  3483. }
  3484. /**
  3485. * @brief Disable CTS Interrupt
  3486. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  3487. * Hardware Flow control feature is supported by the USARTx instance.
  3488. * @rmtoll CR3 CTSIE LL_USART_DisableIT_CTS
  3489. * @param USARTx USART Instance
  3490. * @retval None
  3491. */
  3492. __STATIC_INLINE void LL_USART_DisableIT_CTS(USART_TypeDef *USARTx)
  3493. {
  3494. CLEAR_BIT(USARTx->CR3, USART_CR3_CTSIE);
  3495. }
  3496. /**
  3497. * @brief Disable Wake Up from Stop Mode Interrupt
  3498. * @note Macro @ref IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  3499. * Wake-up from Stop mode feature is supported by the USARTx instance.
  3500. * @rmtoll CR3 WUFIE LL_USART_DisableIT_WKUP
  3501. * @param USARTx USART Instance
  3502. * @retval None
  3503. */
  3504. __STATIC_INLINE void LL_USART_DisableIT_WKUP(USART_TypeDef *USARTx)
  3505. {
  3506. CLEAR_BIT(USARTx->CR3, USART_CR3_WUFIE);
  3507. }
  3508. /**
  3509. * @brief Disable TX FIFO Threshold Interrupt
  3510. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3511. * FIFO mode feature is supported by the USARTx instance.
  3512. * @rmtoll CR3 TXFTIE LL_USART_DisableIT_TXFT
  3513. * @param USARTx USART Instance
  3514. * @retval None
  3515. */
  3516. __STATIC_INLINE void LL_USART_DisableIT_TXFT(USART_TypeDef *USARTx)
  3517. {
  3518. CLEAR_BIT(USARTx->CR3, USART_CR3_TXFTIE);
  3519. }
  3520. /**
  3521. * @brief Disable Smartcard Transmission Complete Before Guard Time Interrupt
  3522. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  3523. * Smartcard feature is supported by the USARTx instance.
  3524. * @rmtoll CR3 TCBGTIE LL_USART_DisableIT_TCBGT
  3525. * @param USARTx USART Instance
  3526. * @retval None
  3527. */
  3528. __STATIC_INLINE void LL_USART_DisableIT_TCBGT(USART_TypeDef *USARTx)
  3529. {
  3530. CLEAR_BIT(USARTx->CR3, USART_CR3_TCBGTIE);
  3531. }
  3532. /**
  3533. * @brief Disable RX FIFO Threshold Interrupt
  3534. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3535. * FIFO mode feature is supported by the USARTx instance.
  3536. * @rmtoll CR3 RXFTIE LL_USART_DisableIT_RXFT
  3537. * @param USARTx USART Instance
  3538. * @retval None
  3539. */
  3540. __STATIC_INLINE void LL_USART_DisableIT_RXFT(USART_TypeDef *USARTx)
  3541. {
  3542. CLEAR_BIT(USARTx->CR3, USART_CR3_RXFTIE);
  3543. }
  3544. /**
  3545. * @brief Check if the USART IDLE Interrupt source is enabled or disabled.
  3546. * @rmtoll CR1 IDLEIE LL_USART_IsEnabledIT_IDLE
  3547. * @param USARTx USART Instance
  3548. * @retval State of bit (1 or 0).
  3549. */
  3550. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_IDLE(USART_TypeDef *USARTx)
  3551. {
  3552. return ((READ_BIT(USARTx->CR1, USART_CR1_IDLEIE) == (USART_CR1_IDLEIE)) ? 1U : 0U);
  3553. }
  3554. /* Legacy define */
  3555. #define LL_USART_IsEnabledIT_RXNE LL_USART_IsEnabledIT_RXNE_RXFNE
  3556. /**
  3557. * @brief Check if the USART RX Not Empty and USART RX FIFO Not Empty Interrupt is enabled or disabled.
  3558. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3559. * FIFO mode feature is supported by the USARTx instance.
  3560. * @rmtoll CR1 RXNEIE_RXFNEIE LL_USART_IsEnabledIT_RXNE_RXFNE
  3561. * @param USARTx USART Instance
  3562. * @retval State of bit (1 or 0).
  3563. */
  3564. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RXNE_RXFNE(USART_TypeDef *USARTx)
  3565. {
  3566. return ((READ_BIT(USARTx->CR1, USART_CR1_RXNEIE_RXFNEIE) == (USART_CR1_RXNEIE_RXFNEIE)) ? 1U : 0U);
  3567. }
  3568. /**
  3569. * @brief Check if the USART Transmission Complete Interrupt is enabled or disabled.
  3570. * @rmtoll CR1 TCIE LL_USART_IsEnabledIT_TC
  3571. * @param USARTx USART Instance
  3572. * @retval State of bit (1 or 0).
  3573. */
  3574. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TC(USART_TypeDef *USARTx)
  3575. {
  3576. return ((READ_BIT(USARTx->CR1, USART_CR1_TCIE) == (USART_CR1_TCIE)) ? 1U : 0U);
  3577. }
  3578. /* Legacy define */
  3579. #define LL_USART_IsEnabledIT_TXE LL_USART_IsEnabledIT_TXE_TXFNF
  3580. /**
  3581. * @brief Check if the USART TX Empty and USART TX FIFO Not Full Interrupt is enabled or disabled
  3582. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3583. * FIFO mode feature is supported by the USARTx instance.
  3584. * @rmtoll CR1 TXEIE_TXFNFIE LL_USART_IsEnabledIT_TXE_TXFNF
  3585. * @param USARTx USART Instance
  3586. * @retval State of bit (1 or 0).
  3587. */
  3588. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TXE_TXFNF(USART_TypeDef *USARTx)
  3589. {
  3590. return ((READ_BIT(USARTx->CR1, USART_CR1_TXEIE_TXFNFIE) == (USART_CR1_TXEIE_TXFNFIE)) ? 1U : 0U);
  3591. }
  3592. /**
  3593. * @brief Check if the USART Parity Error Interrupt is enabled or disabled.
  3594. * @rmtoll CR1 PEIE LL_USART_IsEnabledIT_PE
  3595. * @param USARTx USART Instance
  3596. * @retval State of bit (1 or 0).
  3597. */
  3598. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_PE(USART_TypeDef *USARTx)
  3599. {
  3600. return ((READ_BIT(USARTx->CR1, USART_CR1_PEIE) == (USART_CR1_PEIE)) ? 1U : 0U);
  3601. }
  3602. /**
  3603. * @brief Check if the USART Character Match Interrupt is enabled or disabled.
  3604. * @rmtoll CR1 CMIE LL_USART_IsEnabledIT_CM
  3605. * @param USARTx USART Instance
  3606. * @retval State of bit (1 or 0).
  3607. */
  3608. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_CM(USART_TypeDef *USARTx)
  3609. {
  3610. return ((READ_BIT(USARTx->CR1, USART_CR1_CMIE) == (USART_CR1_CMIE)) ? 1U : 0U);
  3611. }
  3612. /**
  3613. * @brief Check if the USART Receiver Timeout Interrupt is enabled or disabled.
  3614. * @rmtoll CR1 RTOIE LL_USART_IsEnabledIT_RTO
  3615. * @param USARTx USART Instance
  3616. * @retval State of bit (1 or 0).
  3617. */
  3618. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RTO(USART_TypeDef *USARTx)
  3619. {
  3620. return ((READ_BIT(USARTx->CR1, USART_CR1_RTOIE) == (USART_CR1_RTOIE)) ? 1U : 0U);
  3621. }
  3622. /**
  3623. * @brief Check if the USART End Of Block Interrupt is enabled or disabled.
  3624. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  3625. * Smartcard feature is supported by the USARTx instance.
  3626. * @rmtoll CR1 EOBIE LL_USART_IsEnabledIT_EOB
  3627. * @param USARTx USART Instance
  3628. * @retval State of bit (1 or 0).
  3629. */
  3630. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_EOB(USART_TypeDef *USARTx)
  3631. {
  3632. return ((READ_BIT(USARTx->CR1, USART_CR1_EOBIE) == (USART_CR1_EOBIE)) ? 1U : 0U);
  3633. }
  3634. /**
  3635. * @brief Check if the USART TX FIFO Empty Interrupt is enabled or disabled
  3636. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3637. * FIFO mode feature is supported by the USARTx instance.
  3638. * @rmtoll CR1 TXFEIE LL_USART_IsEnabledIT_TXFE
  3639. * @param USARTx USART Instance
  3640. * @retval State of bit (1 or 0).
  3641. */
  3642. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TXFE(USART_TypeDef *USARTx)
  3643. {
  3644. return ((READ_BIT(USARTx->CR1, USART_CR1_TXFEIE) == (USART_CR1_TXFEIE)) ? 1U : 0U);
  3645. }
  3646. /**
  3647. * @brief Check if the USART RX FIFO Full Interrupt is enabled or disabled
  3648. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3649. * FIFO mode feature is supported by the USARTx instance.
  3650. * @rmtoll CR1 RXFFIE LL_USART_IsEnabledIT_RXFF
  3651. * @param USARTx USART Instance
  3652. * @retval State of bit (1 or 0).
  3653. */
  3654. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RXFF(USART_TypeDef *USARTx)
  3655. {
  3656. return ((READ_BIT(USARTx->CR1, USART_CR1_RXFFIE) == (USART_CR1_RXFFIE)) ? 1U : 0U);
  3657. }
  3658. /**
  3659. * @brief Check if the USART LIN Break Detection Interrupt is enabled or disabled.
  3660. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  3661. * LIN feature is supported by the USARTx instance.
  3662. * @rmtoll CR2 LBDIE LL_USART_IsEnabledIT_LBD
  3663. * @param USARTx USART Instance
  3664. * @retval State of bit (1 or 0).
  3665. */
  3666. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_LBD(USART_TypeDef *USARTx)
  3667. {
  3668. return ((READ_BIT(USARTx->CR2, USART_CR2_LBDIE) == (USART_CR2_LBDIE)) ? 1U : 0U);
  3669. }
  3670. /**
  3671. * @brief Check if the USART Error Interrupt is enabled or disabled.
  3672. * @rmtoll CR3 EIE LL_USART_IsEnabledIT_ERROR
  3673. * @param USARTx USART Instance
  3674. * @retval State of bit (1 or 0).
  3675. */
  3676. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_ERROR(USART_TypeDef *USARTx)
  3677. {
  3678. return ((READ_BIT(USARTx->CR3, USART_CR3_EIE) == (USART_CR3_EIE)) ? 1U : 0U);
  3679. }
  3680. /**
  3681. * @brief Check if the USART CTS Interrupt is enabled or disabled.
  3682. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  3683. * Hardware Flow control feature is supported by the USARTx instance.
  3684. * @rmtoll CR3 CTSIE LL_USART_IsEnabledIT_CTS
  3685. * @param USARTx USART Instance
  3686. * @retval State of bit (1 or 0).
  3687. */
  3688. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_CTS(USART_TypeDef *USARTx)
  3689. {
  3690. return ((READ_BIT(USARTx->CR3, USART_CR3_CTSIE) == (USART_CR3_CTSIE)) ? 1U : 0U);
  3691. }
  3692. /**
  3693. * @brief Check if the USART Wake Up from Stop Mode Interrupt is enabled or disabled.
  3694. * @note Macro @ref IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  3695. * Wake-up from Stop mode feature is supported by the USARTx instance.
  3696. * @rmtoll CR3 WUFIE LL_USART_IsEnabledIT_WKUP
  3697. * @param USARTx USART Instance
  3698. * @retval State of bit (1 or 0).
  3699. */
  3700. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_WKUP(USART_TypeDef *USARTx)
  3701. {
  3702. return ((READ_BIT(USARTx->CR3, USART_CR3_WUFIE) == (USART_CR3_WUFIE)) ? 1U : 0U);
  3703. }
  3704. /**
  3705. * @brief Check if USART TX FIFO Threshold Interrupt is enabled or disabled
  3706. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3707. * FIFO mode feature is supported by the USARTx instance.
  3708. * @rmtoll CR3 TXFTIE LL_USART_IsEnabledIT_TXFT
  3709. * @param USARTx USART Instance
  3710. * @retval State of bit (1 or 0).
  3711. */
  3712. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TXFT(USART_TypeDef *USARTx)
  3713. {
  3714. return ((READ_BIT(USARTx->CR3, USART_CR3_TXFTIE) == (USART_CR3_TXFTIE)) ? 1U : 0U);
  3715. }
  3716. /**
  3717. * @brief Check if the Smartcard Transmission Complete Before Guard Time Interrupt is enabled or disabled.
  3718. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  3719. * Smartcard feature is supported by the USARTx instance.
  3720. * @rmtoll CR3 TCBGTIE LL_USART_IsEnabledIT_TCBGT
  3721. * @param USARTx USART Instance
  3722. * @retval State of bit (1 or 0).
  3723. */
  3724. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TCBGT(USART_TypeDef *USARTx)
  3725. {
  3726. return ((READ_BIT(USARTx->CR3, USART_CR3_TCBGTIE) == (USART_CR3_TCBGTIE)) ? 1U : 0U);
  3727. }
  3728. /**
  3729. * @brief Check if USART RX FIFO Threshold Interrupt is enabled or disabled
  3730. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3731. * FIFO mode feature is supported by the USARTx instance.
  3732. * @rmtoll CR3 RXFTIE LL_USART_IsEnabledIT_RXFT
  3733. * @param USARTx USART Instance
  3734. * @retval State of bit (1 or 0).
  3735. */
  3736. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RXFT(USART_TypeDef *USARTx)
  3737. {
  3738. return ((READ_BIT(USARTx->CR3, USART_CR3_RXFTIE) == (USART_CR3_RXFTIE)) ? 1U : 0U);
  3739. }
  3740. /**
  3741. * @}
  3742. */
  3743. /** @defgroup USART_LL_EF_DMA_Management DMA_Management
  3744. * @{
  3745. */
  3746. /**
  3747. * @brief Enable DMA Mode for reception
  3748. * @rmtoll CR3 DMAR LL_USART_EnableDMAReq_RX
  3749. * @param USARTx USART Instance
  3750. * @retval None
  3751. */
  3752. __STATIC_INLINE void LL_USART_EnableDMAReq_RX(USART_TypeDef *USARTx)
  3753. {
  3754. SET_BIT(USARTx->CR3, USART_CR3_DMAR);
  3755. }
  3756. /**
  3757. * @brief Disable DMA Mode for reception
  3758. * @rmtoll CR3 DMAR LL_USART_DisableDMAReq_RX
  3759. * @param USARTx USART Instance
  3760. * @retval None
  3761. */
  3762. __STATIC_INLINE void LL_USART_DisableDMAReq_RX(USART_TypeDef *USARTx)
  3763. {
  3764. CLEAR_BIT(USARTx->CR3, USART_CR3_DMAR);
  3765. }
  3766. /**
  3767. * @brief Check if DMA Mode is enabled for reception
  3768. * @rmtoll CR3 DMAR LL_USART_IsEnabledDMAReq_RX
  3769. * @param USARTx USART Instance
  3770. * @retval State of bit (1 or 0).
  3771. */
  3772. __STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_RX(USART_TypeDef *USARTx)
  3773. {
  3774. return ((READ_BIT(USARTx->CR3, USART_CR3_DMAR) == (USART_CR3_DMAR)) ? 1U : 0U);
  3775. }
  3776. /**
  3777. * @brief Enable DMA Mode for transmission
  3778. * @rmtoll CR3 DMAT LL_USART_EnableDMAReq_TX
  3779. * @param USARTx USART Instance
  3780. * @retval None
  3781. */
  3782. __STATIC_INLINE void LL_USART_EnableDMAReq_TX(USART_TypeDef *USARTx)
  3783. {
  3784. SET_BIT(USARTx->CR3, USART_CR3_DMAT);
  3785. }
  3786. /**
  3787. * @brief Disable DMA Mode for transmission
  3788. * @rmtoll CR3 DMAT LL_USART_DisableDMAReq_TX
  3789. * @param USARTx USART Instance
  3790. * @retval None
  3791. */
  3792. __STATIC_INLINE void LL_USART_DisableDMAReq_TX(USART_TypeDef *USARTx)
  3793. {
  3794. CLEAR_BIT(USARTx->CR3, USART_CR3_DMAT);
  3795. }
  3796. /**
  3797. * @brief Check if DMA Mode is enabled for transmission
  3798. * @rmtoll CR3 DMAT LL_USART_IsEnabledDMAReq_TX
  3799. * @param USARTx USART Instance
  3800. * @retval State of bit (1 or 0).
  3801. */
  3802. __STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_TX(USART_TypeDef *USARTx)
  3803. {
  3804. return ((READ_BIT(USARTx->CR3, USART_CR3_DMAT) == (USART_CR3_DMAT)) ? 1U : 0U);
  3805. }
  3806. /**
  3807. * @brief Enable DMA Disabling on Reception Error
  3808. * @rmtoll CR3 DDRE LL_USART_EnableDMADeactOnRxErr
  3809. * @param USARTx USART Instance
  3810. * @retval None
  3811. */
  3812. __STATIC_INLINE void LL_USART_EnableDMADeactOnRxErr(USART_TypeDef *USARTx)
  3813. {
  3814. SET_BIT(USARTx->CR3, USART_CR3_DDRE);
  3815. }
  3816. /**
  3817. * @brief Disable DMA Disabling on Reception Error
  3818. * @rmtoll CR3 DDRE LL_USART_DisableDMADeactOnRxErr
  3819. * @param USARTx USART Instance
  3820. * @retval None
  3821. */
  3822. __STATIC_INLINE void LL_USART_DisableDMADeactOnRxErr(USART_TypeDef *USARTx)
  3823. {
  3824. CLEAR_BIT(USARTx->CR3, USART_CR3_DDRE);
  3825. }
  3826. /**
  3827. * @brief Indicate if DMA Disabling on Reception Error is disabled
  3828. * @rmtoll CR3 DDRE LL_USART_IsEnabledDMADeactOnRxErr
  3829. * @param USARTx USART Instance
  3830. * @retval State of bit (1 or 0).
  3831. */
  3832. __STATIC_INLINE uint32_t LL_USART_IsEnabledDMADeactOnRxErr(USART_TypeDef *USARTx)
  3833. {
  3834. return ((READ_BIT(USARTx->CR3, USART_CR3_DDRE) == (USART_CR3_DDRE)) ? 1U : 0U);
  3835. }
  3836. /**
  3837. * @brief Get the data register address used for DMA transfer
  3838. * @rmtoll RDR RDR LL_USART_DMA_GetRegAddr\n
  3839. * @rmtoll TDR TDR LL_USART_DMA_GetRegAddr
  3840. * @param USARTx USART Instance
  3841. * @param Direction This parameter can be one of the following values:
  3842. * @arg @ref LL_USART_DMA_REG_DATA_TRANSMIT
  3843. * @arg @ref LL_USART_DMA_REG_DATA_RECEIVE
  3844. * @retval Address of data register
  3845. */
  3846. __STATIC_INLINE uint32_t LL_USART_DMA_GetRegAddr(USART_TypeDef *USARTx, uint32_t Direction)
  3847. {
  3848. uint32_t data_reg_addr;
  3849. if (Direction == LL_USART_DMA_REG_DATA_TRANSMIT)
  3850. {
  3851. /* return address of TDR register */
  3852. data_reg_addr = (uint32_t) & (USARTx->TDR);
  3853. }
  3854. else
  3855. {
  3856. /* return address of RDR register */
  3857. data_reg_addr = (uint32_t) & (USARTx->RDR);
  3858. }
  3859. return data_reg_addr;
  3860. }
  3861. /**
  3862. * @}
  3863. */
  3864. /** @defgroup USART_LL_EF_Data_Management Data_Management
  3865. * @{
  3866. */
  3867. /**
  3868. * @brief Read Receiver Data register (Receive Data value, 8 bits)
  3869. * @rmtoll RDR RDR LL_USART_ReceiveData8
  3870. * @param USARTx USART Instance
  3871. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  3872. */
  3873. __STATIC_INLINE uint8_t LL_USART_ReceiveData8(USART_TypeDef *USARTx)
  3874. {
  3875. return (uint8_t)(READ_BIT(USARTx->RDR, USART_RDR_RDR) & 0xFFU);
  3876. }
  3877. /**
  3878. * @brief Read Receiver Data register (Receive Data value, 9 bits)
  3879. * @rmtoll RDR RDR LL_USART_ReceiveData9
  3880. * @param USARTx USART Instance
  3881. * @retval Value between Min_Data=0x00 and Max_Data=0x1FF
  3882. */
  3883. __STATIC_INLINE uint16_t LL_USART_ReceiveData9(USART_TypeDef *USARTx)
  3884. {
  3885. return (uint16_t)(READ_BIT(USARTx->RDR, USART_RDR_RDR));
  3886. }
  3887. /**
  3888. * @brief Write in Transmitter Data Register (Transmit Data value, 8 bits)
  3889. * @rmtoll TDR TDR LL_USART_TransmitData8
  3890. * @param USARTx USART Instance
  3891. * @param Value between Min_Data=0x00 and Max_Data=0xFF
  3892. * @retval None
  3893. */
  3894. __STATIC_INLINE void LL_USART_TransmitData8(USART_TypeDef *USARTx, uint8_t Value)
  3895. {
  3896. USARTx->TDR = Value;
  3897. }
  3898. /**
  3899. * @brief Write in Transmitter Data Register (Transmit Data value, 9 bits)
  3900. * @rmtoll TDR TDR LL_USART_TransmitData9
  3901. * @param USARTx USART Instance
  3902. * @param Value between Min_Data=0x00 and Max_Data=0x1FF
  3903. * @retval None
  3904. */
  3905. __STATIC_INLINE void LL_USART_TransmitData9(USART_TypeDef *USARTx, uint16_t Value)
  3906. {
  3907. USARTx->TDR = Value & 0x1FFUL;
  3908. }
  3909. /**
  3910. * @}
  3911. */
  3912. /** @defgroup USART_LL_EF_Execution Execution
  3913. * @{
  3914. */
  3915. /**
  3916. * @brief Request an Automatic Baud Rate measurement on next received data frame
  3917. * @note Macro @ref IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  3918. * Auto Baud Rate detection feature is supported by the USARTx instance.
  3919. * @rmtoll RQR ABRRQ LL_USART_RequestAutoBaudRate
  3920. * @param USARTx USART Instance
  3921. * @retval None
  3922. */
  3923. __STATIC_INLINE void LL_USART_RequestAutoBaudRate(USART_TypeDef *USARTx)
  3924. {
  3925. SET_BIT(USARTx->RQR, USART_RQR_ABRRQ);
  3926. }
  3927. /**
  3928. * @brief Request Break sending
  3929. * @rmtoll RQR SBKRQ LL_USART_RequestBreakSending
  3930. * @param USARTx USART Instance
  3931. * @retval None
  3932. */
  3933. __STATIC_INLINE void LL_USART_RequestBreakSending(USART_TypeDef *USARTx)
  3934. {
  3935. SET_BIT(USARTx->RQR, USART_RQR_SBKRQ);
  3936. }
  3937. /**
  3938. * @brief Put USART in mute mode and set the RWU flag
  3939. * @rmtoll RQR MMRQ LL_USART_RequestEnterMuteMode
  3940. * @param USARTx USART Instance
  3941. * @retval None
  3942. */
  3943. __STATIC_INLINE void LL_USART_RequestEnterMuteMode(USART_TypeDef *USARTx)
  3944. {
  3945. SET_BIT(USARTx->RQR, USART_RQR_MMRQ);
  3946. }
  3947. /**
  3948. * @brief Request a Receive Data and FIFO flush
  3949. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3950. * FIFO mode feature is supported by the USARTx instance.
  3951. * @note Allows to discard the received data without reading them, and avoid an overrun
  3952. * condition.
  3953. * @rmtoll RQR RXFRQ LL_USART_RequestRxDataFlush
  3954. * @param USARTx USART Instance
  3955. * @retval None
  3956. */
  3957. __STATIC_INLINE void LL_USART_RequestRxDataFlush(USART_TypeDef *USARTx)
  3958. {
  3959. SET_BIT(USARTx->RQR, USART_RQR_RXFRQ);
  3960. }
  3961. /**
  3962. * @brief Request a Transmit data and FIFO flush
  3963. * @note Macro @ref IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  3964. * FIFO mode feature is supported by the USARTx instance.
  3965. * @rmtoll RQR TXFRQ LL_USART_RequestTxDataFlush
  3966. * @param USARTx USART Instance
  3967. * @retval None
  3968. */
  3969. __STATIC_INLINE void LL_USART_RequestTxDataFlush(USART_TypeDef *USARTx)
  3970. {
  3971. SET_BIT(USARTx->RQR, USART_RQR_TXFRQ);
  3972. }
  3973. /**
  3974. * @}
  3975. */
  3976. #if defined(USE_FULL_LL_DRIVER)
  3977. /** @defgroup USART_LL_EF_Init Initialization and de-initialization functions
  3978. * @{
  3979. */
  3980. ErrorStatus LL_USART_DeInit(USART_TypeDef *USARTx);
  3981. ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct);
  3982. void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct);
  3983. ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
  3984. void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
  3985. /**
  3986. * @}
  3987. */
  3988. #endif /* USE_FULL_LL_DRIVER */
  3989. /**
  3990. * @}
  3991. */
  3992. /**
  3993. * @}
  3994. */
  3995. #endif /* USART1 */
  3996. /**
  3997. * @}
  3998. */
  3999. #ifdef __cplusplus
  4000. }
  4001. #endif
  4002. #endif /* STM32WBxx_LL_USART_H */
  4003. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/