im-tomu/fomu-flash

spi broken after fomu flash on raspberry pi

mattvenn opened this issue · 3 comments

after flashing with fomu, this doesn't produce a clock on the spi clock pin:

./spidev_test -v -p "\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -D /dev/spidev0.1 -s 1000000

this works to fix it:

sudo rmmod spi_bcm2835
sudo modprobe spi_bcm2835

would be nice to avoid this if possible.

xobs commented

This is by design.

fomu-flash doesn't use spidev. This is because fomu-flash supports dual, quad, and qpi modes, and also because I ran into some kernel bugs when using it. Bitbanging the pins resulted in faster transfers and more reliable operations across multiple kernels and boards.

Now fomu-flash used to reset the pins, but that was changed in 1b0feb2. This is because the Pi drives pins such as SCLK, MOSI, and CE, which means the ICE40 will fight to drive those -- the Pi will drive SCLK high, and the FPGA will drive SCLK low, and you'll end up with both devices fighting.

Instead, we set them as INPUT, so you can reset the FPGA and have it actually boot.

Thanks for all the hard work on fomu-flash;
the procedure I have working now is;

sudo fomu-flash -w  bitstream_filename
sudo fomu-flash -r
sudo rmmod spi_bcm2835
sudo modprobe spi_bcm2835

All in all, great work but requesting "sudo privileges" for bitbanging some pins and hereafter also
requiring a modprobe for normal operation is not optimal. The SPI library is broken but does work with some tricks.

I typically use the following to set and write pins on rasp

#pragma once
#include <bcm2835.h>
#include <stdio.h>
#include <stdint.h>
#define INPUT BCM2835_GPIO_FSEL_INPT
#define INPUT_PULLUP BCM2835_GPIO_PUD_UP
#define INPUT_PULLDOWN BCM2835_GPIO_PUD_DOWN
#define OUTPUT BCM2835_GPIO_FSEL_OUTP

#define pinMode(PIN, MODE) bcm2835_gpio_fsel(PIN, MODE); if (MODE == (uint8_t)BCM2835_GPIO_PUD_UP || MODE == (uint8_t)BCM2835_GPIO_PUD_DOWN) bcm2835_gpio_set_pud(PIN, MODE)
#define digitalWrite(PIN, MODE) bcm2835_gpio_write(PIN, MODE)
#define digitalRead(PIN)  bcm2835_gpio_lev(PIN)