Functions
Peripheral State and Errors functions
Peripheral Driver » HAL Driver » SPI » Functions

SPI control functions. More...

## Functions
hal_spi_state_t | hal_spi_get_state (spi_handle_t *p_spi)
| Return the SPI handle state. More...
uint32_t | hal_spi_get_error (spi_handle_t *p_spi)
| Return the SPI error code. More...
void | hal_spi_set_timeout (spi_handle_t *p_spi, uint32_t timeout)
| Set the SPI internal process timeout value. More...
hal_status_t | hal_spi_set_tx_fifo_threshold (spi_handle_t *p_spi, uint32_t threshold)
| Set the TX FIFO threshold. More...
hal_status_t | hal_spi_set_rx_fifo_threshold (spi_handle_t *p_spi, uint32_t threshold)
| Set the RX FIFO threshold. More...
uint32_t | hal_spi_get_tx_fifo_threshold (spi_handle_t *p_spi)
| Get the TX FIFO threshold. More...
uint32_t | hal_spi_get_rx_fifo_threshold (spi_handle_t *p_spi)
| Get the RX FIFO threshold. More...
hal_status_t | hal_spi_suspend_reg (spi_handle_t *p_spi)
| Suspend some registers related to SPI configuration before sleep. More...
hal_status_t | hal_spi_resume_reg (spi_handle_t *p_spi)
| Restore some registers related to SPI configuration after sleep. This function must be used in conjunction with the hal_spi_suspend_reg(). More...
hal_spi_state_t | hal_spi_v2_get_state (spi_handle_t *p_spi)
| Return the SPI handle state. More...
uint32_t | hal_spi_v2_get_error (spi_handle_t *p_spi)
| Return the SPI error code. More...
void | hal_spi_v2_set_timeout (spi_handle_t *p_spi, uint32_t timeout)
| Set the SPI internal process timeout value. More...
uint32_t | hal_spi_v2_get_tx_fifo_threshold (spi_handle_t *p_spi)
| Get the TX FIFO threshold. More...
uint32_t | hal_spi_v2_get_rx_fifo_threshold (spi_handle_t *p_spi)
| Get the RX FIFO threshold. More...
hal_status_t | hal_spi_v2_suspend_reg (spi_handle_t *p_spi)
| Suspend some registers related to SPI configuration before sleep. More...
hal_status_t | hal_spi_v2_resume_reg (spi_handle_t *p_spi)
| Restore some registers related to SPI configuration after sleep. This function must be used in conjunction with the hal_spi_suspend_reg(). More...
hal_status_t | hal_spi_v2_transmit_dma_with_toggle (spi_handle_t *p_spi, uint32_t data_size, uint8_t *p_data, uint32_t length)
| Using DMA to Transmit data by toggling CS in every data beat. More...

## Detailed Description

SPI control functions.

     ===============================================================================
                          ##### Peripheral State and Errors functions #####
     ===============================================================================
        [..]
        This subsection provides a set of functions allowing to control the SPI.
         (+) hal_spi_get_state() API can be helpful to check in run-time the state of the SPI peripheral
         (+) hal_spi_get_error() check in run-time Errors occurring during communication
         (+) hal_spi_set_timeout() set the timeout during internal process
         (+) hal_spi_set_tx_fifo_threshold() set the TX FIFO Threshold
         (+) hal_spi_set_rx_fifo_threshold() set the RX FIFO Threshold
         (+) hal_spi_get_tx_fifo_threshold() get the TX FIFO Threshold
         (+) hal_spi_get_rx_fifo_threshold() get the RX FIFO Threshold

     ===============================================================================
                          ##### Peripheral State and Errors functions #####
     ===============================================================================
        [..]
        This subsection provides a set of functions allowing to control the SPI.
         (+) hal_spi_get_state() API can be helpful to check in run-time the state of the SPI peripheral
         (+) hal_spi_get_error() check in run-time Errors occurring during communication
         (+) hal_spi_set_timeout() set the timeout during internal process
         (+) hal_spi_get_tx_fifo_threshold() get the TX FIFO Threshold
         (+) hal_spi_get_rx_fifo_threshold() get the RX FIFO Threshold

