Go to the documentation of this file.
21 #ifndef __STM32F4xx_HAL_UART_H
22 #define __STM32F4xx_HAL_UART_H
174 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
191 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
197 HAL_UART_TX_HALFCOMPLETE_CB_ID = 0x00U,
198 HAL_UART_TX_COMPLETE_CB_ID = 0x01U,
199 HAL_UART_RX_HALFCOMPLETE_CB_ID = 0x02U,
200 HAL_UART_RX_COMPLETE_CB_ID = 0x03U,
201 HAL_UART_ERROR_CB_ID = 0x04U,
202 HAL_UART_ABORT_COMPLETE_CB_ID = 0x05U,
203 HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x06U,
204 HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID = 0x07U,
205 HAL_UART_WAKEUP_CB_ID = 0x08U,
207 HAL_UART_MSPINIT_CB_ID = 0x0BU,
208 HAL_UART_MSPDEINIT_CB_ID = 0x0CU
210 } HAL_UART_CallbackIDTypeDef;
231 #define HAL_UART_ERROR_NONE 0x00000000U
232 #define HAL_UART_ERROR_PE 0x00000001U
233 #define HAL_UART_ERROR_NE 0x00000002U
234 #define HAL_UART_ERROR_FE 0x00000004U
235 #define HAL_UART_ERROR_ORE 0x00000008U
236 #define HAL_UART_ERROR_DMA 0x00000010U
237 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
238 #define HAL_UART_ERROR_INVALID_CALLBACK 0x00000020U
247 #define UART_WORDLENGTH_8B 0x00000000U
248 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
256 #define UART_STOPBITS_1 0x00000000U
257 #define UART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1)
265 #define UART_PARITY_NONE 0x00000000U
266 #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
267 #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
275 #define UART_HWCONTROL_NONE 0x00000000U
276 #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE)
277 #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE)
278 #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
286 #define UART_MODE_RX ((uint32_t)USART_CR1_RE)
287 #define UART_MODE_TX ((uint32_t)USART_CR1_TE)
288 #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE | USART_CR1_RE))
296 #define UART_STATE_DISABLE 0x00000000U
297 #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE)
305 #define UART_OVERSAMPLING_16 0x00000000U
306 #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8)
314 #define UART_LINBREAKDETECTLENGTH_10B 0x00000000U
315 #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL)
323 #define UART_WAKEUPMETHOD_IDLELINE 0x00000000U
324 #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE)
334 #define UART_FLAG_CTS ((uint32_t)USART_SR_CTS)
335 #define UART_FLAG_LBD ((uint32_t)USART_SR_LBD)
336 #define UART_FLAG_TXE ((uint32_t)USART_SR_TXE)
337 #define UART_FLAG_TC ((uint32_t)USART_SR_TC)
338 #define UART_FLAG_RXNE ((uint32_t)USART_SR_RXNE)
339 #define UART_FLAG_IDLE ((uint32_t)USART_SR_IDLE)
340 #define UART_FLAG_ORE ((uint32_t)USART_SR_ORE)
341 #define UART_FLAG_NE ((uint32_t)USART_SR_NE)
342 #define UART_FLAG_FE ((uint32_t)USART_SR_FE)
343 #define UART_FLAG_PE ((uint32_t)USART_SR_PE)
358 #define UART_IT_PE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
359 #define UART_IT_TXE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
360 #define UART_IT_TC ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
361 #define UART_IT_RXNE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
362 #define UART_IT_IDLE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
364 #define UART_IT_LBD ((uint32_t)(UART_CR2_REG_INDEX << 28U | USART_CR2_LBDIE))
366 #define UART_IT_CTS ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_CTSIE))
367 #define UART_IT_ERR ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_EIE))
387 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
388 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \
389 (__HANDLE__)->gState = HAL_UART_STATE_RESET; \
390 (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \
391 (__HANDLE__)->MspInitCallback = NULL; \
392 (__HANDLE__)->MspDeInitCallback = NULL; \
395 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \
396 (__HANDLE__)->gState = HAL_UART_STATE_RESET; \
397 (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \
406 #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
426 #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
450 #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
458 #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) \
460 __IO uint32_t tmpreg = 0x00U; \
461 tmpreg = (__HANDLE__)->Instance->SR; \
462 tmpreg = (__HANDLE__)->Instance->DR; \
472 #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
480 #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
488 #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
496 #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
514 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \
515 (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & UART_IT_MASK)): \
516 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK)))
534 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
535 (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
536 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK)))
553 #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == UART_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == UART_CR2_REG_INDEX)? \
554 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK))
570 #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \
572 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
573 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \
590 #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \
592 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
593 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \
610 #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \
612 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
613 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \
630 #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \
632 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
633 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \
640 #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
646 #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
652 #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
658 #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
682 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
762 #define UART_IT_MASK 0x0000FFFFU
764 #define UART_CR1_REG_INDEX 1U
765 #define UART_CR2_REG_INDEX 2U
766 #define UART_CR3_REG_INDEX 3U
775 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \
776 ((LENGTH) == UART_WORDLENGTH_9B))
777 #define IS_UART_LIN_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B))
778 #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \
779 ((STOPBITS) == UART_STOPBITS_2))
780 #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \
781 ((PARITY) == UART_PARITY_EVEN) || \
782 ((PARITY) == UART_PARITY_ODD))
783 #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
784 (((CONTROL) == UART_HWCONTROL_NONE) || \
785 ((CONTROL) == UART_HWCONTROL_RTS) || \
786 ((CONTROL) == UART_HWCONTROL_CTS) || \
787 ((CONTROL) == UART_HWCONTROL_RTS_CTS))
788 #define IS_UART_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x00U))
789 #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \
790 ((STATE) == UART_STATE_ENABLE))
791 #define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \
792 ((SAMPLING) == UART_OVERSAMPLING_8))
793 #define IS_UART_LIN_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16))
794 #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
795 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
796 #define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \
797 ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK))
798 #define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) <= 10500000U)
799 #define IS_UART_ADDRESS(ADDRESS) ((ADDRESS) <= 0x0FU)
801 #define UART_DIV_SAMPLING16(_PCLK_, _BAUD_) ((uint32_t)((((uint64_t)(_PCLK_))*25U)/(4U*((uint64_t)(_BAUD_)))))
802 #define UART_DIVMANT_SAMPLING16(_PCLK_, _BAUD_) (UART_DIV_SAMPLING16((_PCLK_), (_BAUD_))/100U)
803 #define UART_DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_) ((((UART_DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100U)) * 16U) + 50U) / 100U)
806 #define UART_BRR_SAMPLING16(_PCLK_, _BAUD_) ((UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4U) + \
807 (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0xF0U) + \
808 (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0FU))
810 #define UART_DIV_SAMPLING8(_PCLK_, _BAUD_) ((uint32_t)((((uint64_t)(_PCLK_))*25U)/(2U*((uint64_t)(_BAUD_)))))
811 #define UART_DIVMANT_SAMPLING8(_PCLK_, _BAUD_) (UART_DIV_SAMPLING8((_PCLK_), (_BAUD_))/100U)
812 #define UART_DIVFRAQ_SAMPLING8(_PCLK_, _BAUD_) ((((UART_DIV_SAMPLING8((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) * 100U)) * 8U) + 50U) / 100U)
815 #define UART_BRR_SAMPLING8(_PCLK_, _BAUD_) ((UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) << 4U) + \
816 ((UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0xF8U) << 1U) + \
817 (UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0x07U))
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart)
HAL_StatusTypeDef
HAL Status structures definition
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
HAL_UART_StateTypeDef
HAL UART State structures definition.
HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart)
Universal Synchronous Asynchronous Receiver Transmitter.
HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart)
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
DMA handle Structure definition.
HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
__IO uint16_t TxXferCount
HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart)
HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart)
UART handle Structure definition.
HAL_LockTypeDef
HAL Lock structures definition
HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart)
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
UART MSP Initialization This function configures the hardware resources used in this example.
HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart)
UART Init Structure definition.
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
DMA_HandleTypeDef * hdmatx
HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart)
HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart)
This file contains HAL common defines, enumeration, macros and structures definitions.
HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart)
HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart)
struct __UART_HandleTypeDef UART_HandleTypeDef
UART handle Structure definition.
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
__IO HAL_UART_StateTypeDef RxState
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
__IO HAL_UART_StateTypeDef gState
DMA_HandleTypeDef * hdmarx
@ HAL_UART_STATE_BUSY_TX_RX
HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart)
HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod)
HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart)
HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength)
void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart)
void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart)
HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart)
void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart)
void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart)
HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart)
void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart)
__IO uint16_t RxXferCount
void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
UART MSP De-Initialization This function freeze the hardware resources used in this example.
HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart)
HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart)
uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart)