bf0_hal_spi.h

Header file of SPI HAL module.

Author

Sifli software development team

Attention

Defines

HAL_SPI_ERROR_NONE

No error

HAL_SPI_ERROR_MODF

MODF error

HAL_SPI_ERROR_CRC

CRC error

HAL_SPI_ERROR_OVR

OVR error

HAL_SPI_ERROR_FRE

FRE error

HAL_SPI_ERROR_DMA

DMA transfer error

HAL_SPI_ERROR_FLAG

Error on RXNE/TXE/BSY/FTLVL/FRLVL Flag

HAL_SPI_ERROR_ABORT

Error during SPI Abort procedure

HAL_SPI_ERROR_UDR

Underrun error

HAL_SPI_ERROR_EOC

Endof dma chain

HAL_SPI_ERROR_PINT

Peripheral Trailing Byte

HAL_SPI_ERROR_RXTO

Receiver Time-out

HAL_SPI_ERROR_BCE

Bit Count Error

SPI_MODE_SLAVE
SPI_MODE_MASTER
SPI_DIRECTION_2LINES
SPI_DIRECTION_2LINES_RXONLY
SPI_DIRECTION_1LINE
SPI_DATASIZE_4BIT
SPI_DATASIZE_5BIT
SPI_DATASIZE_6BIT
SPI_DATASIZE_7BIT
SPI_DATASIZE_8BIT
SPI_DATASIZE_9BIT
SPI_DATASIZE_10BIT
SPI_DATASIZE_11BIT
SPI_DATASIZE_12BIT
SPI_DATASIZE_13BIT
SPI_DATASIZE_14BIT
SPI_DATASIZE_15BIT
SPI_DATASIZE_16BIT
SPI_POLARITY_LOW
SPI_POLARITY_HIGH
SPI_PHASE_1EDGE
SPI_PHASE_2EDGE
SPI_SFRMPOL_LOW
SPI_SFRMPOL_HIGH
SPI_BAUDRATE_PRESCALER_MAX

SPI_SFRM_POL

SPI_IT_TXE
SPI_IT_RXNE
SPI_IT_ERR
SPI_MSK_IT_ERR
SPI_FLAG_RXNE
SPI_FLAG_TXE
SPI_FLAG_BSY
SPI_FLAG_OVR
SPI_FLAG_UDR
SPI_FLAG_FTLVL
SPI_FLAG_FRLVL
SPI_FLAG_EXT
SPI_FTLVL_EMPTY
SPI_FTLVL_FULL
SPI_FRLVL_EMPTY
SPI_FRLVL_FULL
SPI_FRAME_FORMAT_SPI
SPI_FRAME_FORMAT_SSP
SPI_FRAME_FORMAT_NM
SPI_CRCCALCULATION_DISABLE
SPI_CRCCALCULATION_ENABLE
SPI_CRC_LENGTH_DATASIZE
SPI_CRC_LENGTH_8BIT
SPI_CRC_LENGTH_16BIT
SPI_RXFIFO_THRESHOLD
SPI_RXFIFO_THRESHOLD_QF
SPI_RXFIFO_THRESHOLD_HF
__HAL_SPI_RESET_HANDLE_STATE(__HANDLE__)

Reset SPI handle state.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

__HAL_SPI_IS_ENABLE_IT(__HANDLE__, __INTERRUPT__)

Return true if the specified SPI interrupts is enabled.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

  • __INTERRUPT__ – specifies the interrupt source to enable. This parameter can be one of the following values:

    • SPI_IT_TXE: Tx buffer empty interrupt enable

    • SPI_IT_RXNE: RX buffer not empty interrupt enable

    • SPI_IT_ERR: Error interrupt enable

返回值:

None

__HAL_SPI_ENABLE_IT(__HANDLE__, __INTERRUPT__)

Enable the specified SPI interrupts.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

  • __INTERRUPT__ – specifies the interrupt source to enable. This parameter can be one of the following values:

    • SPI_IT_TXE: Tx buffer empty interrupt enable

    • SPI_IT_RXNE: RX buffer not empty interrupt enable

    • SPI_IT_ERR: Error interrupt enable

