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.
 
 
 

1380 lines
68 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_uart.h
  4. * @author MCD Application Team
  5. * @version V1.3.0
  6. * @date 29-January-2016
  7. * @brief Header file of UART HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 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 __STM32L4xx_HAL_UART_H
  39. #define __STM32L4xx_HAL_UART_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l4xx_hal_def.h"
  45. /** @addtogroup STM32L4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup UART
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup UART_Exported_Types UART Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief UART Init Structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t BaudRate; /*!< This member configures the UART communication baud rate.
  61. The baud rate register is computed using the following formula:
  62. - If oversampling is 16 or in LIN mode,
  63. Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate)))
  64. - If oversampling is 8,
  65. - - Baud Rate Register[15:4] = ((2 * PCLKx) / ((huart->Init.BaudRate)))[15:4]
  66. - - Baud Rate Register[3] = 0
  67. - - Baud Rate Register[2:0] = (((2 * PCLKx) / ((huart->Init.BaudRate)))[3:0]) >> 1 */
  68. uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
  69. This parameter can be a value of @ref UARTEx_Word_Length. */
  70. uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
  71. This parameter can be a value of @ref UART_Stop_Bits. */
  72. uint32_t Parity; /*!< Specifies the parity mode.
  73. This parameter can be a value of @ref UART_Parity
  74. @note When parity is enabled, the computed parity is inserted
  75. at the MSB position of the transmitted data (9th bit when
  76. the word length is set to 9 data bits; 8th bit when the
  77. word length is set to 8 data bits). */
  78. uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
  79. This parameter can be a value of @ref UART_Mode. */
  80. uint32_t HwFlowCtl; /*!< Specifies whether the hardware flow control mode is enabled
  81. or disabled.
  82. This parameter can be a value of @ref UART_Hardware_Flow_Control. */
  83. uint32_t OverSampling; /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to f_PCLK/8).
  84. This parameter can be a value of @ref UART_Over_Sampling. */
  85. uint32_t OneBitSampling; /*!< Specifies whether a single sample or three samples' majority vote is selected.
  86. Selecting the single sample method increases the receiver tolerance to clock
  87. deviations. This parameter can be a value of @ref UART_OneBit_Sampling. */
  88. }UART_InitTypeDef;
  89. /**
  90. * @brief UART Advanced Features initalization structure definition
  91. */
  92. typedef struct
  93. {
  94. uint32_t AdvFeatureInit; /*!< Specifies which advanced UART features is initialized. Several
  95. Advanced Features may be initialized at the same time .
  96. This parameter can be a value of @ref UART_Advanced_Features_Initialization_Type. */
  97. uint32_t TxPinLevelInvert; /*!< Specifies whether the TX pin active level is inverted.
  98. This parameter can be a value of @ref UART_Tx_Inv. */
  99. uint32_t RxPinLevelInvert; /*!< Specifies whether the RX pin active level is inverted.
  100. This parameter can be a value of @ref UART_Rx_Inv. */
  101. uint32_t DataInvert; /*!< Specifies whether data are inverted (positive/direct logic
  102. vs negative/inverted logic).
  103. This parameter can be a value of @ref UART_Data_Inv. */
  104. uint32_t Swap; /*!< Specifies whether TX and RX pins are swapped.
  105. This parameter can be a value of @ref UART_Rx_Tx_Swap. */
  106. uint32_t OverrunDisable; /*!< Specifies whether the reception overrun detection is disabled.
  107. This parameter can be a value of @ref UART_Overrun_Disable. */
  108. uint32_t DMADisableonRxError; /*!< Specifies whether the DMA is disabled in case of reception error.
  109. This parameter can be a value of @ref UART_DMA_Disable_on_Rx_Error. */
  110. uint32_t AutoBaudRateEnable; /*!< Specifies whether auto Baud rate detection is enabled.
  111. This parameter can be a value of @ref UART_AutoBaudRate_Enable */
  112. uint32_t AutoBaudRateMode; /*!< If auto Baud rate detection is enabled, specifies how the rate
  113. detection is carried out.
  114. This parameter can be a value of @ref UART_AutoBaud_Rate_Mode. */
  115. uint32_t MSBFirst; /*!< Specifies whether MSB is sent first on UART line.
  116. This parameter can be a value of @ref UART_MSB_First. */
  117. } UART_AdvFeatureInitTypeDef;
  118. /**
  119. * @brief HAL UART State structures definition
  120. */
  121. typedef enum
  122. {
  123. HAL_UART_STATE_RESET = 0x00, /*!< Peripheral is not initialized */
  124. HAL_UART_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
  125. HAL_UART_STATE_BUSY = 0x02, /*!< an internal process is ongoing */
  126. HAL_UART_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */
  127. HAL_UART_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */
  128. HAL_UART_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission and Reception process is ongoing */
  129. HAL_UART_STATE_TIMEOUT = 0x03, /*!< Timeout state */
  130. HAL_UART_STATE_ERROR = 0x04 /*!< Error */
  131. }HAL_UART_StateTypeDef;
  132. /**
  133. * @brief HAL UART Error Code structure definition
  134. */
  135. typedef enum
  136. {
  137. HAL_UART_ERROR_NONE = 0x00, /*!< No error */
  138. HAL_UART_ERROR_PE = 0x01, /*!< Parity error */
  139. HAL_UART_ERROR_NE = 0x02, /*!< Noise error */
  140. HAL_UART_ERROR_FE = 0x04, /*!< frame error */
  141. HAL_UART_ERROR_ORE = 0x08, /*!< Overrun error */
  142. HAL_UART_ERROR_DMA = 0x10 /*!< DMA transfer error */
  143. }HAL_UART_ErrorTypeDef;
  144. /**
  145. * @brief UART clock sources definition
  146. */
  147. typedef enum
  148. {
  149. UART_CLOCKSOURCE_PCLK1 = 0x00, /*!< PCLK1 clock source */
  150. UART_CLOCKSOURCE_PCLK2 = 0x01, /*!< PCLK2 clock source */
  151. UART_CLOCKSOURCE_HSI = 0x02, /*!< HSI clock source */
  152. UART_CLOCKSOURCE_SYSCLK = 0x04, /*!< SYSCLK clock source */
  153. UART_CLOCKSOURCE_LSE = 0x08, /*!< LSE clock source */
  154. UART_CLOCKSOURCE_UNDEFINED = 0x10 /*!< Undefined clock source */
  155. }UART_ClockSourceTypeDef;
  156. /**
  157. * @brief UART handle Structure definition
  158. */
  159. typedef struct
  160. {
  161. USART_TypeDef *Instance; /*!< UART registers base address */
  162. UART_InitTypeDef Init; /*!< UART communication parameters */
  163. UART_AdvFeatureInitTypeDef AdvancedInit; /*!< UART Advanced Features initialization parameters */
  164. uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */
  165. uint16_t TxXferSize; /*!< UART Tx Transfer size */
  166. uint16_t TxXferCount; /*!< UART Tx Transfer Counter */
  167. uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */
  168. uint16_t RxXferSize; /*!< UART Rx Transfer size */
  169. uint16_t RxXferCount; /*!< UART Rx Transfer Counter */
  170. uint16_t Mask; /*!< UART Rx RDR register mask */
  171. DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */
  172. DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */
  173. HAL_LockTypeDef Lock; /*!< Locking object */
  174. __IO HAL_UART_StateTypeDef State; /*!< UART communication state */
  175. __IO uint32_t ErrorCode; /*!< UART Error code */
  176. }UART_HandleTypeDef;
  177. /**
  178. * @}
  179. */
  180. /* Exported constants --------------------------------------------------------*/
  181. /** @defgroup UART_Exported_Constants UART Exported Constants
  182. * @{
  183. */
  184. /** @defgroup UART_Stop_Bits UART Number of Stop Bits
  185. * @{
  186. */
  187. #define UART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< UART frame with 0.5 stop bit */
  188. #define UART_STOPBITS_1 ((uint32_t)0x00000000) /*!< UART frame with 1 stop bit */
  189. #define UART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< UART frame with 1.5 stop bits */
  190. #define UART_STOPBITS_2 USART_CR2_STOP_1 /*!< UART frame with 2 stop bits */
  191. /**
  192. * @}
  193. */
  194. /** @defgroup UART_Parity UART Parity
  195. * @{
  196. */
  197. #define UART_PARITY_NONE ((uint32_t)0x00000000) /*!< No parity */
  198. #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) /*!< Even parity */
  199. #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) /*!< Odd parity */
  200. /**
  201. * @}
  202. */
  203. /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
  204. * @{
  205. */
  206. #define UART_HWCONTROL_NONE ((uint32_t)0x00000000) /*!< No hardware control */
  207. #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE) /*!< Request To Send */
  208. #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE) /*!< Clear To Send */
  209. #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE)) /*!< Request and Clear To Send */
  210. /**
  211. * @}
  212. */
  213. /** @defgroup UART_Mode UART Transfer Mode
  214. * @{
  215. */
  216. #define UART_MODE_RX ((uint32_t)USART_CR1_RE) /*!< RX mode */
  217. #define UART_MODE_TX ((uint32_t)USART_CR1_TE) /*!< TX mode */
  218. #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) /*!< RX and TX mode */
  219. /**
  220. * @}
  221. */
  222. /** @defgroup UART_State UART State
  223. * @{
  224. */
  225. #define UART_STATE_DISABLE ((uint32_t)0x00000000) /*!< UART disabled */
  226. #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE) /*!< UART enabled */
  227. /**
  228. * @}
  229. */
  230. /** @defgroup UART_Over_Sampling UART Over Sampling
  231. * @{
  232. */
  233. #define UART_OVERSAMPLING_16 ((uint32_t)0x00000000) /*!< Oversampling by 16 */
  234. #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8) /*!< Oversampling by 8 */
  235. /**
  236. * @}
  237. */
  238. /** @defgroup UART_OneBit_Sampling UART One Bit Sampling Method
  239. * @{
  240. */
  241. #define UART_ONE_BIT_SAMPLE_DISABLE ((uint32_t)0x00000000) /*!< One-bit sampling disable */
  242. #define UART_ONE_BIT_SAMPLE_ENABLE ((uint32_t)USART_CR3_ONEBIT) /*!< One-bit sampling enable */
  243. /**
  244. * @}
  245. */
  246. /** @defgroup UART_AutoBaud_Rate_Mode UART Advanced Feature AutoBaud Rate Mode
  247. * @{
  248. */
  249. #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT ((uint32_t)0x0000) /*!< Auto Baud rate detection on start bit */
  250. #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE ((uint32_t)USART_CR2_ABRMODE_0) /*!< Auto Baud rate detection on falling edge */
  251. #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME ((uint32_t)USART_CR2_ABRMODE_1) /*!< Auto Baud rate detection on 0x7F frame detection */
  252. #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME ((uint32_t)USART_CR2_ABRMODE) /*!< Auto Baud rate detection on 0x55 frame detection */
  253. /**
  254. * @}
  255. */
  256. /** @defgroup UART_Receiver_TimeOut UART Receiver TimeOut
  257. * @{
  258. */
  259. #define UART_RECEIVER_TIMEOUT_DISABLE ((uint32_t)0x00000000) /*!< UART receiver timeout disable */
  260. #define UART_RECEIVER_TIMEOUT_ENABLE ((uint32_t)USART_CR2_RTOEN) /*!< UART receiver timeout enable */
  261. /**
  262. * @}
  263. */
  264. /** @defgroup UART_LIN UART Local Interconnection Network mode
  265. * @{
  266. */
  267. #define UART_LIN_DISABLE ((uint32_t)0x00000000) /*!< Local Interconnect Network disable */
  268. #define UART_LIN_ENABLE ((uint32_t)USART_CR2_LINEN) /*!< Local Interconnect Network enable */
  269. /**
  270. * @}
  271. */
  272. /** @defgroup UART_LIN_Break_Detection UART LIN Break Detection
  273. * @{
  274. */
  275. #define UART_LINBREAKDETECTLENGTH_10B ((uint32_t)0x00000000) /*!< LIN 10-bit break detection length */
  276. #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL) /*!< LIN 11-bit break detection length */
  277. /**
  278. * @}
  279. */
  280. /** @defgroup UART_DMA_Tx UART DMA Tx
  281. * @{
  282. */
  283. #define UART_DMA_TX_DISABLE ((uint32_t)0x00000000) /*!< UART DMA TX disabled */
  284. #define UART_DMA_TX_ENABLE ((uint32_t)USART_CR3_DMAT) /*!< UART DMA TX enabled */
  285. /**
  286. * @}
  287. */
  288. /** @defgroup UART_DMA_Rx UART DMA Rx
  289. * @{
  290. */
  291. #define UART_DMA_RX_DISABLE ((uint32_t)0x0000) /*!< UART DMA RX disabled */
  292. #define UART_DMA_RX_ENABLE ((uint32_t)USART_CR3_DMAR) /*!< UART DMA RX enabled */
  293. /**
  294. * @}
  295. */
  296. /** @defgroup UART_Half_Duplex_Selection UART Half Duplex Selection
  297. * @{
  298. */
  299. #define UART_HALF_DUPLEX_DISABLE ((uint32_t)0x0000) /*!< UART half-duplex disabled */
  300. #define UART_HALF_DUPLEX_ENABLE ((uint32_t)USART_CR3_HDSEL) /*!< UART half-duplex enabled */
  301. /**
  302. * @}
  303. */
  304. /** @defgroup UART_WakeUp_Methods UART WakeUp Methods
  305. * @{
  306. */
  307. #define UART_WAKEUPMETHOD_IDLELINE ((uint32_t)0x00000000) /*!< UART wake-up on idle line */
  308. #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE) /*!< UART wake-up on address mark */
  309. /**
  310. * @}
  311. */
  312. /** @defgroup UART_Request_Parameters UART Request Parameters
  313. * @{
  314. */
  315. #define UART_AUTOBAUD_REQUEST ((uint32_t)USART_RQR_ABRRQ) /*!< Auto-Baud Rate Request */
  316. #define UART_SENDBREAK_REQUEST ((uint32_t)USART_RQR_SBKRQ) /*!< Send Break Request */
  317. #define UART_MUTE_MODE_REQUEST ((uint32_t)USART_RQR_MMRQ) /*!< Mute Mode Request */
  318. #define UART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
  319. #define UART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
  320. /**
  321. * @}
  322. */
  323. /** @defgroup UART_Advanced_Features_Initialization_Type UART Advanced Feature Initialization Type
  324. * @{
  325. */
  326. #define UART_ADVFEATURE_NO_INIT ((uint32_t)0x00000000) /*!< No advanced feature initialization */
  327. #define UART_ADVFEATURE_TXINVERT_INIT ((uint32_t)0x00000001) /*!< TX pin active level inversion */
  328. #define UART_ADVFEATURE_RXINVERT_INIT ((uint32_t)0x00000002) /*!< RX pin active level inversion */
  329. #define UART_ADVFEATURE_DATAINVERT_INIT ((uint32_t)0x00000004) /*!< Binary data inversion */
  330. #define UART_ADVFEATURE_SWAP_INIT ((uint32_t)0x00000008) /*!< TX/RX pins swap */
  331. #define UART_ADVFEATURE_RXOVERRUNDISABLE_INIT ((uint32_t)0x00000010) /*!< RX overrun disable */
  332. #define UART_ADVFEATURE_DMADISABLEONERROR_INIT ((uint32_t)0x00000020) /*!< DMA disable on Reception Error */
  333. #define UART_ADVFEATURE_AUTOBAUDRATE_INIT ((uint32_t)0x00000040) /*!< Auto Baud rate detection initialization */
  334. #define UART_ADVFEATURE_MSBFIRST_INIT ((uint32_t)0x00000080) /*!< Most significant bit sent/received first */
  335. /**
  336. * @}
  337. */
  338. /** @defgroup UART_Tx_Inv UART Advanced Feature TX Pin Active Level Inversion
  339. * @{
  340. */
  341. #define UART_ADVFEATURE_TXINV_DISABLE ((uint32_t)0x00000000) /*!< TX pin active level inversion disable */
  342. #define UART_ADVFEATURE_TXINV_ENABLE ((uint32_t)USART_CR2_TXINV) /*!< TX pin active level inversion enable */
  343. /**
  344. * @}
  345. */
  346. /** @defgroup UART_Rx_Inv UART Advanced Feature RX Pin Active Level Inversion
  347. * @{
  348. */
  349. #define UART_ADVFEATURE_RXINV_DISABLE ((uint32_t)0x00000000) /*!< RX pin active level inversion disable */
  350. #define UART_ADVFEATURE_RXINV_ENABLE ((uint32_t)USART_CR2_RXINV) /*!< RX pin active level inversion enable */
  351. /**
  352. * @}
  353. */
  354. /** @defgroup UART_Data_Inv UART Advanced Feature Binary Data Inversion
  355. * @{
  356. */
  357. #define UART_ADVFEATURE_DATAINV_DISABLE ((uint32_t)0x00000000) /*!< Binary data inversion disable */
  358. #define UART_ADVFEATURE_DATAINV_ENABLE ((uint32_t)USART_CR2_DATAINV) /*!< Binary data inversion enable */
  359. /**
  360. * @}
  361. */
  362. /** @defgroup UART_Rx_Tx_Swap UART Advanced Feature RX TX Pins Swap
  363. * @{
  364. */
  365. #define UART_ADVFEATURE_SWAP_DISABLE ((uint32_t)0x00000000) /*!< TX/RX pins swap disable */
  366. #define UART_ADVFEATURE_SWAP_ENABLE ((uint32_t)USART_CR2_SWAP) /*!< TX/RX pins swap enable */
  367. /**
  368. * @}
  369. */
  370. /** @defgroup UART_Overrun_Disable UART Advanced Feature Overrun Disable
  371. * @{
  372. */
  373. #define UART_ADVFEATURE_OVERRUN_ENABLE ((uint32_t)0x00000000) /*!< RX overrun enable */
  374. #define UART_ADVFEATURE_OVERRUN_DISABLE ((uint32_t)USART_CR3_OVRDIS) /*!< RX overrun disable */
  375. /**
  376. * @}
  377. */
  378. /** @defgroup UART_AutoBaudRate_Enable UART Advanced Feature Auto BaudRate Enable
  379. * @{
  380. */
  381. #define UART_ADVFEATURE_AUTOBAUDRATE_DISABLE ((uint32_t)0x00000000) /*!< RX Auto Baud rate detection enable */
  382. #define UART_ADVFEATURE_AUTOBAUDRATE_ENABLE ((uint32_t)USART_CR2_ABREN) /*!< RX Auto Baud rate detection disable */
  383. /**
  384. * @}
  385. */
  386. /** @defgroup UART_DMA_Disable_on_Rx_Error UART Advanced Feature DMA Disable On Rx Error
  387. * @{
  388. */
  389. #define UART_ADVFEATURE_DMA_ENABLEONRXERROR ((uint32_t)0x00000000) /*!< DMA enable on Reception Error */
  390. #define UART_ADVFEATURE_DMA_DISABLEONRXERROR ((uint32_t)USART_CR3_DDRE) /*!< DMA disable on Reception Error */
  391. /**
  392. * @}
  393. */
  394. /** @defgroup UART_MSB_First UART Advanced Feature MSB First
  395. * @{
  396. */
  397. #define UART_ADVFEATURE_MSBFIRST_DISABLE ((uint32_t)0x00000000) /*!< Most significant bit sent/received first disable */
  398. #define UART_ADVFEATURE_MSBFIRST_ENABLE ((uint32_t)USART_CR2_MSBFIRST) /*!< Most significant bit sent/received first enable */
  399. /**
  400. * @}
  401. */
  402. /** @defgroup UART_Stop_Mode_Enable UART Advanced Feature Stop Mode Enable
  403. * @{
  404. */
  405. #define UART_ADVFEATURE_STOPMODE_DISABLE ((uint32_t)0x00000000) /*!< UART stop mode disable */
  406. #define UART_ADVFEATURE_STOPMODE_ENABLE ((uint32_t)USART_CR1_UESM) /*!< UART stop mode enable */
  407. /**
  408. * @}
  409. */
  410. /** @defgroup UART_Mute_Mode UART Advanced Feature Mute Mode Enable
  411. * @{
  412. */
  413. #define UART_ADVFEATURE_MUTEMODE_DISABLE ((uint32_t)0x00000000) /*!< UART mute mode disable */
  414. #define UART_ADVFEATURE_MUTEMODE_ENABLE ((uint32_t)USART_CR1_MME) /*!< UART mute mode enable */
  415. /**
  416. * @}
  417. */
  418. /** @defgroup UART_CR2_ADDRESS_LSB_POS UART Address-matching LSB Position In CR2 Register
  419. * @{
  420. */
  421. #define UART_CR2_ADDRESS_LSB_POS ((uint32_t) 24) /*!< UART address-matching LSB position in CR2 register */
  422. /**
  423. * @}
  424. */
  425. /** @defgroup UART_WakeUp_from_Stop_Selection UART WakeUp From Stop Selection
  426. * @{
  427. */
  428. #define UART_WAKEUP_ON_ADDRESS ((uint32_t)0x00000000) /*!< UART wake-up on address */
  429. #define UART_WAKEUP_ON_STARTBIT ((uint32_t)USART_CR3_WUS_1) /*!< UART wake-up on start bit */
  430. #define UART_WAKEUP_ON_READDATA_NONEMPTY ((uint32_t)USART_CR3_WUS) /*!< UART wake-up on receive data register not empty */
  431. /**
  432. * @}
  433. */
  434. /** @defgroup UART_DriverEnable_Polarity UART DriverEnable Polarity
  435. * @{
  436. */
  437. #define UART_DE_POLARITY_HIGH ((uint32_t)0x00000000) /*!< Driver enable signal is active high */
  438. #define UART_DE_POLARITY_LOW ((uint32_t)USART_CR3_DEP) /*!< Driver enable signal is active low */
  439. /**
  440. * @}
  441. */
  442. /** @defgroup UART_CR1_DEAT_ADDRESS_LSB_POS UART Driver Enable Assertion Time LSB Position In CR1 Register
  443. * @{
  444. */
  445. #define UART_CR1_DEAT_ADDRESS_LSB_POS ((uint32_t) 21) /*!< UART Driver Enable assertion time LSB position in CR1 register */
  446. /**
  447. * @}
  448. */
  449. /** @defgroup UART_CR1_DEDT_ADDRESS_LSB_POS UART Driver Enable DeAssertion Time LSB Position In CR1 Register
  450. * @{
  451. */
  452. #define UART_CR1_DEDT_ADDRESS_LSB_POS ((uint32_t) 16) /*!< UART Driver Enable de-assertion time LSB position in CR1 register */
  453. /**
  454. * @}
  455. */
  456. /** @defgroup UART_Interruption_Mask UART Interruptions Flag Mask
  457. * @{
  458. */
  459. #define UART_IT_MASK ((uint32_t)0x001F) /*!< UART interruptions flags mask */
  460. /**
  461. * @}
  462. */
  463. /** @defgroup UART_TimeOut_Value UART polling-based communications time-out value
  464. * @{
  465. */
  466. #define HAL_UART_TIMEOUT_VALUE 0x1FFFFFF /*!< UART polling-based communications time-out value */
  467. /**
  468. * @}
  469. */
  470. /** @defgroup UART_Flags UART Status Flags
  471. * Elements values convention: 0xXXXX
  472. * - 0xXXXX : Flag mask in the ISR register
  473. * @{
  474. */
  475. #define UART_FLAG_REACK ((uint32_t)0x00400000) /*!< UART receive enable acknowledge flag */
  476. #define UART_FLAG_TEACK ((uint32_t)0x00200000) /*!< UART transmit enable acknowledge flag */
  477. #define UART_FLAG_WUF ((uint32_t)0x00100000) /*!< UART wake-up from stop mode flag */
  478. #define UART_FLAG_RWU ((uint32_t)0x00080000) /*!< UART receiver wake-up from mute mode flag */
  479. #define UART_FLAG_SBKF ((uint32_t)0x00040000) /*!< UART send break flag */
  480. #define UART_FLAG_CMF ((uint32_t)0x00020000) /*!< UART character match flag */
  481. #define UART_FLAG_BUSY ((uint32_t)0x00010000) /*!< UART busy flag */
  482. #define UART_FLAG_ABRF ((uint32_t)0x00008000) /*!< UART auto Baud rate flag */
  483. #define UART_FLAG_ABRE ((uint32_t)0x00004000) /*!< UART uto Baud rate error */
  484. #define UART_FLAG_EOBF ((uint32_t)0x00001000) /*!< UART end of block flag */
  485. #define UART_FLAG_RTOF ((uint32_t)0x00000800) /*!< UART receiver timeout flag */
  486. #define UART_FLAG_CTS ((uint32_t)0x00000400) /*!< UART clear to send flag */
  487. #define UART_FLAG_CTSIF ((uint32_t)0x00000200) /*!< UART clear to send interrupt flag */
  488. #define UART_FLAG_LBDF ((uint32_t)0x00000100) /*!< UART LIN break detection flag */
  489. #define UART_FLAG_TXE ((uint32_t)0x00000080) /*!< UART transmit data register empty */
  490. #define UART_FLAG_TC ((uint32_t)0x00000040) /*!< UART transmission complete */
  491. #define UART_FLAG_RXNE ((uint32_t)0x00000020) /*!< UART read data register not empty */
  492. #define UART_FLAG_IDLE ((uint32_t)0x00000010) /*!< UART idle flag */
  493. #define UART_FLAG_ORE ((uint32_t)0x00000008) /*!< UART overrun error */
  494. #define UART_FLAG_NE ((uint32_t)0x00000004) /*!< UART noise error */
  495. #define UART_FLAG_FE ((uint32_t)0x00000002) /*!< UART frame error */
  496. #define UART_FLAG_PE ((uint32_t)0x00000001) /*!< UART parity error */
  497. /**
  498. * @}
  499. */
  500. /** @defgroup UART_Interrupt_definition UART Interrupts Definition
  501. * Elements values convention: 000ZZZZZ0XXYYYYYb
  502. * - YYYYY : Interrupt source position in the XX register (5bits)
  503. * - XX : Interrupt source register (2bits)
  504. * - 01: CR1 register
  505. * - 10: CR2 register
  506. * - 11: CR3 register
  507. * - ZZZZZ : Flag position in the ISR register(5bits)
  508. * @{
  509. */
  510. #define UART_IT_PE ((uint32_t)0x0028) /*!< UART parity error interruption */
  511. #define UART_IT_TXE ((uint32_t)0x0727) /*!< UART transmit data register empty interruption */
  512. #define UART_IT_TC ((uint32_t)0x0626) /*!< UART transmission complete interruption */
  513. #define UART_IT_RXNE ((uint32_t)0x0525) /*!< UART read data register not empty interruption */
  514. #define UART_IT_IDLE ((uint32_t)0x0424) /*!< UART idle interruption */
  515. #define UART_IT_LBD ((uint32_t)0x0846) /*!< UART LIN break detection interruption */
  516. #define UART_IT_CTS ((uint32_t)0x096A) /*!< UART CTS interruption */
  517. #define UART_IT_CM ((uint32_t)0x112E) /*!< UART character match interruption */
  518. #define UART_IT_WUF ((uint32_t)0x1476) /*!< UART wake-up from stop mode interruption */
  519. /* Elements values convention: 000000000XXYYYYYb
  520. - YYYYY : Interrupt source position in the XX register (5bits)
  521. - XX : Interrupt source register (2bits)
  522. - 01: CR1 register
  523. - 10: CR2 register
  524. - 11: CR3 register */
  525. #define UART_IT_ERR ((uint32_t)0x0060) /*!< UART error interruption */
  526. /* Elements values convention: 0000ZZZZ00000000b
  527. - ZZZZ : Flag position in the ISR register(4bits) */
  528. #define UART_IT_ORE ((uint32_t)0x0300) /*!< UART overrun error interruption */
  529. #define UART_IT_NE ((uint32_t)0x0200) /*!< UART noise error interruption */
  530. #define UART_IT_FE ((uint32_t)0x0100) /*!< UART frame error interruption */
  531. /**
  532. * @}
  533. */
  534. /** @defgroup UART_IT_CLEAR_Flags UART Interruption Clear Flags
  535. * @{
  536. */
  537. #define UART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
  538. #define UART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
  539. #define UART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
  540. #define UART_CLEAR_OREF USART_ICR_ORECF /*!< Overrun Error Clear Flag */
  541. #define UART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
  542. #define UART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
  543. #define UART_CLEAR_LBDF USART_ICR_LBDCF /*!< LIN Break Detection Clear Flag */
  544. #define UART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
  545. #define UART_CLEAR_RTOF USART_ICR_RTOCF /*!< Receiver Time Out Clear Flag */
  546. #define UART_CLEAR_EOBF USART_ICR_EOBCF /*!< End Of Block Clear Flag */
  547. #define UART_CLEAR_CMF USART_ICR_CMCF /*!< Character Match Clear Flag */
  548. #define UART_CLEAR_WUF USART_ICR_WUCF /*!< Wake Up from stop mode Clear Flag */
  549. /**
  550. * @}
  551. */
  552. /**
  553. * @}
  554. */
  555. /* Exported macros -----------------------------------------------------------*/
  556. /** @defgroup UART_Exported_Macros UART Exported Macros
  557. * @{
  558. */
  559. /** @brief Reset UART handle state.
  560. * @param __HANDLE__: UART handle.
  561. * @retval None
  562. */
  563. #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_UART_STATE_RESET)
  564. /** @brief Flush the UART Data registers.
  565. * @param __HANDLE__: specifies the UART Handle.
  566. * @retval None
  567. */
  568. #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) \
  569. do{ \
  570. SET_BIT((__HANDLE__)->Instance->RQR, UART_RXDATA_FLUSH_REQUEST); \
  571. SET_BIT((__HANDLE__)->Instance->RQR, UART_TXDATA_FLUSH_REQUEST); \
  572. } while(0)
  573. /** @brief Clear the specified UART pending flag.
  574. * @param __HANDLE__: specifies the UART Handle.
  575. * @param __FLAG__: specifies the flag to check.
  576. * This parameter can be any combination of the following values:
  577. * @arg @ref UART_CLEAR_PEF Parity Error Clear Flag
  578. * @arg @ref UART_CLEAR_FEF Framing Error Clear Flag
  579. * @arg @ref UART_CLEAR_NEF Noise detected Clear Flag
  580. * @arg @ref UART_CLEAR_OREF Overrun Error Clear Flag
  581. * @arg @ref UART_CLEAR_IDLEF IDLE line detected Clear Flag
  582. * @arg @ref UART_CLEAR_TCF Transmission Complete Clear Flag
  583. * @arg @ref UART_CLEAR_LBDF LIN Break Detection Clear Flag
  584. * @arg @ref UART_CLEAR_CTSF CTS Interrupt Clear Flag
  585. * @arg @ref UART_CLEAR_RTOF Receiver Time Out Clear Flag
  586. * @arg @ref UART_CLEAR_EOBF End Of Block Clear Flag
  587. * @arg @ref UART_CLEAR_CMF Character Match Clear Flag
  588. * @arg @ref UART_CLEAR_WUF Wake Up from stop mode Clear Flag
  589. * @retval None
  590. */
  591. #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
  592. /** @brief Clear the UART PE pending flag.
  593. * @param __HANDLE__: specifies the UART Handle.
  594. * @retval None
  595. */
  596. #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_PEF)
  597. /** @brief Clear the UART FE pending flag.
  598. * @param __HANDLE__: specifies the UART Handle.
  599. * @retval None
  600. */
  601. #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_FEF)
  602. /** @brief Clear the UART NE pending flag.
  603. * @param __HANDLE__: specifies the UART Handle.
  604. * @retval None
  605. */
  606. #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_NEF)
  607. /** @brief Clear the UART ORE pending flag.
  608. * @param __HANDLE__: specifies the UART Handle.
  609. * @retval None
  610. */
  611. #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_OREF)
  612. /** @brief Clear the UART IDLE pending flag.
  613. * @param __HANDLE__: specifies the UART Handle.
  614. * @retval None
  615. */
  616. #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_IDLEF)
  617. /** @brief Check whether the specified UART flag is set or not.
  618. * @param __HANDLE__: specifies the UART Handle.
  619. * @param __FLAG__: specifies the flag to check.
  620. * This parameter can be one of the following values:
  621. * @arg @ref UART_FLAG_REACK Receive enable acknowledge flag
  622. * @arg @ref UART_FLAG_TEACK Transmit enable acknowledge flag
  623. * @arg @ref UART_FLAG_WUF Wake up from stop mode flag
  624. * @arg @ref UART_FLAG_RWU Receiver wake up flag (if the UART in mute mode)
  625. * @arg @ref UART_FLAG_SBKF Send Break flag
  626. * @arg @ref UART_FLAG_CMF Character match flag
  627. * @arg @ref UART_FLAG_BUSY Busy flag
  628. * @arg @ref UART_FLAG_ABRF Auto Baud rate detection flag
  629. * @arg @ref UART_FLAG_ABRE Auto Baud rate detection error flag
  630. * @arg @ref UART_FLAG_EOBF End of block flag
  631. * @arg @ref UART_FLAG_RTOF Receiver timeout flag
  632. * @arg @ref UART_FLAG_CTS CTS Change flag
  633. * @arg @ref UART_FLAG_LBDF LIN Break detection flag
  634. * @arg @ref UART_FLAG_TXE Transmit data register empty flag
  635. * @arg @ref UART_FLAG_TC Transmission Complete flag
  636. * @arg @ref UART_FLAG_RXNE Receive data register not empty flag
  637. * @arg @ref UART_FLAG_IDLE Idle Line detection flag
  638. * @arg @ref UART_FLAG_ORE Overrun Error flag
  639. * @arg @ref UART_FLAG_NE Noise Error flag
  640. * @arg @ref UART_FLAG_FE Framing Error flag
  641. * @arg @ref UART_FLAG_PE Parity Error flag
  642. * @retval The new state of __FLAG__ (TRUE or FALSE).
  643. */
  644. #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
  645. /** @brief Enable the specified UART interrupt.
  646. * @param __HANDLE__: specifies the UART Handle.
  647. * @param __INTERRUPT__: specifies the UART interrupt source to enable.
  648. * This parameter can be one of the following values:
  649. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  650. * @arg @ref UART_IT_CM Character match interrupt
  651. * @arg @ref UART_IT_CTS CTS change interrupt
  652. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  653. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  654. * @arg @ref UART_IT_TC Transmission complete interrupt
  655. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  656. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  657. * @arg @ref UART_IT_PE Parity Error interrupt
  658. * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
  659. * @retval None
  660. */
  661. #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  662. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  663. ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))))
  664. /** @brief Disable the specified UART interrupt.
  665. * @param __HANDLE__: specifies the UART Handle.
  666. * @param __INTERRUPT__: specifies the UART interrupt source to disable.
  667. * This parameter can be one of the following values:
  668. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  669. * @arg @ref UART_IT_CM Character match interrupt
  670. * @arg @ref UART_IT_CTS CTS change interrupt
  671. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  672. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  673. * @arg @ref UART_IT_TC Transmission complete interrupt
  674. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  675. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  676. * @arg @ref UART_IT_PE Parity Error interrupt
  677. * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
  678. * @retval None
  679. */
  680. #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  681. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  682. ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))))
  683. /** @brief Check whether the specified UART interrupt has occurred or not.
  684. * @param __HANDLE__: specifies the UART Handle.
  685. * @param __IT__: specifies the UART interrupt to check.
  686. * This parameter can be one of the following values:
  687. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  688. * @arg @ref UART_IT_CM Character match interrupt
  689. * @arg @ref UART_IT_CTS CTS change interrupt
  690. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  691. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  692. * @arg @ref UART_IT_TC Transmission complete interrupt
  693. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  694. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  695. * @arg @ref UART_IT_ORE Overrun Error interrupt
  696. * @arg @ref UART_IT_NE Noise Error interrupt
  697. * @arg @ref UART_IT_FE Framing Error interrupt
  698. * @arg @ref UART_IT_PE Parity Error interrupt
  699. * @retval The new state of __IT__ (TRUE or FALSE).
  700. */
  701. #define __HAL_UART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
  702. /** @brief Check whether the specified UART interrupt source is enabled or not.
  703. * @param __HANDLE__: specifies the UART Handle.
  704. * @param __IT__: specifies the UART interrupt source to check.
  705. * This parameter can be one of the following values:
  706. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  707. * @arg @ref UART_IT_CM Character match interrupt
  708. * @arg @ref UART_IT_CTS CTS change interrupt
  709. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  710. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  711. * @arg @ref UART_IT_TC Transmission complete interrupt
  712. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  713. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  714. * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
  715. * @arg @ref UART_IT_PE Parity Error interrupt
  716. * @retval The new state of __IT__ (TRUE or FALSE).
  717. */
  718. #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5U) == 2)? \
  719. (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << (((uint16_t)(__IT__)) & UART_IT_MASK)))
  720. /** @brief Clear the specified UART ISR flag, in setting the proper ICR register flag.
  721. * @param __HANDLE__: specifies the UART Handle.
  722. * @param __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
  723. * to clear the corresponding interrupt
  724. * This parameter can be one of the following values:
  725. * @arg @ref UART_CLEAR_PEF Parity Error Clear Flag
  726. * @arg @ref UART_CLEAR_FEF Framing Error Clear Flag
  727. * @arg @ref UART_CLEAR_NEF Noise detected Clear Flag
  728. * @arg @ref UART_CLEAR_OREF Overrun Error Clear Flag
  729. * @arg @ref UART_CLEAR_IDLEF IDLE line detected Clear Flag
  730. * @arg @ref UART_CLEAR_TCF Transmission Complete Clear Flag
  731. * @arg @ref UART_CLEAR_LBDF LIN Break Detection Clear Flag
  732. * @arg @ref UART_CLEAR_CTSF CTS Interrupt Clear Flag
  733. * @arg @ref UART_CLEAR_CMF Character Match Clear Flag
  734. * @arg @ref UART_CLEAR_WUF Wake Up from stop mode Clear Flag
  735. * @retval None
  736. */
  737. #define __HAL_UART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
  738. /** @brief Set a specific UART request flag.
  739. * @param __HANDLE__: specifies the UART Handle.
  740. * @param __REQ__: specifies the request flag to set
  741. * This parameter can be one of the following values:
  742. * @arg @ref UART_AUTOBAUD_REQUEST Auto-Baud Rate Request
  743. * @arg @ref UART_SENDBREAK_REQUEST Send Break Request
  744. * @arg @ref UART_MUTE_MODE_REQUEST Mute Mode Request
  745. * @arg @ref UART_RXDATA_FLUSH_REQUEST Receive Data flush Request
  746. * @arg @ref UART_TXDATA_FLUSH_REQUEST Transmit data flush Request
  747. * @retval None
  748. */
  749. #define __HAL_UART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint32_t)(__REQ__))
  750. /** @brief Enable the UART one bit sample method.
  751. * @param __HANDLE__: specifies the UART Handle.
  752. * @retval None
  753. */
  754. #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
  755. /** @brief Disable the UART one bit sample method.
  756. * @param __HANDLE__: specifies the UART Handle.
  757. * @retval None
  758. */
  759. #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
  760. /** @brief Enable UART.
  761. * @param __HANDLE__: specifies the UART Handle.
  762. * @retval None
  763. */
  764. #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
  765. /** @brief Disable UART.
  766. * @param __HANDLE__: specifies the UART Handle.
  767. * @retval None
  768. */
  769. #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
  770. /** @brief Enable CTS flow control.
  771. * @note This macro allows to enable CTS hardware flow control for a given UART instance,
  772. * without need to call HAL_UART_Init() function.
  773. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  774. * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
  775. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  776. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  777. * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
  778. * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  779. * @param __HANDLE__: specifies the UART Handle.
  780. * @retval None
  781. */
  782. #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \
  783. do{ \
  784. SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
  785. (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \
  786. } while(0)
  787. /** @brief Disable CTS flow control.
  788. * @note This macro allows to disable CTS hardware flow control for a given UART instance,
  789. * without need to call HAL_UART_Init() function.
  790. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  791. * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
  792. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  793. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  794. * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
  795. * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  796. * @param __HANDLE__: specifies the UART Handle.
  797. * @retval None
  798. */
  799. #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \
  800. do{ \
  801. CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
  802. (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \
  803. } while(0)
  804. /** @brief Enable RTS flow control.
  805. * @note This macro allows to enable RTS hardware flow control for a given UART instance,
  806. * without need to call HAL_UART_Init() function.
  807. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  808. * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
  809. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  810. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  811. * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
  812. * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  813. * @param __HANDLE__: specifies the UART Handle.
  814. * @retval None
  815. */
  816. #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \
  817. do{ \
  818. SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
  819. (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \
  820. } while(0)
  821. /** @brief Disable RTS flow control.
  822. * @note This macro allows to disable RTS hardware flow control for a given UART instance,
  823. * without need to call HAL_UART_Init() function.
  824. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  825. * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
  826. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  827. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  828. * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
  829. * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  830. * @param __HANDLE__: specifies the UART Handle.
  831. * @retval None
  832. */
  833. #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \
  834. do{ \
  835. CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
  836. (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \
  837. } while(0)
  838. /**
  839. * @}
  840. */
  841. /* Private macros --------------------------------------------------------*/
  842. /** @defgroup UART_Private_Macros UART Private Macros
  843. * @{
  844. */
  845. /** @brief BRR division operation to set BRR register with LPUART.
  846. * @param __PCLK__: LPUART clock.
  847. * @param __BAUD__: Baud rate set by the user.
  848. * @retval Division result
  849. */
  850. #define UART_DIV_LPUART(__PCLK__, __BAUD__) (((uint64_t)(__PCLK__)*256)/((__BAUD__)))
  851. /** @brief BRR division operation to set BRR register in 8-bit oversampling mode.
  852. * @param __PCLK__: UART clock.
  853. * @param __BAUD__: Baud rate set by the user.
  854. * @retval Division result
  855. */
  856. #define UART_DIV_SAMPLING8(__PCLK__, __BAUD__) (((__PCLK__)*2)/((__BAUD__)))
  857. /** @brief BRR division operation to set BRR register in 16-bit oversampling mode.
  858. * @param __PCLK__: UART clock.
  859. * @param __BAUD__: Baud rate set by the user.
  860. * @retval Division result
  861. */
  862. #define UART_DIV_SAMPLING16(__PCLK__, __BAUD__) (((__PCLK__))/((__BAUD__)))
  863. /** @brief Check whether or not UART instance is Low Power UART.
  864. * @param __HANDLE__: specifies the UART Handle.
  865. * @retval SET (instance is LPUART) or RESET (instance isn't LPUART)
  866. */
  867. #define UART_INSTANCE_LOWPOWER(__HANDLE__) (((__HANDLE__)->Instance == LPUART1) ? SET : RESET )
  868. /** @brief Check UART Baud rate.
  869. * @param __BAUDRATE__: Baudrate specified by the user.
  870. * The maximum Baud Rate is derived from the maximum clock on L4 (i.e. 80 MHz)
  871. * divided by the smallest oversampling used on the USART (i.e. 8)
  872. * @retval SET (__BAUDRATE__ is valid) or RESET (__BAUDRATE__ is invalid)
  873. */
  874. #define IS_UART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 10000001)
  875. /** @brief Check UART assertion time.
  876. * @param __TIME__: 5-bit value assertion time.
  877. * @retval Test result (TRUE or FALSE).
  878. */
  879. #define IS_UART_ASSERTIONTIME(__TIME__) ((__TIME__) <= 0x1F)
  880. /** @brief Check UART deassertion time.
  881. * @param __TIME__: 5-bit value deassertion time.
  882. * @retval Test result (TRUE or FALSE).
  883. */
  884. #define IS_UART_DEASSERTIONTIME(__TIME__) ((__TIME__) <= 0x1F)
  885. /**
  886. * @brief Ensure that UART frame number of stop bits is valid.
  887. * @param __STOPBITS__: UART frame number of stop bits.
  888. * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid) UART_STOPBITS_1_5
  889. */
  890. #define IS_UART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == UART_STOPBITS_0_5) || \
  891. ((__STOPBITS__) == UART_STOPBITS_1) || \
  892. ((__STOPBITS__) == UART_STOPBITS_1_5) || \
  893. ((__STOPBITS__) == UART_STOPBITS_2))
  894. /**
  895. * @brief Ensure that LPUART frame number of stop bits is valid.
  896. * @param __STOPBITS__: LPUART frame number of stop bits.
  897. * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
  898. */
  899. #define IS_LPUART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == UART_STOPBITS_1) || \
  900. ((__STOPBITS__) == UART_STOPBITS_2))
  901. /**
  902. * @brief Ensure that UART frame parity is valid.
  903. * @param __PARITY__: UART frame parity.
  904. * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
  905. */
  906. #define IS_UART_PARITY(__PARITY__) (((__PARITY__) == UART_PARITY_NONE) || \
  907. ((__PARITY__) == UART_PARITY_EVEN) || \
  908. ((__PARITY__) == UART_PARITY_ODD))
  909. /**
  910. * @brief Ensure that UART hardware flow control is valid.
  911. * @param __CONTROL__: UART hardware flow control.
  912. * @retval SET (__CONTROL__ is valid) or RESET (__CONTROL__ is invalid)
  913. */
  914. #define IS_UART_HARDWARE_FLOW_CONTROL(__CONTROL__)\
  915. (((__CONTROL__) == UART_HWCONTROL_NONE) || \
  916. ((__CONTROL__) == UART_HWCONTROL_RTS) || \
  917. ((__CONTROL__) == UART_HWCONTROL_CTS) || \
  918. ((__CONTROL__) == UART_HWCONTROL_RTS_CTS))
  919. /**
  920. * @brief Ensure that UART communication mode is valid.
  921. * @param __MODE__: UART communication mode.
  922. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  923. */
  924. #define IS_UART_MODE(__MODE__) ((((__MODE__) & (~((uint32_t)(UART_MODE_TX_RX)))) == (uint32_t)0x00) && ((__MODE__) != (uint32_t)0x00))
  925. /**
  926. * @brief Ensure that UART state is valid.
  927. * @param __STATE__: UART state.
  928. * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid)
  929. */
  930. #define IS_UART_STATE(__STATE__) (((__STATE__) == UART_STATE_DISABLE) || \
  931. ((__STATE__) == UART_STATE_ENABLE))
  932. /**
  933. * @brief Ensure that UART oversampling is valid.
  934. * @param __SAMPLING__: UART oversampling.
  935. * @retval SET (__SAMPLING__ is valid) or RESET (__SAMPLING__ is invalid)
  936. */
  937. #define IS_UART_OVERSAMPLING(__SAMPLING__) (((__SAMPLING__) == UART_OVERSAMPLING_16) || \
  938. ((__SAMPLING__) == UART_OVERSAMPLING_8))
  939. /**
  940. * @brief Ensure that UART frame sampling is valid.
  941. * @param __ONEBIT__: UART frame sampling.
  942. * @retval SET (__ONEBIT__ is valid) or RESET (__ONEBIT__ is invalid)
  943. */
  944. #define IS_UART_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == UART_ONE_BIT_SAMPLE_DISABLE) || \
  945. ((__ONEBIT__) == UART_ONE_BIT_SAMPLE_ENABLE))
  946. /**
  947. * @brief Ensure that UART auto Baud rate detection mode is valid.
  948. * @param __MODE__: UART auto Baud rate detection mode.
  949. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  950. */
  951. #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(__MODE__) (((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT) || \
  952. ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE) || \
  953. ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME) || \
  954. ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME))
  955. /**
  956. * @brief Ensure that UART receiver timeout setting is valid.
  957. * @param __TIMEOUT__: UART receiver timeout setting.
  958. * @retval SET (__TIMEOUT__ is valid) or RESET (__TIMEOUT__ is invalid)
  959. */
  960. #define IS_UART_RECEIVER_TIMEOUT(__TIMEOUT__) (((__TIMEOUT__) == UART_RECEIVER_TIMEOUT_DISABLE) || \
  961. ((__TIMEOUT__) == UART_RECEIVER_TIMEOUT_ENABLE))
  962. /**
  963. * @brief Ensure that UART LIN state is valid.
  964. * @param __LIN__: UART LIN state.
  965. * @retval SET (__LIN__ is valid) or RESET (__LIN__ is invalid)
  966. */
  967. #define IS_UART_LIN(__LIN__) (((__LIN__) == UART_LIN_DISABLE) || \
  968. ((__LIN__) == UART_LIN_ENABLE))
  969. /**
  970. * @brief Ensure that UART LIN break detection length is valid.
  971. * @param __LENGTH__: UART LIN break detection length.
  972. * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
  973. */
  974. #define IS_UART_LIN_BREAK_DETECT_LENGTH(__LENGTH__) (((__LENGTH__) == UART_LINBREAKDETECTLENGTH_10B) || \
  975. ((__LENGTH__) == UART_LINBREAKDETECTLENGTH_11B))
  976. /**
  977. * @brief Ensure that UART DMA TX state is valid.
  978. * @param __DMATX__: UART DMA TX state.
  979. * @retval SET (__DMATX__ is valid) or RESET (__DMATX__ is invalid)
  980. */
  981. #define IS_UART_DMA_TX(__DMATX__) (((__DMATX__) == UART_DMA_TX_DISABLE) || \
  982. ((__DMATX__) == UART_DMA_TX_ENABLE))
  983. /**
  984. * @brief Ensure that UART DMA RX state is valid.
  985. * @param __DMARX__: UART DMA RX state.
  986. * @retval SET (__DMARX__ is valid) or RESET (__DMARX__ is invalid)
  987. */
  988. #define IS_UART_DMA_RX(__DMARX__) (((__DMARX__) == UART_DMA_RX_DISABLE) || \
  989. ((__DMARX__) == UART_DMA_RX_ENABLE))
  990. /**
  991. * @brief Ensure that UART half-duplex state is valid.
  992. * @param __HDSEL__: UART half-duplex state.
  993. * @retval SET (__HDSEL__ is valid) or RESET (__HDSEL__ is invalid)
  994. */
  995. #define IS_UART_HALF_DUPLEX(__HDSEL__) (((__HDSEL__) == UART_HALF_DUPLEX_DISABLE) || \
  996. ((__HDSEL__) == UART_HALF_DUPLEX_ENABLE))
  997. /**
  998. * @brief Ensure that UART wake-up method is valid.
  999. * @param __WAKEUP__: UART wake-up method .
  1000. * @retval SET (__WAKEUP__ is valid) or RESET (__WAKEUP__ is invalid)
  1001. */
  1002. #define IS_UART_WAKEUPMETHOD(__WAKEUP__) (((__WAKEUP__) == UART_WAKEUPMETHOD_IDLELINE) || \
  1003. ((__WAKEUP__) == UART_WAKEUPMETHOD_ADDRESSMARK))
  1004. /**
  1005. * @brief Ensure that UART request parameter is valid.
  1006. * @param __PARAM__: UART request parameter.
  1007. * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
  1008. */
  1009. #define IS_UART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == UART_AUTOBAUD_REQUEST) || \
  1010. ((__PARAM__) == UART_SENDBREAK_REQUEST) || \
  1011. ((__PARAM__) == UART_MUTE_MODE_REQUEST) || \
  1012. ((__PARAM__) == UART_RXDATA_FLUSH_REQUEST) || \
  1013. ((__PARAM__) == UART_TXDATA_FLUSH_REQUEST))
  1014. /**
  1015. * @brief Ensure that UART advanced features initialization is valid.
  1016. * @param __INIT__: UART advanced features initialization.
  1017. * @retval SET (__INIT__ is valid) or RESET (__INIT__ is invalid)
  1018. */
  1019. #define IS_UART_ADVFEATURE_INIT(__INIT__) ((__INIT__) <= (UART_ADVFEATURE_NO_INIT | \
  1020. UART_ADVFEATURE_TXINVERT_INIT | \
  1021. UART_ADVFEATURE_RXINVERT_INIT | \
  1022. UART_ADVFEATURE_DATAINVERT_INIT | \
  1023. UART_ADVFEATURE_SWAP_INIT | \
  1024. UART_ADVFEATURE_RXOVERRUNDISABLE_INIT | \
  1025. UART_ADVFEATURE_DMADISABLEONERROR_INIT | \
  1026. UART_ADVFEATURE_AUTOBAUDRATE_INIT | \
  1027. UART_ADVFEATURE_MSBFIRST_INIT))
  1028. /**
  1029. * @brief Ensure that UART frame TX inversion setting is valid.
  1030. * @param __TXINV__: UART frame TX inversion setting.
  1031. * @retval SET (__TXINV__ is valid) or RESET (__TXINV__ is invalid)
  1032. */
  1033. #define IS_UART_ADVFEATURE_TXINV(__TXINV__) (((__TXINV__) == UART_ADVFEATURE_TXINV_DISABLE) || \
  1034. ((__TXINV__) == UART_ADVFEATURE_TXINV_ENABLE))
  1035. /**
  1036. * @brief Ensure that UART frame RX inversion setting is valid.
  1037. * @param __RXINV__: UART frame RX inversion setting.
  1038. * @retval SET (__RXINV__ is valid) or RESET (__RXINV__ is invalid)
  1039. */
  1040. #define IS_UART_ADVFEATURE_RXINV(__RXINV__) (((__RXINV__) == UART_ADVFEATURE_RXINV_DISABLE) || \
  1041. ((__RXINV__) == UART_ADVFEATURE_RXINV_ENABLE))
  1042. /**
  1043. * @brief Ensure that UART frame data inversion setting is valid.
  1044. * @param __DATAINV__: UART frame data inversion setting.
  1045. * @retval SET (__DATAINV__ is valid) or RESET (__DATAINV__ is invalid)
  1046. */
  1047. #define IS_UART_ADVFEATURE_DATAINV(__DATAINV__) (((__DATAINV__) == UART_ADVFEATURE_DATAINV_DISABLE) || \
  1048. ((__DATAINV__) == UART_ADVFEATURE_DATAINV_ENABLE))
  1049. /**
  1050. * @brief Ensure that UART frame RX/TX pins swap setting is valid.
  1051. * @param __SWAP__: UART frame RX/TX pins swap setting.
  1052. * @retval SET (__SWAP__ is valid) or RESET (__SWAP__ is invalid)
  1053. */
  1054. #define IS_UART_ADVFEATURE_SWAP(__SWAP__) (((__SWAP__) == UART_ADVFEATURE_SWAP_DISABLE) || \
  1055. ((__SWAP__) == UART_ADVFEATURE_SWAP_ENABLE))
  1056. /**
  1057. * @brief Ensure that UART frame overrun setting is valid.
  1058. * @param __OVERRUN__: UART frame overrun setting.
  1059. * @retval SET (__OVERRUN__ is valid) or RESET (__OVERRUN__ is invalid)
  1060. */
  1061. #define IS_UART_OVERRUN(__OVERRUN__) (((__OVERRUN__) == UART_ADVFEATURE_OVERRUN_ENABLE) || \
  1062. ((__OVERRUN__) == UART_ADVFEATURE_OVERRUN_DISABLE))
  1063. /**
  1064. * @brief Ensure that UART auto Baud rate state is valid.
  1065. * @param __AUTOBAUDRATE__: UART auto Baud rate state.
  1066. * @retval SET (__AUTOBAUDRATE__ is valid) or RESET (__AUTOBAUDRATE__ is invalid)
  1067. */
  1068. #define IS_UART_ADVFEATURE_AUTOBAUDRATE(__AUTOBAUDRATE__) (((__AUTOBAUDRATE__) == UART_ADVFEATURE_AUTOBAUDRATE_DISABLE) || \
  1069. ((__AUTOBAUDRATE__) == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE))
  1070. /**
  1071. * @brief Ensure that UART DMA enabling or disabling on error setting is valid.
  1072. * @param __DMA__: UART DMA enabling or disabling on error setting.
  1073. * @retval SET (__DMA__ is valid) or RESET (__DMA__ is invalid)
  1074. */
  1075. #define IS_UART_ADVFEATURE_DMAONRXERROR(__DMA__) (((__DMA__) == UART_ADVFEATURE_DMA_ENABLEONRXERROR) || \
  1076. ((__DMA__) == UART_ADVFEATURE_DMA_DISABLEONRXERROR))
  1077. /**
  1078. * @brief Ensure that UART frame MSB first setting is valid.
  1079. * @param __MSBFIRST__: UART frame MSB first setting.
  1080. * @retval SET (__MSBFIRST__ is valid) or RESET (__MSBFIRST__ is invalid)
  1081. */
  1082. #define IS_UART_ADVFEATURE_MSBFIRST(__MSBFIRST__) (((__MSBFIRST__) == UART_ADVFEATURE_MSBFIRST_DISABLE) || \
  1083. ((__MSBFIRST__) == UART_ADVFEATURE_MSBFIRST_ENABLE))
  1084. /**
  1085. * @brief Ensure that UART stop mode state is valid.
  1086. * @param __STOPMODE__: UART stop mode state.
  1087. * @retval SET (__STOPMODE__ is valid) or RESET (__STOPMODE__ is invalid)
  1088. */
  1089. #define IS_UART_ADVFEATURE_STOPMODE(__STOPMODE__) (((__STOPMODE__) == UART_ADVFEATURE_STOPMODE_DISABLE) || \
  1090. ((__STOPMODE__) == UART_ADVFEATURE_STOPMODE_ENABLE))
  1091. /**
  1092. * @brief Ensure that UART mute mode state is valid.
  1093. * @param __MUTE__: UART mute mode state.
  1094. * @retval SET (__MUTE__ is valid) or RESET (__MUTE__ is invalid)
  1095. */
  1096. #define IS_UART_MUTE_MODE(__MUTE__) (((__MUTE__) == UART_ADVFEATURE_MUTEMODE_DISABLE) || \
  1097. ((__MUTE__) == UART_ADVFEATURE_MUTEMODE_ENABLE))
  1098. /**
  1099. * @brief Ensure that UART wake-up selection is valid.
  1100. * @param __WAKE__: UART wake-up selection.
  1101. * @retval SET (__WAKE__ is valid) or RESET (__WAKE__ is invalid)
  1102. */
  1103. #define IS_UART_WAKEUP_SELECTION(__WAKE__) (((__WAKE__) == UART_WAKEUP_ON_ADDRESS) || \
  1104. ((__WAKE__) == UART_WAKEUP_ON_STARTBIT) || \
  1105. ((__WAKE__) == UART_WAKEUP_ON_READDATA_NONEMPTY))
  1106. /**
  1107. * @brief Ensure that UART driver enable polarity is valid.
  1108. * @param __POLARITY__: UART driver enable polarity.
  1109. * @retval SET (__POLARITY__ is valid) or RESET (__POLARITY__ is invalid)
  1110. */
  1111. #define IS_UART_DE_POLARITY(__POLARITY__) (((__POLARITY__) == UART_DE_POLARITY_HIGH) || \
  1112. ((__POLARITY__) == UART_DE_POLARITY_LOW))
  1113. /**
  1114. * @}
  1115. */
  1116. /* Include UART HAL Extended module */
  1117. #include "stm32l4xx_hal_uart_ex.h"
  1118. /* Exported functions --------------------------------------------------------*/
  1119. /** @addtogroup UART_Exported_Functions UART Exported Functions
  1120. * @{
  1121. */
  1122. /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
  1123. * @{
  1124. */
  1125. /* Initialization and de-initialization functions ****************************/
  1126. HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
  1127. HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
  1128. HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
  1129. HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
  1130. HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
  1131. void HAL_UART_MspInit(UART_HandleTypeDef *huart);
  1132. void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
  1133. /**
  1134. * @}
  1135. */
  1136. /** @addtogroup UART_Exported_Functions_Group2 IO operation functions
  1137. * @{
  1138. */
  1139. /* IO operation functions *****************************************************/
  1140. HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  1141. HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  1142. HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1143. HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1144. HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1145. HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1146. HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
  1147. HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
  1148. HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
  1149. void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
  1150. void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
  1151. void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
  1152. void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
  1153. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
  1154. void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
  1155. /**
  1156. * @}
  1157. */
  1158. /** @addtogroup UART_Exported_Functions_Group3 Peripheral Control functions
  1159. * @{
  1160. */
  1161. /* Peripheral Control functions ************************************************/
  1162. HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
  1163. HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart);
  1164. HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart);
  1165. void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
  1166. HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
  1167. HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
  1168. /**
  1169. * @}
  1170. */
  1171. /** @addtogroup UART_Exported_Functions_Group4 Peripheral State and Error functions
  1172. * @{
  1173. */
  1174. /* Peripheral State and Errors functions **************************************************/
  1175. HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
  1176. uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart);
  1177. /**
  1178. * @}
  1179. */
  1180. /**
  1181. * @}
  1182. */
  1183. /* Private functions -----------------------------------------------------------*/
  1184. /** @addtogroup UART_Private_Functions UART Private Functions
  1185. * @{
  1186. */
  1187. HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart);
  1188. HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart);
  1189. HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
  1190. void UART_AdvFeatureConfig(UART_HandleTypeDef *huart);
  1191. /**
  1192. * @}
  1193. */
  1194. /**
  1195. * @}
  1196. */
  1197. /**
  1198. * @}
  1199. */
  1200. #ifdef __cplusplus
  1201. }
  1202. #endif
  1203. #endif /* __STM32L4xx_HAL_UART_H */
  1204. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/