## Function Documentation

## ◆ hal_spi_get_error()

uint32_t hal_spi_get_error | ( | spi_handle_t * | p_spi | ) |

Return the SPI error code.

Parameters

  [in] | p_spi | Pointer to an SPI handle which contains the configuration information for the specified SPI module.

Returns
  SPI error code in bitmap format

## ◆ hal_spi_get_rx_fifo_threshold()

uint32_t hal_spi_get_rx_fifo_threshold | ( | spi_handle_t * | p_spi | ) |

Get the RX FIFO threshold.

Parameters

  [in] | p_spi | Pointer to an SPI handle which contains the configuration information for the specified SPI module.

Returns
  RX FIFO threshold

## ◆ hal_spi_get_state()

hal_spi_state_t hal_spi_get_state | ( | spi_handle_t * | p_spi | ) |

Return the SPI handle state.

Parameters

  [in] | p_spi | Pointer to an SPI handle which contains the configuration information for the specified SPI module.

Return values

  HAL_SPI_STATE_RESET | Peripheral not initialized.
  HAL_SPI_STATE_READY | Peripheral initialized and ready for use.
  HAL_SPI_STATE_BUSY | An internal process is ongoing.
  HAL_SPI_STATE_BUSY_TX | Data Transmission process is ongoing.
  HAL_SPI_STATE_BUSY_RX | Data Reception process is ongoing.
  HAL_SPI_STATE_BUSY_TX_RX | Data Transmission and Reception process is ongoing.
  HAL_SPI_STATE_ABORT | Peripheral with abort request ongoing.
  HAL_SPI_STATE_ERROR | Peripheral in error.

## ◆ hal_spi_get_tx_fifo_threshold()

uint32_t hal_spi_get_tx_fifo_threshold | ( | spi_handle_t * | p_spi | ) |

Get the TX FIFO threshold.

Parameters

  [in] | p_spi | Pointer to an SPI handle which contains the configuration information for the specified SPI module.

Returns
  TX FIFO threshold

## ◆ hal_spi_resume_reg()

hal_status_t hal_spi_resume_reg | ( | spi_handle_t * | p_spi | ) |

Restore some registers related to SPI configuration after sleep. This function must be used in conjunction with the hal_spi_suspend_reg().

Parameters

  [in] | p_spi | Pointer to a SPI handle which contains the configuration information for the specified SPI module.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_spi_set_rx_fifo_threshold()

hal_status_t hal_spi_set_rx_fifo_threshold | ( | spi_handle_t * | p_spi,
|  | uint32_t | threshold
| ) |  |

Set the RX FIFO threshold.

Parameters

  [in] | p_spi | Pointer to an SPI handle which contains the configuration information for the specified SPI module.
  [in] | threshold | RX FIFO threshold value ranging bwtween 0x0U ~ 0x7U.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_spi_set_timeout()

void hal_spi_set_timeout | ( | spi_handle_t * | p_spi,
|  | uint32_t | timeout
| ) |  |

Set the SPI internal process timeout value.

Parameters

  [in] | p_spi | Pointer to an SPI handle which contains the configuration information for the specified SPI module.
  [in] | timeout | Internal process timeout value.

## ◆ hal_spi_set_tx_fifo_threshold()

hal_status_t hal_spi_set_tx_fifo_threshold | ( | spi_handle_t * | p_spi,
|  | uint32_t | threshold
| ) |  |

Set the TX FIFO threshold.

Parameters

  [in] | p_spi | Pointer to an SPI handle which contains the configuration information for the specified SPI module.
  [in] | threshold | TX FIFO threshold value ranging bwtween 0x0U ~ 0x7U.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_spi_suspend_reg()

hal_status_t hal_spi_suspend_reg | ( | spi_handle_t * | p_spi | ) |

