Utilities to work with Fomu, as attached to a Raspberry Pi
Go to file
2019-02-25 22:17:38 +08:00
.gitignore fomu-flash: first full commit 2018-11-28 13:19:51 -05:00
fomu-flash.c fomu-flash: add -l (rom) option to load a rom 2019-02-25 13:51:27 +08:00
fpga.c fomu-flash: first full commit 2018-11-28 13:19:51 -05:00
fpga.h fomu-flash: first full commit 2018-11-28 13:19:51 -05:00
ice40.c ice40: lower fuzz size to improve patcher reliability 2019-02-25 22:16:31 +08:00
ice40.h ice40: convert from dos to unix line endings 2019-02-25 18:38:53 +08:00
LICENSE documentation: add readme and license file 2018-12-17 22:09:00 +08:00
Makefile fomu-flash: first full commit 2018-11-28 13:19:51 -05:00
pinout.png README: add pinout and connection instructions 2019-01-02 18:37:25 +08:00
README.md Merge branch 'master' into hardware-spi 2019-02-25 17:10:11 +08:00
rpi.c initial commit 2018-11-28 10:52:27 -05:00
rpi.h initial commit 2018-11-28 10:52:27 -05:00
spi.c erase the security register pages before writing 2019-01-13 20:01:51 -05:00
spi.h enable capacity overriding 2018-12-19 00:00:25 -05:00

Fomu FPGA Tools

The EVT version of Fomu is a "stretch" PCB with a Raspberry Pi header. Additionally, the factory test jig for production versions of Fomu has pins that match up with a test jig with the same pinout.

These tools can be used to control an FPGA and its accompanying SPI flash chip.

Building

To build this repository, simply run make.

Test Jig Setup

The EVT boards can be attached directly to the Raspberry Pi as a "hat". When building a test jig, attach wires according to the following image:

Raspberry Pi Pinout

The only pins that are required are 5V, GND, CRESET, SPI_MOSI, SPI_MISO, SPI_CLK, and SPI_CS.

The Pi's hardware SPI interface must be enabled in the kernel- use raspi-config or add dtparam=spi=on to /boot/config.txt and reboot before using. You can improve performance by attaching SPI_IO2 and SPI_IO3 and running fomu-flash in quad/qpi mode by specifying -t 4 or -t q.

You can get serial interaction by connecting the UART pins, but they are not necessary for flashing.

Loading a Bitstream

The most basic usecase is to load a program into configuration RAM. This is a very quick process, and can be used for rapid prototyping.

To load top.bin, use the -f argument:

# ./fomu-flash -f top.bin

This will reset the FPGA, reset the SPI flash, load the bitstream into the FPGA, and then start running the program.

Programming SPI Flash

To write a binary file to SPI flash, use -w:

# ./fomu-flash -w top.bin   # Write top.bin to SPI Flash
# ./fomu-flash -r           # Reset the FPGA

This will erase just enough of the SPI to hold the new binary file, then flash the binary to SPI.

It will not reset the FPGA. To do that, you must re-run with -r.

Verifying SPI flash

You can verify the SPI flash was programmed with the -v command:

# ./tomu-flash -v top.bin

Checking SPI Flash was Written

You can "peek" at 256 bytes of SPI with -p [offset]. This can be used to quickly verify that something was written.

Patching ROM

fomu-flash supports patching ROM. To do this, you must synthesize your bitstream with a fixed random ROM contents. This is so fomu-flash has something to look for.

The Python code for this would look like:

def xorshift32(x):
    x = x ^ (x << 13) & 0xffffffff
    x = x ^ (x >> 17) & 0xffffffff
    x = x ^ (x << 5)  & 0xffffffff
    return x & 0xffffffff

def get_rand(x):
    out = 0
    for i in range(32):
        x = xorshift32(x)
        if (x & 1) == 1:
            out = out | (1 << i)
    return out & 0xffffffff

def get_bit(x):
    return (256 * (x & 7)) + (x >> 3)

And the corresponding C code looks like:

uint32_t xorshift32(uint32_t x)
{
	/* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
	x = x ^ (x << 13);
	x = x ^ (x >> 17);
	x = x ^ (x << 5);
	return x;
}

uint32_t get_rand(uint32_t x) {
    uint32_t out = 0;
    int i;
    for (i = 0; i < 32; i++) {
        x = xorshift32(x);
        if ((x & 1) == 1)
            out = out | (1 << i);
    }
    return out;
}

static uint32_t fill_rand(uint32_t *bfr, int count) {
    int i;
    uint32_t last = 1;
    for (i = 0; i < count / 4; i++) {
        last = get_rand(last);
        bfr[i] = last;
    }
    return i;
}

Currently, fomu-flash only supports 8192-byte ROMs, though there is no reason why it can't be extended to other sizes.

Specify a ROM to load on the command line with -l.