This project helps you to flash FPGA via GPIO of Raspberry Pi without usb-blaster (or any other device) using urjtag tool using .svf files generated by Quartus software. It's tested for Raspberry Pi 4B and Cyclone IV FPGA on the OMDAZZ development board. The code is a modified version of the urjtag.
The first problem of Raspberry Pi flashing the FPGA is the fact that the Quartus is not supported for the ARM devices (like Raspberry Pi). There's an open-source tool called urjtag, but unfortunately it works with an old sysfs GPIO interface which is now deprecated and is no longer used. The new approach for working with the GPIO is the "character device". There's a libgpiod library for this case. So, in order to be able to flash the FGPA from Raspberry Pi, you can use this modified version of the urjtag in which I rewrote the gpio module using the libgpiod under the hood.
And I really want to save the next guy trying to flash the FPGA using GPIOs from a few days of suffering :D
You need to have the libgpiod installed on your Raspberry Pi. This project uses the version 2.1.2. You can verify the version by calling:
$ gpiodetect --version
Also, make sure that you have the library files located in /usr/include/gpiod.h and /lib/aarch64-linux-gnu/libgpiod.a or .so If you don't, then visit the libgpiod
Simply run
./configure CFLAGS="-I/usr/include" LDFLAGS="-lgpiod” && make
If you face some errors, it can be probably caused by the libgpiod installation
And if everything's fine, then
sudo make install
Now you should see the executable file ./src/apps/jtag/jtag which is the modified urjtag you can use to flash the FPGA.
- Wire the GPIOs to the OMDAZZ board's JTAG conntectors.
- Run the "jtag" executable file you got by completing the Installation section.
- Run the "cable gpio" and follow the instructions on how to set up the proper Raspberry Pi GPIO numbers for JTAG pins on the board. In my case I did "cable gpio tdi=23 tdo=24 tck=25 tms=18"
- Run "detect".
- Run idcode.
- After the p.4 you could probably see the "Unknown part!" text. It means that urjtag doesn't support the board by default, but it's easy to fix. Download the BSDL file (this one is an example for OMDAZZ Cyclone IV, the one you need can differ) and use it by typing "include ". In my case it was "include /home/pi/EP4CE10E22.bsdl".
- Now you're ready to flash the Cyclone IV! Use the "svf" command. In my case it was "svf /home/pi/lab_1.svf".
The only file changed is /src/tap/cable/gpio.c