Litex is an awesome project that allow us to create SoC on FPGA using Python! (yeah, Python is eating the software).
On the other hand, Alhambra II is one of the first open hardware based on the famous Lattice ICE40 FPGA family.
When I discovered the Litex project I miss the presence of the Alhambra II board, so I did a PR to include it.
This gist show you how to implement a lite RISC-V microprocessor on it.
-
You must have installed Python3
-
You need the open source ICE Storm project (nextpnr-ice40, yosys and iceprog).
-
You need to install Litex. Follow the LiteX Quick Start Guide
When all the requirements are done, we can build our SoC for Alhambra II
Go to shell (ensure that the migen, litex and other modules are under the PYTHONPATH).
A normal RISC-V CPU doesn't fit inside the ice40-hx-8k FPGA. We have to synth the lite version. Even for this version, we have to store the "bios" in the SPI flash memory. Just after the FPGA bitstream.
The following command must create our hardware and software.
python3 -m litex_boards.targets.fpgawars_alhambra2 --cpu-variant=lite --build
After some minutes, you must see a new folder "build/fpgawars_alhambra2" with two subfolders: gateware
and software
.
In gateware is our hardware bitstream. We are going to flash them into the SPI flash memory at position 0x0. When the FPGA starts, it'll be configured using this flash memory.
Connect your board using a USB wire and execute the following
iceprog build/fpgawars_alhambra2/gateware/fpgawars_alhambra2.bit
If everything goes well, you leds on your board must roll-out like the Knight Rider's car.
...but if you connect to the serial line, nothing happens. It's time to upload our software.
If you look at the target code, you can view that the CPU reset is defined at spiflash.origin + 0x50000. So we need to flash our bios code at that offset.
Execute the following to do that
iceprog -o 327680 build/fpgawars_alhambra2/software/bios/bios.bin
Brilliant!
After that, if you open a serial program for the device /dev/ttyUSB1 at 115200 bauds... you will see the LiteX prompt!
Awesome, right?
Here is the ...
Enjoy!