Updated and Validated
[betaflight.git] / lib / main / STM32F3 / Drivers / STM32F3xx_HAL_Driver / Inc / stm32f3xx_hal_usart.h
blob104fad20be9e180d5a8f21bec4b3deceeb0d16f8
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_hal_usart.h
4 * @author MCD Application Team
5 * @brief Header file of USART HAL module.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
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.
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.
33 ******************************************************************************
36 /* Define to prevent recursive inclusion -------------------------------------*/
37 #ifndef __STM32F3xx_HAL_USART_H
38 #define __STM32F3xx_HAL_USART_H
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32f3xx_hal_def.h"
47 /** @addtogroup STM32F3xx_HAL_Driver
48 * @{
51 /** @addtogroup USART
52 * @{
55 /* Exported types ------------------------------------------------------------*/
56 /** @defgroup USART_Exported_Types USART Exported Types
57 * @{
60 /**
61 * @brief USART Init Structure definition
63 typedef struct
65 uint32_t BaudRate; /*!< This member configures the Usart communication baud rate.
66 The baud rate is computed using the following formula:
67 Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate))). */
69 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
70 This parameter can be a value of @ref USARTEx_Word_Length. */
72 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
73 This parameter can be a value of @ref USART_Stop_Bits. */
75 uint32_t Parity; /*!< Specifies the parity mode.
76 This parameter can be a value of @ref USART_Parity
77 @note When parity is enabled, the computed parity is inserted
78 at the MSB position of the transmitted data (9th bit when
79 the word length is set to 9 data bits; 8th bit when the
80 word length is set to 8 data bits). */
82 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
83 This parameter can be a value of @ref USART_Mode. */
85 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
86 This parameter can be a value of @ref USART_Clock_Polarity. */
88 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
89 This parameter can be a value of @ref USART_Clock_Phase. */
91 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
92 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
93 This parameter can be a value of @ref USART_Last_Bit. */
94 }USART_InitTypeDef;
96 /**
97 * @brief HAL USART State structures definition
99 typedef enum
101 HAL_USART_STATE_RESET = 0x00U, /*!< Peripheral is not initialized */
102 HAL_USART_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
103 HAL_USART_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */
104 HAL_USART_STATE_BUSY_TX = 0x12U, /*!< Data Transmission process is ongoing */
105 HAL_USART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */
106 HAL_USART_STATE_BUSY_TX_RX = 0x32U, /*!< Data Transmission Reception process is ongoing */
107 HAL_USART_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
108 HAL_USART_STATE_ERROR = 0x04U /*!< Error */
109 }HAL_USART_StateTypeDef;
112 * @brief USART clock sources definitions
114 typedef enum
116 USART_CLOCKSOURCE_PCLK1 = 0x00U, /*!< PCLK1 clock source */
117 USART_CLOCKSOURCE_PCLK2 = 0x01U, /*!< PCLK2 clock source */
118 USART_CLOCKSOURCE_HSI = 0x02U, /*!< HSI clock source */
119 USART_CLOCKSOURCE_SYSCLK = 0x04U, /*!< SYSCLK clock source */
120 USART_CLOCKSOURCE_LSE = 0x08U, /*!< LSE clock source */
121 USART_CLOCKSOURCE_UNDEFINED = 0x10U /*!< Undefined clock source */
122 }USART_ClockSourceTypeDef;
126 * @brief USART handle Structure definition
128 typedef struct
130 USART_TypeDef *Instance; /*!< USART registers base address */
132 USART_InitTypeDef Init; /*!< USART communication parameters */
134 uint8_t *pTxBuffPtr; /*!< Pointer to USART Tx transfer Buffer */
136 uint16_t TxXferSize; /*!< USART Tx Transfer size */
138 __IO uint16_t TxXferCount; /*!< USART Tx Transfer Counter */
140 uint8_t *pRxBuffPtr; /*!< Pointer to USART Rx transfer Buffer */
142 uint16_t RxXferSize; /*!< USART Rx Transfer size */
144 __IO uint16_t RxXferCount; /*!< USART Rx Transfer Counter */
146 uint16_t Mask; /*!< USART Rx RDR register mask */
148 DMA_HandleTypeDef *hdmatx; /*!< USART Tx DMA Handle parameters */
150 DMA_HandleTypeDef *hdmarx; /*!< USART Rx DMA Handle parameters */
152 HAL_LockTypeDef Lock; /*!< Locking object */
154 __IO HAL_USART_StateTypeDef State; /*!< USART communication state */
156 __IO uint32_t ErrorCode; /*!< USART Error code */
158 }USART_HandleTypeDef;
161 * @}
164 /* Exported constants --------------------------------------------------------*/
165 /** @defgroup USART_Exported_Constants USART Exported Constants
166 * @{
169 /** @defgroup USART_Error USART Error
170 * @{
172 #define HAL_USART_ERROR_NONE (0x00000000U) /*!< No error */
173 #define HAL_USART_ERROR_PE (0x00000001U) /*!< Parity error */
174 #define HAL_USART_ERROR_NE (0x00000002U) /*!< Noise error */
175 #define HAL_USART_ERROR_FE (0x00000004U) /*!< frame error */
176 #define HAL_USART_ERROR_ORE (0x00000008U) /*!< Overrun error */
177 #define HAL_USART_ERROR_DMA (0x00000010U) /*!< DMA transfer error */
179 * @}
182 /** @defgroup USART_Stop_Bits USART Number of Stop Bits
183 * @{
185 #define USART_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0) /*!< USART frame with 0.5 stop bit */
186 #define USART_STOPBITS_1 (0x00000000U) /*!< USART frame with 1 stop bit */
187 #define USART_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1)) /*!< USART frame with 1.5 stop bits */
188 #define USART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1) /*!< USART frame with 2 stop bits */
190 * @}
193 /** @defgroup USART_Parity USART Parity
194 * @{
196 #define USART_PARITY_NONE (0x00000000U) /*!< No parity */
197 #define USART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) /*!< Even parity */
198 #define USART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) /*!< Odd parity */
200 * @}
203 /** @defgroup USART_Mode USART Mode
204 * @{
206 #define USART_MODE_RX ((uint32_t)USART_CR1_RE) /*!< RX mode */
207 #define USART_MODE_TX ((uint32_t)USART_CR1_TE) /*!< TX mode */
208 #define USART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) /*!< RX and TX mode */
210 * @}
213 /** @defgroup USART_Clock USART Clock
214 * @{
216 #define USART_CLOCK_DISABLE (0x00000000U) /*!< USART clock disable */
217 #define USART_CLOCK_ENABLE ((uint32_t)USART_CR2_CLKEN) /*!< USART clock enable */
219 * @}
222 /** @defgroup USART_Clock_Polarity USART Clock Polarity
223 * @{
225 #define USART_POLARITY_LOW (0x00000000U) /*!< USART Clock signal is steady Low */
226 #define USART_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL) /*!< USART Clock signal is steady High */
228 * @}
231 /** @defgroup USART_Clock_Phase USART Clock Phase
232 * @{
234 #define USART_PHASE_1EDGE (0x00000000U) /*!< USART frame phase on first clock transition */
235 #define USART_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA) /*!< USART frame phase on second clock transition */
237 * @}
240 /** @defgroup USART_Last_Bit USART Last Bit
241 * @{
243 #define USART_LASTBIT_DISABLE (0x00000000U) /*!< USART frame last data bit clock pulse not output to SCLK pin */
244 #define USART_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL) /*!< USART frame last data bit clock pulse output to SCLK pin */
246 * @}
249 /** @defgroup USART_Request_Parameters USART Request Parameters
250 * @{
252 #define USART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
253 #define USART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
255 * @}
258 /** @defgroup USART_Flags USART Flags
259 * Elements values convention: 0xXXXX
260 * - 0xXXXX : Flag mask in the ISR register
261 * @{
263 #define USART_FLAG_REACK (0x00400000U) /*!< USART receive enable acknowledge flag */
264 #define USART_FLAG_TEACK (0x00200000U) /*!< USART transmit enable acknowledge flag */
265 #define USART_FLAG_BUSY (0x00010000U) /*!< USART busy flag */
266 #define USART_FLAG_CTS (0x00000400U) /*!< USART clear to send flag */
267 #define USART_FLAG_CTSIF (0x00000200U) /*!< USART clear to send interrupt flag */
268 #define USART_FLAG_LBDF (0x00000100U) /*!< USART LIN break detection flag */
269 #define USART_FLAG_TXE (0x00000080U) /*!< USART transmit data register empty */
270 #define USART_FLAG_TC (0x00000040U) /*!< USART transmission complete */
271 #define USART_FLAG_RXNE (0x00000020U) /*!< USART read data register not empty */
272 #define USART_FLAG_IDLE (0x00000010U) /*!< USART idle flag */
273 #define USART_FLAG_ORE (0x00000008U) /*!< USART overrun error */
274 #define USART_FLAG_NE (0x00000004U) /*!< USART noise error */
275 #define USART_FLAG_FE (0x00000002U) /*!< USART frame error */
276 #define USART_FLAG_PE (0x00000001U) /*!< USART parity error */
278 * @}
281 /** @defgroup USART_Interrupt_definition USART Interrupts Definition
282 * Elements values convention: 0000ZZZZ0XXYYYYYb
283 * - YYYYY : Interrupt source position in the XX register (5bits)
284 * - XX : Interrupt source register (2bits)
285 * - 01: CR1 register
286 * - 10: CR2 register
287 * - 11: CR3 register
288 * - ZZZZ : Flag position in the ISR register(4bits)
289 * @{
292 #define USART_IT_PE ((uint16_t)0x0028U) /*!< USART parity error interruption */
293 #define USART_IT_TXE ((uint16_t)0x0727U) /*!< USART transmit data register empty interruption */
294 #define USART_IT_TC ((uint16_t)0x0626U) /*!< USART transmission complete interruption */
295 #define USART_IT_RXNE ((uint16_t)0x0525U) /*!< USART read data register not empty interruption */
296 #define USART_IT_IDLE ((uint16_t)0x0424U) /*!< USART idle interruption */
297 #define USART_IT_ERR ((uint16_t)0x0060U) /*!< USART error interruption */
298 #define USART_IT_ORE ((uint16_t)0x0300U) /*!< USART overrun error interruption */
299 #define USART_IT_NE ((uint16_t)0x0200U) /*!< USART noise error interruption */
300 #define USART_IT_FE ((uint16_t)0x0100U) /*!< USART frame error interruption */
302 * @}
305 /** @defgroup USART_IT_CLEAR_Flags USART Interruption Clear Flags
306 * @{
308 #define USART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
309 #define USART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
310 #define USART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
311 #define USART_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
312 #define USART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
313 #define USART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
314 #define USART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
316 * @}
319 /** @defgroup USART_Interruption_Mask USART Interruption Flags Mask
320 * @{
322 #define USART_IT_MASK ((uint16_t)0x001FU) /*!< USART interruptions flags mask */
324 * @}
328 * @}
331 /* Exported macros -----------------------------------------------------------*/
332 /** @defgroup USART_Exported_Macros USART Exported Macros
333 * @{
336 /** @brief Reset USART handle state.
337 * @param __HANDLE__ USART handle.
338 * @retval None
340 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET)
342 /** @brief Flush the USART Data registers.
343 * @param __HANDLE__ specifies the USART Handle.
344 * @retval None
346 #define __HAL_USART_FLUSH_DRREGISTER(__HANDLE__) \
347 do{ \
348 SET_BIT((__HANDLE__)->Instance->RQR, USART_RXDATA_FLUSH_REQUEST); \
349 SET_BIT((__HANDLE__)->Instance->RQR, USART_TXDATA_FLUSH_REQUEST); \
350 } while(0U)
352 /** @brief Check whether the specified USART flag is set or not.
353 * @param __HANDLE__ specifies the USART Handle
354 * @param __FLAG__ specifies the flag to check.
355 * This parameter can be one of the following values:
356 * @arg @ref USART_FLAG_REACK Receive enable acknowledge flag
357 * @arg @ref USART_FLAG_TEACK Transmit enable acknowledge flag
358 * @arg @ref USART_FLAG_BUSY Busy flag
359 * @arg @ref USART_FLAG_CTS CTS Change flag
360 * @arg @ref USART_FLAG_TXE Transmit data register empty flag
361 * @arg @ref USART_FLAG_TC Transmission Complete flag
362 * @arg @ref USART_FLAG_RXNE Receive data register not empty flag
363 * @arg @ref USART_FLAG_IDLE Idle Line detection flag
364 * @arg @ref USART_FLAG_ORE OverRun Error flag
365 * @arg @ref USART_FLAG_NE Noise Error flag
366 * @arg @ref USART_FLAG_FE Framing Error flag
367 * @arg @ref USART_FLAG_PE Parity Error flag
368 * @retval The new state of __FLAG__ (TRUE or FALSE).
370 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
372 /** @brief Clear the specified USART pending flag.
373 * @param __HANDLE__ specifies the USART Handle.
374 * @param __FLAG__ specifies the flag to check.
375 * This parameter can be any combination of the following values:
376 * @arg @ref USART_CLEAR_PEF
377 * @arg @ref USART_CLEAR_FEF
378 * @arg @ref USART_CLEAR_NEF
379 * @arg @ref USART_CLEAR_OREF
380 * @arg @ref USART_CLEAR_IDLEF
381 * @arg @ref USART_CLEAR_TCF
382 * @arg @ref USART_CLEAR_CTSF
383 * @retval None
385 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
387 /** @brief Clear the USART PE pending flag.
388 * @param __HANDLE__ specifies the USART Handle.
389 * @retval None
391 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_PEF)
393 /** @brief Clear the USART FE pending flag.
394 * @param __HANDLE__ specifies the USART Handle.
395 * @retval None
397 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_FEF)
399 /** @brief Clear the USART NE pending flag.
400 * @param __HANDLE__ specifies the USART Handle.
401 * @retval None
403 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_NEF)
405 /** @brief Clear the USART ORE pending flag.
406 * @param __HANDLE__ specifies the USART Handle.
407 * @retval None
409 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_OREF)
411 /** @brief Clear the USART IDLE pending flag.
412 * @param __HANDLE__ specifies the USART Handle.
413 * @retval None
415 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_IDLEF)
417 /** @brief Enable the specified USART interrupt.
418 * @param __HANDLE__ specifies the USART Handle.
419 * @param __INTERRUPT__ specifies the USART interrupt source to enable.
420 * This parameter can be one of the following values:
421 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
422 * @arg @ref USART_IT_TC Transmission complete interrupt
423 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
424 * @arg @ref USART_IT_IDLE Idle line detection interrupt
425 * @arg @ref USART_IT_PE Parity Error interrupt
426 * @arg @ref USART_IT_ERR Error interrupt(Frame error, noise error, overrun error)
427 * @retval None
429 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((__INTERRUPT__) & 0xFFU) >> 5U) == 1U)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
430 ((((__INTERRUPT__) & 0xFFU) >> 5U) == 2U)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
431 ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))))
433 /** @brief Disable the specified USART interrupt.
434 * @param __HANDLE__ specifies the USART Handle.
435 * @param __INTERRUPT__ specifies the USART interrupt source to disable.
436 * This parameter can be one of the following values:
437 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
438 * @arg @ref USART_IT_TC Transmission complete interrupt
439 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
440 * @arg @ref USART_IT_IDLE Idle line detection interrupt
441 * @arg @ref USART_IT_PE Parity Error interrupt
442 * @arg @ref USART_IT_ERR Error interrupt(Frame error, noise error, overrun error)
443 * @retval None
445 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((__INTERRUPT__) & 0xFFU) >> 5U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
446 ((((__INTERRUPT__) & 0xFFU) >> 5U) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
447 ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))))
450 /** @brief Check whether the specified USART interrupt has occurred or not.
451 * @param __HANDLE__ specifies the USART Handle.
452 * @param __IT__ specifies the USART interrupt source to check.
453 * This parameter can be one of the following values:
454 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
455 * @arg @ref USART_IT_TC Transmission complete interrupt
456 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
457 * @arg @ref USART_IT_IDLE Idle line detection interrupt
458 * @arg @ref USART_IT_ORE OverRun Error interrupt
459 * @arg @ref USART_IT_NE Noise Error interrupt
460 * @arg @ref USART_IT_FE Framing Error interrupt
461 * @arg @ref USART_IT_PE Parity Error interrupt
462 * @retval The new state of __IT__ (TRUE or FALSE).
464 #define __HAL_USART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & (1U << ((__IT__)>> 0x08U)))
466 /** @brief Check whether the specified USART interrupt source is enabled or not.
467 * @param __HANDLE__ specifies the USART Handle.
468 * @param __IT__ specifies the USART interrupt source to check.
469 * This parameter can be one of the following values:
470 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
471 * @arg @ref USART_IT_TC Transmission complete interrupt
472 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
473 * @arg @ref USART_IT_IDLE Idle line detection interrupt
474 * @arg @ref USART_IT_ORE OverRun Error interrupt
475 * @arg @ref USART_IT_NE Noise Error interrupt
476 * @arg @ref USART_IT_FE Framing Error interrupt
477 * @arg @ref USART_IT_PE Parity Error interrupt
478 * @retval The new state of __IT__ (TRUE or FALSE).
480 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1U)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5U) == 2U)? \
481 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (1U << \
482 (((uint16_t)(__IT__)) & USART_IT_MASK)))
485 /** @brief Clear the specified USART ISR flag, in setting the proper ICR register flag.
486 * @param __HANDLE__ specifies the USART Handle.
487 * @param __IT_CLEAR__ specifies the interrupt clear register flag that needs to be set
488 * to clear the corresponding interrupt.
489 * This parameter can be one of the following values:
490 * @arg @ref USART_CLEAR_PEF Parity Error Clear Flag
491 * @arg @ref USART_CLEAR_FEF Framing Error Clear Flag
492 * @arg @ref USART_CLEAR_NEF Noise detected Clear Flag
493 * @arg @ref USART_CLEAR_OREF OverRun Error Clear Flag
494 * @arg @ref USART_CLEAR_IDLEF IDLE line detected Clear Flag
495 * @arg @ref USART_CLEAR_TCF Transmission Complete Clear Flag
496 * @arg @ref USART_CLEAR_CTSF CTS Interrupt Clear Flag
497 * @retval None
499 #define __HAL_USART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
501 /** @brief Set a specific USART request flag.
502 * @param __HANDLE__ specifies the USART Handle.
503 * @param __REQ__ specifies the request flag to set.
504 * This parameter can be one of the following values:
505 * @arg @ref USART_RXDATA_FLUSH_REQUEST Receive Data flush Request
506 * @arg @ref USART_TXDATA_FLUSH_REQUEST Transmit data flush Request
508 * @retval None
510 #define __HAL_USART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (__REQ__))
512 /** @brief Enable the USART one bit sample method.
513 * @param __HANDLE__ specifies the USART Handle.
514 * @retval None
516 #define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
518 /** @brief Disable the USART one bit sample method.
519 * @param __HANDLE__ specifies the USART Handle.
520 * @retval None
522 #define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
524 /** @brief Enable USART.
525 * @param __HANDLE__ specifies the USART Handle.
526 * @retval None
528 #define __HAL_USART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
530 /** @brief Disable USART.
531 * @param __HANDLE__ specifies the USART Handle.
532 * @retval None
534 #define __HAL_USART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
537 * @}
540 /* Private macros --------------------------------------------------------*/
541 /** @defgroup USART_Private_Macros USART Private Macros
542 * @{
545 /** @brief Check USART Baud rate.
546 * @param __BAUDRATE__ Baudrate specified by the user.
547 * The maximum Baud Rate is derived from the maximum clock on F3 (i.e. 72 MHz)
548 * divided by the smallest oversampling used on the USART (i.e. 8).
549 * @retval Test result (TRUE or FALSE).
551 #define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 9000001U)
554 * @brief Ensure that USART frame number of stop bits is valid.
555 * @param __STOPBITS__ USART frame number of stop bits.
556 * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
558 #define IS_USART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == USART_STOPBITS_0_5) || \
559 ((__STOPBITS__) == USART_STOPBITS_1) || \
560 ((__STOPBITS__) == USART_STOPBITS_1_5) || \
561 ((__STOPBITS__) == USART_STOPBITS_2))
564 * @brief Ensure that USART frame parity is valid.
565 * @param __PARITY__ USART frame parity.
566 * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
568 #define IS_USART_PARITY(__PARITY__) (((__PARITY__) == USART_PARITY_NONE) || \
569 ((__PARITY__) == USART_PARITY_EVEN) || \
570 ((__PARITY__) == USART_PARITY_ODD))
573 * @brief Ensure that USART communication mode is valid.
574 * @param __MODE__ USART communication mode.
575 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
577 #define IS_USART_MODE(__MODE__) ((((__MODE__) & 0xFFFFFFF3U) == 0x00U) && ((__MODE__) != 0x00U))
580 * @brief Ensure that USART clock state is valid.
581 * @param __CLOCK__ USART clock state.
582 * @retval SET (__CLOCK__ is valid) or RESET (__CLOCK__ is invalid)
584 #define IS_USART_CLOCK(__CLOCK__) (((__CLOCK__) == USART_CLOCK_DISABLE) || \
585 ((__CLOCK__) == USART_CLOCK_ENABLE))
588 * @brief Ensure that USART frame polarity is valid.
589 * @param __CPOL__ USART frame polarity.
590 * @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid)
592 #define IS_USART_POLARITY(__CPOL__) (((__CPOL__) == USART_POLARITY_LOW) || ((__CPOL__) == USART_POLARITY_HIGH))
595 * @brief Ensure that USART frame phase is valid.
596 * @param __CPHA__ USART frame phase.
597 * @retval SET (__CPHA__ is valid) or RESET (__CPHA__ is invalid)
599 #define IS_USART_PHASE(__CPHA__) (((__CPHA__) == USART_PHASE_1EDGE) || ((__CPHA__) == USART_PHASE_2EDGE))
602 * @brief Ensure that USART frame last bit clock pulse setting is valid.
603 * @param __LASTBIT__ USART frame last bit clock pulse setting.
604 * @retval SET (__LASTBIT__ is valid) or RESET (__LASTBIT__ is invalid)
606 #define IS_USART_LASTBIT(__LASTBIT__) (((__LASTBIT__) == USART_LASTBIT_DISABLE) || \
607 ((__LASTBIT__) == USART_LASTBIT_ENABLE))
610 * @brief Ensure that USART request parameter is valid.
611 * @param __PARAM__ USART request parameter.
612 * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
614 #define IS_USART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == USART_RXDATA_FLUSH_REQUEST) || \
615 ((__PARAM__) == USART_TXDATA_FLUSH_REQUEST))
618 * @}
621 /* Include USART HAL Extended module */
622 #include "stm32f3xx_hal_usart_ex.h"
624 /* Exported functions --------------------------------------------------------*/
625 /** @addtogroup USART_Exported_Functions USART Exported Functions
626 * @{
629 /** @addtogroup USART_Exported_Functions_Group1 Initialization and de-initialization functions
630 * @{
633 /* Initialization and de-initialization functions ****************************/
634 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
635 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
636 void HAL_USART_MspInit(USART_HandleTypeDef *husart);
637 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
640 * @}
643 /** @addtogroup USART_Exported_Functions_Group2 IO operation functions
644 * @{
647 /* IO operation functions *****************************************************/
648 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
649 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
650 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
651 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
652 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
653 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
654 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
655 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
656 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
657 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
658 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
659 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
660 /* Transfer Abort functions */
661 HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart);
662 HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart);
664 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
665 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
666 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
667 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
668 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
669 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
670 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
671 void HAL_USART_AbortCpltCallback (USART_HandleTypeDef *husart);
674 * @}
677 /* Peripheral Control functions ***********************************************/
679 /** @addtogroup USART_Exported_Functions_Group3 Peripheral State and Error functions
680 * @{
683 /* Peripheral State and Error functions ***************************************/
684 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
685 uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart);
688 * @}
692 * @}
696 * @}
700 * @}
703 #ifdef __cplusplus
705 #endif
707 #endif /* __STM32F3xx_HAL_USART_H */
709 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/