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.
 
 
 

2540 lines
96 KiB

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