A presentation summarising FPGAs, their history, their benefits, and showing how to program them. It provides some historical background on the development of computers, from the Difference Engine to the Intel 4004 to the AMD Ryzen Threadripper PRO 3995WX. It shows how the number of transistors increased dramatically but also how this increase led to more complexity and more bugs. It then introduces Field-programmable gate arrays (FPGA) as an alternative. It then presents how to program such FPGA using data-flow graphs. It discusses some tools (Yosys, NextPnR, and IceStorm) and illustrates them with a typical "Hello World" (i.e., blinking an LED) using Cygwin on Windows 10.
1. Yann-Gaël Guéhéneuc
This work is licensed under a Creative
Commons Attribution-NonCommercial-
ShareAlike 3.0 Unported License
Are CPUs VMs
Like Any Others?
How did I fall into this rabbit hole?
Version 1.0
2020/10/09
2. 2/84
Outline
A bit of history
About FPGAs
Programming
– Basics
– Simulation
– Deployment
– More…
Conclusion
4. 4/84
A Bit of History
Of course, we start with a bit of history!
https://en.wikiquote.org/wiki/George_Santayana
“Those who cannot remember
the past are condemned to
repeat it.”
George Santayana (1863 –1952)
5. 5/84
A Bit of History
Of course, we start with a bit of history!
https://en.wikiquote.org/wiki/George_Santayana
“Those who cannot remember
the past are condemned to
repeat it.”
George Santayana (1863 –1952)
Or to overlook it…
6. 6/84
At The Beginning of Times
ENIAC machine, 1945
https://en.wikipedia.org/wiki/Difference_engine
https://en.wikipedia.org/wiki/ENIAC
https://www.engineering.com/ElectronicsDesign/ElectronicsDesignArticles/ ArticleID/16337/Vacuum-Tubes-The-World-Before-Transistors.aspx
Difference engine, 1822
13. 13/84
(In)Famous CPU Bugs
Pentium FDIV bug
– Incorrect floating-point
divisions
– Missing entries in the
lookup table of the
floating-point division
circuitry
– Equivalent to
$743 million in 2019
14. 14/84
(In)Famous CPU Bugs
Intel x86 CPUs
IBM POWER CPUS
Some ARM CPUs
– A process can read all
the memory
– CVE-2017-5754
– Unclear costs?
16. 16/84
Alternatives?
What if we could (re)program CPUs as we
program/update software?
FPGAs as alternative to CPUs
– Field-programmable gate arrays
– Integrated circuit configured after manufacturing
https://en.wikipedia.org/wiki/Field-programmable_gate_array
18. 18/84
Field-programmable Gate Arrays
A gate: OR, AND…
– Any logic function can be built from gates
An array: a set of unconnected gates
Field-programmable: configured by a
customer after manufacturing
28. 28/84
Data Flow Graphs (Procedure)
Silvia Regina Vergilio, José Carlos Maldonado, and Mario Jino ; Infeasible Paths in the
Context of Data Flow Based Testing Criteria: Identification, Classification and Prediction
; Journal of the Brazilian Computer Society, Springer, 2006
29. 29/84
Data Flow Graphs (Interprocedural)
Rohan Padhye and Uday P. Khedker ; Interprocedural Data Flow Analysis in Soot using
Value Contexts; Proceedings of the 2nd ACM SIGPLAN International Workshop on State
Of the Art in Java Program analysis, ACM Press, 2013
30. 30/84
Development
Time(ing) is of the
essence
Functions are like
processes that trigger
updates at the clock
signal
https://www.designboom.com/art/alex-chinneck-ties-antique-clock-05-18-2018/
35. 35/84
Development
Yosys
– Compiles Verilog into Berkeley Logic
Interchange Format (BLIF), aka synthesis
NextPnR
– Decides which CLBs should implement what
logic blocks of the design
– Decides which programmable switches to turn
ON to connect CLBs
https://www.eng.uwo.ca/people/wwang/ece616a/616_extra/notes_web/5_dphysicaldesign.pdf
36. 36/84
Development
IceStorm
– Converts ASC to a binary file that can be upload
onto the FPGA
– Generates a bitstream
– iCE is actually a brand name of Lattice
Semiconductor, which produce FPGAs
– Several FPGAs support their format because
it is open source
https://en.wikipedia.org/wiki/ICE_%28FPGA%29#Open_source
38. 38/84
Hello World?
“Hello World” is the typical first program
written in any language
https://www.softwaretestinghelp.com/java/hello-world-first-java-program/
40. 40/84
Hello World!
“FPGA design for Software Engineers”
– Jeff DeWall
– 2019/10/16
– www.walknsqualk.com/post/014-tiny-fpga-bx/
41. 41/84
Development
Jae-yeob Kim, Eui-sub Kim, Jun-beom Yoo, Young Lee, and Jong-gyun Choi ; An
Integrated Software Testing Framework for FPGA-based Controllers in Nuclear Power
Plants ; Nuclear Engineering and Technology, Elsevier, 2016
47. 47/84
CMake .
– To generate the Makefile and other files
Make
– To compile and generate the executable
bin/blinky.exe
– To simulate and generate trace.vcd
GTKWave
– To visualise trace.vcd
Simulation
50. 50/84
Install CMake
– Build process manager
– Which led to adding all sort of dependencies
Install Conan
– C/C++ package manager
– Which would not compile on Cygwin…
– Which was missing conanbuildinfo.cmake…
Simulation
51. 51/84
Install Yosys
– A framework for Verilog RTL synthesis
– Which would not compile on Cygwin…
Install Project IceStorm
– Place and route tool
– Which would not compile on Cygwin…
Simulation
52. 52/84
Install NextPnR
– Place and route tool
– Which would not compile on Cygwin…
Fixes for the compilation
– -DCMAKE_CXX_FLAGS=-std=c++11
– Implement strdup()...
– Modify
• /usr/local/share/verilator/include/verilated.cpp
• /usr/local/share/verilator/include/verilatedos.h
Simulation
62. 62/84
“FPGA design for Software Engineers”
– Jeff DeWall
– 2019/10/16
– www.walknsqualk.com/post/014-tiny-fpga-bx/
“TinyFPGA BX User Guide”
– 2020/10/01
– https://tinyfpga.com/bx/guide.html
Deployment
∧
∧
∧
∧
63. 63/84
Windows 10
– Because why not?
– Because it works!
Cygwin
– Not possible!
Deployment
64. 64/84
Doesn’t work in Cygwin
– Packages not (yet?) available
Break on my %TEMP% in Windows
– Space + Accents
– Had to Set TEMP=D:Temp
Deployment
65. 65/84
Doesn’t work in Cygwin
– Packages not (yet?) available
Break on my %TEMP% in Windows
– Space + Accents
– Had to Set TEMP=D:Temp
Deployment
66. 66/84
Deployment
Create a file apio.ini
Generate and upload the bitstream
[env]
board = TinyFPGA-BX
apio build
apio upload
67. 67/84
Deployment
Produces 3 files
– Hardware.blif BLIF
– Hardware.asc Place and route
– Hardware.bin Bitstream
apio build
77. 77/84
State Machine
Must consider the
speed of the FPGA
16Mhz 16 x 1,000 x
1,000 per second
27 bits register reg
[26:0] counter;
24 bits, every 22nd bit
83. 83/84
Okay But…
Different applications
– MCU: fix hardware, flexible “software”
– FPGA: flexible hardware, flexible “software”
Reimplementing a processor would be
difficult (impossible) with a MCU
https://www.quora.com/Should-I-learn-FPGA-or-STM32
84. 84/84
And More…
How do we interconnect these with other
sensors and actuators?
How do we test such systems?
How do we debug/update such systems?