返回值:

None

__HAL_SPI_DISABLE_IT(__HANDLE__, __INTERRUPT__)

Disable the specified SPI interrupts.

参数:
  • __HANDLE__ – specifies the SPI handle. This parameter can be SPIx where x: 1, 2, or 3 to select the SPI peripheral.

  • __INTERRUPT__ – specifies the interrupt source to disable. This parameter can be one of the following values:

    • SPI_IT_TXE: Tx buffer empty interrupt enable

    • SPI_IT_RXNE: RX buffer not empty interrupt enable

    • SPI_IT_ERR: Error interrupt enable

返回值:

None

__HAL_SPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)

Check whether the specified SPI interrupt source is enabled or not.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

  • __INTERRUPT__ – specifies the SPI interrupt source to check. This parameter can be one of the following values:

    • SPI_IT_TXE: Tx buffer empty interrupt enable

    • SPI_IT_RXNE: RX buffer not empty interrupt enable

    • SPI_IT_ERR: Error interrupt enable

返回值:

The – new state of IT (TRUE or FALSE).

__HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__)

Check whether the specified SPI flag is set or not.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

  • __FLAG__ – specifies the flag to check. This parameter can be one of the following values:

    • SPI_FLAG_RXNE: Receive buffer not empty flag

    • SPI_FLAG_TXE: Transmit buffer empty flag

    • SPI_FLAG_CRCERR: CRC error flag

    • SPI_FLAG_MODF: Mode fault flag

    • SPI_FLAG_OVR: Overrun flag

    • SPI_FLAG_BSY: Busy flag

    • SPI_FLAG_FRE: Frame format error flag

    • SPI_FLAG_FTLVL: SPI fifo transmission level

    • SPI_FLAG_FRLVL: SPI fifo reception level

返回值:

The – new state of FLAG (TRUE or FALSE).

__HAL_SPI_CLEAR_OVRFLAG(__HANDLE__)

Clear the SPI OVR pending flag.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

__HAL_SPI_CLEAR_FREFLAG(__HANDLE__)

Clear the SPI FRE pending flag.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

__HAL_SPI_CLEAR_UDRFLAG(__HANDLE__)

Clear the SPI UDR pending flag.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

__HAL_SPI_CLEAR_EXT_ERR_FLAG(__HANDLE__)

Clear the SPI extend error flag.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

__HAL_SPI_ENABLE(__HANDLE__)

Enable the SPI peripheral.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

__HAL_SPI_DISABLE(__HANDLE__)

Disable the SPI peripheral.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

__HAL_SPI_TAKE_CS(__HANDLE__)

Take SPI CS (to low).

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

__HAL_SPI_RELEASE_CS(__HANDLE__)

Release SPI CS (to high).

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

__HAL_SPI_CLEAR_MODFFLAG(__HANDLE__)

Clear the SPI MODF pending flag.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

SPI_1LINE_TX(__HANDLE__)

Set the SPI transmit-only mode.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

SPI_1LINE_RX(__HANDLE__)

Set the SPI receive-only mode.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

SPI_RESET_CRC(__HANDLE__)

Reset the CRC calculation of the SPI.

参数:
  • __HANDLE__ – specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.

返回值:

None

IS_SPI_MODE(MODE)
IS_SPI_DIRECTION(MODE)
IS_SPI_DIRECTION_2LINES(MODE)
IS_SPI_DIRECTION_2LINES_OR_1LINE(MODE)
IS_SPI_DATASIZE(DATASIZE)
IS_SPI_CPOL(CPOL)
IS_SPI_CPHA(CPHA)
IS_SPI_FRAME_FORMAT(MODE)
IS_SPI_SFRMPOL(SFRMPOL)
IS_SPI_CRC_CALCULATION(CALCULATION)
IS_SPI_CRC_LENGTH(LENGTH)
IS_SPI_CRC_POLYNOMIAL(POLYNOMIAL)
IS_SPI_DMA_HANDLE(HANDLE)
IS_SPI_16BIT_ALIGNED_ADDRESS(DATA)
IS_SPI_ALL_INSTANCE(__INSTANCE__)
IS_SPI_BAUDRATE_PRESCALER(PRESCALER)

