Seyed Masoud Hosseini · Overview · Study log · Ideas · Transcript · RSS feed
FPGA & Verilog Design · Lecture 2 of 12 · 18:50
Part 2: Getting Started with Yosys, IceStorm, and Apio
Study guide
What this lecture covers
This lecture follows the series introduction by getting the open-source iCE40 toolchain installed and working end to end. It answers a practical question: what tools turn a Verilog file into a bitstream running on real hardware, and how do you install and drive them?
You'll come away with apio, Yosys, nextpnr, and Project IceStorm installed, the iCEstick's FTDI drivers configured, and a working understanding of how a project folder is structured - the Verilog source, the physical constraints file (PCF), a test bench, and the apio.ini file. By the end you'll have built and uploaded the "leds" example so all onboard LEDs light up, and you'll know where to find the datasheet and pinout documents you'll keep referring back to.
Key ideas
- apio: a Python-based command-line tool that wraps Yosys, nextpnr, and Project IceStorm so you don't have to call each tool manually; it also ships example projects for supported dev boards.
- Toolchain roles: Yosys performs synthesis (Verilog to gate-level netlist), nextpnr performs place-and-route (netlist to chip-specific layout), icepack converts that into a binary bitstream, and iceprog uploads it to the board.
- Physical constraints file (
.pcf): maps names used in your Verilog (like an LED signal) to physical pin numbers on the FPGA package; it is not Verilog code. - Version pinning: the lecture recommends apio 0.6.7 rather than the newest release, since 0.7.6 had installation issues at the time of recording.
- FTDI drivers: boards like the iCEstick need a driver (installed via Zadig on Windows) so apio can talk to the board's USB interface.
- apio workflow:
apio verifychecks syntax,apio simruns a test bench in GTKWave,apio buildsynthesizes and place-and-routes the design, andapio uploadsends the resulting binary to the board's flash memory. - Configuration memory: the iCE40 loses its configuration whenever power is removed and re-reads it from an external SPI flash chip on every boot; a separate one-time-write internal memory exists for permanent deployment.
Walkthrough
Setting up the toolchain (0:08)
The lecture reviews what Yosys, nextpnr, and the IceStorm tools (icepack, iceprog) each do, then introduces apio as the tool that manages all of them together, plus a brief mention of the graphical, block-based icestudio environment (not used in this series).
Installing Python and apio (3:26)
Python 3.5 or later is required. apio is installed with pip, pinned to version 0.6.7 due to known issues in the newer release. The lecture demonstrates the install on Windows and flags that the process differs slightly by operating system.
Installing the tool suite and drivers (4:26)
With apio installed, the underlying tool suite (Yosys, IceStorm, etc.) is installed separately, followed by the board's FTDI drivers. On Windows this requires using Zadig to install the libusbK driver for the board while it's plugged in. The lecture also shows a known conflict where having more than one FTDI device connected (such as an Analog Discovery 2 alongside the iCEstick) causes a "lib usb open failed" error, resolved by disconnecting the extra device.
Running the LEDs example (7:07)
Using apio examples, the lecture creates the iCEstick "leds" example and walks through its files: leds.v (ties all LEDs high), the .pcf file mapping signal names to physical pins, a test bench, a GTKWave save-state file, and apio.ini (declares the target board, regenerated with apio init --board icestick).
FPGA pin mapping and schematic (10:28)
The lecture shows how to cross-reference the iCE40HX1K pinout spreadsheet and the iCEstick user manual to find which physical pin (for example, pin 99) connects to which onboard LED, which is the information you need to write a .pcf file for your own design.
Building and uploading (12:08)
The lecture runs through apio verify, apio sim (GTKWave), apio build (synthesis and place-and-route), and apio upload (writes the binary to the board via iceprog), confirming that all LEDs turn on once uploaded.
FPGA internals and configuration memory (16:26)
Using the iCE40HX datasheet, the lecture points out programmable logic blocks (each containing eight logic cells), I/O banks with configurable pull-up/pull-down resistors, dedicated SPI logic, and a phase-locked loop. It explains that the chip's configuration lives in external SPI flash and is reloaded on every power-up, unlike the one-time-write internal configuration memory.
Before you watch
- Watch Part 1 ("What is an FPGA?") first for context on FPGA fabric and the design flow.
- Have an iCE40-based dev board (the lecture uses the Lattice iCEstick) and a computer with Python 3.5+ available if you want to follow along.
Check your understanding
- What does each of Yosys, nextpnr, icepack, and iceprog do in the build pipeline?
- Why does a
.pcffile matter, and what information does it contain? - What problem can occur on Windows if multiple FTDI devices are connected, and how is it fixed?
- Why does the iCE40 need to reload its configuration from external SPI flash every time it powers on?
- What do
apio verify,apio sim,apio build, andapio uploadeach do?
Chapters
- 0:00 <Untitled Chapter 1>
- 0:08 Install the Tool Chain
- 3:26 Installing Python
- 4:26 Install the Tool Suite
- 10:28 Fpga Schematic
- 16:26 Non-Volatile Configuration Memory
From the YouTube description
In this tutorial, we install the open-source iCE40 FPGA toolchain, which consists of apio, yosys, nextpnr, and Project IceStorm.
A field-programmable gate array (FPGA) is an integrated circuit (IC) that lets you implement custom digital circuits. You can use an FPGA to create optimized digital logic for things like digital signal processing (DSP), machine learning, and cryptocurrency mining. Because of the FPGA’s flexibility, you can often implement entire processors using its digital logic. You can find FPGAs in consumer electronics, satellites, and in servers used to perform specialized calculations.
In this series, we will see how an FPGA works and demonstrate how to create custom digital logic using the Verilog hardware description language (HDL).
In the previous episode (https://youtu.be/lLg1AgA2Xoo), we examined how an FPGA works and why you might want to use it in your projects or products. In this episode, we demonstrate how to install apio and the various open-source tools required to build and upload designs to a Lattice iCE40 development board.
The solution to the challenge at the end of the episode can be found here: https://www.digikey.com/en/maker/projects/introduction-to-fpga-part-2-toolchain-setup/563a9518cd11466fb6a75cf3cb684d6d
All code examples and solutions for this series can be found here: https://github.com/ShawnHymel/introduction-to-fpga
Lattice iCE40 product page (with pinout spreadsheet and datasheet): https://www.latticesemi.com/en/Products/FPGAandCPLD/iCE40
We install the apio tool (https://github.com/FPGAwars/apio), which will help us install and control other lower-level tools required to synthesize, simulate, and upload our FPGA designs:
- Synthesis: http://yosyshq.net/yosys/
- Simulation: http://gtkwave.sourceforge.net/
- Place and route: https://github.com/YosysHQ/nextpnr
- Package: icepack (as part of Project IceStorm: https://github.com/YosysHQ/icestorm)
- Upload: iceprog (as part of Project IceStorm: https://github.com/YosysHQ/icestorm)
The apio documentation can be found here: https://apiodoc.readthedocs.io/en/stable/source/installation.html
Note that there might be some differences between the various operating systems (e.g. Windows, macOS, Linux) during installation. I demonstrate installation on Windows and try to point out the differences from other operating systems.
Important! At this time, the latest version of apio (0.7.6) has several issues. Until those issues are resolved, I recommend sticking to v0.6.7 (as shown in the video). You can read about some of those issues here: https://github.com/FPGAwars/apio/issues.
Apio includes several examples to get you started. We demonstrate one such example that illuminates all of the onboard LEDs. We finish by issuing a challenge to modify the leds.v example to turn off one of the LEDs.
Product Links:
https://www.digikey.com/en/products/detail/lattice-semiconductor-corporation/ICE40HX1K-STICK-EVN/4289604
Related Videos:
https://www.youtube.com/watch?v=z8Oldd-nrfs
https://www.youtube.com/watch?v=5kNXX67mchE
https://www.youtube.com/watch?v=iwcxLQ6AB88
Related Project Links:
https://www.digikey.com/en/maker/projects/introduction-to-fpga-part-2-toolchain-setup/563a9518cd11466fb6a75cf3cb684d6d
Related Articles:
https://www.digikey.com/en/pdf/r/renesas-electronics-america/powering-fpga-applications
https://www.digikey.com/en/videos/d/dsp/edge-machine-deep-learning-on-fpga
https://www.digikey.com/en/product-highlight/l/lattice/ice40-fpga-family-developmental-solutions
Learn more:
Maker.io - https://www.digikey.com/en/maker
Digi-Key’s Blog – TheCircuit https://www.digikey.com/en/blog
Connect with Digi-Key on Facebook https://www.facebook.com/digikey.electronics/
And follow us on Twitter https://twitter.com/digikey
← Part 1: What is an FPGA? · Part 3: Getting Started with Verilog →
