stm32f7xx_hal_uart.h 55 KB

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