Stefan finally got approval for his project, and we were able to get the FPGALink/AVR firmware running nicely on his iCEblink40 board.
In case anyone else wants to do it, here's the instructions. You should realise that this is an irreversible operation, because Lattice have deliberately prevented you from making a backup of the existing firmware. It will also invalidate your warranty. If you brick your board in the process, I will try to help you recover it, but I will not be held responsible.
You'll need an iCEblink40 board and an AVR-ISP programmer (Lattice unhelpfully disabled the AVR bootloader). Attach the programmer to J7 on the board, being careful to match the signals given in the iCEblink40 schematic with the signals on your programmer's header.
I attached a 20131101 label to the FPGALink code so you should be able to build it yourself. Rather than requiring you to build the firmware from source, I published the .hex file here:
https://gist.github.com/makestuff/7282251/raw/95123dcd0652ba1d2454b584a84a6454b8397852/firmware.hexYou can install it in one of two ways. Like this:
Install the LUFA bootloader[1] using your AVR-ISP, e.g with avrdude:
avrdude -c avrispmkII -P usb -p at90usb162 -e -U flash:w:BootloaderDFU.hex -U hfuse:w:0xD9:m -U lfuse:w:0x5E:m -U efuse:w:0xF4:m
This installs the bootloader in the top 4KiB of flash. You can now detach your AVR-ISP - we're finished with it.
The board will now start the bootloader when you connect it. You can use either Atmel FLIP[2] or dfu-programmer[3] to write the firmware.hex file (the FPGALink/AVR firmware) to the bottom 12KiB of flash.
The advantage of doing it this way is you can update the FPGALink firmware without needing to attach your AVR-ISP again.
Or like this:
Write firmware.hex directly using your AVR-ISP, e.g avrdude:
avrdude -c avrispmkII -P usb -p at90usb162 -e -U flash:w:firmware.hex -U hfuse:w:0xD9:m -U lfuse:w:0x5E:m -U efuse:w:0xF4:m
...and you're done.
It might seem like option 2 is easier, but I recommend you do option 1 because it makes future firmware updates easier.
Note that in both cases I'm resetting the low, high and extended fuse bytes to their factory-default settings listed in the AT90USB162 datasheet.
Having installed the FPGALink firmware, the board will now enumerate as an FPGALink/AVR device. You'll need a driver for it, which you can install by running Zadig.exe[4] and choosing the device with VID/PID 1D50:602B.
Now you can build the 20131101-tagged release of the FPGALink host-side code:
1) Download
http://www.swaton.ukfsn.org/bin/makestuff-windows-20130829.tar.gz2) Unpack as C:\makestuff.
2) Run C:\makestuff\setup.exe, select a C compiler and click "Create Shortcut".
3) Launch the desktop shortcut created by setup.exe.
4) Continue:
cd $HOME/apps
../scripts/msget.sh makestuff/flcli/20131101
cd flcli
make deps
cd ..
../scripts/msget.sh makestuff/gordon
cd gordon
make deps
The "gordon" tool is for programming your board, and flcli is the regular FPGALink command-line tool. You're now ready to build the cksum example. Unfortunately I was unable to make the Lattice tools work with hdlmake.py, so you'll have to fetch the code manually and build it in the iCEcube2 GUI:
cd $HOME
scripts/msget.sh makestuff/hdlmake
cd hdlmake/libs
mkdir makestuff
cd makestuff
../../../scripts/msget.sh makestuff/comm-fpga
../../../scripts/msget.sh makestuff/seven-seg
cd ../../apps
mkdir makestuff
cd makestuff
../../../scripts/msget.sh makestuff/swled
cd swled/cksum/vhdl
wget -q
https://gist.github.com/makestuff/7255059/raw/185474c70af5ba33a95b10292f5f108f0e948952/cksum_sbt.projectNow launch iCEcube2, press ctrl-o and double-click the cksum_sbt.project in C:\makestuff\hdlmake\apps\makestuff\vhdl, then select the physical constraint file:
1) Open "P&R Flow -> Add P&R Files".
2) Right-click "Constraint Files" and choose "Add Files".
3) Navigate to ../../templates/epp/boards/iceblink40/board.pcf
You can now build it into a .bin file, which you can then load like this:
cd $HOME/apps/gordon win.x86/rel/gordon -v 1d50:602b -p ../../hdlmake/apps/makestuff/swled/cksum/vhdl/cksum_Implmnt/sbt/outputs/bitmap/top_level_bitmap.bin
Once it's loaded you can interact with it like this:
../flcli/win.x86/rel/flcli -v 1d50:602b -a 'w1 CA;w2 FE;r1;r2'
You will want to solder a 3-way SIL strip into JP2 on your board. This selects different clock speeds. Leaving it open gives you 3.33MHz. Shorting the top two pins with a jumper gives you 333kHz, and shorting the bottom two pins gives you 33.3MHz. You can see how the choice of clock-frequency affects the throughput. Here's me copying 1MiB of random data into my board, first at 333kHz, then at 3.33MHz and finally at 33.3Mz:
$ dd if=/dev/urandom of=random.dat bs=1024 count=1024
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.0745853 s, 14.1 MB/s
$ win.x86/rel/flcli -v 1d50:602b:0001 -a 'w1 00;w2 00;w0 "random.dat";r1;r2' -b
Attempting to open connection to FPGALink device 1d50:602b:0001...
Executing CommFPGA actions on FPGALink device 1d50:602b:0001...
Wrote 1 bytes (checksum 0x0000) to channel 1 at 0.003117 MiB/s
Wrote 1 bytes (checksum 0x0000) to channel 2 at 0.004436 MiB/s
Wrote 1048576 bytes (checksum 0x84F4) to channel 0 at 0.048841 MiB/s
Read 1 bytes (checksum 0x0084) from channel 1 at 0.000609 MiB/s
Read 1 bytes (checksum 0x00F4) from channel 2 at 0.004277 MiB/s
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 84 F4 ..
$ win.x86/rel/flcli -v 1d50:602b:0001 -a 'w1 00;w2 00;w0 "random.dat";r1;r2' -b
Attempting to open connection to FPGALink device 1d50:602b:0001...
Executing CommFPGA actions on FPGALink device 1d50:602b:0001...
Wrote 1 bytes (checksum 0x0000) to channel 1 at 0.001855 MiB/s
Wrote 1 bytes (checksum 0x0000) to channel 2 at 0.003455 MiB/s
Wrote 1048576 bytes (checksum 0x84F4) to channel 0 at 0.125537 MiB/s
Read 1 bytes (checksum 0x0084) from channel 1 at 0.002167 MiB/s
Read 1 bytes (checksum 0x00F4) from channel 2 at 0.004375 MiB/s
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 84 F4 ..
$ win.x86/rel/flcli -v 1d50:602b:0001 -a 'w1 00;w2 00;w0 "random.dat";r1;r2' -b
Attempting to open connection to FPGALink device 1d50:602b:0001...
Executing CommFPGA actions on FPGALink device 1d50:602b:0001...
Wrote 1 bytes (checksum 0x0000) to channel 1 at 0.001979 MiB/s
Wrote 1 bytes (checksum 0x0000) to channel 2 at 0.003076 MiB/s
Wrote 1048576 bytes (checksum 0x84F4) to channel 0 at 0.146952 MiB/s
Read 1 bytes (checksum 0x0084) from channel 1 at 0.003668 MiB/s
Read 1 bytes (checksum 0x00F4) from channel 2 at 0.004436 MiB/s
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 84 F4 ..
Notice that at 333kHz, the FPGALink transfer rate is only 49KiB/s. This rises to 126KiB/s at 3.33MHz, and finally reaches 147KiB/s at 33.3MHz. This is roughly half the 330KiB/s throughput quoted in the FPGALink manual because the manual assumes a 16MHz AVR clock, whereas the iCEblink40's AVR only has an 8MHz crystal.
For future reference, assuming you installed the bootloader, you can tell the board to return to the bootloader by running "gordon -v 1d50:602b -b". At that point you can either install updated FPGALink firmware (using FLIP or dfu-programmer), or you can power-cycle the board to get back to the existing FPGALink firmware. If you wish to build the firmware yourself, there's a few special options[5] you'll need in order to get firmware suitable for the iCEblink40.
Have fun!
Chris
[1]
https://gist.github.com/makestuff/7282251/raw/645c803741e14e10f2ccbbb6e2aa648b88cf789f/BootloaderDFU.hex[2]
http://www.atmel.com/tools/FLIP.aspx[3]
http://dfu-programmer.sourceforge.net/[4]
http://zadig.akeo.ie/[5]
https://gist.github.com/makestuff/7282251/raw/28a5d6f934207d038a03bd7de8c8a0d10a652108/HOWTO.txt