Previously posted on reddit (https://www.reddit.com/r/raspberry_pi/comments/9h1ve3/cant_program_spi_flash/)
I'm trying to program my ice40 HX8K. I am using a pi B+ ver2, which is offered as an alternate programming method on the wiki page for this board (https://www.olimex.com/wiki/ICE40HX1K-EVB#Iceprog_with_Raspberry_PI). These instructions are for the HX1K, so my connections are different.
GND | GND
GPIO 25 | iCE40-CRESET
CE0# | iCE40-SS_B
MOSI | iCE40-SDO
MISO | iCE40-SDI
SCLK | iCE40-SCK
The setup looks like this (https://i.imgur.com/CCZsDec.jpg). I can turn off/on the iCE40-CRESET LED using GPIO25, like in the guide. However, when I try to read the flash contents I get
$ flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=20000 -r dump.bin
flashrom v0.9.9-r1954 on Linux 4.9.41+ (armv6l)
flashrom is free software, get the source code at https://flashrom.org
Calibrating delay loop... OK.
No EEPROM/flash device found.
Note: flashrom can never write if the flash chip isn't found automatically.
I have checked all my connections, tried switching from CE0# to CE1#, tried switching MISO and MOSI, tried all /dev/spidev?.? devices, tried rewiring to use SPI1 (pins 36-40), tried different baud rates, tried building flashrom from source (instead of using the packaged version), and rebooted. I have also tried powering the board via the raspberry pi, and using a pi rev 3 B. The jumper cables have been checked. I have the spi interface enabled in /boot/config.txt. I first asked on #raspberrypi on freenode, and again on ##electronics, but they were out of ideas. Thanks in advance for any suggestions.
> These instructions are for the HX1K, so my connections are different.
I don't think your hardware connections should be different. The 1K and 8K boards have nearly identical programming connectors. Compare the programming connector in these PDFs:
Also the original project can be found here: https://github.com/anse1/olimex-ice40-notes
> I don't think your hardware connections should be different. The 1K and 8K boards have nearly identical programming connectors. Compare the programming connector in these PDFs:
Well it's more that the original instructions were for using IDC connectors and I am making the connection with jumper cables, as seen in the picture. Again, I have listed out the connections I made in the code box in the original post. I have checked them against the schematic for the HX8K and the pi.
I made another try today and got it working (not sure what changed...)
On the wiki, it is much easier to pad firmware by doing
truncate -s 2M image
Instead of remembering those dd incantations
I gave up on using 32u4 board because my version was 'A'. Changing the port numbers to match did not work plus the port jumped between /dev/ACM0 and /dev/ACM1 on board reset.
I configured a cable and flashrom software for a Pi 3B per the notes at the end of the Linux setup.
The files were modified in the ice40hx1k-evb for the ice40hx8k.evb.
Create an ice40hx8k-evb.pcf with the proper pin numbers:
set_io CLK J3
set_io BUT1 K11
set_io BUT2 P13
set_io LED1 M12
set_io LED2 R16
Modify the make file lines to target the 8k device:
PIN_DEF = ice40hx8k-evb.pcf
DEVICE = hx8k
perform the make, leaving you with an example.bin.
The .bin file generation is done my main Ubuntu system.
A Samba share on the Pi was used to transfer the bin to the Pi.
On the Pi side, a readflash and writeflash script were created and made executable with chmod +x <'readflash' | 'writeflash'>
echo 24> /sys/class/gpio/export
echo out /sys/class/gpio/gpio24/direction
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=10000 -r f_dump.bin
writeflash <inputBinary outputImageFile>
dd if=/dev/zero ibs=1k count=2k | tr "\000" "\377" > $2
dd if=$1 of=$2 conv=notrunc
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=10000 -w $2
echo in >/sys/class/gpio/gpio24/direction
Note that readflash should be executed at least once before writeflash to setup gpio24.
Or, just copy the first two lines from readflash to writeflash.
I prefer this solution as it has been working reliably. Flashrom is well supported on linux.