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.
 
 
 

3741 lines
142 KiB

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