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.
 
 
 

3561 lines
134 KiB

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