SPI
Full-duplex synchronous serial for fast peripherals — flash, displays, IMUs. core_spi is a blocking SPI master with software-managed chip-select; hal_spi and ll_spi sit underneath. Use the Core / HAL / LL toggle at the top of the sidebar to switch.
Overview
You pick an SPI instance (SPI1, …), a clock prescaler, and the clock polarity/phase (CPOL / CPHA — the four standard SPI modes). Chip-select is a regular GPIO you drive around each transaction, so one bus can address many devices.
Core.ST.L0 has no SPI). DMA is verified on L4; the newer SPI v2 IP on W5/H5 is still being brought up. The support matrix below has the specifics.Transfers
Init, point chip-select at a tile pad, then transact. transfer is one full-duplex byte (send and receive at once); xfer wraps a multi-byte transfer in select/deselect for you:
#include "core.h"
hal_spi_t spi;
hal_spi_config_t cfg = { .prescaler = LL_SPI_PRESCALER_8, .cpol = 0, .cpha = 0 };
core_spi_init(&spi, SPI1, &cfg);
core_spi_set_cs(&spi, 8); // chip-select on tile pad 8
core_spi_select(&spi);
uint8_t id = core_spi_transfer(&spi, 0x9F); // e.g. flash JEDEC ID
core_spi_deselect(&spi);
uint8_t tx[4] = { 0x03, 0, 0, 0 }, rx[4];
core_spi_xfer(&spi, tx, rx, sizeof(tx)); // select + xfer + deselectDMA transfers
For large transfers, hand the buffers to DMA and get a callback on completion — the CPU is free in the meantime. Both buffers must stay valid until the callback fires:
static void on_done(void *ctx) { /* transfer complete */ }
if (core_spi_xfer_dma(&spi, tx, rx, len, on_done, NULL) != HAL_OK) {
// busy or unsupported on this Core
}
while (core_spi_busy(&spi)) { /* or go do other work */ }Core.ST.L4; on the SPI v2 Cores it falls back or returns an error while the GPDMA path is finished.Cross-architecture support
Polling master transfers are the baseline on the Cores that have SPI; DMA and the SPI v2 bring-up vary. The same core_spi contract holds where the peripheral exists:
See the implementation status for the full matrix.
API reference
int core_spi_xfer_byte_bus(uint8_t bus, uint8_t cs_pad, uint8_t tx);hal_status_t core_spi_init(hal_spi_t * h, SPI_TypeDef * instance, const hal_spi_config_t * cfg);void core_spi_set_cs(hal_spi_t * h, uint8_t pad);void core_spi_select(hal_spi_t * h);void core_spi_deselect(hal_spi_t * h);uint8_t core_spi_transfer(hal_spi_t * h, uint8_t tx);void core_spi_write(hal_spi_t * h, const uint8_t * data, uint32_t len);void core_spi_read(hal_spi_t * h, uint8_t * buf, uint32_t len);void core_spi_xfer(hal_spi_t * h, const uint8_t * tx, uint8_t * rx, uint32_t len);hal_status_t core_spi_xfer_dma(hal_spi_t * h, const uint8_t * tx, uint8_t * rx, uint32_t len, hal_callback_t cb, void * ctx);int core_spi_busy(hal_spi_t * h);Generated from core_spi.h — tiles@d3cff63.

