spi-analyzer

CLI reference

glasgow run spi-analyzer

Capture transactions on the SPI bus.

SPI data is captured in a clock domain driven by the SCK pin and reset by the CS# pin. This approach enables capturing data at very high SCK frequencies (up to 100 MHz), but requires a small delay between the last SCK rising edge and CS# rising edge, otherwise the last byte of a transaction will not be captured correctly. Typically, SPI controllers do provide this delay.

Signal integrity is exceptionally important for this applet. When using flywires, twist every signal wire (at the very least, CS# and SCK wires) with a ground wire connected to ground at both ends, otherwise the captured data will likely be nonsense.

The capture file format is Comma Separated Values, in one of the following line formats:

  • <COPI>,<CIPO>, where <COPI> and <CIPO> are hexadecimal byte sequences with each eight bits corresponding to samples of COPI and CIPO, respectively (from MSB to LSB); this format is used if one CS# pin is provided.

  • <CS>,<COPI>,<CIPO>, where <CS> is a 0-based CS# pin index and <COPI> and <CIPO> are the same as above; this format is used if multiple CS# pins are provided.

If your DUT is a 25-series SPI Flash memory, use the tool memory-25q to extract data from capture files. If quad-IO commands are in use, use the qspi-analyzer applet to capture data.

usage: glasgow run spi-analyzer [-h] [-V VOLTS] [--cs PINS] [--sck PIN]
                                [--copi PIN] [--cipo PIN]
                                [--buffer-size BYTES]
                                [FILE]
file

save communications to FILE as pairs of hex sequences

-h, --help

show this help message and exit

-V <volts>, --voltage <volts>

bus power (voltage reference of the inputs) (range: 1.8..5 V, or ‘S<port>’ to follow the voltage sensed on a port; default: unchanged)

--cs <pins>

bind chip selects to PINS (default: ‘A0’, required)

--sck <pin>

bind serial clock to PIN (default: ‘A1’, required)

--copi <pin>

bind controller out, peripheral in to PIN (default: ‘A2’, required)

--cipo <pin>

bind controller in, peripheral out to PIN (default: ‘A3’, required)

--buffer-size <bytes>

set FPGA trace buffer size to BYTES (must be power of 2, default: 16384)

API reference

exception glasgow.applet.interface.spi_analyzer.SPIAnalyzerOverflow
class glasgow.applet.interface.spi_analyzer.SPIAnalyzerPorts(*, supply: glasgow.abstract.GlasgowSupply, cs: amaranth.lib.io.PortLike, sck: amaranth.lib.io.PortLike, copi: amaranth.lib.io.PortLike, cipo: amaranth.lib.io.PortLike)
supply: GlasgowSupply

bus power (voltage reference of the inputs)

cs: PortLike

chip selects

sck: PortLike

serial clock

copi: PortLike

controller out, peripheral in

cipo: PortLike

controller in, peripheral out

class glasgow.applet.interface.spi_analyzer.SPIAnalyzerInterface(logger: Logger, assembly: AbstractAssembly, ports: SPIAnalyzerPorts, *, buffer_size=512)
async capture() → tuple[int, bytes, bytes]

Capture a transaction.

Returns a 3-tuple (chip, copi, cipo), where chip is the chip select index, copi are bytes transmitted from controller to peripheral, and cipo are bytes transmitted from peripheral to controller.

Raises:

SPIAnalyzerOverflow – When the FPGA buffer overflows. The last few transactions before the overflow occurred may be dropped as well.