STM32F4 SPI API

group STM32F4_HAL_SPI

Functions

static hal_spi_handle *hal_spi_get_handle(KSPINum spi)

Fetches SPI bus data structure.

Return
hal_spi_handle* pointer to data structure
Parameters
  • spi: SPI bus num to fetch

static hal_spi_handle *hal_spi_device_init(KSPI *spi)

Initializes SPI bus structure with data needed to setup hardware.

Return
hal_spi_handle* NULL if bad bus num, otherwise data ready for dev setup
Parameters
  • spi: higher level HAL SPI data

static KSPIStatus hal_spi_hw_init(hal_spi_handle *handle)

Initializes the SPI according to the specified parameters in the configuration and creates the associated handle.

Return
KSPIStatus SPI_OK if success, otherwise a specific error flag
Parameters

static void hal_spi_terminate(hal_spi_handle *handle)

SPI hardware cleanup and disabling.

Parameters

static void hal_spi_gpio_init(hal_spi_handle *handle)

Initializes the SPI bus pins.

Parameters

KSPIStatus kprv_spi_dev_init(KSPINum spi_num)

Setup and enable SPI bus.

Return
KSPIStatus SPI_OK if success, otherwise a specific error flag
Parameters
  • spi_num: SPI bus to initialize

KSPIStatus kprv_spi_dev_terminate(KSPINum spi)

SPI hardware cleanup and disabling.

Return
KSPIStatus SPI_OK if success, otherwise a specific error flag
Parameters
  • spi: bus num to terminate

KSPIStatus kprv_spi_write(KSPINum spi, uint8_t *buffer, uint32_t len)

Write data over SPI bus.

Return
KSPIStatus SPI_OK on success, otherwise failure
Parameters
  • spi: SPI bus to write to
  • buffer: pointer to data buffer
  • len: length of data to write

KSPIStatus kprv_spi_read(KSPINum spi, uint8_t *buffer, uint32_t len)

Read data over SPI bus.

Return
KSPIStatus SPI_OK on success, otherwise failure
Parameters
  • spi: SPI bus to read from
  • buffer: pointer to data buffer
  • len: length of data to read

KSPIStatus kprv_spi_write_read(KSPINum spi, uint8_t *txBuffer, uint8_t *rxBuffer, uint32_t len)

Write and read data over SPI bus.

Return
KSPIStatus SPI_OK on success, otherwise failure
Parameters
  • spi: SPI bus to write to
  • txBuffer: pointer to data buffer to write from
  • rxBuffer: pointer to data buffer to read into
  • len: length of data to write and read

Variables

hal_spi_handle hal_spi_dev[K_NUM_SPI]

Static array of SPI bus handles.

uint32_t spi_timeout = 1000

Default SPI request timeout value.

struct hal_spi_pins
#include <spi.h>

Structure defining pins for SPI device.

Public Members

uint16_t miso

Master-In Slave-Out.

uint16_t mosi

Master-Out Slave-In.

uint16_t sck

Clock.

GPIO_TypeDef *port

STM32CubeF4 GPIO port.

uint16_t alt

Alternate pin setting.

struct hal_spi_handle
#include <spi.h>

Structure for SPI device.

Public Members

KSPI *kspi

KubOS-HAL structure.

SPI_HandleTypeDef hal_handle

STM32CubeF4’s special structure.

hal_spi_pins pins

SPI pins struct.