STM32F439xx HAL User Manual
Functions
IO operation functions
SPI Exported Functions

Data transfers functions. More...

Functions

HAL_StatusTypeDef HAL_SPI_Transmit (SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
 Transmit an amount of data in blocking mode.
HAL_StatusTypeDef HAL_SPI_Receive (SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
 Receive an amount of data in blocking mode.
HAL_StatusTypeDef HAL_SPI_TransmitReceive (SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
 Transmit and Receive an amount of data in blocking mode.
HAL_StatusTypeDef HAL_SPI_Transmit_IT (SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
 Transmit an amount of data in non-blocking mode with Interrupt.
HAL_StatusTypeDef HAL_SPI_Receive_IT (SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
 Receive an amount of data in non-blocking mode with Interrupt.
HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT (SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
 Transmit and Receive an amount of data in non-blocking mode with Interrupt.
HAL_StatusTypeDef HAL_SPI_Transmit_DMA (SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
 Transmit an amount of data in non-blocking mode with DMA.
HAL_StatusTypeDef HAL_SPI_Receive_DMA (SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
 Receive an amount of data in non-blocking mode with DMA.
HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA (SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
 Transmit and Receive an amount of data in non-blocking mode with DMA.
HAL_StatusTypeDef HAL_SPI_Abort (SPI_HandleTypeDef *hspi)
 Abort ongoing transfer (blocking mode).
HAL_StatusTypeDef HAL_SPI_Abort_IT (SPI_HandleTypeDef *hspi)
 Abort ongoing transfer (Interrupt mode).
HAL_StatusTypeDef HAL_SPI_DMAPause (SPI_HandleTypeDef *hspi)
 Pause the DMA Transfer.
HAL_StatusTypeDef HAL_SPI_DMAResume (SPI_HandleTypeDef *hspi)
 Resume the DMA Transfer.
HAL_StatusTypeDef HAL_SPI_DMAStop (SPI_HandleTypeDef *hspi)
 Stop the DMA Transfer.
void HAL_SPI_IRQHandler (SPI_HandleTypeDef *hspi)
 Handle SPI interrupt request.
__weak void HAL_SPI_TxCpltCallback (SPI_HandleTypeDef *hspi)
 Tx Transfer completed callback.
__weak void HAL_SPI_RxCpltCallback (SPI_HandleTypeDef *hspi)
 Rx Transfer completed callback.
__weak void HAL_SPI_TxRxCpltCallback (SPI_HandleTypeDef *hspi)
 Tx and Rx Transfer completed callback.
__weak void HAL_SPI_TxHalfCpltCallback (SPI_HandleTypeDef *hspi)
 Tx Half Transfer completed callback.
__weak void HAL_SPI_RxHalfCpltCallback (SPI_HandleTypeDef *hspi)
 Rx Half Transfer completed callback.
__weak void HAL_SPI_TxRxHalfCpltCallback (SPI_HandleTypeDef *hspi)
 Tx and Rx Half Transfer callback.
__weak void HAL_SPI_ErrorCallback (SPI_HandleTypeDef *hspi)
 SPI error callback.
__weak void HAL_SPI_AbortCpltCallback (SPI_HandleTypeDef *hspi)
 SPI Abort Complete callback.

Detailed Description

Data transfers functions.

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

    [..] The SPI supports master and slave mode :

    (#) 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 APIs return the HAL status.
            The end of the data processing will be indicated through the
            dedicated SPI IRQ when using Interrupt mode or the DMA IRQ when
            using DMA mode.
            The HAL_SPI_TxCpltCallback(), HAL_SPI_RxCpltCallback() and HAL_SPI_TxRxCpltCallback() user callbacks
            will be executed respectively at the end of the transmit or Receive process
            The HAL_SPI_ErrorCallback()user callback will be executed when a communication error is detected

    (#) APIs provided for these 2 transfer modes (Blocking mode or Non blocking mode using either Interrupt or DMA)
        exist for 1Line (simplex) and 2Lines (full duplex) modes.


Function Documentation

HAL_StatusTypeDef HAL_SPI_Abort ( SPI_HandleTypeDef hspi)

Abort ongoing transfer (blocking mode).

Parameters:
hspiSPI handle.
Note:
This procedure could be used for aborting any ongoing transfer (Tx and Rx), started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable SPI 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.
Once transfer is aborted, the __HAL_SPI_CLEAR_OVRFLAG() macro must be called in user application before starting new SPI receive process.
Return values:
HALstatus

Definition at line 1617 of file stm32f4xx_hal_spi.c.

References __HAL_SPI_CLEAR_FREFLAG, __HAL_SPI_CLEAR_OVRFLAG, __HAL_SPI_DISABLE, __SPI_HandleTypeDef::ErrorCode, HAL_DMA_Abort(), HAL_SPI_ERROR_FLAG, HAL_SPI_ERROR_NONE, HAL_SPI_STATE_READY, __SPI_HandleTypeDef::hdmarx, __SPI_HandleTypeDef::hdmatx, __SPI_HandleTypeDef::Instance, __SPI_HandleTypeDef::RxISR, __SPI_HandleTypeDef::RxXferCount, SPI_AbortRx_ISR(), SPI_AbortTx_ISR(), SPI_DEFAULT_TIMEOUT, SPI_FLAG_TXE, __SPI_HandleTypeDef::State, __SPI_HandleTypeDef::TxISR, __SPI_HandleTypeDef::TxXferCount, and __DMA_HandleTypeDef::XferAbortCallback.

HAL_StatusTypeDef HAL_SPI_Abort_IT ( SPI_HandleTypeDef hspi)

Abort ongoing transfer (Interrupt mode).

Parameters:
hspiSPI handle.
Note:
This procedure could be used for aborting any ongoing transfer (Tx and Rx), started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable SPI 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).
Once transfer is aborted, the __HAL_SPI_CLEAR_OVRFLAG() macro must be called in user application before starting new SPI receive process.
Return values:
HALstatus

Definition at line 1714 of file stm32f4xx_hal_spi.c.

References __HAL_SPI_CLEAR_FREFLAG, __HAL_SPI_CLEAR_OVRFLAG, __SPI_HandleTypeDef::ErrorCode, HAL_DMA_Abort_IT(), HAL_SPI_AbortCpltCallback(), HAL_SPI_ERROR_NONE, HAL_SPI_STATE_READY, __SPI_HandleTypeDef::hdmarx, __SPI_HandleTypeDef::hdmatx, __SPI_HandleTypeDef::Instance, __SPI_HandleTypeDef::RxISR, __SPI_HandleTypeDef::RxXferCount, SPI_AbortRx_ISR(), SPI_AbortTx_ISR(), SPI_DMARxAbortCallback(), SPI_DMATxAbortCallback(), __SPI_HandleTypeDef::State, __SPI_HandleTypeDef::TxISR, __SPI_HandleTypeDef::TxXferCount, and __DMA_HandleTypeDef::XferAbortCallback.

SPI Abort Complete callback.

Parameters:
hspiSPI handle.
Return values:
None

Definition at line 2134 of file stm32f4xx_hal_spi.c.

Referenced by HAL_SPI_Abort_IT(), SPI_DMARxAbortCallback(), and SPI_DMATxAbortCallback().

HAL_StatusTypeDef HAL_SPI_DMAPause ( SPI_HandleTypeDef hspi)

Pause the DMA Transfer.

Parameters:
hspipointer to a SPI_HandleTypeDef structure that contains the configuration information for the specified SPI module.
Return values:
HALstatus

Definition at line 1860 of file stm32f4xx_hal_spi.c.

References __SPI_HandleTypeDef::Instance.

HAL_StatusTypeDef HAL_SPI_DMAResume ( SPI_HandleTypeDef hspi)

Resume the DMA Transfer.

Parameters:
hspipointer to a SPI_HandleTypeDef structure that contains the configuration information for the specified SPI module.
Return values:
HALstatus

Definition at line 1880 of file stm32f4xx_hal_spi.c.

References __SPI_HandleTypeDef::Instance.

HAL_StatusTypeDef HAL_SPI_DMAStop ( SPI_HandleTypeDef hspi)

Stop the DMA Transfer.

Parameters:
hspipointer to a SPI_HandleTypeDef structure that contains the configuration information for the specified SPI module.
Return values:
HALstatus

Definition at line 1900 of file stm32f4xx_hal_spi.c.

References HAL_DMA_Abort(), HAL_SPI_STATE_READY, __SPI_HandleTypeDef::hdmarx, __SPI_HandleTypeDef::hdmatx, __SPI_HandleTypeDef::Instance, and __SPI_HandleTypeDef::State.

SPI error callback.

Parameters:
hspipointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.
Return values:
None

Definition at line 2117 of file stm32f4xx_hal_spi.c.

Referenced by HAL_SPI_IRQHandler(), SPI_CloseRx_ISR(), SPI_CloseRxTx_ISR(), SPI_CloseTx_ISR(), SPI_DMAAbortOnError(), SPI_DMAError(), SPI_DMAReceiveCplt(), SPI_DMATransmitCplt(), and SPI_DMATransmitReceiveCplt().

HAL_StatusTypeDef HAL_SPI_Receive ( SPI_HandleTypeDef hspi,
uint8_t *  pData,
uint16_t  Size,
uint32_t  Timeout 
)
HAL_StatusTypeDef HAL_SPI_Receive_DMA ( SPI_HandleTypeDef hspi,
uint8_t *  pData,
uint16_t  Size 
)
HAL_StatusTypeDef HAL_SPI_Receive_IT ( SPI_HandleTypeDef hspi,
uint8_t *  pData,
uint16_t  Size 
)

Rx Transfer completed callback.

Parameters:
hspipointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.
Return values:
None

Definition at line 2042 of file stm32f4xx_hal_spi.c.

Referenced by SPI_CloseRx_ISR(), SPI_CloseRxTx_ISR(), and SPI_DMAReceiveCplt().

Rx Half Transfer completed callback.

Parameters:
hspipointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.
Return values:
None

Definition at line 2087 of file stm32f4xx_hal_spi.c.

Referenced by SPI_DMAHalfReceiveCplt().

HAL_StatusTypeDef HAL_SPI_Transmit ( SPI_HandleTypeDef hspi,
uint8_t *  pData,
uint16_t  Size,
uint32_t  Timeout 
)
HAL_StatusTypeDef HAL_SPI_Transmit_DMA ( SPI_HandleTypeDef hspi,
uint8_t *  pData,
uint16_t  Size 
)
HAL_StatusTypeDef HAL_SPI_Transmit_IT ( SPI_HandleTypeDef hspi,
uint8_t *  pData,
uint16_t  Size 
)
HAL_StatusTypeDef HAL_SPI_TransmitReceive ( SPI_HandleTypeDef hspi,
uint8_t *  pTxData,
uint8_t *  pRxData,
uint16_t  Size,
uint32_t  Timeout 
)
HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA ( SPI_HandleTypeDef hspi,
uint8_t *  pTxData,
uint8_t *  pRxData,
uint16_t  Size 
)

Transmit and Receive an amount of data in non-blocking mode with DMA.

Parameters:
hspipointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.
pTxDatapointer to transmission data buffer
pRxDatapointer to reception data buffer
Note:
When the CRC feature is enabled the pRxData Length must be Size + 1
Parameters:
Sizeamount of data to be sent
Return values:
HALstatus

Definition at line 1495 of file stm32f4xx_hal_spi.c.

References __HAL_SPI_ENABLE, assert_param, SPI_InitTypeDef::CRCCalculation, SPI_InitTypeDef::Direction, __SPI_HandleTypeDef::ErrorCode, HAL_DMA_Start_IT(), HAL_SPI_ERROR_NONE, HAL_SPI_STATE_BUSY_RX, HAL_SPI_STATE_BUSY_TX_RX, HAL_SPI_STATE_READY, __SPI_HandleTypeDef::hdmarx, __SPI_HandleTypeDef::hdmatx, __SPI_HandleTypeDef::Init, __SPI_HandleTypeDef::Instance, IS_SPI_DIRECTION_2LINES, SPI_InitTypeDef::Mode, __SPI_HandleTypeDef::pRxBuffPtr, __SPI_HandleTypeDef::pTxBuffPtr, __SPI_HandleTypeDef::RxISR, __SPI_HandleTypeDef::RxXferCount, __SPI_HandleTypeDef::RxXferSize, SPI_CRCCALCULATION_ENABLE, SPI_DIRECTION_2LINES, SPI_DMAError(), SPI_DMAHalfReceiveCplt(), SPI_DMAHalfTransmitReceiveCplt(), SPI_DMAReceiveCplt(), SPI_DMATransmitReceiveCplt(), SPI_MODE_MASTER, SPI_RESET_CRC, __SPI_HandleTypeDef::State, __SPI_HandleTypeDef::TxISR, __SPI_HandleTypeDef::TxXferCount, __SPI_HandleTypeDef::TxXferSize, __DMA_HandleTypeDef::XferAbortCallback, __DMA_HandleTypeDef::XferCpltCallback, __DMA_HandleTypeDef::XferErrorCallback, and __DMA_HandleTypeDef::XferHalfCpltCallback.

Referenced by HAL_SPI_Receive_DMA().

HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT ( SPI_HandleTypeDef hspi,
uint8_t *  pTxData,
uint8_t *  pRxData,
uint16_t  Size 
)

Tx Transfer completed callback.

Parameters:
hspipointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.
Return values:
None

Definition at line 2027 of file stm32f4xx_hal_spi.c.

Referenced by SPI_CloseTx_ISR(), and SPI_DMATransmitCplt().

Tx Half Transfer completed callback.

Parameters:
hspipointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.
Return values:
None

Definition at line 2072 of file stm32f4xx_hal_spi.c.

Referenced by SPI_DMAHalfTransmitCplt().

Tx and Rx Transfer completed callback.

Parameters:
hspipointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.
Return values:
None

Definition at line 2057 of file stm32f4xx_hal_spi.c.

Referenced by SPI_CloseRxTx_ISR(), and SPI_DMATransmitReceiveCplt().

Tx and Rx Half Transfer callback.

Parameters:
hspipointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.
Return values:
None

Definition at line 2102 of file stm32f4xx_hal_spi.c.

Referenced by SPI_DMAHalfTransmitReceiveCplt().