Hello! Long time no write… Guess who forgot to upload their finished blog posts in the correct format?
With the school holidays wrapping up in 2 days, I thought I might cover what I did for fun over the 3 week break I got.
I decided to get into the world of fpga programming!
An fpga (field programmable gate array) is a close relative to the cpu, with a key small difference.
While a cpu has a set pattern of logic gates constructed at the factory using a laser to etch into silicon, an fpga can change it’s gates depending on what you want.
This makes it incredibly pansexual useful for anything in the realm of digital electronics.
For example, it can be any logic gate, a gpu, a cpu, a video encoder, a tool to mine bitcoin, and more.
In this post, I’ll go over the details of the process I went through to program this little bugger, and how to replace the default blinking an led Green with a new exciting color: Blue! (And slightly faster).
First, let’s install the iceprog cmd line tools, as per their documentation:
1 | git clone https://github.com/YosysHQ/icestorm.git icestorm |
(This assumes you already have the dependancies installed)
Alternatively, if on arch linux, simply yay install icestorm-git, arachne-pnr-git, and yosys-git
Then run:
1 | git clone https://github.com/FPGAwars/toolchain-icesprog.git |
If this errors out, do the following:
1 | wget https://github.com/FPGAwars/tools-oss-cad-suite/releases/download/v0.0.8/tools-oss-cad-suite-linux_x86_64-0.0.8.tar.gz |
After this, you should be able to run icesprog --help
to display the following:
1 | usage: /usr/libexec/icesprog [OPTION] [FILE] |
Hurrah!
Now, if you run icesprog -r
it will error out, saying iCELink open fail!
If we look at the iceSugar-Pro github issues page, we get nothing.
But, if we look at the model before it, we do!
This is on macos, but, macos is still unix based. Lets see if it fixes things…
After this, we can compile our program.
Now we need to upload it.
To install the tools for this, simply run:
1 | git clone https://github.com/ntfreak/openocd.git |
Then, by using the fancy pants “drag and drop” programming that this dev board supports, we can simply plug the board into our computer, and then drag and drop our compiled file.
Next, lets make our first program.
I’ll be using verilog as it’s a more gentle learning curve
To program our fpga, we use 2 files:
- The .v file, this contains our “code” we want to execute
- The .lpf file, this contains our definitions for what pins do what, for example, saying that
led_o
is actually pin B11.
So, lets go over our v file first:
1 | module blink ( |
Next, lets cover our lpf file:
1 |
|
To upload this, we drag and drop our 2 output files from compiling into the emulated usb storage device.
The current LED blinking program should halt (the large white body rgb led blinking Green), and then a small red led near the usb port should flash, that means that our program is now getting put into the flash memory of the board, meaning it will persist on our next reboot.
After this, simply hit the reset button (in the middle of the rgb led and usb-c port), and tada!
IMPORTANT NOTE
TO PROGRAM, DO NOT USE THE USB-C PROVIDED IN THE BREAKOUT (GREEN) BOARD, AS THIS WILL NOT UPLOAD OUR FILES AND ERROR OUT SILENTLY
INSTEAD, UNPLUG THE ENTIRE MODULE FROM THE BREAKOUT BOARD, AND CONNECT YOUR USB CABLE TO THE PORT ON THAT.
Now as a fun exercise for the reader, try adjusting the speed of the blinking LED.
For the sake of being able to replicate things; I’ll include my makefile, basically ripped of the documentation, minus a small inconvenience:
1 | TARGET=blink_slow |
And my config file (which i have named out.config
) is straight from the github page here.
I’m planning another project involving this fpga, one thats more challenging than anything i’ve really ever programmed, so hopefully that goes well!
See ya round - GhostDog