Skip to content

Instantly share code, notes, and snippets.

@jmrobles
Last active October 27, 2022 20:39
Show Gist options
  • Save jmrobles/f89e5cd110ea3b72533b7b311cbf09f1 to your computer and use it in GitHub Desktop.
Save jmrobles/f89e5cd110ea3b72533b7b311cbf09f1 to your computer and use it in GitHub Desktop.
How to create a LiteX SoC in Alhambra 2 FPGA

Litex on FPGAWars Alhambra II

Motivation

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.

image

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.

Requirements

Let's go

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

Proof of work

Proof

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment