STM32F439xx HAL User Manual
Functions
IO operation functions
UART Exported Functions

UART Transmit and Receive functions. More...

Functions

HAL_StatusTypeDef HAL_UART_Transmit (UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
 Sends an amount of data in blocking mode.
HAL_StatusTypeDef HAL_UART_Receive (UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
 Receives an amount of data in blocking mode.
HAL_StatusTypeDef HAL_UART_Transmit_IT (UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
 Sends an amount of data in non blocking mode.
HAL_StatusTypeDef HAL_UART_Receive_IT (UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
 Receives an amount of data in non blocking mode.
HAL_StatusTypeDef HAL_UART_Transmit_DMA (UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
 Sends an amount of data in non blocking mode.
HAL_StatusTypeDef HAL_UART_Receive_DMA (UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
 Receives an amount of data in non blocking mode.
HAL_StatusTypeDef HAL_UART_DMAPause (UART_HandleTypeDef *huart)
 Pauses the DMA Transfer.
HAL_StatusTypeDef HAL_UART_DMAResume (UART_HandleTypeDef *huart)
 Resumes the DMA Transfer.
HAL_StatusTypeDef HAL_UART_DMAStop (UART_HandleTypeDef *huart)
 Stops the DMA Transfer.
HAL_StatusTypeDef HAL_UART_Abort (UART_HandleTypeDef *huart)
 Abort ongoing transfers (blocking mode).
HAL_StatusTypeDef HAL_UART_AbortTransmit (UART_HandleTypeDef *huart)
 Abort ongoing Transmit transfer (blocking mode).
HAL_StatusTypeDef HAL_UART_AbortReceive (UART_HandleTypeDef *huart)
 Abort ongoing Receive transfer (blocking mode).
HAL_StatusTypeDef HAL_UART_Abort_IT (UART_HandleTypeDef *huart)
 Abort ongoing transfers (Interrupt mode).
HAL_StatusTypeDef HAL_UART_AbortTransmit_IT (UART_HandleTypeDef *huart)
 Abort ongoing Transmit transfer (Interrupt mode).
HAL_StatusTypeDef HAL_UART_AbortReceive_IT (UART_HandleTypeDef *huart)
 Abort ongoing Receive transfer (Interrupt mode).
void HAL_UART_IRQHandler (UART_HandleTypeDef *huart)
 This function handles UART interrupt request.
__weak void HAL_UART_TxCpltCallback (UART_HandleTypeDef *huart)
 Tx Transfer completed callbacks.
__weak void HAL_UART_TxHalfCpltCallback (UART_HandleTypeDef *huart)
 Tx Half Transfer completed callbacks.
__weak void HAL_UART_RxCpltCallback (UART_HandleTypeDef *huart)
 Rx Transfer completed callbacks.
__weak void HAL_UART_RxHalfCpltCallback (UART_HandleTypeDef *huart)
 Rx Half Transfer completed callbacks.
__weak void HAL_UART_ErrorCallback (UART_HandleTypeDef *huart)
 UART error callbacks.
__weak void HAL_UART_AbortCpltCallback (UART_HandleTypeDef *huart)
 UART Abort Complete callback.
__weak void HAL_UART_AbortTransmitCpltCallback (UART_HandleTypeDef *huart)
 UART Abort Complete callback.
__weak void HAL_UART_AbortReceiveCpltCallback (UART_HandleTypeDef *huart)
 UART Abort Receive Complete callback.

Detailed Description

UART Transmit and Receive functions.

  ==============================================================================
                      ##### IO operation functions #####
  ==============================================================================  
  [..]
    This subsection provides a set of functions allowing to manage the UART asynchronous
    and Half duplex data transfers.

    (#) There are two modes of transfer:
       (++) Blocking mode: The communication is performed in polling mode. 
            The HAL status of all data processing is returned by the same function 
            after finishing transfer.  
       (++) Non blocking mode: The communication is performed using Interrupts 
            or DMA, these APIs return the HAL status.
            The end of the data processing will be indicated through the 
            dedicated UART IRQ when using Interrupt mode or the DMA IRQ when 
            using DMA mode.
            The HAL_UART_TxCpltCallback(), HAL_UART_RxCpltCallback() user callbacks 
            will be executed respectively at the end of the transmit or receive process.
            The HAL_UART_ErrorCallback() user callback will be executed when 
            a communication error is detected.

    (#) Blocking mode APIs are:
        (++) HAL_UART_Transmit()
        (++) HAL_UART_Receive() 
        
    (#) Non Blocking mode APIs with Interrupt are:
        (++) HAL_UART_Transmit_IT()
        (++) HAL_UART_Receive_IT()
        (++) HAL_UART_IRQHandler()

    (#) Non Blocking mode functions with DMA are:
        (++) HAL_UART_Transmit_DMA()
        (++) HAL_UART_Receive_DMA()

    (#) A set of Transfer Complete Callbacks are provided in non blocking mode:
        (++) HAL_UART_TxCpltCallback()
        (++) HAL_UART_RxCpltCallback()
        (++) HAL_UART_ErrorCallback()

    [..] 
      (@) In the Half duplex communication, it is forbidden to run the transmit 
          and receive process in parallel, the UART state HAL_UART_STATE_BUSY_TX_RX 
          can't be useful.
      

Function Documentation

HAL_StatusTypeDef HAL_UART_Abort ( UART_HandleTypeDef huart)

Abort ongoing transfers (blocking mode).

Parameters:
huartUART handle.
Note:
This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable PPP Interrupts
  • Disable the DMA transfer in the peripheral register (if enabled)
  • Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
  • Set handle State to READY
This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
Return values:
HALstatus

Definition at line 1127 of file stm32f4xx_hal_uart.c.

References UART_HandleTypeDef::ErrorCode, UART_HandleTypeDef::gState, HAL_DMA_Abort(), HAL_UART_ERROR_NONE, HAL_UART_STATE_READY, UART_HandleTypeDef::hdmarx, UART_HandleTypeDef::hdmatx, UART_HandleTypeDef::Instance, UART_HandleTypeDef::RxState, UART_HandleTypeDef::RxXferCount, UART_HandleTypeDef::TxXferCount, and __DMA_HandleTypeDef::XferAbortCallback.

HAL_StatusTypeDef HAL_UART_Abort_IT ( UART_HandleTypeDef huart)

Abort ongoing transfers (Interrupt mode).

Parameters:
huartUART handle.
Note:
This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable PPP Interrupts
  • Disable the DMA transfer in the peripheral register (if enabled)
  • Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
  • Set handle State to READY
  • At abort completion, call user abort complete callback
This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when user abort complete callback is executed (not when exiting function).
Return values:
HALstatus

Definition at line 1278 of file stm32f4xx_hal_uart.c.

References UART_HandleTypeDef::ErrorCode, UART_HandleTypeDef::gState, HAL_DMA_Abort_IT(), HAL_UART_AbortCpltCallback(), HAL_UART_ERROR_NONE, HAL_UART_STATE_READY, UART_HandleTypeDef::hdmarx, UART_HandleTypeDef::hdmatx, UART_HandleTypeDef::Instance, UART_HandleTypeDef::RxState, UART_HandleTypeDef::RxXferCount, UART_HandleTypeDef::TxXferCount, UART_DMARxAbortCallback(), UART_DMATxAbortCallback(), and __DMA_HandleTypeDef::XferAbortCallback.

UART Abort Complete callback.

Parameters:
huartUART handle.
Return values:
None

Definition at line 1724 of file stm32f4xx_hal_uart.c.

Referenced by HAL_UART_Abort_IT(), UART_DMARxAbortCallback(), and UART_DMATxAbortCallback().

HAL_StatusTypeDef HAL_UART_AbortReceive ( UART_HandleTypeDef huart)

Abort ongoing Receive transfer (blocking mode).

Parameters:
huartUART handle.
Note:
This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable PPP Interrupts
  • Disable the DMA transfer in the peripheral register (if enabled)
  • Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
  • Set handle State to READY
This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
Return values:
HALstatus

Definition at line 1233 of file stm32f4xx_hal_uart.c.

References HAL_DMA_Abort(), HAL_UART_STATE_READY, UART_HandleTypeDef::hdmarx, UART_HandleTypeDef::Instance, UART_HandleTypeDef::RxState, UART_HandleTypeDef::RxXferCount, and __DMA_HandleTypeDef::XferAbortCallback.

HAL_StatusTypeDef HAL_UART_AbortReceive_IT ( UART_HandleTypeDef huart)

Abort ongoing Receive transfer (Interrupt mode).

Parameters:
huartUART handle.
Note:
This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable PPP Interrupts
  • Disable the DMA transfer in the peripheral register (if enabled)
  • Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
  • Set handle State to READY
  • At abort completion, call user abort complete callback
This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when user abort complete callback is executed (not when exiting function).
Return values:
HALstatus

Definition at line 1465 of file stm32f4xx_hal_uart.c.

References HAL_DMA_Abort_IT(), HAL_UART_AbortReceiveCpltCallback(), HAL_UART_STATE_READY, UART_HandleTypeDef::hdmarx, UART_HandleTypeDef::Instance, UART_HandleTypeDef::RxState, UART_HandleTypeDef::RxXferCount, UART_DMARxOnlyAbortCallback(), and __DMA_HandleTypeDef::XferAbortCallback.

UART Abort Receive Complete callback.

Parameters:
huartUART handle.
Return values:
None

Definition at line 1753 of file stm32f4xx_hal_uart.c.

Referenced by HAL_UART_AbortReceive_IT(), and UART_DMARxOnlyAbortCallback().

HAL_StatusTypeDef HAL_UART_AbortTransmit ( UART_HandleTypeDef huart)

Abort ongoing Transmit transfer (blocking mode).

Parameters:
huartUART handle.
Note:
This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable PPP Interrupts
  • Disable the DMA transfer in the peripheral register (if enabled)
  • Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
  • Set handle State to READY
This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
Return values:
HALstatus

Definition at line 1191 of file stm32f4xx_hal_uart.c.

References UART_HandleTypeDef::gState, HAL_DMA_Abort(), HAL_UART_STATE_READY, UART_HandleTypeDef::hdmatx, UART_HandleTypeDef::Instance, UART_HandleTypeDef::TxXferCount, and __DMA_HandleTypeDef::XferAbortCallback.

HAL_StatusTypeDef HAL_UART_AbortTransmit_IT ( UART_HandleTypeDef huart)

Abort ongoing Transmit transfer (Interrupt mode).

Parameters:
huartUART handle.
Note:
This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable PPP Interrupts
  • Disable the DMA transfer in the peripheral register (if enabled)
  • Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
  • Set handle State to READY
  • At abort completion, call user abort complete callback
This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when user abort complete callback is executed (not when exiting function).
Return values:
HALstatus

Definition at line 1400 of file stm32f4xx_hal_uart.c.

References UART_HandleTypeDef::gState, HAL_DMA_Abort_IT(), HAL_UART_AbortTransmitCpltCallback(), HAL_UART_STATE_READY, UART_HandleTypeDef::hdmatx, UART_HandleTypeDef::Instance, UART_HandleTypeDef::TxXferCount, UART_DMATxOnlyAbortCallback(), and __DMA_HandleTypeDef::XferAbortCallback.

UART Abort Complete callback.

Parameters:
huartUART handle.
Return values:
None

Definition at line 1738 of file stm32f4xx_hal_uart.c.

Referenced by HAL_UART_AbortTransmit_IT(), and UART_DMATxOnlyAbortCallback().

HAL_StatusTypeDef HAL_UART_DMAPause ( UART_HandleTypeDef huart)

Pauses the DMA Transfer.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
Return values:
HALstatus

Definition at line 1005 of file stm32f4xx_hal_uart.c.

References UART_HandleTypeDef::gState, HAL_UART_STATE_BUSY_RX, HAL_UART_STATE_BUSY_TX, UART_HandleTypeDef::Instance, and UART_HandleTypeDef::RxState.

HAL_StatusTypeDef HAL_UART_DMAResume ( UART_HandleTypeDef huart)

Resumes the DMA Transfer.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
Return values:
HALstatus

Definition at line 1040 of file stm32f4xx_hal_uart.c.

References __HAL_UART_CLEAR_OREFLAG, UART_HandleTypeDef::gState, HAL_UART_STATE_BUSY_RX, HAL_UART_STATE_BUSY_TX, UART_HandleTypeDef::Instance, and UART_HandleTypeDef::RxState.

HAL_StatusTypeDef HAL_UART_DMAStop ( UART_HandleTypeDef huart)

Stops the DMA Transfer.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
Return values:
HALstatus

Definition at line 1075 of file stm32f4xx_hal_uart.c.

References UART_HandleTypeDef::gState, HAL_DMA_Abort(), HAL_UART_STATE_BUSY_RX, HAL_UART_STATE_BUSY_TX, UART_HandleTypeDef::hdmarx, UART_HandleTypeDef::hdmatx, UART_HandleTypeDef::Instance, UART_HandleTypeDef::RxState, UART_EndRxTransfer(), and UART_EndTxTransfer().

UART error callbacks.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
Return values:
None

Definition at line 1710 of file stm32f4xx_hal_uart.c.

Referenced by HAL_UART_IRQHandler(), UART_DMAAbortOnError(), and UART_DMAError().

HAL_StatusTypeDef HAL_UART_Receive ( UART_HandleTypeDef huart,
uint8_t *  pData,
uint16_t  Size,
uint32_t  Timeout 
)

Receives an amount of data in blocking mode.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
pDataPointer to data buffer
SizeAmount of data to be received
TimeoutTimeout duration
Return values:
HALstatus

Definition at line 698 of file stm32f4xx_hal_uart.c.

References UART_HandleTypeDef::ErrorCode, HAL_GetTick(), HAL_UART_ERROR_NONE, HAL_UART_STATE_BUSY_RX, HAL_UART_STATE_READY, UART_HandleTypeDef::Init, UART_HandleTypeDef::Instance, UART_InitTypeDef::Parity, UART_HandleTypeDef::RxState, UART_HandleTypeDef::RxXferCount, UART_HandleTypeDef::RxXferSize, UART_FLAG_RXNE, UART_PARITY_NONE, UART_WaitOnFlagUntilTimeout(), UART_WORDLENGTH_9B, and UART_InitTypeDef::WordLength.

HAL_StatusTypeDef HAL_UART_Receive_DMA ( UART_HandleTypeDef huart,
uint8_t *  pData,
uint16_t  Size 
)

Receives an amount of data in non blocking mode.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
pDataPointer to data buffer
SizeAmount of data to be received
Note:
When the UART parity is enabled (PCE = 1) the data received contain the parity bit.
Return values:
HALstatus

Definition at line 938 of file stm32f4xx_hal_uart.c.

References __HAL_UART_CLEAR_OREFLAG, UART_HandleTypeDef::ErrorCode, HAL_DMA_Start_IT(), HAL_UART_ERROR_NONE, HAL_UART_STATE_BUSY_RX, HAL_UART_STATE_READY, UART_HandleTypeDef::hdmarx, UART_HandleTypeDef::Instance, UART_HandleTypeDef::pRxBuffPtr, UART_HandleTypeDef::RxState, UART_HandleTypeDef::RxXferSize, UART_DMAError(), UART_DMAReceiveCplt(), UART_DMARxHalfCplt(), __DMA_HandleTypeDef::XferAbortCallback, __DMA_HandleTypeDef::XferCpltCallback, __DMA_HandleTypeDef::XferErrorCallback, and __DMA_HandleTypeDef::XferHalfCpltCallback.

HAL_StatusTypeDef HAL_UART_Receive_IT ( UART_HandleTypeDef huart,
uint8_t *  pData,
uint16_t  Size 
)

Receives an amount of data in non blocking mode.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
pDataPointer to data buffer
SizeAmount of data to be received
Return values:
HALstatus

Definition at line 828 of file stm32f4xx_hal_uart.c.

References UART_HandleTypeDef::ErrorCode, HAL_UART_ERROR_NONE, HAL_UART_STATE_BUSY_RX, HAL_UART_STATE_READY, UART_HandleTypeDef::Instance, UART_HandleTypeDef::pRxBuffPtr, UART_HandleTypeDef::RxState, UART_HandleTypeDef::RxXferCount, and UART_HandleTypeDef::RxXferSize.

Rx Transfer completed callbacks.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
Return values:
None

Definition at line 1680 of file stm32f4xx_hal_uart.c.

Referenced by UART_DMAReceiveCplt(), and UART_Receive_IT().

Rx Half Transfer completed callbacks.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
Return values:
None

Definition at line 1695 of file stm32f4xx_hal_uart.c.

Referenced by UART_DMARxHalfCplt().

HAL_StatusTypeDef HAL_UART_Transmit ( UART_HandleTypeDef huart,
uint8_t *  pData,
uint16_t  Size,
uint32_t  Timeout 
)

Sends an amount of data in blocking mode.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
pDataPointer to data buffer
SizeAmount of data to be sent
TimeoutTimeout duration
Return values:
HALstatus

Definition at line 616 of file stm32f4xx_hal_uart.c.

References UART_HandleTypeDef::ErrorCode, UART_HandleTypeDef::gState, HAL_GetTick(), HAL_UART_ERROR_NONE, HAL_UART_STATE_BUSY_TX, HAL_UART_STATE_READY, UART_HandleTypeDef::Init, UART_HandleTypeDef::Instance, UART_InitTypeDef::Parity, UART_HandleTypeDef::TxXferCount, UART_HandleTypeDef::TxXferSize, UART_FLAG_TC, UART_FLAG_TXE, UART_PARITY_NONE, UART_WaitOnFlagUntilTimeout(), UART_WORDLENGTH_9B, and UART_InitTypeDef::WordLength.

HAL_StatusTypeDef HAL_UART_Transmit_DMA ( UART_HandleTypeDef huart,
uint8_t *  pData,
uint16_t  Size 
)
HAL_StatusTypeDef HAL_UART_Transmit_IT ( UART_HandleTypeDef huart,
uint8_t *  pData,
uint16_t  Size 
)

Sends an amount of data in non blocking mode.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
pDataPointer to data buffer
SizeAmount of data to be sent
Return values:
HALstatus

Definition at line 786 of file stm32f4xx_hal_uart.c.

References UART_HandleTypeDef::ErrorCode, UART_HandleTypeDef::gState, HAL_UART_ERROR_NONE, HAL_UART_STATE_BUSY_TX, HAL_UART_STATE_READY, UART_HandleTypeDef::Instance, UART_HandleTypeDef::pTxBuffPtr, UART_HandleTypeDef::TxXferCount, and UART_HandleTypeDef::TxXferSize.

Tx Transfer completed callbacks.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
Return values:
None

Definition at line 1650 of file stm32f4xx_hal_uart.c.

Referenced by UART_DMATransmitCplt(), and UART_EndTransmit_IT().

Tx Half Transfer completed callbacks.

Parameters:
huartpointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module.
Return values:
None

Definition at line 1665 of file stm32f4xx_hal_uart.c.

Referenced by UART_DMATxHalfCplt().