STM32F439xx HAL User Manual
Functions
IO operation functions
USART Exported Functions

USART Transmit and Receive functions. More...

Functions

HAL_StatusTypeDef HAL_USART_Transmit (USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout)
 Simplex Send an amount of data in blocking mode.
HAL_StatusTypeDef HAL_USART_Receive (USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
 Full-Duplex Receive an amount of data in blocking mode.
HAL_StatusTypeDef HAL_USART_TransmitReceive (USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
 Full-Duplex Send receive an amount of data in full-duplex mode (blocking mode).
HAL_StatusTypeDef HAL_USART_Transmit_IT (USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size)
 Simplex Send an amount of data in non-blocking mode.
HAL_StatusTypeDef HAL_USART_Receive_IT (USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size)
 Simplex Receive an amount of data in non-blocking mode.
HAL_StatusTypeDef HAL_USART_TransmitReceive_IT (USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
 Full-Duplex Send receive an amount of data in full-duplex mode (non-blocking).
HAL_StatusTypeDef HAL_USART_Transmit_DMA (USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size)
 Simplex Send an amount of data in non-blocking mode.
HAL_StatusTypeDef HAL_USART_Receive_DMA (USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size)
 Full-Duplex Receive an amount of data in non-blocking mode.
HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA (USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
 Full-Duplex Transmit Receive an amount of data in non-blocking mode.
HAL_StatusTypeDef HAL_USART_DMAPause (USART_HandleTypeDef *husart)
 Pauses the DMA Transfer.
HAL_StatusTypeDef HAL_USART_DMAResume (USART_HandleTypeDef *husart)
 Resumes the DMA Transfer.
HAL_StatusTypeDef HAL_USART_DMAStop (USART_HandleTypeDef *husart)
 Stops the DMA Transfer.
HAL_StatusTypeDef HAL_USART_Abort (USART_HandleTypeDef *husart)
 Abort ongoing transfer (blocking mode).
HAL_StatusTypeDef HAL_USART_Abort_IT (USART_HandleTypeDef *husart)
 Abort ongoing transfer (Interrupt mode).
void HAL_USART_IRQHandler (USART_HandleTypeDef *husart)
 This function handles USART interrupt request.
__weak void HAL_USART_TxCpltCallback (USART_HandleTypeDef *husart)
 Tx Transfer completed callbacks.
__weak void HAL_USART_TxHalfCpltCallback (USART_HandleTypeDef *husart)
 Tx Half Transfer completed callbacks.
__weak void HAL_USART_RxCpltCallback (USART_HandleTypeDef *husart)
 Rx Transfer completed callbacks.
__weak void HAL_USART_RxHalfCpltCallback (USART_HandleTypeDef *husart)
 Rx Half Transfer completed callbacks.
__weak void HAL_USART_TxRxCpltCallback (USART_HandleTypeDef *husart)
 Tx/Rx Transfers completed callback for the non-blocking process.
__weak void HAL_USART_ErrorCallback (USART_HandleTypeDef *husart)
 USART error callbacks.
__weak void HAL_USART_AbortCpltCallback (USART_HandleTypeDef *husart)
 USART Abort Complete callback.

Detailed Description

USART Transmit and Receive functions.

  ==============================================================================
                         ##### IO operation functions #####
  ==============================================================================
  [..]
    This subsection provides a set of functions allowing to manage the USART synchronous
    data transfers.

  [..]
    The USART supports master mode only: it cannot receive or send data related to an input
    clock (SCLK is always an output).

    (#) 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.
        (++) No-Blocking mode: The communication is performed using Interrupts
             or DMA, These API's return the HAL status.
             The end of the data processing will be indicated through the
             dedicated USART IRQ when using Interrupt mode or the DMA IRQ when
             using DMA mode.
             The HAL_USART_TxCpltCallback(), HAL_USART_RxCpltCallback() and HAL_USART_TxRxCpltCallback()
              user callbacks
             will be executed respectively at the end of the transmit or Receive process
             The HAL_USART_ErrorCallback() user callback will be executed when a communication
             error is detected

    (#) Blocking mode APIs are :
        (++) HAL_USART_Transmit() in simplex mode
        (++) HAL_USART_Receive() in full duplex receive only
        (++) HAL_USART_TransmitReceive() in full duplex mode

    (#) Non Blocking mode APIs with Interrupt are :
        (++) HAL_USART_Transmit_IT()in simplex mode
        (++) HAL_USART_Receive_IT() in full duplex receive only
        (++) HAL_USART_TransmitReceive_IT() in full duplex mode
        (++) HAL_USART_IRQHandler()

    (#) Non Blocking mode functions with DMA are :
        (++) HAL_USART_Transmit_DMA()in simplex mode
        (++) HAL_USART_Receive_DMA() in full duplex receive only
        (++) HAL_USART_TransmitReceie_DMA() in full duplex mode
        (++) HAL_USART_DMAPause()
        (++) HAL_USART_DMAResume()
        (++) HAL_USART_DMAStop()

    (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
        (++) HAL_USART_TxHalfCpltCallback()
        (++) HAL_USART_TxCpltCallback()
        (++) HAL_USART_RxHalfCpltCallback()
        (++) HAL_USART_RxCpltCallback()
        (++) HAL_USART_ErrorCallback()
        (++) HAL_USART_TxRxCpltCallback()


Function Documentation

HAL_StatusTypeDef HAL_USART_Abort ( USART_HandleTypeDef husart)

Abort ongoing transfer (blocking mode).

Parameters:
husartUSART handle.
Note:
This procedure could be used for aborting any ongoing transfer (either Tx or Rx, as described by TransferType parameter) started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable PPP Interrupts (depending of transfer direction)
  • 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 1193 of file stm32f4xx_hal_usart.c.

References USART_HandleTypeDef::ErrorCode, HAL_DMA_Abort(), HAL_USART_ERROR_NONE, HAL_USART_STATE_READY, USART_HandleTypeDef::hdmarx, USART_HandleTypeDef::hdmatx, USART_HandleTypeDef::Instance, USART_HandleTypeDef::RxXferCount, USART_HandleTypeDef::State, USART_HandleTypeDef::TxXferCount, and __DMA_HandleTypeDef::XferAbortCallback.

HAL_StatusTypeDef HAL_USART_Abort_IT ( USART_HandleTypeDef husart)

Abort ongoing transfer (Interrupt mode).

Parameters:
husartUSART handle.
Note:
This procedure could be used for aborting any ongoing transfer (either Tx or Rx, as described by TransferType parameter) started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable PPP Interrupts (depending of transfer direction)
  • 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 1259 of file stm32f4xx_hal_usart.c.

References USART_HandleTypeDef::ErrorCode, HAL_DMA_Abort_IT(), HAL_USART_AbortCpltCallback(), HAL_USART_ERROR_NONE, HAL_USART_STATE_READY, USART_HandleTypeDef::hdmarx, USART_HandleTypeDef::hdmatx, USART_HandleTypeDef::Instance, USART_HandleTypeDef::RxXferCount, USART_HandleTypeDef::State, USART_HandleTypeDef::TxXferCount, USART_DMARxAbortCallback(), USART_DMATxAbortCallback(), and __DMA_HandleTypeDef::XferAbortCallback.

USART Abort Complete callback.

Parameters:
husartUSART handle.
Return values:
None

Definition at line 1605 of file stm32f4xx_hal_usart.c.

Referenced by HAL_USART_Abort_IT(), USART_DMARxAbortCallback(), and USART_DMATxAbortCallback().

HAL_StatusTypeDef HAL_USART_DMAPause ( USART_HandleTypeDef husart)

Pauses the DMA Transfer.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
Return values:
HALstatus

Definition at line 1096 of file stm32f4xx_hal_usart.c.

References USART_HandleTypeDef::Instance.

HAL_StatusTypeDef HAL_USART_DMAResume ( USART_HandleTypeDef husart)

Resumes the DMA Transfer.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
Return values:
HALstatus

Definition at line 1116 of file stm32f4xx_hal_usart.c.

References USART_HandleTypeDef::Instance.

HAL_StatusTypeDef HAL_USART_DMAStop ( USART_HandleTypeDef husart)

Stops the DMA Transfer.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
Return values:
HALstatus

Definition at line 1136 of file stm32f4xx_hal_usart.c.

References HAL_DMA_Abort(), HAL_USART_STATE_BUSY_RX, HAL_USART_STATE_BUSY_TX, USART_HandleTypeDef::hdmarx, USART_HandleTypeDef::hdmatx, USART_HandleTypeDef::Instance, USART_HandleTypeDef::State, USART_EndRxTransfer(), and USART_EndTxTransfer().

USART error callbacks.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
Return values:
None

Definition at line 1591 of file stm32f4xx_hal_usart.c.

Referenced by HAL_USART_IRQHandler(), USART_DMAAbortOnError(), and USART_DMAError().

HAL_StatusTypeDef HAL_USART_Receive ( USART_HandleTypeDef husart,
uint8_t *  pRxData,
uint16_t  Size,
uint32_t  Timeout 
)

Full-Duplex Receive an amount of data in blocking mode.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
pRxDataPointer to data buffer
SizeAmount of data to be received
TimeoutTimeout duration
Return values:
HALstatus

Definition at line 485 of file stm32f4xx_hal_usart.c.

References DUMMY_DATA, USART_HandleTypeDef::ErrorCode, HAL_GetTick(), HAL_USART_ERROR_NONE, HAL_USART_STATE_BUSY_RX, HAL_USART_STATE_READY, USART_HandleTypeDef::Init, USART_HandleTypeDef::Instance, USART_InitTypeDef::Parity, USART_HandleTypeDef::RxXferCount, USART_HandleTypeDef::RxXferSize, USART_HandleTypeDef::State, USART_FLAG_RXNE, USART_FLAG_TXE, USART_PARITY_NONE, USART_WaitOnFlagUntilTimeout(), USART_WORDLENGTH_9B, and USART_InitTypeDef::WordLength.

HAL_StatusTypeDef HAL_USART_Receive_DMA ( USART_HandleTypeDef husart,
uint8_t *  pRxData,
uint16_t  Size 
)

Full-Duplex Receive an amount of data in non-blocking mode.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
pRxDataPointer to data buffer
SizeAmount of data to be received
Return values:
HALstatus
Note:
The USART DMA transmit stream must be configured in order to generate the clock for the slave.
When the USART parity is enabled (PCE = 1) the data received contain the parity bit.

Definition at line 917 of file stm32f4xx_hal_usart.c.

References __HAL_USART_CLEAR_OREFLAG, USART_HandleTypeDef::ErrorCode, HAL_DMA_Start_IT(), HAL_USART_ERROR_NONE, HAL_USART_STATE_BUSY_RX, HAL_USART_STATE_READY, USART_HandleTypeDef::hdmarx, USART_HandleTypeDef::hdmatx, USART_HandleTypeDef::Instance, USART_HandleTypeDef::pRxBuffPtr, USART_HandleTypeDef::pTxBuffPtr, USART_HandleTypeDef::RxXferSize, USART_HandleTypeDef::State, USART_HandleTypeDef::TxXferSize, USART_DMAError(), USART_DMAReceiveCplt(), USART_DMARxHalfCplt(), __DMA_HandleTypeDef::XferAbortCallback, __DMA_HandleTypeDef::XferCpltCallback, __DMA_HandleTypeDef::XferErrorCallback, and __DMA_HandleTypeDef::XferHalfCpltCallback.

HAL_StatusTypeDef HAL_USART_Receive_IT ( USART_HandleTypeDef husart,
uint8_t *  pRxData,
uint16_t  Size 
)

Simplex Receive an amount of data in non-blocking mode.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
pRxDataPointer to data buffer
SizeAmount of data to be received
Return values:
HALstatus

Definition at line 754 of file stm32f4xx_hal_usart.c.

References DUMMY_DATA, USART_HandleTypeDef::ErrorCode, HAL_USART_ERROR_NONE, HAL_USART_STATE_BUSY_RX, HAL_USART_STATE_READY, USART_HandleTypeDef::Instance, USART_HandleTypeDef::pRxBuffPtr, USART_HandleTypeDef::RxXferCount, USART_HandleTypeDef::RxXferSize, and USART_HandleTypeDef::State.

Rx Transfer completed callbacks.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
Return values:
None

Definition at line 1546 of file stm32f4xx_hal_usart.c.

Referenced by USART_DMAReceiveCplt(), and USART_Receive_IT().

Rx Half Transfer completed callbacks.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
Return values:
None

Definition at line 1561 of file stm32f4xx_hal_usart.c.

Referenced by USART_DMARxHalfCplt().

HAL_StatusTypeDef HAL_USART_Transmit ( USART_HandleTypeDef husart,
uint8_t *  pTxData,
uint16_t  Size,
uint32_t  Timeout 
)

Simplex Send an amount of data in blocking mode.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
pTxDataPointer to data buffer
SizeAmount of data to be sent
TimeoutTimeout duration
Return values:
HALstatus

Definition at line 404 of file stm32f4xx_hal_usart.c.

References USART_HandleTypeDef::ErrorCode, HAL_GetTick(), HAL_USART_ERROR_NONE, HAL_USART_STATE_BUSY_TX, HAL_USART_STATE_READY, USART_HandleTypeDef::Init, USART_HandleTypeDef::Instance, USART_InitTypeDef::Parity, USART_HandleTypeDef::State, USART_HandleTypeDef::TxXferCount, USART_HandleTypeDef::TxXferSize, USART_FLAG_TC, USART_FLAG_TXE, USART_PARITY_NONE, USART_WaitOnFlagUntilTimeout(), USART_WORDLENGTH_9B, and USART_InitTypeDef::WordLength.

HAL_StatusTypeDef HAL_USART_Transmit_DMA ( USART_HandleTypeDef husart,
uint8_t *  pTxData,
uint16_t  Size 
)
HAL_StatusTypeDef HAL_USART_Transmit_IT ( USART_HandleTypeDef husart,
uint8_t *  pTxData,
uint16_t  Size 
)

Simplex Send an amount of data in non-blocking mode.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
pTxDataPointer to data buffer
SizeAmount of data to be sent
Return values:
HALstatus
Note:
The USART errors are not managed to avoid the overrun error.

Definition at line 705 of file stm32f4xx_hal_usart.c.

References USART_HandleTypeDef::ErrorCode, HAL_USART_ERROR_NONE, HAL_USART_STATE_BUSY_TX, HAL_USART_STATE_READY, USART_HandleTypeDef::Instance, USART_HandleTypeDef::pTxBuffPtr, USART_HandleTypeDef::State, USART_HandleTypeDef::TxXferCount, and USART_HandleTypeDef::TxXferSize.

HAL_StatusTypeDef HAL_USART_TransmitReceive ( USART_HandleTypeDef husart,
uint8_t *  pTxData,
uint8_t *  pRxData,
uint16_t  Size,
uint32_t  Timeout 
)

Full-Duplex Send receive an amount of data in full-duplex mode (blocking mode).

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
pTxDataPointer to data transmitted buffer
pRxDataPointer to data received buffer
SizeAmount of data to be sent
TimeoutTimeout duration
Return values:
HALstatus

Definition at line 591 of file stm32f4xx_hal_usart.c.

References USART_HandleTypeDef::ErrorCode, HAL_GetTick(), HAL_USART_ERROR_NONE, HAL_USART_STATE_BUSY_RX, HAL_USART_STATE_READY, USART_HandleTypeDef::Init, USART_HandleTypeDef::Instance, USART_InitTypeDef::Parity, USART_HandleTypeDef::RxXferCount, USART_HandleTypeDef::RxXferSize, USART_HandleTypeDef::State, USART_HandleTypeDef::TxXferCount, USART_HandleTypeDef::TxXferSize, USART_FLAG_RXNE, USART_FLAG_TXE, USART_PARITY_NONE, USART_WaitOnFlagUntilTimeout(), USART_WORDLENGTH_9B, and USART_InitTypeDef::WordLength.

HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA ( USART_HandleTypeDef husart,
uint8_t *  pTxData,
uint8_t *  pRxData,
uint16_t  Size 
)

Full-Duplex Transmit Receive an amount of data in non-blocking mode.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
pTxDataPointer to data transmitted buffer
pRxDataPointer to data received buffer
SizeAmount of data to be received
Note:
When the USART parity is enabled (PCE = 1) the data received contain the parity bit.
Return values:
HALstatus

Definition at line 1009 of file stm32f4xx_hal_usart.c.

References __HAL_USART_CLEAR_FLAG, __HAL_USART_CLEAR_OREFLAG, USART_HandleTypeDef::ErrorCode, HAL_DMA_Start_IT(), HAL_USART_ERROR_NONE, HAL_USART_STATE_BUSY_TX_RX, HAL_USART_STATE_READY, USART_HandleTypeDef::hdmarx, USART_HandleTypeDef::hdmatx, USART_HandleTypeDef::Instance, USART_HandleTypeDef::pRxBuffPtr, USART_HandleTypeDef::pTxBuffPtr, USART_HandleTypeDef::RxXferSize, USART_HandleTypeDef::State, USART_HandleTypeDef::TxXferSize, USART_DMAError(), USART_DMAReceiveCplt(), USART_DMARxHalfCplt(), USART_DMATransmitCplt(), USART_DMATxHalfCplt(), USART_FLAG_TC, __DMA_HandleTypeDef::XferAbortCallback, __DMA_HandleTypeDef::XferCpltCallback, __DMA_HandleTypeDef::XferErrorCallback, and __DMA_HandleTypeDef::XferHalfCpltCallback.

HAL_StatusTypeDef HAL_USART_TransmitReceive_IT ( USART_HandleTypeDef husart,
uint8_t *  pTxData,
uint8_t *  pRxData,
uint16_t  Size 
)

Full-Duplex Send receive an amount of data in full-duplex mode (non-blocking).

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
pTxDataPointer to data transmitted buffer
pRxDataPointer to data received buffer
SizeAmount of data to be received
Return values:
HALstatus

Definition at line 801 of file stm32f4xx_hal_usart.c.

References USART_HandleTypeDef::ErrorCode, HAL_USART_ERROR_NONE, HAL_USART_STATE_BUSY_TX_RX, HAL_USART_STATE_READY, USART_HandleTypeDef::Instance, USART_HandleTypeDef::pRxBuffPtr, USART_HandleTypeDef::pTxBuffPtr, USART_HandleTypeDef::RxXferCount, USART_HandleTypeDef::RxXferSize, USART_HandleTypeDef::State, USART_HandleTypeDef::TxXferCount, and USART_HandleTypeDef::TxXferSize.

Tx Transfer completed callbacks.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
Return values:
None

Definition at line 1516 of file stm32f4xx_hal_usart.c.

Referenced by USART_DMATransmitCplt(), and USART_EndTransmit_IT().

Tx Half Transfer completed callbacks.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
Return values:
None

Definition at line 1531 of file stm32f4xx_hal_usart.c.

Referenced by USART_DMATxHalfCplt().

Tx/Rx Transfers completed callback for the non-blocking process.

Parameters:
husartpointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module.
Return values:
None

Definition at line 1576 of file stm32f4xx_hal_usart.c.

Referenced by USART_DMAReceiveCplt(), and USART_TransmitReceive_IT().