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.
 
 
 

1166 lines
51 KiB

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