Suspend some registers related to SPI configuration before sleep.

Parameters

  [in] | p_spi | Pointer to a SPI handle which contains the configuration information for the specified SPI module.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_spi_v2_get_error()

uint32_t hal_spi_v2_get_error | ( | spi_handle_t * | p_spi | ) |

Return the SPI error code.

Parameters

  [in] | p_spi | Pointer to an SPI handle which contains the configuration information for the specified SPI module.

Returns
  SPI error code in bitmap format

## ◆ hal_spi_v2_get_rx_fifo_threshold()

uint32_t hal_spi_v2_get_rx_fifo_threshold | ( | spi_handle_t * | p_spi | ) |

Get the RX FIFO threshold.

Parameters

  [in] | p_spi | Pointer to an SPI handle which contains the configuration information for the specified SPI module.

Returns
  RX FIFO threshold

## ◆ hal_spi_v2_get_state()

hal_spi_state_t hal_spi_v2_get_state | ( | spi_handle_t * | p_spi | ) |

Return the SPI handle state.

Parameters

  [in] | p_spi | Pointer to an SPI handle which contains the configuration information for the specified SPI module.

Return values

  HAL_SPI_STATE_RESET | Peripheral not initialized.
  HAL_SPI_STATE_READY | Peripheral initialized and ready for use.
  HAL_SPI_STATE_BUSY | An internal process is ongoing.
  HAL_SPI_STATE_BUSY_TX | Data Transmission process is ongoing.
  HAL_SPI_STATE_BUSY_RX | Data Reception process is ongoing.
  HAL_SPI_STATE_BUSY_TX_RX | Data Transmission and Reception process is ongoing.
  HAL_SPI_STATE_ABORT | Peripheral with abort request ongoing.
  HAL_SPI_STATE_ERROR | Peripheral in error.

## ◆ hal_spi_v2_get_tx_fifo_threshold()

uint32_t hal_spi_v2_get_tx_fifo_threshold | ( | spi_handle_t * | p_spi | ) |

Get the TX FIFO threshold.

Parameters

  [in] | p_spi | Pointer to an SPI handle which contains the configuration information for the specified SPI module.

Returns
  TX FIFO threshold

## ◆ hal_spi_v2_resume_reg()

hal_status_t hal_spi_v2_resume_reg | ( | spi_handle_t * | p_spi | ) |

Restore some registers related to SPI configuration after sleep. This function must be used in conjunction with the hal_spi_suspend_reg().

Parameters

  [in] | p_spi | Pointer to a SPI handle which contains the configuration information for the specified SPI module.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_spi_v2_set_timeout()

void hal_spi_v2_set_timeout | ( | spi_handle_t * | p_spi,
|  | uint32_t | timeout
| ) |  |

Set the SPI internal process timeout value.

Parameters

  [in] | p_spi | Pointer to an SPI handle which contains the configuration information for the specified SPI module.
  [in] | timeout | Internal process timeout value.

## ◆ hal_spi_v2_suspend_reg()

hal_status_t hal_spi_v2_suspend_reg | ( | spi_handle_t * | p_spi | ) |

Suspend some registers related to SPI configuration before sleep.

Parameters

  [in] | p_spi | Pointer to a SPI handle which contains the configuration information for the specified SPI module.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_spi_v2_transmit_dma_with_toggle()

hal_status_t hal_spi_v2_transmit_dma_with_toggle | ( | spi_handle_t * | p_spi,
|  | uint32_t | data_size,
|  | uint8_t * | p_data,
|  | uint32_t | length
| ) |  |

Using DMA to Transmit data by toggling CS in every data beat.

Parameters

  [in] | p_spi | Pointer to a SPI handle which contains the configuration information for the specified SPI module.
  [in] | data_size | Optional value - SPI_DATASIZE_8BIT SPI_DATASIZE_16BIT SPI_DATASIZE_32BIT
  [in] | p_data | Pointer to data buffer
  [in] | length | Length of data to be sent

Returns
  Result of operation.