Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Hardware-as-Code Part I: An Introduction

hackster.io/sthibault/hardware-as-code-part-i-an-introduction-48bacb

Scott Thibault

Things used in this project

Hardware components

× 1
UPduino

Story

1/4
In this multi-part series, we’ll take a look at how you, a software developer, can design
custom hardware without learning a new language or deep knowledge of logic design. This is
possible through a technology called high-level synthesis (HLS) which can generate hardware
logic from algorithms described in C/C++. Not only that, but we can download our custom
hardware into programmable logic without physically building anything! In this first
installment, we’ll cover some background on what "hardware-as-code" means, how is it
different from software, and most importantly answer the question: why would you want to
do that? In subsequent parts, we’ll get hands-on and build real custom hardware as we
progressively explorer different topics. Some embedded-systems experience (e.g., Arduino) is
helpful, but not required; you just need some familiarity with C/C++.

Software is all you need, right?


Clearly, I wouldn’t be writing this if I thought that was the case. The most blaring problem is
that software isn’t very useful if you can’t execute it. Okay yeah, you can look at it and admire
it, but no one would be writing software if you couldn’t execute it, and for that you need
hardware! You say sure, but once we have a compiler and a CPU were good, right? After all,
we have Turing completeness and all that. Yes, but …

Turning completeness tells us what we can do, but it does not imply that we can do it
practically. In practice, there are many different CPUs out there because many different
hardware solutions are required to build practical solutions for different situations. Most
often we are trying to balance the tradeoffs between speed, cost and energy usage. In some
cases, you simply cannot meet resource constraints with any CPU. For example, the area of
tinyML involves using machine learning on resource-constrained devices. That can be very
hard to do with a general-purpose CPU.

Most developers don’t realize that CPUs are actually very inefficient. CPUs spend a large
amount of time and energy reading instructions from memory, decoding the instruction and
scheduling it to execute. An alternative is to build hardware that implements your specific
algorithm without instructions, completely eliminating the overhead found in a CPU. Beyond
that, custom hardware will typically also leverage parallelism not available with a CPU.

Here are some applications where people often find it useful to build custom hardware rather
than use an off-the-shelf CPU+software:

Processing audio (e.g., FFT)


Image processing (e.g., edge detection)
Networking (e.g., packet processing)
Sensor data aggregation/fusion
Security (e.g., encryption)
Machine learning (e.g., neural networks)
Compression

2/4
What is hardware?
The term hardware is used to mean many different things. In this series, as we explore
"hardware-as-code", we mean the type of hardware normally used to implement a CPU. More
specifically, synchronous digital logic circuits. Let’s break down what this means. It’s
probably pretty obvious, but we are talking electrical circuits here, not mechanical devices.
The most familiar term to the software developer is probably digital: manipulating data
represented by 0’s and 1’s (i.e., binary).

Another term you should be familiar with is logic. This means calculations are implemented
by combining logic operations (and, or, xor, not) which are each easily implemented in a
circuit. For example, addition, subtraction and multiplication can all be implemented by
combining various logic operations on binary values. For our purposes, we don’t really care
how; just like we don’t typically concern ourselves with how a compiler translates our code
into instructions.

Finally, you have likely encountered the term synchronous, but probably not with the same
meaning as it is used here. In this case, it means that the whole circuit it controlled by a
clock. The clock is an electric signal that oscillates between 0 and 1 with a fixed period. Each
period is a cycle and values are updated once per cycle. The number of cycles per second is
the clock frequency and this is exactly what we are talking about when we talk about
processor frequency. You’ll learn more about that in later articles when we discuss
performance.

The magic of programmable hardware


This is all great and everything, but are we really going to physically build logic circuits? Well,
although it is possible to follow a similar flow to fabricate an actual chip, we won't do that
here. As I said in the introduction, we can build hardware in programmable logic, a sort of
virtual hardware. Some very clever people figured out a way to build digital circuits that
could be programmed to do different logic operations after the circuit was fabricated. You
can download any logic design onto these chips from your computer in the same way you can
program an Arduino. It’s truly amazing technology.

In this series, we will be using Field Programmable Gate Arrays (FPGAs). These
programmable logic chips consist of an array of blocks that can be programmed in the field to
perform the various logic operations we discussed in the last section. FPGAs also include a
few other important elements beyond the basic logic blocks, but we’ll discover those as we go.

Next steps

At this point, you should have some idea of what I mean by "hardware-as-code", why you
might want to do such a thing, and hopefully, at least a little excitement about learning more?
For our next installment, we go hands-on with some hardware-as-code development tools.

3/4
The tools specifically target an inexpensive FPGA board from our hardware partner
tinyvision.ai. You won’t need the board to use the tools, but I’d encourage you to pick one up
so you can actually run your projects on the board, which is very rewarding. Use the
following link to make sure you get the correct board:
https://tinyvision.ai/products/upduino-v3-0?variant=39608867618919. This one has a pre-
soldered PMOD connector which we will use to connect sensors later in the series. Supplies
may be limited due to the silicon shortage and you'll want to have it when "Hardware-as-
Code Part II: Hello FPGA" drops, so it's a good idea to order now.

The tools do require Windows, so you will need access to a Windows machine.

Continue to Part II: Hello FPGA

Connect

Please follow me to stay up-to-date as I release new installments. There is also a Discord
server (public chat platform) for any comments, questions, or discussion you might have at
https://discord.gg/3sA7FHayGH

Credits

Scott Thibault

3 projects • 3 followers
Doctorate in programming languages + experience in FPGA, design automation, embedded
systems, and machine learning.
Contact

4/4

You might also like