Mimas Artix 7 FPGA Development Board

Running MicroPython on Mimas A7 using LiteX and Migen

163 views November 13, 2019 jyothi-as 0

Introduction

MicroPython is an implementation of the Python 3 programming language and it is developed to run on embedded development boards. We can also run MicroPython firmware on FPGA boards (since FPGA’s are well known for their flexibility and versatility), which is loaded with the gateware/bitstreams which contain the soft CPU. In this article, we are using Litex & Migen technologies to build the gateware and firmware for an FPGA. The TimVideos projects have the LiteX Build Environment for building LiteX and Migen based FPGA designs. This article takes you through the steps to build the gateware and MicroPython firmware and to run the MicroPython on the Mimas Artix7 FPGA Development board using the LiteX Build Environment.

Tools Required

  1. Mimas Artix 7 FPGA Development Board
  2. Linux system (Ubuntu)
  3. USB 2.0 cable for programming the Mimas A7 board

Let’s get started

The following steps should be run in the Linux system. So open the Linux Terminal and execute the following steps.

Step 1:  Download the LiteX Build Environment

Download the Timvideos LiteX Build Environment from here to a suitable location in your system. And in the terminal, change the directory to where you have downloaded the “litex-buildenv” repository. Here the author downloaded litex-buildenv inside the LiteX_Build_Environment folder. So, the command is as shown below. Use the appropriate path to change the directory to where you have downloaded the “litex-buildenv” repository on your PC.

cd Litex_Build_Environment/litex-buildenv

To install the dependency packages required for the build environment, the FPGA toolchain to build the gateware & firmware and the FPGA programming tools to load gateware & firmware onto the FPGA, run the “download-env.sh” script file.

./scripts/download-env.sh

Step 2: Enter the environment

Before running any of the build steps, first, you must enter the development environment. And this step should be done whenever we select a new terminal window.

First set up the build targets by running the command below.

export PLATFORM=mimas_a7 CPU=lm32 TARGET=base FIRMWARE=micropython

The Litex Build Environment has Mimas A7 platform support so we can directly set the Mimas A7 as the platform. The ‘lm32’ and ‘base’ are the default soft CPU and Target respectively. If we haven’t set the soft CPU and Target, by default ‘lm32’ and ‘base’ will be the soft CPU and Target here. We can also use other soft CPUs that are supported by the LiteX Build Environment.

To set up the environment for the above build targets, run the following command:

source scripts/enter-env.sh

If your environment is set up correctly your terminal should show something like this:

(LX P=mimas_a7 F=micropython) #

Step 3: Build the gateware

Once you have entered the environment, you can now build the gateware for the build targets. Usually, building this gateware takes a few minutes. To build the gateware, run:

make gateware

If the command runs successfully, in the end, you should get an output similar to the one shown in the image below.

You can get built gateware in the build/mimas_a7_micropython_lm32/gateware/location.

Step 4: Building MicroPython

We need to generate the MicroPython firmware to load it on the soft CPU. The LiteX Build Environment has a MicroPython script file that generates this MicroPython firmware. To generate MicroPython firmware, run:

./scripts/build-micropython.sh

Step 5: Loading the Gateware and MicroPython onto the Mimas A7

In the previous steps, we generated the gateware and firmware, now in this step we are loading the generated gateware and firmware to the Mimas A7 board. The first step is to connect one end of the USB 2.0 cable to your laptop/PC and the other end to the Mimas A7 board. Before loading the gateware and firmware in the terminal go to ‘File’ select New Window and in the New Window, enter the development environment as described in step 2 and run the following command to load the MicroPython firmware.

make firmware-load

Now load the gateware onto the Mimas A7 board. To load the gateware run this command in the other terminal Window which was opened above:

make gateware-load

The Done LED on the Mimas A7 board should glow when you run the above command. This indicates that the gateware is loading on to Mimas A7.

After loading the gateware onto Mimas A7, the MicroPython firmware starts loading on to the soft CPU which is implemented on the Mimas A7 board. The image below shows the MicroPython firmware loading on to the soft CPU.

Once the load finishes MicroPython should boot, and then you should get a MicroPython console as shown in the image below.

Now you can use this MicroPython console and execute the python code like the examples shown in the image below. As shown in the example, you can print any text, add numbers, and you can also control the Mimas A7 board by implementing the design in Python code.

Congratulations, you’ve successfully run MicroPython on the Mimas A7 board using the LiteX Build Environment.

Was this helpful?

Leave A Comment
*
*