SPI

[中文]

1. Overview

BK7258 provides two SPI controllers (three pin groups for SPI0, one for SPI1). Supports master/slave, 3-wire or 4-wire full-duplex transfers. Typical peripherals include external flash, LCD, and sensors.

See: SPI Driver Guide

2. Code Path

  • CLI: components/bk_cli/cli_spi.c

  • Driver: middleware/driver/spi/spi_driver.c and middleware/driver/spi/spi_flash.c

3. Configuration

Macros for enabling SPI, DMA, statistics dump, TX FIFO ready interrupt, low-power votes, and SPI flash support (CONFIG_SPI etc.).

4. Pins

SPI0 pin groups (choose one):

Function

Group 0

Group 1

Group 2

CLK CS MOSI MISO

GPIO14 GPIO15 GPIO16 GPIO17

GPIO44 GPIO45 GPIO46 GPIO47

GPIO33 GPIO34 GPIO35 GPIO36

SPI1 pins (group 0): CLK GPIO2, CS GPIO3, MOSI GPIO4, MISO GPIO5.

Default settings in hal/spi_ll.h select GPIO14–17 for SPI0; alternate pin sets are commented.

5. CLI Commands

SPI CLI commands

Command

Param

Description

spi_driver {init|deinit}

init/deinit

Initialize or release SPI resources

spi {id} init <role> <bit> <pol> <pha> <wire> <baud> <order> <dma>

id: 0–1; role: master/slave; bit: 8/16; pol/pha: CPOL/CPHA; wire: 3/4-wire; baud: baud rate; order: MSB/LSB; dma: DMA mode

Configure SPI working parameters

spi_config {id} ...

baud_rate, mode, bit_width, wire_mode, bit_order

Adjust parameters after initialization

spi {id} {read|write} <len>

id: 0–1; len: bytes

Transfer data through SPI

Supported baud rates (from source clock divisors) include 26 MHz, 13 MHz, 6.5 MHz, 5.2 MHz, 3.25 MHz, etc.

Mode ↔ CPOL/CPHA mapping:

Mode

CPOL

CPHA

0 1 2 3

0 0 1 1

0 1 0 1

6. Demo

  1. Wire two BK7258 boards via CON4 (share ground). Example pin mapping (SCK P44, CS P45, MOSI P46, MISO P47).

  2. Initialize driver on each board (add cpu1 prefix for AP commands).

    • Master: spi_driver init then spi 0 init master 8 1 1 4 10000000 MSB 1

    • Slave: spi_driver init then spi 0 init slave 8 1 1 4 10000000 MSB 1

  3. Start transfers:

    • Slave waits: spi 0 read 1024

    • Master writes: spi 0 write 1024

  4. Slave output logs show received buffer contents (0x00 … 0xFF).