Verilog Syntax Cheat Sheet



The Verilog Golden Reference Guide is a compact quick reference guide to the Verilog hardware description language, its syntax, semantics, synthesis and application to hardware design. The Verilog Golden Reference Guide is not intended as a replacement for the IEEE Standard Verilog Language Reference Manual. The tutorial code is in individual subdirectories within the basicverilog and cheatsheet directories, with one sub-directory for each exercise. The files are mostly empty, for you to complete. Full solutionns corresponding to the basicverilog files, if you get stuck. Both tools include syntax highlighting. In the case of Altera Quartus editor, there is a very useful feature which is the possibility of entering templates for commonly used code blocks (entity, architecture, component) and also for design units (counters, registers, memories, etc.). Verilog Cheat Sheet. For refreshers on FPGA Verilog HDL syntax and concepts, check out this cheat sheet. Below is a guide on how to flash a premade user-provided FPGA bitstream onto the Xilinx Spartan-6 FPGA for the MATRIX Voice. We first need to install a few prerequisites. Add the MATRIX repository and key.

Getting Started

The TinyFPGA BX boards use Lattice Semiconductor’s iCE40 FPGAs. There are a number of existing software and hardware tools available as well as documentation from Lattice for these FPGAs. This guide will help get you started with the BX board, the tools, and documentation available for the FPGA chips themselves.

Hardware

For this guide you will need a TinyFPGA BX board and a micro USB cable.

Software

You will need to install the latest development environment and other support tools for the iCE40 FPGAs and the BX board. The TinyFPGA BX is supported by open source tools. These instructions should work for all platforms.

1. Install Python

Tools for the TinyFPGA BX require Python. If you don’t already have Python installed, follow the directions below. Linux users should already have Python installed.

Linux

Most Linux distributions install Python by default. If not, install Python using your distribution’s package manager.

Windows

  1. Download and run the Windows Python Installer.
  2. Important: Check the “Add Python 3.6 to PATH” checkbox.
  3. Click on “Install Now”
  4. When Python has finished installing, click “Close”.

MacOS

  1. Download and run the MacOS Python Installer.
  2. Follow the instructions from the installer.

2. Install APIO and tinyprog

APIO is tool that makes it very easy to run the open source FPGA toolchain and program the design onto the FPGA board.

To install APIO and tinyprog, open up a terminal and run the following commands:

These commands install APIO, tinyprog, as well as all of the necessary tools to actually program the FPGA.

On Unix systems, 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:

Verilog syntax list

Connect your TinyFPGA BX board(s) and make sure the bootloader is up to date by running the following command:

This command will check for bootloader updates for all of the connected boards. This is important to do to ensure your boards have the latest bootloaders with any known bugs fixed.

3. Download and install Atom.

Atom is an open source text editor and IDE that is very extensible. The authors of APIO have created the APIO-IDE plugin that enables APIO to be used from within Atom.

Verilog Syntax Cheat Sheet

  1. Download and run the Atom Installer. When the installer finishes it should launch Atom.
  2. Go to “File” and click on “Settings”.
  3. Click on the “Install” tab.
  4. Type in “apio-ide” in the “Search Packages” text box and click “Packages”.
  5. Install “apio-ide”. Click yes for any dependencies. Ignore any warnings about the APIO version.

First Project Tutorial

Once you have all of your hardware and software ready you can get started developing some digital logic. This first project won’t go into all the details of designing and implementing digital logic circuits in general, but it will guide you through the specifics of setting up a simple project, writing verilog, and programming the board with the project.

1. Connect USB cable

Verilog Syntax List

Connect a micro USB cable to the TinyFPGA board. Use a quality cable to minimize programming issues. The power LED should light up when the board is connected. The boot LED should pulse on and off to indicate the bootloader is active.

2. Copy the template project from the TinyFPGA BX Repository

Copy the apio_template directory to a new directory and rename it blink_project.

3. Open your newly copied template project

Open up Atom. From the “File” menu select “Open Folder…”. In the newly opened file chooser, navigate to the “blink_project” directory you just created and click “Select Folder”.

4. Program the FPGA board

From the “Apio” menu, select “Upload”. The project will automatically be built and uploaded to the TinyFPGA BX board.

5. Verify the design works on the board as intended

If everything is working as it should, you should see the user LED on the board blinking a “SOS” in morse code.

If you see the LEDs blinking congratulations! You’ve successfully programmed your open hardware FPGA board with open source tools. If you are familiar with Verilog and digital design you are ready to implement more complicated designs on your board(s).

Tips

Bootloader Behavior

The bootloader behaves differently depending on what is connected to the USB port:

  • If the board is connected to a USB host, the bootloader will stay active. It will wait to be programmed by tinyprog. You can manually exit the bootloader and load the user image from the onboard SPI flash by running tinyprog -b.
  • If the board is connected to a dumb power supply, the bootloader will timeout after one second and load the existing user image from the onboard SPI flash.

Pressing the reset button will always return the board to the bootloader, but it will only stay in the bootloader if its plugged into a USB host.

Updating the Bootloader

The following incantation will update tinyprog if there is a new version available, and check for updates for the bootloaders on all connected TinyFPGA BX boards. tinyprog will give you the option to automatically update the bootloader if an update is available for your board(s). It will list any release notes as well.

Extra Resources

  • Generic FPGA and Verilog Tutorials
  • Lattice iCE40 Page

FPGA

Flashing Guide

⚠️Modifying FPGA source may have unintended consequences⚠️

Device Compatibility

Overview

The FPGA handles:

  • GPIO output
  • Connections between board components
  • Microphone processing (not provided in source code)

FPGA Source

FPGA source code is located here.

Verilog Cheat Sheet

For refreshers on FPGA Verilog HDL syntax and concepts, check out this cheat sheet.

FPGA Flashing

Below is a guide on how to flash a premade user-provided FPGA bitstream onto the Xilinx Spartan-6 FPGA for the MATRIX Voice.

We first need to install a few prerequisites.

Add the MATRIX repository and key.

Update your repository and packages.

Example

Install the required packages.

Reboot your device.

Backup the stock system_voice.bit

Verilog Example

file.

Copy your built system_voice.bit FPGA bitstream file to the blob folder.

Verilog Syntax Cheat Sheet Excel

Now you can flash the FPGA.

Reset the FPGA.

Flash the SPI Flash bootloader onto FPGA.

You should receive the following (may vary due to user-provided file).

Flash the SPI Flash.

You should receive the following (may vary due to user-provided file).

Reset the FPGA.

In order to maintain compatibility with the matrixio-creator-init package, you'll need to backup the original voice.version file, and create your own.

Updating the matrixio-creator-init package will cause the stock FPGA bitstream to be flashed upon next boot.

You can stop sudo apt-get upgrade from automatically updating the matrixio-creator-init package with the following command.

Power off your device.

Wait until the green led on your Raspberry Pi blinks 10 times, then unplug the power cable from your Raspberry Pi.

System Verilog Cheat Sheet

Plug the power cable back into your Raspberry Pi.

Restore Original Firmware

To restore the original firmware, restore the stock system_voice.bit file in the blob folder.

Now you can flash the FPGA.

Reset the FPGA.

Flash the SPI Flash bootloader onto FPGA.

You should receive the following.

Flash the SPI Flash.

You should receive the following.

Reset the FPGA.

Restore the stock voice.version file.

Allow sudo apt-get upgrade to update the matrixio-creator-init package.

Power off your device.

Wait until the green led on your Raspberry Pi blinks 10 times, then unplug the power cable from your Raspberry Pi.

Plug the power cable back into your Raspberry Pi.

Contents