emeb / spi_fiend

STM32F042-based USB to SPI device for programming iCE40 FPGAs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spi_fiend

STM32F042-based USB to SPI device for programming iCE40 FPGAs

board

Most open-source projects that use Lattice iCE40 FPGAs rely on the FTDI FT2232 High-speed UART/FIFO chip to provide a SPI interface for programming the FPGA and SPI Flash chip which contains the bitstream for self-configuration at power-up. I've got nothing against FTDI, but the chips are big, require a crystal and are fairly expensive in DIY quantities. On top of that I've been using STM32 for years and have been looking for an excuse to dig into some more USB applications so a USB to SPI bridge seemed like a good place to start.

This device uses the small and inexpensive STM32F042F6P6 in a 20-pin TSSOP package. It supports crystal-less USB operation by syncing its internal RC oscillator to the USB SOF signal and has enough SRAM and Flash to support a moderately complex feature set:

  • USB powered
  • Crystal-less operation
  • Presents an ordinary ACM / CDC class device that looks like a serial port.
  • Supports direct loading into the iCE40 SRAM for quick development cycles.
  • Supports read/write/erase of standard SPI Flash devices used for FPGA configuration.
  • Includes automatic swapping of MOSI/MISO when switching between FPGA and SPI Flash.
  • MCU Serial port is pinned out for debugging and future expansion.

prerequisites

To build this you will need the following tools:

Building Hardware

The board design is available in the 'hardware' directory. The Kicad PCB can be submitted directly to OSHpark.com, or traditional Gerbers can be exported using the application. Part values and packages are noted in the schematic.

Note: in the Revision 1 PCB layout the USB connector doesn't overhang the PCB edge and there is a slight interference with the lower lip. Filing a slight chamfer on the PCB edge under the connector will allow it to sit flush to the board.

Building Firmware

The Firmware README has instructions on building the preferred firmware for the SPI Fiend.

Building Host Application

The host appliction runs on a Linux PC and communicates with the hardware device via standard USB Serial protocols. Build the host application by changing to the 'host' directory and executing 'make'. The built-in help should provide a guide to available options, but here's a quick list of common actions:

  • load a binary into the FPGA: ./cdc_prog BINARY_FILE
  • load a binary into SPI Flash: ./cdc_prog -a ADDRESS -w BINARY_FILE
  • read SPI flash contents to a file: ./cdc_prog -a ADDRESS -l LENGTH -r > OUTPUT_FILE
  • erase SPI FLASH block: ./cdc_prog -a ADDRESS -e
  • read SPI Flash ID: ./cdc_prog -i

In ordinary operation, the LED nearest the USB connector lights to indicate powerup, the center LED lights when an error is detected during operation and the outer LED lights when programming SPI flash.

Status

2019-05-06

Initial commit with hardware, firmware and host application

2022-11-11

Updated with dual firmware that supports FPGA, flash and UART

About

STM32F042-based USB to SPI device for programming iCE40 FPGAs

License:MIT License


Languages

Language:C 99.8%Language:Assembly 0.2%Language:Makefile 0.1%