Field Programmable Gate Arrays (FPGAs) are very different to a traditional microcontroller board. With a microcontroller, you only have control over the code that runs on the microcontroller chip. FPGAs, on the other hand, allows you to start with a blank slate and design the circuit rather than write the code that runs on it.
Once viewed as exotic and scary, the coming of the age of the maker FPGA boards has allowed hobbyists like me to venture off into the once uncharted territory of hardware description.
The TinyFPGA BX is a maker-friendly breadboardable FPGA board powered by Lattice Semiconductor's ICE40LP8K FPGA chip. The FPGA features 7,680 four-input look-up-tables, 128 KBit of block RAM, Phase Locked Loop (PLL) and 41 user IO pins. The TinyFPGA BX has 8 MBit of SPI flash and can be programmed using a standard micro-USB cable. Onboard 3.3 V (300 mA) and 1.2 V (150 mA) Low-Dropout (LDO) regulators offer protection against voltage fluctuations.
Now that we have talked about TinyFPGA's features, its time to get started with our first hardware descriptor program.
Step 1: Install the Toolchains
The toolchains for the TinyFPGA BX require Python. If you don’t already have Python installed, visit python.org and download Python 3.6 and remember to check the “Add Python 3.6 to PATH” checkbox during installation.
We will be installing two toolchains that will allow us to build and program the TinyFPGA board, namely: APIO and tinyprog. APIO is a tool that makes it very easy to run open source FPGA toolchains and program designs onto the FPGA board.
To install APIO and tinyprog, open up a terminal and run the following commands.
$ pip install apio tinyprog $ apio install system scons icestorm iverilog $ apio drivers --serial-enable
These commands install APIO, tinyprog, as well as all of the necessary tools to actually program the TinyFPGA. If you are on a Unix system, you may need to add yourself to the dialout group in order for your user to be able to access serial ports. You can do that by running:
sudo usermod -a -G dialout $USER
Connect your TinyFPGA BX board and make sure the bootloader is up to date by running the following command:
Step 2: Cloning the APIO Template
Create a directory called Blinky and clone the APIO template by running the following command:
$ mkdir Blinky $ cd Blinky $ git clone https://github.com/tinyfpga/TinyFPGA-BX.git
If you open up the TinyFPGA-BX folder inside your working directory (Blinky), you can see a folder named apio_template. You are free to change the name of this folder, I've decided to name mine src. Move the src folder to the root of your working directory and delete the TinyFPGA-BX folder because you don't really need it anymore.
You can clean up the src folder by deleting the install_apio batch and shell scripts. This leaves us with three files: apio.ini, pins.pcf and top.v. The apio.ini file tells APIO what board we are using while the pins.pcf file is a Physical Constraints File (pcf) that maps the TinyFPGA BX's pin names to the FPGA's pin names. top.v is the Verilog Hardware Descriptor Language (HDL) file that allows us to design the circuit for the FPGA.
Step 3: Build and Upload the Program
Open the src folder in terminal. Run the following commands to build and upload the program to the TinyFPGA.
$ apio build $ tinyprog -p hardware.bin
Once done, you should see the boot LED blinking an SOS pattern. That's it! You have successfully programmed an FPGA! Go ahead and change the code inside of top.v to build anything from drivers to an 8-bit CPU from history, the possibilities are endless!