The Zephyr RTOS is a secure and scalable Real-Time Operating System from the Linux Foundation for IoT embedded devices. It supports multiple architectures such as ARM, Intel x86, NIOS II, RISC-V, etc. The Zephyr RTOS is modular and useful for low-powered, small memory footprint devices and can easily run on FPGAs as well since FPGAs are well known for their flexibility and versatility. Zephyr comes with in-built support for LiteX built SoCs with VexRiscv CPU. The workflow is highly automated with the help of the LiteX Build Environment project from TimVideos which can build the LiteX SoC gateware with Vexriscv CPU, load it on to the FPGA as well as build the Zephyr firmware using just a few commands. This article will walk you through the steps to build Zephyr RTOS firmware and run the firmware on the Mimas A7 Mini FPGA Development board using LiteX Build Environment.
- Mimas A7 Mini FPGA Development board
- Linux system (Ubuntu) with Xilinx Vivado ( >= 2018.2) toolchain installed
- USB 2.0 Micro-B cable for programming Mimas A7 Mini board
Let’s get started
The following steps should be run in a Linux host system. Open a Linux shell and run the commands mentioned in the following steps
Step 1: Download LiteX Build Environment
Download the TimVideos LiteX Build Environment from here to a suitable location in your system. In the terminal, change to the
litex-buildenv directory using the
Run “download-env.sh” script file inside “scripts” directory which will download the dependency packages required by the “litex-buildenv“ such as cross-compilers for RISC-V, programming tools (OpenOCD), etc.
We will use OpenOCD to program the Mimas A7 Mini board. Download the OpenOCD configuration file for Mimas A7 Mini
numato_mimas_a7_mini.cfg from here and save it inside litex-buildenv/build/conda/share/openocd/scripts/board/ directory.
Step 2: Enter the environment
Before running any of the build steps, the first step required is to enter the litex-buildenv environment.
Set up the environment variables that decide the FPGA board platform being used, CPU variant, target SoC configuration and the firmware using the following command.
export PLATFORM=mimas_a7_mini CPU=vexriscv CPU_VARIANT=full TARGET=base FIRMWARE=zephyr
The Litex Build Environment available from our repo comes with Mimas A7 Mini platform support. We are going to deploy LiteX SoC with the VexRiscv CPU on Mimas A7 Mini, so choose CPU as “vexriscv” and CPU variant as “full” to enable all features of the CPU. The litex-buildenv supports many different firmware options such as bare-metal, Linux, MicroPython, Zephyr, etc. For this article, we select
Run the following command to enter the litex-buildenv environment with the previously set variables:
If the environment was set up correctly, the terminal should now show something like this:
LX P=mimas_a7_mini C=vexriscv.full F=zephyr #
Step 3: Build the gateware
After entering the litex-buildenv environment, we can now build the gateware for the Mimas A7 Mini. To start the gateware build process, run:
Building the gateware usually takes a couple of few minutes, depending on the host system’s performance. An output similar to the one shown in the image below means the gateware was successfully built and the bitstream (top.[bit|bin]) generated.
The generated bitstream and related gateware files can be found in the directory: build/mimas_a7_mini_base_vexriscv.full/gateware/
Step 4: Building Zephyr RTOS
We need to compile Zephyr RTOS firmware to load it on the soft CPU. The LiteX Build Environment has a Zephyr script file that sets up Zephyr and compiles this Zephyr firmware. To build the Zephyr firmware, run:
By default, this command builds the Zephyr shell application, similar to a Linux shell. The compiled firmware can be found in the directory: build/mimas_a7_mini_base_vexriscv.full/software/zephyr. It is also possible to build other applications of your choice by setting the
ZEPHYR_APP environment variable. An example is shown below for the
hello world application. Don’t forget to clean up the build directory before going on to build another application.
rm -rf build/mimas_a7_mini_base_vexriscv.full/software/zephyr ZEPHYR_APP=hello_world ./scripts/build-zephyr.sh
Step 5: Loading the Gateware and Zephyr Firmware onto the Mimas A7 Mini
Once the gateware and firmware have been generated, the next step is to load the generated gateware and firmware to the Mimas A7 Mini board. Connect the Mimas A7 Mini board to the host system using USB 2.0 Micro-B cable. Open a new terminal window (keeping the existing terminal shell as it is, it will be used later) and enter into the litex-buildenv environment exactly as described in Step 2. Next, enter the following command in this new terminal to load the Zephyr firmware.
You will see the flterm tool “Starting” that connects to Mimas A7 Mini using /dev/ttyUSB.
The next step is to load the gateware onto the Mimas A7 Mini board. Going back to the previous terminal, run the following command to load the gateware:
Done LED on the Mimas A7 Mini board should glow on for a moment and then go off after running the above command. This indicates that the gateware was successfully loaded to the FPGA on-board Mimas A7 Mini.
After loading the gateware into the FPGA on Mimas A7 Mini, the second terminal should start uploading the Zephyr RTOS firmware to the Vexriscv soft CPU running on the Mimas A7 Mini. The image below shows the RTOS Zephyr firmware loading on to soft CPU.
Once the firmware upload is completed, the Zephyr RTOS should start running. The output will correspond to the Zephyr application for which the firmware has been compiled and generated.
If the firmware was built with the Zephyr
Shell application, the output would be similar to the image below:
If the firmware was built with the Zephyr
Hello World application, the output would be similar to the image below:
Congratulations on getting the Zephyr OS running successfully on the Vexriscv RISC-V CPU built with LiteX on your Mimas A7 Mini FPGA Development Board.