December 18, 2024

Vivado and Tcl - example 3

We are working our way through the following excellent blog posts. We have arrived at the big event, post 3, where he describes a Tcl workflow independent of the vivado GUI.

Lesson 3

The first project he repeats in Tcl is the LED blinker from lesson 1. Here we have the zynq block giving us fabric clock 0. We feed this to a counter, then a slice block, then the slice goes to a single LED.

He recommends this setup to get started:

git clone https://github.com/vvvverre/red-pitaya-tutorials.git
cd red-pitaya-tutorials
source /tools/Xilinx/Vivado/2024.2/settings64.sh
cd blink-led
cp src/bd/blinky.tcl blinky.tcl
cp src/xdc/constraints.xdc constraints.xdc
Note that I changed the path in the above to match where vivado is installed on my system. Also, I decided not to use a "vivado" working directory, but to just do things right in the blink-led directory. This means I had to do two edits in his mk_proj.tcl file:
edit: ../src/bd/blinky.tcl to blinky.tcl
edit: ../src/xdc/constraints.xdc to constraints.xdc
Amazingly pin F16 is also the LED I want to blink on the s9 board, so I don't need to edit the constraints file. Then we do this:
vivado -mode batch -source mk_proj.tcl
And to generate the bitstream we do:
vivado -mode batch -source build.tcl
My file rearranging seems to work. It places all the "source" files in the top level directory. They are:
-rw-r--r-- 1 tom tom    609 Dec 18 20:49 mk_proj.tcl
-rw-r--r-- 1 tom tom   1287 Dec 18 20:39 blinky.tcl
-rw-r--r-- 1 tom tom    271 Dec 17 21:48 build.tcl
-rw-r--r-- 1 tom tom    180 Dec 18 20:50 constraints.xdc
-rw-r--r-- 1 tom tom    130 Dec 18 20:54 Makefile

That's it. The whole project is 4 files and a Makefile. Yes, I have a Makefile. It looks like this:

# Makefile for tcl vivado project

all:
	@echo "Sorry, be more specific"

project:
	vivado -mode batch -source mk_proj.tcl

build:
	vivado -mode batch -source build.tcl
These have been my rules for decades. Every project has its own directory. There is a Makefile in the top level. No confusing elaborate directory structure unless there is a really good reason.

The bitstream generation takes several minutes. There are lots of messages as the process continues. It finishes with:

# puts "Implementation done!"
Implementation done!
The bitstream is in the usual location:
Koala/blink-led/blink-led/blink-led.runs/impl_1/blinky_wrapper.bit
Yes, there is a blink-led directory inside of the top level project directory. We could change the name to "build" or whatever.

The second project

His github collection also has the axi-gpio project. I give it the same treatment. I do need to edit the constraint file to change pin numbers. I can just copy the Makefile from blink-led and:
make project
make build
The first attempt at a build failed because the GPIO had 8 output ports and the constraint file only had definitions for 4. The fix is a quick edit in axi_gpio.tcl changing 8 to 4 and we repeat both make steps. That is quick and easy and much faster than fooling with a GUI.
Now it builds clean and the bitstream is at:
Koala/axi-gpio/axi-gpio/axi-gpio.runs/impl_1/axi_gpio_wrapper.bit
We test this one, and it works just fine.

Analysis

This is fantastic, and a much better way to do business. The meat of things is in blinky.tcl which has all the Tcl commands to set things up and connect them together.
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org