This article discusses how user code can be uploaded to both, the MCU and the FPGA, of the Arduino MKR Vidor 4000. Some time ago, I wrote this summary of the topic which, however, didn’t include an easy to follow tutorial. Instead, it was more of an outline aimed at more experienced users. However, today I tried to re-create the steps, and I noticed that the original article wasn’t as simple to follow for beginners as I’d have liked it to be.
Therefore, I decided to create a ‘redux’ version of the two original articles:
Step 0: Read the original articles
While it’s not necessary, I recommend that you take a look at the original articles. They’re a good summary, and the first one covers the basics of the Quartus IDE. However, don’t install or download anything yet. Some things have changed since I wrote them, and I’ll cover them here.
Step 1: Download Intel Quartus Prime
Navigate over to the Intel Quartus download page and create an account, if necessary. You should see something like this:
Note how I selected version 18.1. This is important! For whatever reason, the newest version of the IDE (20.1) didn’t want to compile the project from GitHub, even with several workarounds applied to it. For me, it didn’t even work with Intel’s official getting started examples from their website:
So for now, id you don’t absolutely need the newest features, I’d recommend you stick to version 18.1 for this tutorial.
Also make sure to select the ‘Lite’ version of Quartus if you don’t have a valid license. You can follow this tutorial with the free version.
Once you made these selections, download the following two files:
The download might take a while, and the Intel FPGA website might be offline for several days (just like it was a week ago). If you find yourself in that situation, you can try using an external download (e.g. JDownloader).
Once the downloads are done, start the installer and follow the on-screen instructions. If you’ve downloaded the device file and saved it in the same folder, you’ll be asked whether you want to install the device support for the Cyclone 10 family as well. Choose to install it and all the required drivers.
Step 2: Install and configure the Arduino IDE
Most of you will already have the Arduino IDE installed. If not, head over to the official download page and download the latest version. Once it’s installed, you need to add support for Arduino SAMD devices.
To do that, navigate to the ‘Boards Manager’ in the Arduino IDE:
Then, search for ‘Vidor 4000’, and install the latest version of the following package:
Step 3: Install cygwin and gcc (Windows only)
The GitHub repository, you’ll download later, contains a short C program that flips the bit order of the tff-file that contains the finished FPGA design. You’ll need to compile it yourself with gcc, which is usually a part of all Unix systems. It, however, doesn’t come with windows.
Visit the cygwin installation page and download the latest version. Once it’s done, run the executable and install the program. During the installation process, you’ll be asked whether you want to install additional packages. For now, you can just choose ‘Next’ and skip this step. Gcc should be included with cygwin by default.
Step 4: Get the code from GitHub
Head over to GitHub and download this repository. It contains a barebones Quartus project and an Arduino Sketch which we won’t use in this tutorial. Instead, I’ll supply you with a slightly altered version that I find easier to work with. However, feel free to use the sketch that comes with this repository if you find it easier to use. It’s essentially the same thing but structured differently.
Anyway, double click the Quartus project to open up the IDE:
Luckily, the project comes pre-configured, and you only have to add your custom code. Note that it’s split in two files:
You’ll only have to change the user.v file. The original file from the repository comes with a simple blinking example. For this tutorial, I created this very simple logic gate demo by changing a single line:
reg [27:0] hadcounter; assign bMKR_D = bMKR_D && bMKR_D; always @(posedge wOSC_CLK) begin if (!rRESETCNT) begin hadcounter<=28'hfffffff; end else begin if (hadcounter==28'h0) hadcounter<=28'hffffffff; else hadcounter<=hadcounter-28'h1; end end
Note that the counter is not required. However, I just left it in.
The most important thing is the following line:
assign bMKR_D = bMKR_D && bMKR_D;
It’ll pull the MKR Vidor 4000’s digital pin 6 HIGH when the digital pins 4 and 5 are both high.
Step 5: Get the Arduino demo sketch
Click here to download a slightly altered version of the Arduino sketch that originally came with the GitHub repository. Note that I completely changed the loop method in the main file to make it work with the logic gate example.
My version of the sketch will wait for the user to input either an ‘A’, a ‘B’, or an ‘R’ in the serial console. If it reads an ‘A’ or a ‘B’, the Arduino toggles the digital pin that’s assigned to that variable. You can check the state of digital pin 6 by sending an ‘R’ over the serial console. Remember: The state of pin 6 is determined by the FPGA which reads the values of the other two pins. Therefore, this example already establishes a simple form of communication between the two systems.
The zip archive already contains a finished version of the FPGA design, we’ll create in the next steps, so you can just go ahead and upload it to your Arduino right away:
Step 6: Create the ttf file with the Quartus IDE
In the Quartus IDE, double-click the ‘Compile Design’ job on the left-hand side of the IDE window. The process should start, and once it’s done, you should see check marks next to all the sub-tasks:
Due to the way the project is configured, the IDE creates a ttf-file in the ‘output_files’ folder of the project:
On Windows, you’ll have to copy this file to the user folder of your cygwin installation (e.g. C:\cygwin64\home\your_username).
Step 7: Preparing the ttf file
If you’re using a Windows computer, you’ll also have to copy the ‘vidorcvt.c’ file to your cygwin user folder:
Then, use gcc to compile the file:
gcc -o vidorcvt vidorcvt.c
Next, you can execute the program to change the bit order in the ttf file. Note that the program uses stdin and stdout to work with the files. Therefore, you’ll have to redirect the in- and output:
./vidorcvt < MKRVIDOR4000.ttf > app.h
This command generates a file called app.h that contains the same information as the ttf file that was generated by Quartus (but with the bit order reversed).
Once the program is done (it should only take one or two seconds), copy the file to the Arduino sketch folder you downloaded from my website earlier.
Step 8: Uploading the code to the FPGA and the Arduino
There are two methods you can utilize to upload code to the FPGA on the MKR Vidor 4000 board. One of them is by directly using the JTAG header on the bottom side of the board (which is not populated). The other method, which we’ll use, is to instruct the MCU to store the code on the FPGA’s flash memory.
And all you need to do to accomplish this is to upload the Arduino sketch you downloaded earlier. As long as the app.h file is present, it’ll get uploaded automatically, because it gets included in the ‘defines.h’ file.
Step 9: Extent the code to suit your needs
As mentioned earlier, you’ll only have to update the user.v file to change the FPGA’s behavior. In my Arduino sketch, you only have to change the main file (named ‘Sketch’) to implement your custom code.
Of course, it’s also possible to only utilize the MCU itself. For that, you simply have to upload a sketch from the Arduino IDE, just like you’d do with any other board.
One last thing to mention: It’s important that you do not use the same pin as an output on both, the MCU and the FPGA simultaneously! Doing so might cause permanent damage to either device or the entire board.
As you just saw, uploading code to the FPGA of the Arduino MKR Vidor 4000 is not as intimidating as it might seem at first. The only usual thing is that you’ll have to utilize quite a few different tools to get things done. Arduino had promised us a streamlined and easy to use IDE, but that has yet to come out.
A special thanks to all of you who made, maintained, and simplified the awesome barebones Quartus project!