Haskell and Python, languages that probably do not spring to mind when you think of languages that let you get down to the “Bare Metal” of your computer… But they can be used to (and are used to!) create that Bare Metal!

During this workshop you will learn how to create digital circuits using Haskell and Python, and about the tools needed to put those circuits on an FPGA, specialized chips that can be reconfigured into any digital logic circuit. Specifically, you are going to specify a RISC-V CPU in Haskell, and then run some small assembly programs on your RISC-V CPU inside of GHCi. Afterward, you will use “Clash”, a Haskell-to-Verilog compiler, to create Verilog from the Haskell description, a hardware description language which is understood by the FPGA tools. You will then package up the generated Verilog into a Python package to move to the next steps: Migen and LiteX.

LiteX is a System-on-Chip (SoC) builder made with the Python-based eDSL for circuit design called Migen. Using LiteX, you will connect the RISC-V CPU that you made in Haskell, to memories from which it will fetch its programs, and a UART to allow it to communicate with the outside world. You will then use Migen to transform the entire SoC to Verilog. You will then use the high-speed Verilog simulator (actually Verilog-to-C++ compiler) called Verilator to run some C-programs on your SoC and interact with it over a virtual UART.

Finally, the workshop mentor will demonstrate the use of the FPGA tools to create a bitstream, the configuration file the FPGA uses to reconfigure itself into the desired digital logic circuit. He will then upload the configuration to a FPGA development board and demonstrate you can interact with the SoC in the same way as you did in the Verilator simulation.

Prerequisites
You will need an intermediary knowledge of Haskell for this workshop.

Workshop Preparation
To follow along, you will need to have the following tools installed:

GHC 8.6.5 or higher (if you’re using Windows 10 2004, you will need GHC 8.10.2)
cabal-install-3.2.0.0 or stack
Working python3 environment together with pip and virtualenv
verilator

Windows users are recommended to use WSL2 for the above: https://docs.microsoft.com/en-us/windows/wsl/install-win10

MuniHac 2020, September 12 / https://munihac.de/
TNG Technology Consulting GmbH / https://www.tngtech.com