HydraFW SPI guide - hydrabus/hydrafw GitHub Wiki

HydraFW Bus SPI (Serial Peripheral Interface)

This guide is updated towards firmware release HydraFW v0.11 and later

Connections: four pins (MOSI/MISO/CLOCK/CS) and ground(GND).
Output type: 3.3volt normal, or open drain
(pull up/pull down resistors integrated in MCU or external).
Pull-up resistors: required for open drain output mode (2K – 10K).
Pull-up/down resistors Integrated in MCU: Between 30 to 50K (Typical 40K).
Maximum voltage: 5.5volts (5volt safe).

Output type - open drain/open collector (high=Hi-Z, low=ground),
 normal (high=3.3volts, low=ground).
Use open drain/open collector output types with pull-up resistors
for multi-voltage interfacing.

Protocol configuration syntax description:

  • show Show SPI parameters or show pins Show pins used in this mode

  • device with parameter 1 or 2 to choose SPI device (1 or 2)

  • pull with parameter up or down or floating to choose internal MCU pull up/down or no pull/external

  • mode with parameter master or slave to choose master or slave SPI mode

  • frequency with floating frequency value: support k (for kHz), m (for MHz) suffix or no suffix (for Hz)

    • Frequencies available for SPI1: 320khz, 650khz, 1.31mhz, 2.62mhz, 5.25mhz, 10.5mhz, 21mhz, 42mhz
    • Frequencies available for SPI2: 160khz, 320khz, 650khz, 1.31mhz, 2.62mhz, 5.25mhz, 10.5mhz, 21mhz
  • polarity with parameter 0 or 1 for clock polarity value (also called CPOL/CKP)

  • phase with parameter 0 or 1 for clock phase value (also called Clock Edge or CKE/CPHA)

  • msb-first or lsb-first to send/receive respectively MSB first or LSB first.

  • exit to exit SPI mode

Note default value for device 1 or 2: 
For device 1 (SPI1):
> spi device 1
Note: SPI parameters have been reset to default values.
Device: SPI1
GPIO resistor: floating
Mode: master
Frequency: 320khz (650khz, 1.31mhz, 2.62mhz, 5.25mhz, 10.50mhz, 21mhz, 42mhz)
Polarity: 0
Phase: 0
Bit order: MSB first

For device 2 (SPI2):
> spi device 2
Note: SPI parameters have been reset to default values.
Device: SPI2
GPIO resistor: floating
Mode: master
Frequency: 160khz (320khz, 650khz, 1.31mhz, 2.62mhz, 5.25mhz, 10.50mhz, 21mhz)
Polarity: 0
Phase: 0
Bit order: MSB first

Configuration options:

Hardware Informations:

spi1> show pins
CS:   PA15
SCK:  PB3
MISO: PB4
MOSI: PB5

spi2> show pins
CS:   PC1 (SW)
SCK:  PB10
MISO: PC2
MOSI: PC3

Protocol configuration example:

Configuration of SPI1 650KHz(using internal MCU pull down):

> spi device 1
Note: SPI parameters have been reset to default values.
Device: SPI1
GPIO resistor: floating
Mode: master
Frequency: 320khz (650khz, 1.31mhz, 2.62mhz, 5.25mhz, 10.50mhz, 21mhz, 42mhz)
Polarity: 0
Phase: 0
Bit order: MSB first

spi1> pull down frequency 650k show
Device: SPI1
GPIO resistor: pull-down
Mode: master
Frequency: 650khz (320khz, 1.31mhz, 2.62mhz, 5.25mhz, 10.50mhz, 21mhz, 42mhz)
Polarity: 0
Phase: 0
Bit order: MSB first

Protocol interaction syntax description:

Bus interaction commands

trigger configures the trigger mode

cs-on or [ Chip select(CS) enable/active (low=state 0/GND).

cs-off or ] Chip select(CS) disable (high=state +3.3V).

Protocol interaction example usage SPI1 write/read:

spi1> [ 0xFF r ] [ 0 r ] [ 1 r ] [ 0x80 r ] [ 0x55 r 0xAA r 0xFF r 0x11:4 r:4 ]
/CS ENABLED
WRITE: 0xFF
READ: 0x00
/CS DISABLED
/CS ENABLED
WRITE: 0x00
READ: 0x00
/CS DISABLED
/CS ENABLED
WRITE: 0x01
READ: 0x00
/CS DISABLED
/CS ENABLED
WRITE: 0x80
READ: 0x00
/CS DISABLED
/CS ENABLED
WRITE: 0x55
READ: 0x00
WRITE: 0xAA
READ: 0x00
WRITE: 0xFF
READ: 0x00
WRITE: 0x11 0x11 0x11 0x11
READ: 0x00 0x00 0x00 0x00
/CS DISABLED

Flashrom usage

Since c10868f345027142b0bcea3c76b8ebd8c27d45c0, it is possible to use Hydrabus with Flashrom using the Serprog protocol.

  • Supported with any version of Flashrom since v0.9.8 or more (tested with success also with Flashrom v1.2 / v1.3)
  • flashrom v1.3 or more can be used with Windows (tested with success with Windows10) it just need to be rebuilt from source with MSYS2/MINGW64

Notes

  • Hydrabus will automatically switch to Serprog mode when running flashrom
  • Only SPI mode is available
  • Serprog mode uses SPI2
  • Hydrabus will stay in Serprog mode after flashrom exits. Either reset Hydrabus or press UBTN to return to console mode.
  • Changing SPI clock speed is supported since https://github.com/hydrabus/hydrafw/pull/124. Default speed is 21MHz

Example connection SPIFlash WINBOND W25Q16DV / HydraBus SPI2

SPI Flash WINBOND W25Q16DV HydraBus SPI2 Details
/CS Pin1 SPI2 CS: PC1 Chip Select
DO(IO1) Pin2 SPI2 MISO: PC2 SPI MISO
/WP(IO2) Pin3 3V3 Disable write protect
GND Pin4 GND
DI(IO0) Pin5 SPI2 MOSI: PC3 SPI MOSI
CLK Pin6 SPI2 SCK: PB10 SPI CLK
/HOLD (IO3) Pin7 3V3 Disable hold
VCC Pin8 3V3

Basic usage

flashrom -p serprog:dev=<serial port>

Advanced usage changing spispeed to 1.31MHz(2M rounded to nearest=>1.31MHz)

flashrom -p serprog:dev=<serial port>,spispeed=2M

Example1 output

Dump the content of a SPI EEPROM :

$ flashrom -p serprog:dev=/dev/hydrabus -r /tmp/dump.bin
flashrom v1.2 on Linux 5.8.3-arch1-1 (x86_64)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns).
serprog: Programmer name is "Hydrabus"
serprog: requested mapping AT45CS1282 is incompatible: 0x1080000 bytes at 0x00000000fef80000.
[...]
===
Found Unknown flash chip "SFDP-capable chip" (4096 kB, SPI) on serprog.
Reading flash... done.

For more information about flashrom usage, check out its man page : man flashrom

Additional informations about SPI

For more details on SPI protocol see: http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus