im-tomu / fomu-flash

Utilities to flash Fomu from a Raspberry Pi
BSD 3-Clause "New" or "Revised" License
18 stars 9 forks source link

spi broken after fomu flash on raspberry pi #8

Open mattvenn opened 4 years ago

mattvenn commented 4 years ago

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 4 years ago

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 1b0feb297f2946508b3ded7235d9a22f4bbec0da. 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.

mattvenn commented 4 years ago

interesting, thanks for the details!

On Sat, 28 Mar 2020 at 02:26, Sean Cross notifications@github.com wrote:

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 https://github.com/im-tomu/fomu-flash/commit/1b0feb297f2946508b3ded7235d9a22f4bbec0da. 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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/im-tomu/fomu-flash/issues/8#issuecomment-605374699, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE223BU3IBOIC4DS4CKFJ3RJVG3VANCNFSM4LVETSUQ .

-- Matthew Venn web mattvenn.net twitter @matthewvenn https://twitter.com/matthewvenn

hstarmans commented 3 years ago

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)