Typedefs

typedef struct __SPI_HandleTypeDef SPI_HandleTypeDef

SPI handle Structure definition.

Enums

enum HAL_SPI_StateTypeDef

HAL SPI State structure definition.

Values:

enumerator HAL_SPI_STATE_RESET

Peripheral not Initialized

enumerator HAL_SPI_STATE_READY

Peripheral Initialized and ready for use

enumerator HAL_SPI_STATE_BUSY

an internal process is ongoing

enumerator HAL_SPI_STATE_BUSY_TX

Data Transmission process is ongoing

enumerator HAL_SPI_STATE_BUSY_RX

Data Reception process is ongoing

enumerator HAL_SPI_STATE_BUSY_TX_RX

Data Transmission and Reception process is ongoing

enumerator HAL_SPI_STATE_ERROR

SPI error state

enumerator HAL_SPI_STATE_ABORT

SPI abort is ongoing

Functions

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.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

HAL – status

HAL_StatusTypeDef HAL_SPI_DeInit(SPI_HandleTypeDef *hspi)

De-Initialize the SPI peripheral.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

HAL – status

void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)

Initialize the SPI MSP.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

None

void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi)

De-Initialize the SPI MSP.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

None

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.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

  • pData – pointer to data buffer

  • Size – amount of data to be sent

  • Timeout – Timeout duration

返回值:

HAL – status

HAL_StatusTypeDef HAL_SPI_FlushRxFifo(SPI_HandleTypeDef *hspi)

Flush the RX fifo.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for the specified SPI module.

返回值:

HAL – status

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.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

  • pData – pointer to data buffer

  • Size – amount of data to be received

  • Timeout – Timeout duration

返回值:

HAL – status

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.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

  • pTxData – pointer to transmission data buffer

  • pRxData – pointer to reception data buffer

  • Size – amount of data to be sent and received

  • Timeout – Timeout duration

返回值:

HAL – status

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.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

  • pData – pointer to data buffer

  • Size – amount of data to be sent

返回值:

HAL – status

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.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

  • pData – pointer to data buffer

  • Size – amount of data to be sent

返回值:

HAL – status

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.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

  • pTxData – pointer to transmission data buffer

  • pRxData – pointer to reception data buffer

  • Size – amount of data to be sent and received

返回值:

HAL – status

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.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

  • pData – pointer to data buffer

  • Size – amount of data to be sent

返回值:

HAL – status

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.

备注

In case of MASTER mode and SPI_DIRECTION_2LINES direction, hdmatx shall be defined.

备注

When the CRC feature is enabled the pData Length must be Size + 1.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

  • pData – pointer to data buffer

  • Size – amount of data to be sent

返回值:

HAL – status

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.

备注

When the CRC feature is enabled the pRxData Length must be Size + 1

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

  • pTxData – pointer to transmission data buffer

  • pRxData – pointer to reception data buffer

  • Size – amount of data to be sent

返回值:

HAL – status

HAL_StatusTypeDef HAL_SPI_Abort(SPI_HandleTypeDef *hspi)

Abort ongoing transfer (blocking mode).

备注

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.

参数:
  • hspi – SPI handle.

返回值:

HAL – status

HAL_StatusTypeDef HAL_SPI_Abort_IT(SPI_HandleTypeDef *hspi)

Abort ongoing transfer (Interrupt mode).

备注

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).

参数:
  • hspi – SPI handle.

返回值:

HAL – status

HAL_StatusTypeDef HAL_SPI_DMAPause(SPI_HandleTypeDef *hspi)

Pause the DMA Transfer.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for the specified SPI module.

返回值:

HAL – status

