Monday 20 January 2020

Arduino MKR Vidor 4000 - Getting Started

At the Arduino site there are a couple of tutorials by Daniel Hertz which show you how to build / download a (pre-existing) design for the Vidor Cyclone10 FPGAand how to create a Quartus project  from scratch.  The best example to use is provided by Al Williams in a Hackaday article and can be downloaded from github.

Building and Loading an FPGA design

The first thing to do is to set up Quartus, I haven't used a Cyclone 10 processor previously so I needed to download and install the appropriate Quartus repository. I then downloaded Al Williams example code which includes a Quartus project file (.QPF) so that I could synthesise an image straightaway.

Normally I would then download a .SOF file to the FPGA using a USB Blaster.  A confusing wrinkle with the arduino setup is that the .TTF file created during Quartus synthesis needs to be converted - its nibbles are in the wrong order - before downloading to the FPGA.  Al Williams provides a simple C program vidorcvt which converts this file to one called app.h.

The second part of the design is an Arduino sketch (provided) which sets up the FPGA and runs SAMD code which interfaces with the FPGA.  When this sketch is compiled and loaded we have a working SAMD/Cyclone implementation running on the Vidor.

Al Williams example is a simple blink program which runs on the FPGA.  A 28 bit counter is used to determine the blink speed.  Bit 27 is used for a 1 second blink and bit 21 gives quicker flashing.  The FPGA code is stored in user.v.  Arduino pin D6 is used for the LED output.  If the user sends a character using the serial monitor, the Arduino sketch toggles pin D5.  user.v then toggles which counter bit is used, i.e. it changes the flashing speed.  This demonstrates simple inter-communication using shared GPIOs.

Creating a Quartus Project

There are a number of things you need to create a Quartus project:
  • pin outs for the various components (.QSF)
  • system constraints file (.SDC)
  • IP code for all the peripheral components
  • Top level Verilog code to initialise the system

These are provided in EmptyVidorProject folders so that it is quick to start writing your own code.
It is instructive to build your own project using the tutorial, although in practice you could copy a skeleton quartus project structure.

It is particularly useful to have the pinouts and SDC as I usually need to spend a lot of time trying to get them right.
The top level verilog code is setup as a boiler plate - you can add your own code in a user.v include file.

Baby Steps

As a check that I can change the code myself I changed the LED output used for blinking.

Copy the blink Quartus project directory to blink2
In user.v assign counter value to bMKR_D[4]  (pin D4) instead of bMKR_D[6] (pin D6)
Synthesise the project
Convert .TTF output to app.h and save in the blink-sketch folder
Compile and upload blink-sketch to Vidor
Now pin D4 blinks instead of D6

This demonstrates that I only need to change code in two places user.v and blink-sketch.





No comments:

Post a Comment