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.
 
 
 

684 lines
30 KiB

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