stm32f7xx_hal_usart.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_usart.h
  4. * @author MCD Application Team
  5. * @brief Header file of USART 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_USART_H
  37. #define __STM32F7xx_HAL_USART_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 USART
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup USART_Exported_Types USART Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief USART Init Structure definition
  55. */
  56. typedef struct
  57. {
  58. uint32_t BaudRate; /*!< This member configures the Usart communication baud rate.
  59. The baud rate is computed using the following formula:
  60. Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate))) */
  61. uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
  62. This parameter can be a value of @ref USARTEx_Word_Length */
  63. uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
  64. This parameter can be a value of @ref USART_Stop_Bits */
  65. uint32_t Parity; /*!< Specifies the parity mode.
  66. This parameter can be a value of @ref USART_Parity
  67. @note When parity is enabled, the computed parity is inserted
  68. at the MSB position of the transmitted data (9th bit when
  69. the word length is set to 9 data bits; 8th bit when the
  70. word length is set to 8 data bits). */
  71. uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
  72. This parameter can be a value of @ref USART_Mode */
  73. uint32_t OverSampling; /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).
  74. This parameter can be a value of @ref USART_Over_Sampling */
  75. uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
  76. This parameter can be a value of @ref USART_Clock_Polarity */
  77. uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
  78. This parameter can be a value of @ref USART_Clock_Phase */
  79. uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
  80. data bit (MSB) has to be output on the SCLK pin in synchronous mode.
  81. This parameter can be a value of @ref USART_Last_Bit */
  82. }USART_InitTypeDef;
  83. /**
  84. * @brief HAL USART State structures definition
  85. */
  86. typedef enum
  87. {
  88. HAL_USART_STATE_RESET = 0x00U, /*!< Peripheral is not initialized */
  89. HAL_USART_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
  90. HAL_USART_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */
  91. HAL_USART_STATE_BUSY_TX = 0x12U, /*!< Data Transmission process is ongoing */
  92. HAL_USART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */
  93. HAL_USART_STATE_BUSY_TX_RX = 0x32U, /*!< Data Transmission Reception process is ongoing */
  94. HAL_USART_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
  95. HAL_USART_STATE_ERROR = 0x04U /*!< Error */
  96. }HAL_USART_StateTypeDef;
  97. /**
  98. * @brief USART clock sources definitions
  99. */
  100. typedef enum
  101. {
  102. USART_CLOCKSOURCE_PCLK1 = 0x00U, /*!< PCLK1 clock source */
  103. USART_CLOCKSOURCE_PCLK2 = 0x01U, /*!< PCLK2 clock source */
  104. USART_CLOCKSOURCE_HSI = 0x02U, /*!< HSI clock source */
  105. USART_CLOCKSOURCE_SYSCLK = 0x04U, /*!< SYSCLK clock source */
  106. USART_CLOCKSOURCE_LSE = 0x08U, /*!< LSE clock source */
  107. USART_CLOCKSOURCE_UNDEFINED = 0x10U /*!< Undefined clock source */
  108. }USART_ClockSourceTypeDef;
  109. /**
  110. * @brief USART handle Structure definition
  111. */
  112. typedef struct
  113. {
  114. USART_TypeDef *Instance; /*!< USART registers base address */
  115. USART_InitTypeDef Init; /*!< USART communication parameters */
  116. uint8_t *pTxBuffPtr; /*!< Pointer to USART Tx transfer Buffer */
  117. uint16_t TxXferSize; /*!< USART Tx Transfer size */
  118. __IO uint16_t TxXferCount; /*!< USART Tx Transfer Counter */
  119. uint8_t *pRxBuffPtr; /*!< Pointer to USART Rx transfer Buffer */
  120. uint16_t RxXferSize; /*!< USART Rx Transfer size */
  121. __IO uint16_t RxXferCount; /*!< USART Rx Transfer Counter */
  122. uint16_t Mask; /*!< USART Rx RDR register mask */
  123. DMA_HandleTypeDef *hdmatx; /*!< USART Tx DMA Handle parameters */
  124. DMA_HandleTypeDef *hdmarx; /*!< USART Rx DMA Handle parameters */
  125. HAL_LockTypeDef Lock; /*!< Locking object */
  126. HAL_USART_StateTypeDef State; /*!< USART communication state */
  127. __IO uint32_t ErrorCode; /*!< USART Error code */
  128. }USART_HandleTypeDef;
  129. /**
  130. * @}
  131. */
  132. /* Exported constants --------------------------------------------------------*/
  133. /** @defgroup USART_Exported_Constants USART Exported Constants
  134. * @{
  135. */
  136. /** @defgroup USART_Error_Code USART Error Code
  137. * @brief USART Error Code
  138. * @{
  139. */
  140. #define HAL_USART_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
  141. #define HAL_USART_ERROR_PE ((uint32_t)0x00000001U) /*!< Parity error */
  142. #define HAL_USART_ERROR_NE ((uint32_t)0x00000002U) /*!< Noise error */
  143. #define HAL_USART_ERROR_FE ((uint32_t)0x00000004U) /*!< Frame error */
  144. #define HAL_USART_ERROR_ORE ((uint32_t)0x00000008U) /*!< Overrun error */
  145. #define HAL_USART_ERROR_DMA ((uint32_t)0x00000010U) /*!< DMA transfer error */
  146. /**
  147. * @}
  148. */
  149. /** @defgroup USART_Stop_Bits USART Number of Stop Bits
  150. * @{
  151. */
  152. #define USART_STOPBITS_1 ((uint32_t)0x0000U)
  153. #define USART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1)
  154. #define USART_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
  155. /**
  156. * @}
  157. */
  158. /** @defgroup USART_Parity USART Parity
  159. * @{
  160. */
  161. #define USART_PARITY_NONE ((uint32_t)0x0000U)
  162. #define USART_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
  163. #define USART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
  164. /**
  165. * @}
  166. */
  167. /** @defgroup USART_Mode USART Mode
  168. * @{
  169. */
  170. #define USART_MODE_RX ((uint32_t)USART_CR1_RE)
  171. #define USART_MODE_TX ((uint32_t)USART_CR1_TE)
  172. #define USART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
  173. /**
  174. * @}
  175. */
  176. /** @defgroup USART_Over_Sampling USART Over Sampling
  177. * @{
  178. */
  179. #define USART_OVERSAMPLING_16 ((uint32_t)0x0000U)
  180. #define USART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8)
  181. /**
  182. * @}
  183. */
  184. /** @defgroup USART_Clock USART Clock
  185. * @{
  186. */
  187. #define USART_CLOCK_DISABLE ((uint32_t)0x0000U)
  188. #define USART_CLOCK_ENABLE ((uint32_t)USART_CR2_CLKEN)
  189. /**
  190. * @}
  191. */
  192. /** @defgroup USART_Clock_Polarity USART Clock Polarity
  193. * @{
  194. */
  195. #define USART_POLARITY_LOW ((uint32_t)0x0000U)
  196. #define USART_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
  197. /**
  198. * @}
  199. */
  200. /** @defgroup USART_Clock_Phase USART Clock Phase
  201. * @{
  202. */
  203. #define USART_PHASE_1EDGE ((uint32_t)0x0000U)
  204. #define USART_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
  205. /**
  206. * @}
  207. */
  208. /** @defgroup USART_Last_Bit USART Last Bit
  209. * @{
  210. */
  211. #define USART_LASTBIT_DISABLE ((uint32_t)0x0000U)
  212. #define USART_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
  213. /**
  214. * @}
  215. */
  216. /** @defgroup USART_Request_Parameters USART Request Parameters
  217. * @{
  218. */
  219. #define USART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
  220. #define USART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
  221. /**
  222. * @}
  223. */
  224. /** @defgroup USART_Flags USART Flags
  225. * Elements values convention: 0xXXXX
  226. * - 0xXXXX : Flag mask in the ISR register
  227. * @{
  228. */
  229. #define USART_FLAG_REACK ((uint32_t)0x00400000U)
  230. #define USART_FLAG_TEACK ((uint32_t)0x00200000U)
  231. #define USART_FLAG_BUSY ((uint32_t)0x00010000U)
  232. #define USART_FLAG_CTS ((uint32_t)0x00000400U)
  233. #define USART_FLAG_CTSIF ((uint32_t)0x00000200U)
  234. #define USART_FLAG_LBDF ((uint32_t)0x00000100U)
  235. #define USART_FLAG_TXE ((uint32_t)0x00000080U)
  236. #define USART_FLAG_TC ((uint32_t)0x00000040U)
  237. #define USART_FLAG_RXNE ((uint32_t)0x00000020U)
  238. #define USART_FLAG_IDLE ((uint32_t)0x00000010U)
  239. #define USART_FLAG_ORE ((uint32_t)0x00000008U)
  240. #define USART_FLAG_NE ((uint32_t)0x00000004U)
  241. #define USART_FLAG_FE ((uint32_t)0x00000002U)
  242. #define USART_FLAG_PE ((uint32_t)0x00000001U)
  243. /**
  244. * @}
  245. */
  246. /** @defgroup USART_Interrupt_definition USART Interrupts Definition
  247. * Elements values convention: 0000ZZZZ0XXYYYYYb
  248. * - YYYYY : Interrupt source position in the XX register (5bits)
  249. * - XX : Interrupt source register (2bits)
  250. * - 01: CR1 register
  251. * - 10: CR2 register
  252. * - 11: CR3 register
  253. * - ZZZZ : Flag position in the ISR register(4bits)
  254. * @{
  255. */
  256. #define USART_IT_PE ((uint16_t)0x0028U)
  257. #define USART_IT_TXE ((uint16_t)0x0727U)
  258. #define USART_IT_TC ((uint16_t)0x0626U)
  259. #define USART_IT_RXNE ((uint16_t)0x0525U)
  260. #define USART_IT_IDLE ((uint16_t)0x0424U)
  261. #define USART_IT_ERR ((uint16_t)0x0060U)
  262. #define USART_IT_ORE ((uint16_t)0x0300U)
  263. #define USART_IT_NE ((uint16_t)0x0200U)
  264. #define USART_IT_FE ((uint16_t)0x0100U)
  265. /**
  266. * @}
  267. */
  268. /** @defgroup USART_IT_CLEAR_Flags USART Interruption Clear Flags
  269. * @{
  270. */
  271. #define USART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
  272. #define USART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
  273. #define USART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
  274. #define USART_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
  275. #define USART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
  276. #define USART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
  277. #define USART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
  278. /**
  279. * @}
  280. */
  281. /**
  282. * @}
  283. */
  284. /* Exported macros -----------------------------------------------------------*/
  285. /** @defgroup USART_Exported_Macros USART Exported Macros
  286. * @{
  287. */
  288. /** @brief Reset USART handle state
  289. * @param __HANDLE__ USART handle.
  290. * @retval None
  291. */
  292. #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET)
  293. /** @brief Checks whether the specified USART flag is set or not.
  294. * @param __HANDLE__ specifies the USART Handle
  295. * @param __FLAG__ specifies the flag to check.
  296. * This parameter can be one of the following values:
  297. * @arg USART_FLAG_REACK: Receive enable acknowledge flag
  298. * @arg USART_FLAG_TEACK: Transmit enable acknowledge flag
  299. * @arg USART_FLAG_BUSY: Busy flag
  300. * @arg USART_FLAG_CTS: CTS Change flag
  301. * @arg USART_FLAG_TXE: Transmit data register empty flag
  302. * @arg USART_FLAG_TC: Transmission Complete flag
  303. * @arg USART_FLAG_RXNE: Receive data register not empty flag
  304. * @arg USART_FLAG_IDLE: Idle Line detection flag
  305. * @arg USART_FLAG_ORE: OverRun Error flag
  306. * @arg USART_FLAG_NE: Noise Error flag
  307. * @arg USART_FLAG_FE: Framing Error flag
  308. * @arg USART_FLAG_PE: Parity Error flag
  309. * @retval The new state of __FLAG__ (TRUE or FALSE).
  310. */
  311. #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
  312. /** @brief Enables the specified USART interrupt.
  313. * @param __HANDLE__ specifies the USART Handle
  314. * @param __INTERRUPT__ specifies the USART interrupt source to enable.
  315. * This parameter can be one of the following values:
  316. * @arg USART_IT_TXE: Transmit Data Register empty interrupt
  317. * @arg USART_IT_TC: Transmission complete interrupt
  318. * @arg USART_IT_RXNE: Receive Data register not empty interrupt
  319. * @arg USART_IT_IDLE: Idle line detection interrupt
  320. * @arg USART_IT_PE: Parity Error interrupt
  321. * @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  322. * @retval None
  323. */
  324. #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
  325. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
  326. ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))))
  327. /** @brief Disables the specified USART interrupt.
  328. * @param __HANDLE__ specifies the USART Handle.
  329. * @param __INTERRUPT__ specifies the USART interrupt source to disable.
  330. * This parameter can be one of the following values:
  331. * @arg USART_IT_TXE: Transmit Data Register empty interrupt
  332. * @arg USART_IT_TC: Transmission complete interrupt
  333. * @arg USART_IT_RXNE: Receive Data register not empty interrupt
  334. * @arg USART_IT_IDLE: Idle line detection interrupt
  335. * @arg USART_IT_PE: Parity Error interrupt
  336. * @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  337. * @retval None
  338. */
  339. #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
  340. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
  341. ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))))
  342. /** @brief Checks whether the specified USART interrupt has occurred or not.
  343. * @param __HANDLE__ specifies the USART Handle
  344. * @param __IT__ specifies the USART interrupt source to check.
  345. * This parameter can be one of the following values:
  346. * @arg USART_IT_TXE: Transmit Data Register empty interrupt
  347. * @arg USART_IT_TC: Transmission complete interrupt
  348. * @arg USART_IT_RXNE: Receive Data register not empty interrupt
  349. * @arg USART_IT_IDLE: Idle line detection interrupt
  350. * @arg USART_IT_ORE: OverRun Error interrupt
  351. * @arg USART_IT_NE: Noise Error interrupt
  352. * @arg USART_IT_FE: Framing Error interrupt
  353. * @arg USART_IT_PE: Parity Error interrupt
  354. * @retval The new state of __IT__ (TRUE or FALSE).
  355. */
  356. #define __HAL_USART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
  357. /** @brief Checks whether the specified USART interrupt source is enabled.
  358. * @param __HANDLE__ specifies the USART Handle.
  359. * @param __IT__ specifies the USART interrupt source to check.
  360. * This parameter can be one of the following values:
  361. * @arg USART_IT_TXE: Transmit Data Register empty interrupt
  362. * @arg USART_IT_TC: Transmission complete interrupt
  363. * @arg USART_IT_RXNE: Receive Data register not empty interrupt
  364. * @arg USART_IT_IDLE: Idle line detection interrupt
  365. * @arg USART_IT_ORE: OverRun Error interrupt
  366. * @arg USART_IT_NE: Noise Error interrupt
  367. * @arg USART_IT_FE: Framing Error interrupt
  368. * @arg USART_IT_PE: Parity Error interrupt
  369. * @retval The new state of __IT__ (TRUE or FALSE).
  370. */
  371. #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5) == 2)? \
  372. (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << \
  373. (((uint16_t)(__IT__)) & USART_IT_MASK)))
  374. /** @brief Clears the specified USART ISR flag, in setting the proper ICR register flag.
  375. * @param __HANDLE__ specifies the USART Handle.
  376. * @param __IT_CLEAR__ specifies the interrupt clear register flag that needs to be set
  377. * to clear the corresponding interrupt
  378. * This parameter can be one of the following values:
  379. * @arg USART_CLEAR_PEF: Parity Error Clear Flag
  380. * @arg USART_CLEAR_FEF: Framing Error Clear Flag
  381. * @arg USART_CLEAR_NEF: Noise detected Clear Flag
  382. * @arg USART_CLEAR_OREF: OverRun Error Clear Flag
  383. * @arg USART_CLEAR_IDLEF: IDLE line detected Clear Flag
  384. * @arg USART_CLEAR_TCF: Transmission Complete Clear Flag
  385. * @arg USART_CLEAR_CTSF: CTS Interrupt Clear Flag
  386. * @retval None
  387. */
  388. #define __HAL_USART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
  389. /** @brief Set a specific USART request flag.
  390. * @param __HANDLE__ specifies the USART Handle.
  391. * @param __REQ__ specifies the request flag to set
  392. * This parameter can be one of the following values:
  393. * @arg USART_RXDATA_FLUSH_REQUEST: Receive Data flush Request
  394. * @arg USART_TXDATA_FLUSH_REQUEST: Transmit data flush Request
  395. *
  396. * @retval None
  397. */
  398. #define __HAL_USART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
  399. /** @brief Enable USART
  400. * @param __HANDLE__ specifies the USART Handle.
  401. * @retval None
  402. */
  403. #define __HAL_USART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
  404. /** @brief Disable USART
  405. * @param __HANDLE__ specifies the USART Handle.
  406. * @retval None
  407. */
  408. #define __HAL_USART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
  409. /**
  410. * @}
  411. */
  412. /* Include UART HAL Extension module */
  413. #include "stm32f7xx_hal_usart_ex.h"
  414. /* Exported functions --------------------------------------------------------*/
  415. /** @addtogroup USART_Exported_Functions
  416. * @{
  417. */
  418. /** @addtogroup USART_Exported_Functions_Group1
  419. * @{
  420. */
  421. /* Initialization/de-initialization functions **********************************/
  422. HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
  423. HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
  424. void HAL_USART_MspInit(USART_HandleTypeDef *husart);
  425. void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
  426. HAL_StatusTypeDef HAL_USART_CheckIdleState(USART_HandleTypeDef *husart);
  427. /**
  428. * @}
  429. */
  430. /** @addtogroup USART_Exported_Functions_Group2
  431. * @{
  432. */
  433. /* IO operation functions *******************************************************/
  434. HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
  435. HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
  436. HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
  437. HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
  438. HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
  439. HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
  440. HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
  441. HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
  442. HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
  443. HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
  444. HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
  445. HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
  446. void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
  447. void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
  448. void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
  449. void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
  450. void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
  451. void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
  452. void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
  453. /**
  454. * @}
  455. */
  456. /** @addtogroup USART_Exported_Functions_Group3
  457. * @{
  458. */
  459. /* Peripheral State functions ************************************************/
  460. HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
  461. uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart);
  462. /**
  463. * @}
  464. */
  465. /**
  466. * @}
  467. */
  468. /* Private types -------------------------------------------------------------*/
  469. /* Private variables ---------------------------------------------------------*/
  470. /* Private constants ---------------------------------------------------------*/
  471. /** @defgroup USART_Private_Constants USART Private Constants
  472. * @{
  473. */
  474. /** @brief USART interruptions flag mask
  475. *
  476. */
  477. #define USART_IT_MASK ((uint16_t)0x001FU)
  478. /**
  479. * @}
  480. */
  481. /* Private macros ------------------------------------------------------------*/
  482. /** @defgroup USART_Private_Macros USART Private Macros
  483. * @{
  484. */
  485. /** @brief Reports the USART clock source.
  486. * @param __HANDLE__ specifies the USART Handle
  487. * @param __CLOCKSOURCE__ output variable
  488. * @retval the USART clocking source, written in __CLOCKSOURCE__.
  489. */
  490. #define USART_GETCLOCKSOURCE(__HANDLE__, __CLOCKSOURCE__)\
  491. do { \
  492. if((__HANDLE__)->Instance == USART1) \
  493. { \
  494. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  495. { \
  496. case RCC_USART1CLKSOURCE_PCLK2: \
  497. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK2; \
  498. break; \
  499. case RCC_USART1CLKSOURCE_HSI: \
  500. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  501. break; \
  502. case RCC_USART1CLKSOURCE_SYSCLK: \
  503. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  504. break; \
  505. case RCC_USART1CLKSOURCE_LSE: \
  506. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  507. break; \
  508. default: \
  509. break; \
  510. } \
  511. } \
  512. else if((__HANDLE__)->Instance == USART2) \
  513. { \
  514. switch(__HAL_RCC_GET_USART2_SOURCE()) \
  515. { \
  516. case RCC_USART2CLKSOURCE_PCLK1: \
  517. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  518. break; \
  519. case RCC_USART2CLKSOURCE_HSI: \
  520. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  521. break; \
  522. case RCC_USART2CLKSOURCE_SYSCLK: \
  523. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  524. break; \
  525. case RCC_USART2CLKSOURCE_LSE: \
  526. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  527. break; \
  528. default: \
  529. break; \
  530. } \
  531. } \
  532. else if((__HANDLE__)->Instance == USART3) \
  533. { \
  534. switch(__HAL_RCC_GET_USART3_SOURCE()) \
  535. { \
  536. case RCC_USART3CLKSOURCE_PCLK1: \
  537. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  538. break; \
  539. case RCC_USART3CLKSOURCE_HSI: \
  540. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  541. break; \
  542. case RCC_USART3CLKSOURCE_SYSCLK: \
  543. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  544. break; \
  545. case RCC_USART3CLKSOURCE_LSE: \
  546. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  547. break; \
  548. default: \
  549. break; \
  550. } \
  551. } \
  552. else if((__HANDLE__)->Instance == USART6) \
  553. { \
  554. switch(__HAL_RCC_GET_USART6_SOURCE()) \
  555. { \
  556. case RCC_USART6CLKSOURCE_PCLK2: \
  557. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK2; \
  558. break; \
  559. case RCC_USART6CLKSOURCE_HSI: \
  560. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  561. break; \
  562. case RCC_USART6CLKSOURCE_SYSCLK: \
  563. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  564. break; \
  565. case RCC_USART6CLKSOURCE_LSE: \
  566. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  567. break; \
  568. default: \
  569. break; \
  570. } \
  571. } \
  572. } while(0)
  573. #define IS_USART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == USART_STOPBITS_1) || \
  574. ((__STOPBITS__) == USART_STOPBITS_1_5) || \
  575. ((__STOPBITS__) == USART_STOPBITS_2))
  576. #define IS_USART_PARITY(__PARITY__) (((__PARITY__) == USART_PARITY_NONE) || \
  577. ((__PARITY__) == USART_PARITY_EVEN) || \
  578. ((__PARITY__) == USART_PARITY_ODD))
  579. #define IS_USART_MODE(__MODE__) ((((__MODE__) & (uint32_t)0xFFFFFFF3U) == 0x00U) && ((__MODE__) != (uint32_t)0x00U))
  580. #define IS_USART_OVERSAMPLING(__SAMPLING__) (((__SAMPLING__) == USART_OVERSAMPLING_16) || \
  581. ((__SAMPLING__) == USART_OVERSAMPLING_8))
  582. #define IS_USART_CLOCK(__CLOCK__) (((__CLOCK__)== USART_CLOCK_DISABLE) || \
  583. ((__CLOCK__)== USART_CLOCK_ENABLE))
  584. #define IS_USART_POLARITY(__CPOL__) (((__CPOL__) == USART_POLARITY_LOW) || ((__CPOL__) == USART_POLARITY_HIGH))
  585. #define IS_USART_PHASE(__CPHA__) (((__CPHA__) == USART_PHASE_1EDGE) || ((__CPHA__) == USART_PHASE_2EDGE))
  586. #define IS_USART_LASTBIT(__LASTBIT__) (((__LASTBIT__) == USART_LASTBIT_DISABLE) || \
  587. ((__LASTBIT__) == USART_LASTBIT_ENABLE))
  588. #define IS_USART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == USART_RXDATA_FLUSH_REQUEST) || \
  589. ((__PARAM__) == USART_TXDATA_FLUSH_REQUEST))
  590. #define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 9000001)
  591. /**
  592. * @}
  593. */
  594. /* Private functions ---------------------------------------------------------*/
  595. /** @defgroup USART_Private_Functions USART Private Functions
  596. * @{
  597. */
  598. /**
  599. * @}
  600. */
  601. /**
  602. * @}
  603. */
  604. /**
  605. * @}
  606. */
  607. #ifdef __cplusplus
  608. }
  609. #endif
  610. #endif /* __STM32F7xx_HAL_USART_H */
  611. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/