quasar_spi.h

This module configure SPI and provides functions to transmit and receive.

Copyright

Copyright (C) 2026 SPARK Microsystems International Inc. All rights reserved.

License

This source code is proprietary and subject to the SPARK Microsystems Software EULA found in this package in file EULA.txt.

Author

SPARK FW Team.

Defines

QUASAR_SPI_GET_SELECTED_HANDLE(spi_selection) ((SPI_HandleTypeDef *)(((spi_selection) <= QUASAR_SPI_SELECTION_SPI3) ? spi_handle_table[(spi_selection)] : NULL))

Return the handle from the selected SPI from quasar_spi_selection_t.

QUASAR_SPI_IS_BUSY(spi_selection) ((QUASAR_SPI_GET_SELECTED_HANDLE(spi_selection)->State != HAL_SPI_STATE_READY) ? true : false)

Return true is the spi is busy, false if not.

Typedefs

typedef enum quasar_spi_selection quasar_spi_selection_t

List of all available SPI instances.

typedef enum quasar_spi_clk_source quasar_spi_clk_source_t

List of all available clock sources for the SPI instances.

Note

From the reference manual:

  • 0b00 : PCLK1 -> set 0

  • 0b01 : SYSCLK -> set 1

  • 0b10 : HSI16 -> set 2

  • 0b11 : MSIK -> set 3

Note

The selected clock source must be initialized and activated before.

typedef enum quasar_spi_prescaler quasar_spi_prescaler_t

List of available SPI prescalers.

typedef struct quasar_spi_config quasar_spi_config_t

Quasar BSP SPI configuration.

Enums

enum quasar_spi_selection

List of all available SPI instances.

Values:

enumerator QUASAR_SPI_SELECTION_SPI1 = 0

Select the full feature SPI 1.

enumerator QUASAR_SPI_SELECTION_SPI2 = 1

Select the full feature SPI 2.

enumerator QUASAR_SPI_SELECTION_SPI3 = 2

Select the limited feature SPI 3.

enumerator _QUASAR_SPI_SELECTION_COUNT = 3

Indicate the number of possible SPI selection.

enum quasar_spi_clk_source

List of all available clock sources for the SPI instances.

Note

From the reference manual:

  • 0b00 : PCLK1 -> set 0

  • 0b01 : SYSCLK -> set 1

  • 0b10 : HSI16 -> set 2

  • 0b11 : MSIK -> set 3

Note

The selected clock source must be initialized and activated before.

Values:

enumerator QUASAR_SPI_CLK_SOURCE_PCLK1 = 0

Select PCLK1 as clock source.

enumerator QUASAR_SPI_CLK_SOURCE_SYSCLK = 1

Select SYSCLK as clock source.

enumerator QUASAR_SPI_CLK_SOURCE_HSI16 = 2

Select HSI16 as clock source.

enumerator QUASAR_SPI_CLK_SOURCE_MSIK = 3

Select MSIK as clock source.

enum quasar_spi_prescaler

List of available SPI prescalers.

Values:

enumerator QUASAR_SPI_PRESCALER_2 = SPI_BAUDRATEPRESCALER_2

Set the SPI prescaler to 2.

enumerator QUASAR_SPI_PRESCALER_4 = SPI_BAUDRATEPRESCALER_4

Set the SPI prescaler to 4.

enumerator QUASAR_SPI_PRESCALER_8 = SPI_BAUDRATEPRESCALER_8

Set the SPI prescaler to 8.

enumerator QUASAR_SPI_PRESCALER_16 = SPI_BAUDRATEPRESCALER_16

Set the SPI prescaler to 16.

enumerator QUASAR_SPI_PRESCALER_32 = SPI_BAUDRATEPRESCALER_32

Set the SPI prescaler to 32.

enumerator QUASAR_SPI_PRESCALER_64 = SPI_BAUDRATEPRESCALER_64

Set the SPI prescaler to 64.

enumerator QUASAR_SPI_PRESCALER_128 = SPI_BAUDRATEPRESCALER_128

Set the SPI prescaler to 128.

