Skip to main content

SPI Protocol Commands

Overview

  • Bus: SPI (serial peripheral interface)
  • Connections: four pins (CDO/CDI/CLK/CS) and ground
  • Output type: 1.65-5volts
  • Maximum voltage: 5volts

SPI is a common 4 wire full duplex protocol. Separate connections for data-in and data-out allow communication to and from the controller at the same time. Multiple sub devices can share the bus, but each will need an individual Chip Select (CS) connection. Chip Select is generally active when low.

Connections

Bus PirateDirectionCircuitDescription
MOSIMOSIMaster Out Sub In
MISOMISOMaster In Sub Out
CSCSChip Select
CLKCLKClock signal
GNDGNDSignal Ground

Configuration options

Bus Pirate [/dev/ttyS0]
SPI speed
1 to 62500KHz
x. Exit
KHz (100KHz*) >
Data bits
4 to 8 bits
x. Exit
Bits (8*) >
Clock polarity
1. Idle LOW*
2. Idle HIGH
x. Exit
Polarity (1) >
Clock phase
1. LEADING edge*
2. TRAILING edge
x. Exit
Phase (1) >
Chip select
1. Active HIGH (CS)
2. Active LOW (/CS)*
x. Exit
CS (2) >
Actual speed: 122KHz
Mode: SPI
SPI>

Syntax

CommandDescription
[Chip select (CS) active (low)
{CS active (low), show the SPI read byte after every write
] or }CS disable (high)
rRead one byte by sending dummy byte (0xff). (r:1…255 for bulk reads)
0bWrite this binary value. Format is 0b00000000 for a byte, but partial bytes are also fine: 0b1001.
0xWrite this HEX value. Format is 0x01. Partial bytes are fine: 0xA. A-F can be lower-case or capital letters.
0-255Write this decimal value. Any number not preceded by 0x or 0b is interpreted as a decimal value.
spaceValue delimiter. Use a space to separate numbers. No delimiter is required between non-number values: {0xa6 0 0 16 5 0b111 0xaF rrrr}.
(#)Run macro, (0) for macro list.

Macro

NumberDescription
0Macro menu

Commands

Bus Pirate 5 has global commands available everywhere, and mode commands specific to the currently selected mode. Type help to see all commands in every mode, or help mode for the currently available mode commands.

flash

The flash command can read, write, and erase common SPI flash memory chips directly in the Bus Pirate terminal. The Serial Flash Universal Driver at the heart of the flash command attempts to identify the flash chip and select the appropriate settings. Most modern flash chips contain SFDP tables that describe the chip capabilities. If a chip doesn't have SFDP tables, the driver has a database of common chips on which to fall back .

Help

Bus Pirate [/dev/ttyS0]
SPI> flash -h
usage:
flash [init|probe|erase|write|read|verify|test]
[-f(ile)] [-e(rase)] [-v(verify)] [-h(elp)]

Initialize and probe: flash probe
Erase and program, with verify: flash write -f example.bin -e -v
Read to file: flash read -f example.bin
Verify with file: flash verify -f example.bin
Test chip (full erase/write/verify): flash test
Force dump: flash read -o -b bytes -f file

read, write and erase flash chips using SFDP info if available
init Reset and initialize flash chip. Default if no options given. flash
probe Probe flash chip for ID and SFDP info. flash probe
erase Erase flash chip. flash erase [-v(erify)]
write Write file to flash chip. flash write -f file [-e(rase)] [-v(erify)]
read Read flash chip to file. flash read -f file
verify Verify flash chip against file. flash verify -f file
test Erase and write full chip with dummy data, verify. flash test
-f File flag. File to write, read or verify. flash verify -f file
-e Erase flag. Add erase before write. flash write -f file -e
-v Verify flag. Add verify after write or erase. flash write -f file -v
tip

Use flash -h to see the latest options and features.

Most Bus Pirate commands have help and usage examples. Add the -h flag to any command to see the available options and examples.

Options and flags

OptionDescription
flash initReset and initialize flash chip. Default if no options given.
flash probeProbe flash chip for ID and SFDP info.
flash eraseErase flash chip.
flash writeWrite file to flash chip. Specify file with -f flag. Use -e flag to erase before write
flash readRead flash chip to file. Specify file with -f flag
flash verifyVerify flash chip against file. Specify file with -f flag
flash testErase and write full chip with dummy data, verify.
FlagDescription
-fFile flag. File to write, read or verify.
-eErase flag. Add erase before write.
-vVerify flag. Add verify after write or erase.

Initialize and identify a flash chip

Bus Pirate [/dev/ttyS0]
SPI> flash init
Probing:
Device ID Manuf ID Type ID Capacity ID
RESID (0xAB) 0x13
REMSID (0x90) 0x13 0xef
RDID (0x9F) 0xef 0x40 0x14

Initializing SPI flash...
Flash device manufacturer ID 0xEF, type ID 0x40, capacity ID 0x14
SFDP V1.5, 0 parameter headers
Type Ver. Length Address
Table 0 JEDEC (0x00) 1.5 64B 0x000080
JEDEC basic flash parameter table info:
MSB-LSB 3 2 1 0
[0001] 0xFF 0xF1 0x20 0xE5
...
[0009] 0x00 0x00 0xD8 0x10
4 KB Erase is supported throughout the device (instruction 0x20)
Write granularity is 64 bytes or larger
Flash status register is non-volatile
3-Byte only addressing
Capacity is 1048576 Bytes
Flash device supports 4KB block erase (instruction 0x20)
Flash device supports 32KB block erase (instruction 0x52)
Flash device supports 64KB block erase (instruction 0xD8)
Found a Winbond flash chip (1048576 bytes)
Flash device reset success

flash, flash init, and flash probe provide various levels of details about a flash chip. The flash command tries three common methods to identify a flash chip (RESID, REMSID, RDID), then attempts to read the SFDP tables.

Read a flash chip

Bus Pirate [/dev/ttyS0]
SPI> flash read -f example.bin
Reading 1048576 bytes from flash to example.bin
[-------C o o o o o]

Read the contents of a flash chip to a file with the flash read command. The file name is specified with the -f flag.

Write a flash chip

Bus Pirate [/dev/ttyS0]
SPI> flash write -f example.bin -e -v
Erasing 1048576 bytes
[-----------------C]
Writing 1048576 bytes from example.bin to flash
[-----------------C]
Verifying 1048576 bytes from example.bin to flash
[-------c o o o o]

Write a file to a flash chip with the flash write command. The file name is specified with the -f flag. Use the -e flag to erase the chip before writing, and the -v flag to verify the write.

Verify a flash chip

Bus Pirate [/dev/ttyS0]
SPI> flash verify -f example.bin
Verifying 1048576 bytes from example.bin to flash
[-------c o o o o]

Verify the contents of a flash chip against a file with the flash verify command. The file name is specified with the -f flag.

Test a flash chip

Bus Pirate [/dev/ttyS0]
SPI> flash test
Erasing 1048576 bytes
[-----------------C]
Writing 1048576 bytes to flash
[-----------------C]
Verifying 1048576 bytes
[-------c o o o o]

The flash test command erases the chip, writes dummy data, and verifies the write. This is a way to test a chip.