HAL_StatusTypeDef HAL_SPI_DMAResume(SPI_HandleTypeDef *hspi)

Resume the DMA Transfer.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for the specified SPI module.

返回值:

HAL – status

HAL_StatusTypeDef HAL_SPI_DMAStop(SPI_HandleTypeDef *hspi)

Stop the DMA Transfer.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for the specified SPI module.

返回值:

HAL – status

void HAL_SPI_IRQHandler(SPI_HandleTypeDef *hspi)

Handle SPI interrupt request.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for the specified SPI module.

返回值:

None

void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)

Tx Transfer completed callback.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

None

void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)

Rx Transfer completed callback.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

None

void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)

Tx and Rx Transfer completed callback.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

None

void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi)

Tx Half Transfer completed callback.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

None

void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi)

Rx Half Transfer completed callback.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

None

void HAL_SPI_TxRxHalfCpltCallback(SPI_HandleTypeDef *hspi)

Tx and Rx Half Transfer callback.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

None

void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)

SPI error callback.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

None

void HAL_SPI_AbortCpltCallback(SPI_HandleTypeDef *hspi)

SPI Abort Complete callback.

参数:
  • hspi – SPI handle.

返回值:

None

HAL_SPI_StateTypeDef HAL_SPI_GetState(SPI_HandleTypeDef *hspi)

Return the SPI handle state.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

SPI – state

uint32_t HAL_SPI_GetError(SPI_HandleTypeDef *hspi)

Return the SPI error code.

参数:
  • hspi – pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module.

返回值:

SPI – error code in bitmap format

struct SPI_InitTypeDef
#include <bf0_hal_spi.h>

SPI Configuration Structure definition.

Public Members

uint32_t Mode

Specifies the SPI operating mode. This parameter can be a value of SPI Mode

uint32_t Direction

Specifies the SPI bidirectional mode state. This parameter can be a value of SPI Direction Mode

uint32_t DataSize

Specifies the SPI data size. This parameter can be a value of SPI Data Size

uint32_t CLKPolarity

Specifies the serial clock steady state. This parameter can be a value of SPI Clock Polarity

uint32_t CLKPhase

Specifies the clock active edge for the bit capture. This parameter can be a value of SPI Clock Phase

uint32_t BaudRatePrescaler

Specifies the Baud Rate prescaler value which will be used to configure the transmit and receive SCK clock.

备注

The communication clock is derived from the master clock. The slave clock does not need to be set.

uint32_t FrameFormat

Specifies the data format. This parameter can be a value of SPI data format

uint32_t SFRMPol

Specifies if the SPI mode frame synchronous signal (SFRMOUT / SFRMIN ) high or low. This parameter can be a value of SPI synchronous signal Polarity

struct __SPI_HandleTypeDef
#include <bf0_hal_spi.h>

SPI handle Structure definition.

Public Members

SPI_TypeDef *Instance

SPI registers base address

SPI_InitTypeDef Init

SPI communication parameters

uint8_t *pTxBuffPtr

Pointer to SPI Tx transfer Buffer

uint16_t TxXferSize

SPI Tx Transfer size

uint16_t TxXferCount

SPI Tx Transfer Counter

uint8_t *pRxBuffPtr

Pointer to SPI Rx transfer Buffer

uint16_t RxXferSize

SPI Rx Transfer size

uint16_t RxXferCount

SPI Rx Transfer Counter

uint32_t CRCSize

SPI CRC size used for the transfer

void (*RxISR)(struct __SPI_HandleTypeDef *hspi)

function pointer on Rx ISR

void (*TxISR)(struct __SPI_HandleTypeDef *hspi)

function pointer on Tx ISR

DMA_HandleTypeDef *hdmatx

SPI Tx DMA Handle parameters

DMA_HandleTypeDef *hdmarx

SPI Rx DMA Handle parameters

uint8_t core

SPI Clock core source

HAL_LockTypeDef Lock

Locking object

HAL_SPI_StateTypeDef State

SPI communication state

uint32_t ErrorCode

SPI Error code