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.
 
 
 

1222 lines
55 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_uart.h
  4. * @author MCD Application Team
  5. * @version V1.2.2
  6. * @date 14-April-2017
  7. * @brief Header file of UART HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_HAL_UART_H
  39. #define __STM32F7xx_HAL_UART_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_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 fPCLK/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 initialization 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. * @note HAL UART State value is a combination of 2 different substates: gState and RxState.
  121. * - gState contains UART state information related to global Handle management
  122. * and also information related to Tx operations.
  123. * gState value coding follow below described bitmap :
  124. * b7-b6 Error information
  125. * 00 : No Error
  126. * 01 : (Not Used)
  127. * 10 : Timeout
  128. * 11 : Error
  129. * b5 IP initilisation status
  130. * 0 : Reset (IP not initialized)
  131. * 1 : Init done (IP not initialized. HAL UART Init function already called)
  132. * b4-b3 (not used)
  133. * xx : Should be set to 00
  134. * b2 Intrinsic process state
  135. * 0 : Ready
  136. * 1 : Busy (IP busy with some configuration or internal operations)
  137. * b1 (not used)
  138. * x : Should be set to 0
  139. * b0 Tx state
  140. * 0 : Ready (no Tx operation ongoing)
  141. * 1 : Busy (Tx operation ongoing)
  142. * - RxState contains information related to Rx operations.
  143. * RxState value coding follow below described bitmap :
  144. * b7-b6 (not used)
  145. * xx : Should be set to 00
  146. * b5 IP initilisation status
  147. * 0 : Reset (IP not initialized)
  148. * 1 : Init done (IP not initialized)
  149. * b4-b2 (not used)
  150. * xxx : Should be set to 000
  151. * b1 Rx state
  152. * 0 : Ready (no Rx operation ongoing)
  153. * 1 : Busy (Rx operation ongoing)
  154. * b0 (not used)
  155. * x : Should be set to 0.
  156. */
  157. typedef enum
  158. {
  159. HAL_UART_STATE_RESET = 0x00U, /*!< Peripheral is not initialized
  160. Value is allowed for gState and RxState */
  161. HAL_UART_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use
  162. Value is allowed for gState and RxState */
  163. HAL_UART_STATE_BUSY = 0x24U, /*!< an internal process is ongoing
  164. Value is allowed for gState only */
  165. HAL_UART_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing
  166. Value is allowed for gState only */
  167. HAL_UART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing
  168. Value is allowed for RxState only */
  169. HAL_UART_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing
  170. Not to be used for neither gState nor RxState.
  171. Value is result of combination (Or) between gState and RxState values */
  172. HAL_UART_STATE_TIMEOUT = 0xA0U, /*!< Timeout state
  173. Value is allowed for gState only */
  174. HAL_UART_STATE_ERROR = 0xE0U /*!< Error
  175. Value is allowed for gState only */
  176. }HAL_UART_StateTypeDef;
  177. /**
  178. * @brief UART clock sources definition
  179. */
  180. typedef enum
  181. {
  182. UART_CLOCKSOURCE_PCLK1 = 0x00U, /*!< PCLK1 clock source */
  183. UART_CLOCKSOURCE_PCLK2 = 0x01U, /*!< PCLK2 clock source */
  184. UART_CLOCKSOURCE_HSI = 0x02U, /*!< HSI clock source */
  185. UART_CLOCKSOURCE_SYSCLK = 0x04U, /*!< SYSCLK clock source */
  186. UART_CLOCKSOURCE_LSE = 0x08U, /*!< LSE clock source */
  187. UART_CLOCKSOURCE_UNDEFINED = 0x10U /*!< Undefined clock source */
  188. }UART_ClockSourceTypeDef;
  189. /**
  190. * @brief UART handle Structure definition
  191. */
  192. typedef struct
  193. {
  194. USART_TypeDef *Instance; /*!< UART registers base address */
  195. UART_InitTypeDef Init; /*!< UART communication parameters */
  196. UART_AdvFeatureInitTypeDef AdvancedInit; /*!< UART Advanced Features initialization parameters */
  197. uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */
  198. uint16_t TxXferSize; /*!< UART Tx Transfer size */
  199. __IO uint16_t TxXferCount; /*!< UART Tx Transfer Counter */
  200. uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */
  201. uint16_t RxXferSize; /*!< UART Rx Transfer size */
  202. __IO uint16_t RxXferCount; /*!< UART Rx Transfer Counter */
  203. uint16_t Mask; /*!< UART Rx RDR register mask */
  204. DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */
  205. DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */
  206. HAL_LockTypeDef Lock; /*!< Locking object */
  207. __IO HAL_UART_StateTypeDef gState; /*!< UART state information related to global Handle management
  208. and also related to Tx operations.
  209. This parameter can be a value of @ref HAL_UART_StateTypeDef */
  210. __IO HAL_UART_StateTypeDef RxState; /*!< UART state information related to Rx operations.
  211. This parameter can be a value of @ref HAL_UART_StateTypeDef */
  212. __IO uint32_t ErrorCode; /*!< UART Error code */
  213. }UART_HandleTypeDef;
  214. /**
  215. * @}
  216. */
  217. /* Exported constants --------------------------------------------------------*/
  218. /** @defgroup UART_Exported_Constants UART Exported Constants
  219. * @{
  220. */
  221. /** @defgroup UART_Error_Definition UART Error Definition
  222. * @{
  223. */
  224. #define HAL_UART_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
  225. #define HAL_UART_ERROR_PE ((uint32_t)0x00000001U) /*!< Parity error */
  226. #define HAL_UART_ERROR_NE ((uint32_t)0x00000002U) /*!< Noise error */
  227. #define HAL_UART_ERROR_FE ((uint32_t)0x00000004U) /*!< frame error */
  228. #define HAL_UART_ERROR_ORE ((uint32_t)0x00000008U) /*!< Overrun error */
  229. #define HAL_UART_ERROR_DMA ((uint32_t)0x00000010U) /*!< DMA transfer error */
  230. /**
  231. * @}
  232. */
  233. /** @defgroup UART_Stop_Bits UART Number of Stop Bits
  234. * @{
  235. */
  236. #define UART_STOPBITS_1 ((uint32_t)0x00000000U)
  237. #define UART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1)
  238. /**
  239. * @}
  240. */
  241. /** @defgroup UART_Parity UART Parity
  242. * @{
  243. */
  244. #define UART_PARITY_NONE ((uint32_t)0x00000000U)
  245. #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
  246. #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
  247. /**
  248. * @}
  249. */
  250. /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
  251. * @{
  252. */
  253. #define UART_HWCONTROL_NONE ((uint32_t)0x00000000U)
  254. #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE)
  255. #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE)
  256. #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
  257. /**
  258. * @}
  259. */
  260. /** @defgroup UART_Mode UART Transfer Mode
  261. * @{
  262. */
  263. #define UART_MODE_RX ((uint32_t)USART_CR1_RE)
  264. #define UART_MODE_TX ((uint32_t)USART_CR1_TE)
  265. #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
  266. /**
  267. * @}
  268. */
  269. /** @defgroup UART_State UART State
  270. * @{
  271. */
  272. #define UART_STATE_DISABLE ((uint32_t)0x00000000U)
  273. #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE)
  274. /**
  275. * @}
  276. */
  277. /** @defgroup UART_Over_Sampling UART Over Sampling
  278. * @{
  279. */
  280. #define UART_OVERSAMPLING_16 ((uint32_t)0x00000000U)
  281. #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8)
  282. /**
  283. * @}
  284. */
  285. /** @defgroup UART_OneBit_Sampling UART One Bit Sampling Method
  286. * @{
  287. */
  288. #define UART_ONE_BIT_SAMPLE_DISABLE ((uint32_t)0x00000000U)
  289. #define UART_ONE_BIT_SAMPLE_ENABLE ((uint32_t)USART_CR3_ONEBIT)
  290. /**
  291. * @}
  292. */
  293. /** @defgroup UART_AutoBaud_Rate_Mode UART Advanced Feature AutoBaud Rate Mode
  294. * @{
  295. */
  296. #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT ((uint32_t)0x0000U)
  297. #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE ((uint32_t)USART_CR2_ABRMODE_0)
  298. #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME ((uint32_t)USART_CR2_ABRMODE_1)
  299. #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME ((uint32_t)USART_CR2_ABRMODE)
  300. /**
  301. * @}
  302. */
  303. /** @defgroup UART_Receiver_TimeOut UART Receiver TimeOut
  304. * @{
  305. */
  306. #define UART_RECEIVER_TIMEOUT_DISABLE ((uint32_t)0x00000000U)
  307. #define UART_RECEIVER_TIMEOUT_ENABLE ((uint32_t)USART_CR2_RTOEN)
  308. /**
  309. * @}
  310. */
  311. /** @defgroup UART_LIN UART Local Interconnection Network mode
  312. * @{
  313. */
  314. #define UART_LIN_DISABLE ((uint32_t)0x00000000U)
  315. #define UART_LIN_ENABLE ((uint32_t)USART_CR2_LINEN)
  316. /**
  317. * @}
  318. */
  319. /** @defgroup UART_LIN_Break_Detection UART LIN Break Detection
  320. * @{
  321. */
  322. #define UART_LINBREAKDETECTLENGTH_10B ((uint32_t)0x00000000U)
  323. #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL)
  324. /**
  325. * @}
  326. */
  327. /** @defgroup UART_DMA_Tx UART DMA Tx
  328. * @{
  329. */
  330. #define UART_DMA_TX_DISABLE ((uint32_t)0x00000000U)
  331. #define UART_DMA_TX_ENABLE ((uint32_t)USART_CR3_DMAT)
  332. /**
  333. * @}
  334. */
  335. /** @defgroup UART_DMA_Rx UART DMA Rx
  336. * @{
  337. */
  338. #define UART_DMA_RX_DISABLE ((uint32_t)0x0000U)
  339. #define UART_DMA_RX_ENABLE ((uint32_t)USART_CR3_DMAR)
  340. /**
  341. * @}
  342. */
  343. /** @defgroup UART_Half_Duplex_Selection UART Half Duplex Selection
  344. * @{
  345. */
  346. #define UART_HALF_DUPLEX_DISABLE ((uint32_t)0x0000U)
  347. #define UART_HALF_DUPLEX_ENABLE ((uint32_t)USART_CR3_HDSEL)
  348. /**
  349. * @}
  350. */
  351. /** @defgroup UART_WakeUp_Methods UART WakeUp Methods
  352. * @{
  353. */
  354. #define UART_WAKEUPMETHOD_IDLELINE ((uint32_t)0x00000000U)
  355. #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE)
  356. /**
  357. * @}
  358. */
  359. /** @defgroup UART_Request_Parameters UART Request Parameters
  360. * @{
  361. */
  362. #define UART_AUTOBAUD_REQUEST ((uint32_t)USART_RQR_ABRRQ) /*!< Auto-Baud Rate Request */
  363. #define UART_SENDBREAK_REQUEST ((uint32_t)USART_RQR_SBKRQ) /*!< Send Break Request */
  364. #define UART_MUTE_MODE_REQUEST ((uint32_t)USART_RQR_MMRQ) /*!< Mute Mode Request */
  365. #define UART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
  366. #define UART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
  367. /**
  368. * @}
  369. */
  370. /** @defgroup UART_Advanced_Features_Initialization_Type UART Advanced Feature Initialization Type
  371. * @{
  372. */
  373. #define UART_ADVFEATURE_NO_INIT ((uint32_t)0x00000000U)
  374. #define UART_ADVFEATURE_TXINVERT_INIT ((uint32_t)0x00000001U)
  375. #define UART_ADVFEATURE_RXINVERT_INIT ((uint32_t)0x00000002U)
  376. #define UART_ADVFEATURE_DATAINVERT_INIT ((uint32_t)0x00000004U)
  377. #define UART_ADVFEATURE_SWAP_INIT ((uint32_t)0x00000008U)
  378. #define UART_ADVFEATURE_RXOVERRUNDISABLE_INIT ((uint32_t)0x00000010U)
  379. #define UART_ADVFEATURE_DMADISABLEONERROR_INIT ((uint32_t)0x00000020U)
  380. #define UART_ADVFEATURE_AUTOBAUDRATE_INIT ((uint32_t)0x00000040U)
  381. #define UART_ADVFEATURE_MSBFIRST_INIT ((uint32_t)0x00000080U)
  382. /**
  383. * @}
  384. */
  385. /** @defgroup UART_Tx_Inv UART Advanced Feature TX Pin Active Level Inversion
  386. * @{
  387. */
  388. #define UART_ADVFEATURE_TXINV_DISABLE ((uint32_t)0x00000000U)
  389. #define UART_ADVFEATURE_TXINV_ENABLE ((uint32_t)USART_CR2_TXINV)
  390. /**
  391. * @}
  392. */
  393. /** @defgroup UART_Rx_Inv UART Advanced Feature RX Pin Active Level Inversion
  394. * @{
  395. */
  396. #define UART_ADVFEATURE_RXINV_DISABLE ((uint32_t)0x00000000U)
  397. #define UART_ADVFEATURE_RXINV_ENABLE ((uint32_t)USART_CR2_RXINV)
  398. /**
  399. * @}
  400. */
  401. /** @defgroup UART_Data_Inv UART Advanced Feature Binary Data Inversion
  402. * @{
  403. */
  404. #define UART_ADVFEATURE_DATAINV_DISABLE ((uint32_t)0x00000000U)
  405. #define UART_ADVFEATURE_DATAINV_ENABLE ((uint32_t)USART_CR2_DATAINV)
  406. /**
  407. * @}
  408. */
  409. /** @defgroup UART_Rx_Tx_Swap UART Advanced Feature RX TX Pins Swap
  410. * @{
  411. */
  412. #define UART_ADVFEATURE_SWAP_DISABLE ((uint32_t)0x00000000U)
  413. #define UART_ADVFEATURE_SWAP_ENABLE ((uint32_t)USART_CR2_SWAP)
  414. /**
  415. * @}
  416. */
  417. /** @defgroup UART_Overrun_Disable UART Advanced Feature Overrun Disable
  418. * @{
  419. */
  420. #define UART_ADVFEATURE_OVERRUN_ENABLE ((uint32_t)0x00000000U)
  421. #define UART_ADVFEATURE_OVERRUN_DISABLE ((uint32_t)USART_CR3_OVRDIS)
  422. /**
  423. * @}
  424. */
  425. /** @defgroup UART_AutoBaudRate_Enable UART Advanced Feature Auto BaudRate Enable
  426. * @{
  427. */
  428. #define UART_ADVFEATURE_AUTOBAUDRATE_DISABLE ((uint32_t)0x00000000U)
  429. #define UART_ADVFEATURE_AUTOBAUDRATE_ENABLE ((uint32_t)USART_CR2_ABREN)
  430. /**
  431. * @}
  432. */
  433. /** @defgroup UART_DMA_Disable_on_Rx_Error UART Advanced Feature DMA Disable On Rx Error
  434. * @{
  435. */
  436. #define UART_ADVFEATURE_DMA_ENABLEONRXERROR ((uint32_t)0x00000000U)
  437. #define UART_ADVFEATURE_DMA_DISABLEONRXERROR ((uint32_t)USART_CR3_DDRE)
  438. /**
  439. * @}
  440. */
  441. /** @defgroup UART_MSB_First UART Advanced Feature MSB First
  442. * @{
  443. */
  444. #define UART_ADVFEATURE_MSBFIRST_DISABLE ((uint32_t)0x00000000U)
  445. #define UART_ADVFEATURE_MSBFIRST_ENABLE ((uint32_t)USART_CR2_MSBFIRST)
  446. /**
  447. * @}
  448. */
  449. /** @defgroup UART_Mute_Mode UART Advanced Feature Mute Mode Enable
  450. * @{
  451. */
  452. #define UART_ADVFEATURE_MUTEMODE_DISABLE ((uint32_t)0x00000000U)
  453. #define UART_ADVFEATURE_MUTEMODE_ENABLE ((uint32_t)USART_CR1_MME)
  454. /**
  455. * @}
  456. */
  457. /** @defgroup UART_CR2_ADDRESS_LSB_POS UART Address-matching LSB Position In CR2 Register
  458. * @{
  459. */
  460. #define UART_CR2_ADDRESS_LSB_POS ((uint32_t) 24U)
  461. /**
  462. * @}
  463. */
  464. /** @defgroup UART_DriverEnable_Polarity UART DriverEnable Polarity
  465. * @{
  466. */
  467. #define UART_DE_POLARITY_HIGH ((uint32_t)0x00000000U)
  468. #define UART_DE_POLARITY_LOW ((uint32_t)USART_CR3_DEP)
  469. /**
  470. * @}
  471. */
  472. /** @defgroup UART_CR1_DEAT_ADDRESS_LSB_POS UART Driver Enable Assertion Time LSB Position In CR1 Register
  473. * @{
  474. */
  475. #define UART_CR1_DEAT_ADDRESS_LSB_POS ((uint32_t) 21U)
  476. /**
  477. * @}
  478. */
  479. /** @defgroup UART_CR1_DEDT_ADDRESS_LSB_POS UART Driver Enable DeAssertion Time LSB Position In CR1 Register
  480. * @{
  481. */
  482. #define UART_CR1_DEDT_ADDRESS_LSB_POS ((uint32_t) 16U)
  483. /**
  484. * @}
  485. */
  486. /** @defgroup UART_Interruption_Mask UART Interruptions Flag Mask
  487. * @{
  488. */
  489. #define UART_IT_MASK ((uint32_t)0x001FU)
  490. /**
  491. * @}
  492. */
  493. /** @defgroup UART_TimeOut_Value UART polling-based communications time-out value
  494. * @{
  495. */
  496. #define HAL_UART_TIMEOUT_VALUE 0x1FFFFFFU
  497. /**
  498. * @}
  499. */
  500. /** @defgroup UART_Flags UART Status Flags
  501. * Elements values convention: 0xXXXX
  502. * - 0xXXXX : Flag mask in the ISR register
  503. * @{
  504. */
  505. #define UART_FLAG_TEACK ((uint32_t)0x00200000U)
  506. #define UART_FLAG_SBKF ((uint32_t)0x00040000U)
  507. #define UART_FLAG_CMF ((uint32_t)0x00020000U)
  508. #define UART_FLAG_BUSY ((uint32_t)0x00010000U)
  509. #define UART_FLAG_ABRF ((uint32_t)0x00008000U)
  510. #define UART_FLAG_ABRE ((uint32_t)0x00004000U)
  511. #define UART_FLAG_EOBF ((uint32_t)0x00001000U)
  512. #define UART_FLAG_RTOF ((uint32_t)0x00000800U)
  513. #define UART_FLAG_CTS ((uint32_t)0x00000400U)
  514. #define UART_FLAG_CTSIF ((uint32_t)0x00000200U)
  515. #define UART_FLAG_LBDF ((uint32_t)0x00000100U)
  516. #define UART_FLAG_TXE ((uint32_t)0x00000080U)
  517. #define UART_FLAG_TC ((uint32_t)0x00000040U)
  518. #define UART_FLAG_RXNE ((uint32_t)0x00000020U)
  519. #define UART_FLAG_IDLE ((uint32_t)0x00000010U)
  520. #define UART_FLAG_ORE ((uint32_t)0x00000008U)
  521. #define UART_FLAG_NE ((uint32_t)0x00000004U)
  522. #define UART_FLAG_FE ((uint32_t)0x00000002U)
  523. #define UART_FLAG_PE ((uint32_t)0x00000001U)
  524. /**
  525. * @}
  526. */
  527. /** @defgroup UART_Interrupt_definition UART Interrupts Definition
  528. * Elements values convention: 0000ZZZZ0XXYYYYYb
  529. * - YYYYY : Interrupt source position in the XX register (5bits)
  530. * - XX : Interrupt source register (2bits)
  531. * - 01: CR1 register
  532. * - 10: CR2 register
  533. * - 11: CR3 register
  534. * - ZZZZ : Flag position in the ISR register(4bits)
  535. * @{
  536. */
  537. #define UART_IT_PE ((uint32_t)0x0028U)
  538. #define UART_IT_TXE ((uint32_t)0x0727U)
  539. #define UART_IT_TC ((uint32_t)0x0626U)
  540. #define UART_IT_RXNE ((uint32_t)0x0525U)
  541. #define UART_IT_IDLE ((uint32_t)0x0424U)
  542. #define UART_IT_LBD ((uint32_t)0x0846U)
  543. #define UART_IT_CTS ((uint32_t)0x096AU)
  544. #define UART_IT_CM ((uint32_t)0x112EU)
  545. /** Elements values convention: 000000000XXYYYYYb
  546. * - YYYYY : Interrupt source position in the XX register (5bits)
  547. * - XX : Interrupt source register (2bits)
  548. * - 01: CR1 register
  549. * - 10: CR2 register
  550. * - 11: CR3 register
  551. */
  552. #define UART_IT_ERR ((uint32_t)0x0060U)
  553. /** Elements values convention: 0000ZZZZ00000000b
  554. * - ZZZZ : Flag position in the ISR register(4bits)
  555. */
  556. #define UART_IT_ORE ((uint32_t)0x0300U)
  557. #define UART_IT_NE ((uint32_t)0x0200U)
  558. #define UART_IT_FE ((uint32_t)0x0100U)
  559. /**
  560. * @}
  561. */
  562. /** @defgroup UART_IT_CLEAR_Flags UART Interruption Clear Flags
  563. * @{
  564. */
  565. #define UART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
  566. #define UART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
  567. #define UART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
  568. #define UART_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
  569. #define UART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
  570. #define UART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
  571. #define UART_CLEAR_LBDF USART_ICR_LBDCF /*!< LIN Break Detection Clear Flag */
  572. #define UART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
  573. #define UART_CLEAR_RTOF USART_ICR_RTOCF /*!< Receiver Time Out Clear Flag */
  574. #define UART_CLEAR_EOBF USART_ICR_EOBCF /*!< End Of Block Clear Flag */
  575. #define UART_CLEAR_CMF USART_ICR_CMCF /*!< Character Match Clear Flag */
  576. /**
  577. * @}
  578. */
  579. /**
  580. * @}
  581. */
  582. /* Exported macros -----------------------------------------------------------*/
  583. /** @defgroup UART_Exported_Macros UART Exported Macros
  584. * @{
  585. */
  586. /** @brief Reset UART handle state
  587. * @param __HANDLE__: UART handle.
  588. * @retval None
  589. */
  590. #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \
  591. (__HANDLE__)->gState = HAL_UART_STATE_RESET; \
  592. (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \
  593. } while(0)
  594. /** @brief Flush the UART Data registers
  595. * @param __HANDLE__: specifies the UART Handle.
  596. */
  597. #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) \
  598. do{ \
  599. SET_BIT((__HANDLE__)->Instance->RQR, UART_RXDATA_FLUSH_REQUEST); \
  600. SET_BIT((__HANDLE__)->Instance->RQR, UART_TXDATA_FLUSH_REQUEST); \
  601. } while(0)
  602. /** @brief Clears the specified UART ISR flag, in setting the proper ICR register flag.
  603. * @param __HANDLE__: specifies the UART Handle.
  604. * @param __FLAG__: specifies the interrupt clear register flag that needs to be set
  605. * to clear the corresponding interrupt
  606. * This parameter can be one of the following values:
  607. * @arg UART_CLEAR_PEF: Parity Error Clear Flag
  608. * @arg UART_CLEAR_FEF: Framing Error Clear Flag
  609. * @arg UART_CLEAR_NEF: Noise detected Clear Flag
  610. * @arg UART_CLEAR_OREF: OverRun Error Clear Flag
  611. * @arg UART_CLEAR_IDLEF: IDLE line detected Clear Flag
  612. * @arg UART_CLEAR_TCF: Transmission Complete Clear Flag
  613. * @arg UART_CLEAR_LBDF: LIN Break Detection Clear Flag
  614. * @arg UART_CLEAR_CTSF: CTS Interrupt Clear Flag
  615. * @arg UART_CLEAR_RTOF: Receiver Time Out Clear Flag
  616. * @arg UART_CLEAR_EOBF: End Of Block Clear Flag
  617. * @arg UART_CLEAR_CMF: Character Match Clear Flag
  618. * @retval None
  619. */
  620. #define __HAL_UART_CLEAR_IT(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__FLAG__))
  621. /** @brief Clear the UART PE pending flag.
  622. * @param __HANDLE__: specifies the UART Handle.
  623. * @retval None
  624. */
  625. #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) __HAL_UART_CLEAR_IT((__HANDLE__),UART_CLEAR_PEF)
  626. /** @brief Clear the UART FE pending flag.
  627. * @param __HANDLE__: specifies the UART Handle.
  628. * @retval None
  629. */
  630. #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_IT((__HANDLE__),UART_CLEAR_FEF)
  631. /** @brief Clear the UART NE pending flag.
  632. * @param __HANDLE__: specifies the UART Handle.
  633. * @retval None
  634. */
  635. #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_IT((__HANDLE__),UART_CLEAR_NEF)
  636. /** @brief Clear the UART ORE pending flag.
  637. * @param __HANDLE__: specifies the UART Handle.
  638. * @retval None
  639. */
  640. #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_IT((__HANDLE__),UART_CLEAR_OREF)
  641. /** @brief Clear the UART IDLE pending flag.
  642. * @param __HANDLE__: specifies the UART Handle.
  643. * @retval None
  644. */
  645. #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_IT((__HANDLE__),UART_CLEAR_IDLEF)
  646. /** @brief Checks whether the specified UART flag is set or not.
  647. * @param __HANDLE__: specifies the UART Handle.
  648. * @param __FLAG__: specifies the flag to check.
  649. * This parameter can be one of the following values:
  650. * @arg UART_FLAG_REACK: Receive enable acknowledge flag
  651. * @arg UART_FLAG_TEACK: Transmit enable acknowledge flag
  652. * @arg UART_FLAG_WUF: Wake up from stop mode flag
  653. * @arg UART_FLAG_RWU: Receiver wake up flag (is the UART in mute mode)
  654. * @arg UART_FLAG_SBKF: Send Break flag
  655. * @arg UART_FLAG_CMF: Character match flag
  656. * @arg UART_FLAG_BUSY: Busy flag
  657. * @arg UART_FLAG_ABRF: Auto Baud rate detection flag
  658. * @arg UART_FLAG_ABRE: Auto Baud rate detection error flag
  659. * @arg UART_FLAG_EOBF: End of block flag
  660. * @arg UART_FLAG_RTOF: Receiver timeout flag
  661. * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5)
  662. * @arg UART_FLAG_LBD: LIN Break detection flag
  663. * @arg UART_FLAG_TXE: Transmit data register empty flag
  664. * @arg UART_FLAG_TC: Transmission Complete flag
  665. * @arg UART_FLAG_RXNE: Receive data register not empty flag
  666. * @arg UART_FLAG_IDLE: Idle Line detection flag
  667. * @arg UART_FLAG_ORE: OverRun Error flag
  668. * @arg UART_FLAG_NE: Noise Error flag
  669. * @arg UART_FLAG_FE: Framing Error flag
  670. * @arg UART_FLAG_PE: Parity Error flag
  671. * @retval The new state of __FLAG__ (TRUE or FALSE).
  672. */
  673. #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
  674. /** @brief Enables the specified UART interrupt.
  675. * @param __HANDLE__: specifies the UART Handle.
  676. * @param __INTERRUPT__: specifies the UART interrupt source to enable.
  677. * This parameter can be one of the following values:
  678. * @arg UART_IT_WUF: Wakeup from stop mode interrupt
  679. * @arg UART_IT_CM: Character match interrupt
  680. * @arg UART_IT_CTS: CTS change interrupt
  681. * @arg UART_IT_LBD: LIN Break detection interrupt
  682. * @arg UART_IT_TXE: Transmit Data Register empty interrupt
  683. * @arg UART_IT_TC: Transmission complete interrupt
  684. * @arg UART_IT_RXNE: Receive Data register not empty interrupt
  685. * @arg UART_IT_IDLE: Idle line detection interrupt
  686. * @arg UART_IT_PE: Parity Error interrupt
  687. * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  688. * @retval None
  689. */
  690. #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  691. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  692. ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))))
  693. /** @brief Disables the specified UART interrupt.
  694. * @param __HANDLE__: specifies the UART Handle.
  695. * @param __INTERRUPT__: specifies the UART interrupt source to disable.
  696. * This parameter can be one of the following values:
  697. * @arg UART_IT_CM: Character match interrupt
  698. * @arg UART_IT_CTS: CTS change interrupt
  699. * @arg UART_IT_LBD: LIN Break detection interrupt
  700. * @arg UART_IT_TXE: Transmit Data Register empty interrupt
  701. * @arg UART_IT_TC: Transmission complete interrupt
  702. * @arg UART_IT_RXNE: Receive Data register not empty interrupt
  703. * @arg UART_IT_IDLE: Idle line detection interrupt
  704. * @arg UART_IT_PE: Parity Error interrupt
  705. * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  706. * @retval None
  707. */
  708. #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  709. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  710. ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))))
  711. /** @brief Checks whether the specified UART interrupt has occurred or not.
  712. * @param __HANDLE__: specifies the UART Handle.
  713. * @param __IT__: specifies the UART interrupt to check.
  714. * This parameter can be one of the following values:
  715. * @arg UART_IT_CM: Character match interrupt
  716. * @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
  717. * @arg UART_IT_LBD: LIN Break detection interrupt
  718. * @arg UART_IT_TXE: Transmit Data Register empty interrupt
  719. * @arg UART_IT_TC: Transmission complete interrupt
  720. * @arg UART_IT_RXNE: Receive Data register not empty interrupt
  721. * @arg UART_IT_IDLE: Idle line detection interrupt
  722. * @arg UART_IT_ORE: OverRun Error interrupt
  723. * @arg UART_IT_NE: Noise Error interrupt
  724. * @arg UART_IT_FE: Framing Error interrupt
  725. * @arg UART_IT_PE: Parity Error interrupt
  726. * @retval The new state of __IT__ (TRUE or FALSE).
  727. */
  728. #define __HAL_UART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
  729. /** @brief Checks whether the specified UART interrupt source is enabled.
  730. * @param __HANDLE__: specifies the UART Handle.
  731. * @param __IT__: specifies the UART interrupt source to check.
  732. * This parameter can be one of the following values:
  733. * @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
  734. * @arg UART_IT_LBD: LIN Break detection interrupt
  735. * @arg UART_IT_TXE: Transmit Data Register empty interrupt
  736. * @arg UART_IT_TC: Transmission complete interrupt
  737. * @arg UART_IT_RXNE: Receive Data register not empty interrupt
  738. * @arg UART_IT_IDLE: Idle line detection interrupt
  739. * @arg UART_IT_ORE: OverRun Error interrupt
  740. * @arg UART_IT_NE: Noise Error interrupt
  741. * @arg UART_IT_FE: Framing Error interrupt
  742. * @arg UART_IT_PE: Parity Error interrupt
  743. * @retval The new state of __IT__ (TRUE or FALSE).
  744. */
  745. #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5U) == 2)? \
  746. (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << (((uint16_t)(__IT__)) & UART_IT_MASK)))
  747. /** @brief Set a specific UART request flag.
  748. * @param __HANDLE__: specifies the UART Handle.
  749. * @param __REQ__: specifies the request flag to set
  750. * This parameter can be one of the following values:
  751. * @arg UART_AUTOBAUD_REQUEST: Auto-Baud Rate Request
  752. * @arg UART_SENDBREAK_REQUEST: Send Break Request
  753. * @arg UART_MUTE_MODE_REQUEST: Mute Mode Request
  754. * @arg UART_RXDATA_FLUSH_REQUEST: Receive Data flush Request
  755. * @arg UART_TXDATA_FLUSH_REQUEST: Transmit data flush Request
  756. * @retval None
  757. */
  758. #define __HAL_UART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint32_t)(__REQ__))
  759. /** @brief Enables the UART one bit sample method
  760. * @param __HANDLE__: specifies the UART Handle.
  761. * @retval None
  762. */
  763. #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
  764. /** @brief Disables the UART one bit sample method
  765. * @param __HANDLE__: specifies the UART Handle.
  766. * @retval None
  767. */
  768. #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
  769. /** @brief Enable UART
  770. * @param __HANDLE__: specifies the UART Handle.
  771. * @retval None
  772. */
  773. #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
  774. /** @brief Disable UART
  775. * @param __HANDLE__: specifies the UART Handle.
  776. * @retval None
  777. */
  778. #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
  779. /** @brief Enable CTS flow control
  780. * This macro allows to enable CTS hardware flow control for a given UART instance,
  781. * without need to call HAL_UART_Init() function.
  782. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  783. * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
  784. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  785. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  786. * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
  787. * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
  788. * @param __HANDLE__: specifies the UART Handle.
  789. * The Handle Instance can be USART1, USART2 or LPUART.
  790. * @retval None
  791. */
  792. #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \
  793. do{ \
  794. SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
  795. (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \
  796. } while(0)
  797. /** @brief Disable CTS flow control
  798. * This macro allows to disable CTS hardware flow control for a given UART instance,
  799. * without need to call HAL_UART_Init() function.
  800. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  801. * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
  802. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  803. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  804. * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
  805. * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
  806. * @param __HANDLE__: specifies the UART Handle.
  807. * The Handle Instance can be USART1, USART2 or LPUART.
  808. * @retval None
  809. */
  810. #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \
  811. do{ \
  812. CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
  813. (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \
  814. } while(0)
  815. /** @brief Enable RTS flow control
  816. * This macro allows to enable RTS hardware flow control for a given UART instance,
  817. * without need to call HAL_UART_Init() function.
  818. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  819. * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
  820. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  821. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  822. * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
  823. * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
  824. * @param __HANDLE__: specifies the UART Handle.
  825. * The Handle Instance can be USART1, USART2 or LPUART.
  826. * @retval None
  827. */
  828. #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \
  829. do{ \
  830. SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
  831. (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \
  832. } while(0)
  833. /** @brief Disable RTS flow control
  834. * This macro allows to disable RTS hardware flow control for a given UART instance,
  835. * without need to call HAL_UART_Init() function.
  836. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  837. * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
  838. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  839. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  840. * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
  841. * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
  842. * @param __HANDLE__: specifies the UART Handle.
  843. * The Handle Instance can be USART1, USART2 or LPUART.
  844. * @retval None
  845. */
  846. #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \
  847. do{ \
  848. CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
  849. (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \
  850. } while(0)
  851. /**
  852. * @}
  853. */
  854. /* Private macros --------------------------------------------------------*/
  855. /** @defgroup UART_Private_Macros UART Private Macros
  856. * @{
  857. */
  858. /** @brief BRR division operation to set BRR register with LPUART
  859. * @param _PCLK_: LPUART clock
  860. * @param _BAUD_: Baud rate set by the user
  861. * @retval Division result
  862. */
  863. #define UART_DIV_LPUART(_PCLK_, _BAUD_) ((((_PCLK_)*256)+((_BAUD_)/2))/((_BAUD_)))
  864. /** @brief BRR division operation to set BRR register in 8-bit oversampling mode
  865. * @param _PCLK_: UART clock
  866. * @param _BAUD_: Baud rate set by the user
  867. * @retval Division result
  868. */
  869. #define UART_DIV_SAMPLING8(_PCLK_, _BAUD_) ((((_PCLK_)*2)+((_BAUD_)/2))/((_BAUD_)))
  870. /** @brief BRR division operation to set BRR register in 16-bit oversampling mode
  871. * @param _PCLK_: UART clock
  872. * @param _BAUD_: Baud rate set by the user
  873. * @retval Division result
  874. */
  875. #define UART_DIV_SAMPLING16(_PCLK_, _BAUD_) ((((_PCLK_))+((_BAUD_)/2))/((_BAUD_)))
  876. /** @brief Check UART Baud rate
  877. * @param BAUDRATE: Baudrate specified by the user
  878. * The maximum Baud Rate is derived from the maximum clock on F7 (i.e. 216 MHz)
  879. * divided by the smallest oversampling used on the USART (i.e. 8)
  880. * @retval Test result (TRUE or FALSE).
  881. */
  882. #define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 9000001)
  883. /** @brief Check UART assertion time
  884. * @param TIME: 5-bit value assertion time
  885. * @retval Test result (TRUE or FALSE).
  886. */
  887. #define IS_UART_ASSERTIONTIME(TIME) ((TIME) <= 0x1F)
  888. /** @brief Check UART deassertion time
  889. * @param TIME: 5-bit value deassertion time
  890. * @retval Test result (TRUE or FALSE).
  891. */
  892. #define IS_UART_DEASSERTIONTIME(TIME) ((TIME) <= 0x1F)
  893. #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \
  894. ((STOPBITS) == UART_STOPBITS_2))
  895. #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \
  896. ((PARITY) == UART_PARITY_EVEN) || \
  897. ((PARITY) == UART_PARITY_ODD))
  898. #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
  899. (((CONTROL) == UART_HWCONTROL_NONE) || \
  900. ((CONTROL) == UART_HWCONTROL_RTS) || \
  901. ((CONTROL) == UART_HWCONTROL_CTS) || \
  902. ((CONTROL) == UART_HWCONTROL_RTS_CTS))
  903. #define IS_UART_MODE(MODE) ((((MODE) & (~((uint32_t)(UART_MODE_TX_RX)))) == (uint32_t)0x00) && ((MODE) != (uint32_t)0x00))
  904. #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \
  905. ((STATE) == UART_STATE_ENABLE))
  906. #define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \
  907. ((SAMPLING) == UART_OVERSAMPLING_8))
  908. #define IS_UART_ONE_BIT_SAMPLE(ONEBIT) (((ONEBIT) == UART_ONE_BIT_SAMPLE_DISABLE) || \
  909. ((ONEBIT) == UART_ONE_BIT_SAMPLE_ENABLE))
  910. #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(MODE) (((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT) || \
  911. ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE) || \
  912. ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME) || \
  913. ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME))
  914. #define IS_UART_RECEIVER_TIMEOUT(TIMEOUT) (((TIMEOUT) == UART_RECEIVER_TIMEOUT_DISABLE) || \
  915. ((TIMEOUT) == UART_RECEIVER_TIMEOUT_ENABLE))
  916. #define IS_UART_LIN(LIN) (((LIN) == UART_LIN_DISABLE) || \
  917. ((LIN) == UART_LIN_ENABLE))
  918. #define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \
  919. ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK))
  920. #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
  921. ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
  922. #define IS_UART_DMA_TX(DMATX) (((DMATX) == UART_DMA_TX_DISABLE) || \
  923. ((DMATX) == UART_DMA_TX_ENABLE))
  924. #define IS_UART_DMA_RX(DMARX) (((DMARX) == UART_DMA_RX_DISABLE) || \
  925. ((DMARX) == UART_DMA_RX_ENABLE))
  926. #define IS_UART_HALF_DUPLEX(HDSEL) (((HDSEL) == UART_HALF_DUPLEX_DISABLE) || \
  927. ((HDSEL) == UART_HALF_DUPLEX_ENABLE))
  928. #define IS_UART_REQUEST_PARAMETER(PARAM) (((PARAM) == UART_AUTOBAUD_REQUEST) || \
  929. ((PARAM) == UART_SENDBREAK_REQUEST) || \
  930. ((PARAM) == UART_MUTE_MODE_REQUEST) || \
  931. ((PARAM) == UART_RXDATA_FLUSH_REQUEST) || \
  932. ((PARAM) == UART_TXDATA_FLUSH_REQUEST))
  933. #define IS_UART_ADVFEATURE_INIT(INIT) ((INIT) <= (UART_ADVFEATURE_NO_INIT | \
  934. UART_ADVFEATURE_TXINVERT_INIT | \
  935. UART_ADVFEATURE_RXINVERT_INIT | \
  936. UART_ADVFEATURE_DATAINVERT_INIT | \
  937. UART_ADVFEATURE_SWAP_INIT | \
  938. UART_ADVFEATURE_RXOVERRUNDISABLE_INIT | \
  939. UART_ADVFEATURE_DMADISABLEONERROR_INIT | \
  940. UART_ADVFEATURE_AUTOBAUDRATE_INIT | \
  941. UART_ADVFEATURE_MSBFIRST_INIT))
  942. #define IS_UART_ADVFEATURE_TXINV(TXINV) (((TXINV) == UART_ADVFEATURE_TXINV_DISABLE) || \
  943. ((TXINV) == UART_ADVFEATURE_TXINV_ENABLE))
  944. #define IS_UART_ADVFEATURE_RXINV(RXINV) (((RXINV) == UART_ADVFEATURE_RXINV_DISABLE) || \
  945. ((RXINV) == UART_ADVFEATURE_RXINV_ENABLE))
  946. #define IS_UART_ADVFEATURE_DATAINV(DATAINV) (((DATAINV) == UART_ADVFEATURE_DATAINV_DISABLE) || \
  947. ((DATAINV) == UART_ADVFEATURE_DATAINV_ENABLE))
  948. #define IS_UART_ADVFEATURE_SWAP(SWAP) (((SWAP) == UART_ADVFEATURE_SWAP_DISABLE) || \
  949. ((SWAP) == UART_ADVFEATURE_SWAP_ENABLE))
  950. #define IS_UART_OVERRUN(OVERRUN) (((OVERRUN) == UART_ADVFEATURE_OVERRUN_ENABLE) || \
  951. ((OVERRUN) == UART_ADVFEATURE_OVERRUN_DISABLE))
  952. #define IS_UART_ADVFEATURE_AUTOBAUDRATE(AUTOBAUDRATE) (((AUTOBAUDRATE) == UART_ADVFEATURE_AUTOBAUDRATE_DISABLE) || \
  953. ((AUTOBAUDRATE) == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE))
  954. #define IS_UART_ADVFEATURE_DMAONRXERROR(DMA) (((DMA) == UART_ADVFEATURE_DMA_ENABLEONRXERROR) || \
  955. ((DMA) == UART_ADVFEATURE_DMA_DISABLEONRXERROR))
  956. #define IS_UART_ADVFEATURE_MSBFIRST(MSBFIRST) (((MSBFIRST) == UART_ADVFEATURE_MSBFIRST_DISABLE) || \
  957. ((MSBFIRST) == UART_ADVFEATURE_MSBFIRST_ENABLE))
  958. #define IS_UART_MUTE_MODE(MUTE) (((MUTE) == UART_ADVFEATURE_MUTEMODE_DISABLE) || \
  959. ((MUTE) == UART_ADVFEATURE_MUTEMODE_ENABLE))
  960. #define IS_UART_DE_POLARITY(POLARITY) (((POLARITY) == UART_DE_POLARITY_HIGH) || \
  961. ((POLARITY) == UART_DE_POLARITY_LOW))
  962. /**
  963. * @}
  964. */
  965. /* Include UART HAL Extension module */
  966. #include "stm32f7xx_hal_uart_ex.h"
  967. /* Exported functions --------------------------------------------------------*/
  968. /** @addtogroup UART_Exported_Functions UART Exported Functions
  969. * @{
  970. */
  971. /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
  972. * @{
  973. */
  974. /* Initialization and de-initialization functions ****************************/
  975. HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
  976. HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
  977. HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
  978. HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
  979. HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime, uint32_t DeassertionTime);
  980. HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
  981. void HAL_UART_MspInit(UART_HandleTypeDef *huart);
  982. void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
  983. /**
  984. * @}
  985. */
  986. /** @addtogroup UART_Exported_Functions_Group2 IO operation functions
  987. * @{
  988. */
  989. /* IO operation functions *****************************************************/
  990. HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  991. HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  992. HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  993. HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  994. HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  995. HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  996. HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
  997. HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
  998. HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
  999. void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
  1000. void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
  1001. void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
  1002. void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
  1003. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
  1004. void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
  1005. /**
  1006. * @}
  1007. */
  1008. /** @addtogroup UART_Exported_Functions_Group3 Peripheral Control functions
  1009. * @{
  1010. */
  1011. /* Peripheral Control functions ************************************************/
  1012. HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
  1013. HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength);
  1014. HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart);
  1015. HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart);
  1016. void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
  1017. HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
  1018. HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
  1019. /**
  1020. * @}
  1021. */
  1022. /** @addtogroup UART_Exported_Functions_Group4 Peripheral State and Error functions
  1023. * @{
  1024. */
  1025. /* Peripheral State and Errors functions **************************************************/
  1026. HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
  1027. uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart);
  1028. /**
  1029. * @}
  1030. */
  1031. /**
  1032. * @}
  1033. */
  1034. /* Private functions -----------------------------------------------------------*/
  1035. /** @addtogroup UART_Private_Functions UART Private Functions
  1036. * @{
  1037. */
  1038. HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart);
  1039. HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart);
  1040. HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
  1041. void UART_AdvFeatureConfig(UART_HandleTypeDef *huart);
  1042. /**
  1043. * @}
  1044. */
  1045. /**
  1046. * @}
  1047. */
  1048. /**
  1049. * @}
  1050. */
  1051. #ifdef __cplusplus
  1052. }
  1053. #endif
  1054. #endif /* __STM32F7xx_HAL_UART_H */
  1055. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/