stm32f3xx_hal_usart.h 33 KB

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