STM32F439xx HAL User Manual
|
SPI HAL module driver. This file provides firmware functions to manage the following functionalities of the Serial Peripheral Interface (SPI) peripheral: + Initialization and de-initialization functions + IO operation functions + Peripheral Control functions + Peripheral State functions. More...
#include "stm32f4xx_hal.h"
Go to the source code of this file.
Defines | |
#define | SPI_DEFAULT_TIMEOUT 100U |
Functions | |
static void | SPI_DMATransmitCplt (DMA_HandleTypeDef *hdma) |
DMA SPI transmit process complete callback. | |
static void | SPI_DMAReceiveCplt (DMA_HandleTypeDef *hdma) |
DMA SPI receive process complete callback. | |
static void | SPI_DMATransmitReceiveCplt (DMA_HandleTypeDef *hdma) |
DMA SPI transmit receive process complete callback. | |
static void | SPI_DMAHalfTransmitCplt (DMA_HandleTypeDef *hdma) |
DMA SPI half transmit process complete callback. | |
static void | SPI_DMAHalfReceiveCplt (DMA_HandleTypeDef *hdma) |
DMA SPI half receive process complete callback. | |
static void | SPI_DMAHalfTransmitReceiveCplt (DMA_HandleTypeDef *hdma) |
DMA SPI half transmit receive process complete callback. | |
static void | SPI_DMAError (DMA_HandleTypeDef *hdma) |
DMA SPI communication error callback. | |
static void | SPI_DMAAbortOnError (DMA_HandleTypeDef *hdma) |
DMA SPI communication abort callback, when initiated by HAL services on Error (To be called at end of DMA Abort procedure following error occurrence). | |
static void | SPI_DMATxAbortCallback (DMA_HandleTypeDef *hdma) |
DMA SPI Tx communication abort callback, when initiated by user (To be called at end of DMA Tx Abort procedure following user abort request). | |
static void | SPI_DMARxAbortCallback (DMA_HandleTypeDef *hdma) |
DMA SPI Rx communication abort callback, when initiated by user (To be called at end of DMA Rx Abort procedure following user abort request). | |
static HAL_StatusTypeDef | SPI_WaitFlagStateUntilTimeout (SPI_HandleTypeDef *hspi, uint32_t Flag, uint32_t State, uint32_t Timeout, uint32_t Tickstart) |
Handle SPI Communication Timeout. | |
static void | SPI_TxISR_8BIT (struct __SPI_HandleTypeDef *hspi) |
Handle the data 8-bit transmit in Interrupt mode. | |
static void | SPI_TxISR_16BIT (struct __SPI_HandleTypeDef *hspi) |
Handle the data 16-bit transmit in Interrupt mode. | |
static void | SPI_RxISR_8BIT (struct __SPI_HandleTypeDef *hspi) |
Manage the receive 8-bit in Interrupt context. | |
static void | SPI_RxISR_16BIT (struct __SPI_HandleTypeDef *hspi) |
Manage the 16-bit receive in Interrupt context. | |
static void | SPI_2linesRxISR_8BIT (struct __SPI_HandleTypeDef *hspi) |
Rx 8-bit handler for Transmit and Receive in Interrupt mode. | |
static void | SPI_2linesTxISR_8BIT (struct __SPI_HandleTypeDef *hspi) |
Tx 8-bit handler for Transmit and Receive in Interrupt mode. | |
static void | SPI_2linesTxISR_16BIT (struct __SPI_HandleTypeDef *hspi) |
Tx 16-bit handler for Transmit and Receive in Interrupt mode. | |
static void | SPI_2linesRxISR_16BIT (struct __SPI_HandleTypeDef *hspi) |
Rx 16-bit handler for Transmit and Receive in Interrupt mode. | |
static void | SPI_RxISR_8BITCRC (struct __SPI_HandleTypeDef *hspi) |
Manage the CRC 8-bit receive in Interrupt context. | |
static void | SPI_RxISR_16BITCRC (struct __SPI_HandleTypeDef *hspi) |
Manage the CRC 16-bit receive in Interrupt context. | |
static void | SPI_2linesRxISR_8BITCRC (struct __SPI_HandleTypeDef *hspi) |
Rx 8-bit handler for Transmit and Receive in Interrupt mode. | |
static void | SPI_2linesRxISR_16BITCRC (struct __SPI_HandleTypeDef *hspi) |
Manage the CRC 16-bit receive for Transmit and Receive in Interrupt mode. | |
static void | SPI_AbortRx_ISR (SPI_HandleTypeDef *hspi) |
Handle abort a Tx or Rx transaction. | |
static void | SPI_AbortTx_ISR (SPI_HandleTypeDef *hspi) |
Handle abort a Tx or Rx transaction. | |
static void | SPI_CloseRxTx_ISR (SPI_HandleTypeDef *hspi) |
Handle the end of the RXTX transaction. | |
static void | SPI_CloseRx_ISR (SPI_HandleTypeDef *hspi) |
Handle the end of the RX transaction. | |
static void | SPI_CloseTx_ISR (SPI_HandleTypeDef *hspi) |
Handle the end of the TX transaction. | |
static HAL_StatusTypeDef | SPI_CheckFlag_BSY (SPI_HandleTypeDef *hspi, uint32_t Timeout, uint32_t Tickstart) |
Handle to check BSY flag before start a new transaction. | |
HAL_StatusTypeDef | HAL_SPI_Init (SPI_HandleTypeDef *hspi) |
Initialize the SPI according to the specified parameters in the SPI_InitTypeDef and initialize the associated handle. | |
HAL_StatusTypeDef | HAL_SPI_DeInit (SPI_HandleTypeDef *hspi) |
De Initialize the SPI peripheral. | |
__weak void | HAL_SPI_MspInit (SPI_HandleTypeDef *hspi) |
Initialize the SPI MSP. | |
__weak void | HAL_SPI_MspDeInit (SPI_HandleTypeDef *hspi) |
De-Initialize the SPI MSP. | |
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. | |
HAL_SPI_StateTypeDef | HAL_SPI_GetState (SPI_HandleTypeDef *hspi) |
Return the SPI handle state. | |
uint32_t | HAL_SPI_GetError (SPI_HandleTypeDef *hspi) |
Return the SPI error code. |
SPI HAL module driver. This file provides firmware functions to manage the following functionalities of the Serial Peripheral Interface (SPI) peripheral: + Initialization and de-initialization functions + IO operation functions + Peripheral Control functions + Peripheral State functions.
Using the HAL it is not possible to reach all supported SPI frequency with the differents SPI Modes, the following tables resume the max SPI frequency reached with data size 8bits/16bits, according to frequency used on APBx Peripheral Clock (fPCLK) used by the SPI instance :
DataSize = SPI_DATASIZE_8BIT: +----------------------------------------------------------------------------------------------+ | | | 2Lines Fullduplex | 2Lines RxOnly | 1Line | | Process | Tranfert mode |---------------------|----------------------|----------------------| | | | Master | Slave | Master | Slave | Master | Slave | |==============================================================================================| | T | Polling | Fpclk/2 | Fpclk/2 | NA | NA | NA | NA | | X |----------------|----------|----------|-----------|----------|-----------|----------| | / | Interrupt | Fpclk/4 | Fpclk/8 | NA | NA | NA | NA | | R |----------------|----------|----------|-----------|----------|-----------|----------| | X | DMA | Fpclk/2 | Fpclk/2 | NA | NA | NA | NA | |=========|================|==========|==========|===========|==========|===========|==========| | | Polling | Fpclk/2 | Fpclk/2 | Fpclk/64 | Fpclk/2 | Fpclk/64 | Fpclk/2 | | |----------------|----------|----------|-----------|----------|-----------|----------| | R | Interrupt | Fpclk/8 | Fpclk/8 | Fpclk/64 | Fpclk/2 | Fpclk/64 | Fpclk/2 | | X |----------------|----------|----------|-----------|----------|-----------|----------| | | DMA | Fpclk/2 | Fpclk/2 | Fpclk/64 | Fpclk/2 | Fpclk/128 | Fpclk/2 | |=========|================|==========|==========|===========|==========|===========|==========| | | Polling | Fpclk/2 | Fpclk/4 | NA | NA | Fpclk/2 | Fpclk/64 | | |----------------|----------|----------|-----------|----------|-----------|----------| | T | Interrupt | Fpclk/2 | Fpclk/4 | NA | NA | Fpclk/2 | Fpclk/64 | | X |----------------|----------|----------|-----------|----------|-----------|----------| | | DMA | Fpclk/2 | Fpclk/2 | NA | NA | Fpclk/2 | Fpclk/128| +----------------------------------------------------------------------------------------------+
DataSize = SPI_DATASIZE_16BIT: +----------------------------------------------------------------------------------------------+ | | | 2Lines Fullduplex | 2Lines RxOnly | 1Line | | Process | Tranfert mode |---------------------|----------------------|----------------------| | | | Master | Slave | Master | Slave | Master | Slave | |==============================================================================================| | T | Polling | Fpclk/2 | Fpclk/2 | NA | NA | NA | NA | | X |----------------|----------|----------|-----------|----------|-----------|----------| | / | Interrupt | Fpclk/4 | Fpclk/4 | NA | NA | NA | NA | | R |----------------|----------|----------|-----------|----------|-----------|----------| | X | DMA | Fpclk/2 | Fpclk/2 | NA | NA | NA | NA | |=========|================|==========|==========|===========|==========|===========|==========| | | Polling | Fpclk/2 | Fpclk/2 | Fpclk/64 | Fpclk/2 | Fpclk/32 | Fpclk/2 | | |----------------|----------|----------|-----------|----------|-----------|----------| | R | Interrupt | Fpclk/4 | Fpclk/4 | Fpclk/64 | Fpclk/2 | Fpclk/64 | Fpclk/2 | | X |----------------|----------|----------|-----------|----------|-----------|----------| | | DMA | Fpclk/2 | Fpclk/2 | Fpclk/64 | Fpclk/2 | Fpclk/128 | Fpclk/2 | |=========|================|==========|==========|===========|==========|===========|==========| | | Polling | Fpclk/2 | Fpclk/2 | NA | NA | Fpclk/2 | Fpclk/32 | | |----------------|----------|----------|-----------|----------|-----------|----------| | T | Interrupt | Fpclk/2 | Fpclk/2 | NA | NA | Fpclk/2 | Fpclk/64 | | X |----------------|----------|----------|-----------|----------|-----------|----------| | | DMA | Fpclk/2 | Fpclk/2 | NA | NA | Fpclk/2 | Fpclk/128| +----------------------------------------------------------------------------------------------+ [..] (@) The max SPI frequency depend on SPI data size (8bits, 16bits), SPI mode(2 Lines fullduplex, 2 lines RxOnly, 1 line TX/RX) and Process mode (Polling, IT, DMA). (@) (+@) TX/RX processes are HAL_SPI_TransmitReceive(), HAL_SPI_TransmitReceive_IT() and HAL_SPI_TransmitReceive_DMA() (+@) RX processes are HAL_SPI_Receive(), HAL_SPI_Receive_IT() and HAL_SPI_Receive_DMA() (+@) TX processes are HAL_SPI_Transmit(), HAL_SPI_Transmit_IT() and HAL_SPI_Transmit_DMA()
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of STMicroelectronics nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition in file stm32f4xx_hal_spi.c.