Go to the documentation of this file.
21 #ifndef STM32F7xx_HAL_USART_H
22 #define STM32F7xx_HAL_USART_H
150 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
165 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
171 HAL_USART_TX_HALFCOMPLETE_CB_ID = 0x00U,
172 HAL_USART_TX_COMPLETE_CB_ID = 0x01U,
173 HAL_USART_RX_HALFCOMPLETE_CB_ID = 0x02U,
174 HAL_USART_RX_COMPLETE_CB_ID = 0x03U,
175 HAL_USART_TX_RX_COMPLETE_CB_ID = 0x04U,
176 HAL_USART_ERROR_CB_ID = 0x05U,
177 HAL_USART_ABORT_COMPLETE_CB_ID = 0x06U,
179 HAL_USART_MSPINIT_CB_ID = 0x09U,
180 HAL_USART_MSPDEINIT_CB_ID = 0x0AU
182 } HAL_USART_CallbackIDTypeDef;
203 #define HAL_USART_ERROR_NONE ((uint32_t)0x00000000U)
204 #define HAL_USART_ERROR_PE ((uint32_t)0x00000001U)
205 #define HAL_USART_ERROR_NE ((uint32_t)0x00000002U)
206 #define HAL_USART_ERROR_FE ((uint32_t)0x00000004U)
207 #define HAL_USART_ERROR_ORE ((uint32_t)0x00000008U)
208 #define HAL_USART_ERROR_DMA ((uint32_t)0x00000010U)
209 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
210 #define HAL_USART_ERROR_INVALID_CALLBACK ((uint32_t)0x00000040U)
212 #define HAL_USART_ERROR_RTO ((uint32_t)0x00000080U)
220 #define USART_STOPBITS_0_5 USART_CR2_STOP_0
221 #define USART_STOPBITS_1 0x00000000U
222 #define USART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1)
223 #define USART_STOPBITS_2 USART_CR2_STOP_1
231 #define USART_PARITY_NONE 0x00000000U
232 #define USART_PARITY_EVEN USART_CR1_PCE
233 #define USART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS)
241 #define USART_MODE_RX USART_CR1_RE
242 #define USART_MODE_TX USART_CR1_TE
243 #define USART_MODE_TX_RX (USART_CR1_TE |USART_CR1_RE)
251 #define USART_OVERSAMPLING_16 0x00000000U
252 #define USART_OVERSAMPLING_8 USART_CR1_OVER8
260 #define USART_CLOCK_DISABLE 0x00000000U
261 #define USART_CLOCK_ENABLE USART_CR2_CLKEN
269 #define USART_POLARITY_LOW 0x00000000U
270 #define USART_POLARITY_HIGH USART_CR2_CPOL
278 #define USART_PHASE_1EDGE 0x00000000U
279 #define USART_PHASE_2EDGE USART_CR2_CPHA
287 #define USART_LASTBIT_DISABLE 0x00000000U
288 #define USART_LASTBIT_ENABLE USART_CR2_LBCL
297 #define USART_RXDATA_FLUSH_REQUEST USART_RQR_RXFRQ
298 #define USART_TXDATA_FLUSH_REQUEST USART_RQR_TXFRQ
308 #define USART_FLAG_REACK USART_ISR_REACK
309 #define USART_FLAG_TEACK USART_ISR_TEACK
310 #define USART_FLAG_BUSY USART_ISR_BUSY
311 #define USART_FLAG_TXE USART_ISR_TXE
312 #define USART_FLAG_RTOF USART_ISR_RTOF
313 #define USART_FLAG_TC USART_ISR_TC
314 #define USART_FLAG_RXNE USART_ISR_RXNE
315 #define USART_FLAG_IDLE USART_ISR_IDLE
316 #define USART_FLAG_ORE USART_ISR_ORE
317 #define USART_FLAG_NE USART_ISR_NE
318 #define USART_FLAG_FE USART_ISR_FE
319 #define USART_FLAG_PE USART_ISR_PE
335 #define USART_IT_PE 0x0028U
336 #define USART_IT_TXE 0x0727U
337 #define USART_IT_TC 0x0626U
338 #define USART_IT_RXNE 0x0525U
339 #define USART_IT_IDLE 0x0424U
340 #define USART_IT_ERR 0x0060U
341 #define USART_IT_ORE 0x0300U
342 #define USART_IT_NE 0x0200U
343 #define USART_IT_FE 0x0100U
352 #define USART_CLEAR_PEF USART_ICR_PECF
353 #define USART_CLEAR_FEF USART_ICR_FECF
354 #define USART_CLEAR_NEF USART_ICR_NCF
355 #define USART_CLEAR_OREF USART_ICR_ORECF
356 #define USART_CLEAR_IDLEF USART_ICR_IDLECF
357 #define USART_CLEAR_TCF USART_ICR_TCCF
358 #define USART_CLEAR_RTOF USART_ICR_RTOCF
366 #define USART_IT_MASK 0x001FU
367 #define USART_CR_MASK 0x00E0U
368 #define USART_CR_POS 5U
369 #define USART_ISR_MASK 0x1F00U
370 #define USART_ISR_POS 8U
388 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
389 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) do{ \
390 (__HANDLE__)->State = HAL_USART_STATE_RESET; \
391 (__HANDLE__)->MspInitCallback = NULL; \
392 (__HANDLE__)->MspDeInitCallback = NULL; \
395 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET)
416 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
431 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
437 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_PEF)
443 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_FEF)
449 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_NEF)
455 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_OREF)
461 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_IDLEF)
477 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 1U)? ((__HANDLE__)->Instance->CR1 |= ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))): \
478 ((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 2U)? ((__HANDLE__)->Instance->CR2 |= ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))): \
479 ((__HANDLE__)->Instance->CR3 |= ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))))
493 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~ ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))): \
494 ((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~ ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))): \
495 ((__HANDLE__)->Instance->CR3 &= ~ ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))))
512 #define __HAL_USART_GET_IT(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->ISR\
513 & ((uint32_t)0x01U << (((__INTERRUPT__) & USART_ISR_MASK)>> USART_ISR_POS))) != 0U) ? SET : RESET)
529 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((((((uint8_t)(__INTERRUPT__)) >> 0x05U) == 0x01U) ? (__HANDLE__)->Instance->CR1 : \
530 (((((uint8_t)(__INTERRUPT__)) >> 0x05U) == 0x02U) ? (__HANDLE__)->Instance->CR2 : \
531 (__HANDLE__)->Instance->CR3)) & (0x01U << (((uint16_t)(__INTERRUPT__)) & USART_IT_MASK))) != 0U) ? SET : RESET)
548 #define __HAL_USART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
559 #define __HAL_USART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
565 #define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
571 #define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= ~USART_CR3_ONEBIT)
577 #define __HAL_USART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
583 #define __HAL_USART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
599 #define USART_DIV_SAMPLING8(__PCLK__, __BAUD__) ((((__PCLK__)*2U) + ((__BAUD__)/2U)) / (__BAUD__))
606 #define USART_GETCLOCKSOURCE(__HANDLE__, __CLOCKSOURCE__) \
608 if((__HANDLE__)->Instance == USART1) \
610 switch(__HAL_RCC_GET_USART1_SOURCE()) \
612 case RCC_USART1CLKSOURCE_PCLK2: \
613 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK2; \
615 case RCC_USART1CLKSOURCE_HSI: \
616 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
618 case RCC_USART1CLKSOURCE_SYSCLK: \
619 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
621 case RCC_USART1CLKSOURCE_LSE: \
622 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
625 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
629 else if((__HANDLE__)->Instance == USART2) \
631 switch(__HAL_RCC_GET_USART2_SOURCE()) \
633 case RCC_USART2CLKSOURCE_PCLK1: \
634 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
636 case RCC_USART2CLKSOURCE_HSI: \
637 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
639 case RCC_USART2CLKSOURCE_SYSCLK: \
640 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
642 case RCC_USART2CLKSOURCE_LSE: \
643 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
646 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
650 else if((__HANDLE__)->Instance == USART3) \
652 switch(__HAL_RCC_GET_USART3_SOURCE()) \
654 case RCC_USART3CLKSOURCE_PCLK1: \
655 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
657 case RCC_USART3CLKSOURCE_HSI: \
658 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
660 case RCC_USART3CLKSOURCE_SYSCLK: \
661 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
663 case RCC_USART3CLKSOURCE_LSE: \
664 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
667 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
671 else if((__HANDLE__)->Instance == USART6) \
673 switch(__HAL_RCC_GET_USART6_SOURCE()) \
675 case RCC_USART6CLKSOURCE_PCLK2: \
676 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK2; \
678 case RCC_USART6CLKSOURCE_HSI: \
679 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
681 case RCC_USART6CLKSOURCE_SYSCLK: \
682 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
684 case RCC_USART6CLKSOURCE_LSE: \
685 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
688 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
694 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
703 #define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 27000000U)
710 #define IS_USART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == USART_STOPBITS_0_5) || \
711 ((__STOPBITS__) == USART_STOPBITS_1) || \
712 ((__STOPBITS__) == USART_STOPBITS_1_5) || \
713 ((__STOPBITS__) == USART_STOPBITS_2))
720 #define IS_USART_PARITY(__PARITY__) (((__PARITY__) == USART_PARITY_NONE) || \
721 ((__PARITY__) == USART_PARITY_EVEN) || \
722 ((__PARITY__) == USART_PARITY_ODD))
729 #define IS_USART_MODE(__MODE__) ((((__MODE__) & 0xFFFFFFF3U) == 0x00U) && ((__MODE__) != 0x00U))
736 #define IS_USART_OVERSAMPLING(__SAMPLING__) (((__SAMPLING__) == USART_OVERSAMPLING_16) || \
737 ((__SAMPLING__) == USART_OVERSAMPLING_8))
744 #define IS_USART_CLOCK(__CLOCK__) (((__CLOCK__) == USART_CLOCK_DISABLE) || \
745 ((__CLOCK__) == USART_CLOCK_ENABLE))
752 #define IS_USART_POLARITY(__CPOL__) (((__CPOL__) == USART_POLARITY_LOW) || ((__CPOL__) == USART_POLARITY_HIGH))
759 #define IS_USART_PHASE(__CPHA__) (((__CPHA__) == USART_PHASE_1EDGE) || ((__CPHA__) == USART_PHASE_2EDGE))
766 #define IS_USART_LASTBIT(__LASTBIT__) (((__LASTBIT__) == USART_LASTBIT_DISABLE) || \
767 ((__LASTBIT__) == USART_LASTBIT_ENABLE))
774 #define IS_USART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == USART_RXDATA_FLUSH_REQUEST) || \
775 ((__PARAM__) == USART_TXDATA_FLUSH_REQUEST))
800 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
802 pUSART_CallbackTypeDef pCallback);
818 uint16_t Size, uint32_t Timeout);
USART handle Structure definition.
void(* TxISR)(struct __USART_HandleTypeDef *husart)
void HAL_USART_AbortCpltCallback(USART_HandleTypeDef *husart)
HAL_StatusTypeDef
HAL Status structures definition
Universal Synchronous Asynchronous Receiver Transmitter.
@ HAL_USART_STATE_TIMEOUT
DMA handle Structure definition.
@ USART_CLOCKSOURCE_PCLK1
void HAL_USART_IRQHandler(USART_HandleTypeDef *husart)
void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart)
HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size)
void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart)
HAL_LockTypeDef
HAL Lock structures definition
void HAL_USART_MspDeInit(USART_HandleTypeDef *husart)
void HAL_USART_MspInit(USART_HandleTypeDef *husart)
void(* RxISR)(struct __USART_HandleTypeDef *husart)
HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart)
@ HAL_USART_STATE_BUSY_TX_RX
HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart)
HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart)
@ HAL_USART_STATE_BUSY_TX
void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart)
HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
DMA_HandleTypeDef * hdmatx
HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size)
@ HAL_USART_STATE_BUSY_RX
HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size)
HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
__IO HAL_USART_StateTypeDef State
__IO uint16_t RxXferCount
@ USART_CLOCKSOURCE_UNDEFINED
HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart)
HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart)
struct __USART_HandleTypeDef USART_HandleTypeDef
USART handle Structure definition.
HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size)
This file contains HAL common defines, enumeration, macros and structures definitions.
USART_ClockSourceTypeDef
USART clock sources definitions.
void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart)
HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart)
HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout)
void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart)
Header file of USART HAL Extended module.
@ USART_CLOCKSOURCE_PCLK2
HAL_USART_StateTypeDef
HAL USART State structures definition.
HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart)
HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
USART Init Structure definition.
HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart)
void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart)
@ USART_CLOCKSOURCE_SYSCLK
uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart)
__IO uint16_t TxXferCount
DMA_HandleTypeDef * hdmarx