Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spi broken after fomu flash on raspberry pi #8

Open
mattvenn opened this issue Mar 27, 2020 · 3 comments
Open

spi broken after fomu flash on raspberry pi #8

mattvenn opened this issue Mar 27, 2020 · 3 comments

Comments

@mattvenn
Copy link

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
Copy link
Member

xobs commented Mar 28, 2020

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.

@mattvenn
Copy link
Author

mattvenn commented Mar 30, 2020 via email

@hstarmans
Copy link

hstarmans commented Aug 11, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants