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.
 
 
 

697 lines
32 KiB

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