enumerator QUASAR_SPI_PRESCALER_256 = SPI_BAUDRATEPRESCALER_256

Set the SPI prescaler to 256.

Functions

void quasar_spi_init(quasar_spi_config_t spi_config, quasar_bsp_status_t *err)

Initialize the SPI peripheral.

Parameters:
  • spi_config[in] Configuration of the SPI peripheral.

  • err[out] Pointer to store error status.

void quasar_spi_deinit(quasar_spi_config_t spi_config, quasar_bsp_status_t *err)

Deinitialize the SPI peripheral and it’s associated GPIOs.

Parameters:
  • spi_config[in] Configuration of the SPI peripheral.

  • err[out] Pointer to store error status.

uint8_t quasar_spi_transmit(quasar_spi_selection_t spi_selection, uint8_t data)

Initiate a blocking SPI transmission for a specified SPI instance.

Parameters:
  • spi_selection[in] Selected SPI peripheral.

  • data[in] Data to be transmitted.

Returns:

HAL status.

uint8_t quasar_spi_receive(quasar_spi_selection_t spi_selection, uint8_t *data)

Initiate a blocking SPI reception for a specified SPI instance.

Parameters:
  • spi_selection[in] Selected SPI peripheral.

  • data[out] Data that have been received.

Returns:

HAL status.

void quasar_spi_transfer_full_duplex_blocking(quasar_spi_selection_t spi_selection, uint8_t *tx_data, uint8_t *rx_data, uint16_t data_size)

Initiate a blocking SPI full duplex transfer for a specified SPI instance.

Parameters:
  • spi_selection[in] Selected SPI peripheral.

  • tx_data[in] Data that have to be transmit.

  • rx_data[out] Data that have been received.

  • data_size[in] Size of the data, both received and transmitted.

void quasar_spi_transfer_full_duplex_non_blocking(quasar_spi_selection_t spi_selection, uint8_t *tx_data, uint8_t *rx_data, uint16_t data_size)

Initiate a non blocking SPI full duplex transfer for a specified SPI instance.

Parameters:
  • spi_selection[in] Selected SPI peripheral.

  • tx_data[in] Data that have to be transmit.

  • rx_data[out] Data that have been received.

  • data_size[in] Size of the data, both received and transmitted.

void quasar_spi_clear_cs(GPIO_TypeDef *gpio_port_cs, quasar_gpio_pin_t gpio_pin_cs)

Start a SPI transaction for a specified chip select.

Parameters:
  • gpio_port_cs[in] The reference HAL GPIO port for the chip select.

  • gpio_pin_cs[in] GPIO pin of the chip select.

void quasar_spi_set_cs(GPIO_TypeDef *gpio_port_cs, quasar_gpio_pin_t gpio_pin_cs)

Stop a SPI transaction for a specified chip select.

Parameters:
  • gpio_port_cs[in] The reference HAL GPIO port for the chip select.

  • gpio_pin_cs[in] GPIO pin of the chip select.

void quasar_spi_set_baudrate(quasar_spi_selection_t spi_selection, quasar_spi_prescaler_t prescaler, quasar_bsp_status_t *err)

Set the baudrate for a specified SPI.

Parameters:
  • spi_selection[in] Selected SPI.

  • prescaler[in] Prescaler value that has to be set.

  • err[out] Pointer to store error status.

Variables

SPI_HandleTypeDef *const spi_handle_table[]
struct quasar_spi_config
#include <quasar_spi.h>

Quasar BSP SPI configuration.

Public Members

quasar_spi_selection_t spi_selection

Selected SPI instance.

quasar_spi_prescaler_t spi_prescaler

Selected SPI prescaler.

quasar_gpio_config_t gpio_config_sck

Selected GPIO configuration used for SCK.

quasar_gpio_config_t gpio_config_mosi

Selected GPIO configuration used for MOSI.

quasar_gpio_config_t gpio_config_miso

Selected GPIO configuration used for MISO.

quasar_gpio_config_t gpio_config_ncs

Selected GPIO configuration used for chip select.

quasar_spi_clk_source_t clk_source

Selected clock source.