TclVivado Byu-Cpe - BYU-Computing-Tutorials Wiki
TclVivado Byu-Cpe - BYU-Computing-Tutorials Wiki
TclVivado
Jump to bottom
Vivado can be nearly 100% controlled using Tcl from a command prompt (probably 100% but
there are some things we haven't yet figured out how to do in Tcl). This makes it possible to
create scripts to do just about everything you may want to do. This tutorial will help you get
started.
There are lots of other references out htere you should learn to work with. One is: Vivado Design
Suite Tcl Command Reference Guide (2019.1).
Also, typing part of a command name in the Tcl command prompt and hitting ESC will show all
the commands that start with that. Then, typing the command name followed by -help will give
you all the details on the command.
vivado
# Just run a tcl script and never create a GUI or a command line
For the first two versons above, you can turn the GUI on and off from the Tcl command line as
you like:
start_gui
https://github.com/byu-cpe/BYU-Computing-Tutorials/wiki/TclVivado 1/10
28/9/22, 20:44 TclVivado · byu-cpe/BYU-Computing-Tutorials Wiki
stop_gui
Thus, you can work in whatever mode is mode comfortable. DON'T FORGET - you can run all the
Tcl commands you want even when in GUI mode from the Tcl Command Line. But, commands
will operate more slowly in GUI mode - if you have lots of processing to do, turn off the GUI
while you do it and it will go faster.
Compiling a Design
Vivado has two modes of operation: project mode and non-project mode.
Project mode is what you get when you open the GUI, selected Create New Project, add
sources, etc. You know a project was created this way when there is a .xpr file created and in
the directory.
Non-project mode is typically what you get when you just use Tcl commands to read,
synthesize, and implement HDL files into bitstreams.
As mentioned above, you can run Vivado in non-GUI mode - non-project mode is what you get
when you run Vivado this way and write scripts to create and compile your designs. However, as
noted, you can always start and stop the GUI.
Here is a basic compilation script which will compile all the HDL files in the current directory. It is
classical non-project mode and gives a starting point for a script you could create for your needs.
# It will compile all the .sv, .v, and .vhd files in a directory.
puts ""
close_project -quiet
puts "Continuing..."
# Compile any .sv, .v, and .vhd files that exist in the current directory
https://github.com/byu-cpe/BYU-Computing-Tutorials/wiki/TclVivado 2/10
28/9/22, 20:44 TclVivado · byu-cpe/BYU-Computing-Tutorials Wiki
read_xdc $top.xdc
# You will get DRC errors without the next two lineswhen you
# generate a bitstream.
# If you don't need an .xdc for pinouts (just generating designs for analysis),
# you can include the next line to avoid errors about unconstrained pins.
place_design
route_design
# but probably not since you may want to do things with the design.
#close_project
To run this script from a Tcl command prompt, you first need to have put it into a file such as
basicCompile.tcl in your directory. Once running Vivado, you can load it from the Tcl console
by typing:
source basicCompile.tcl
compile mydesign
https://github.com/byu-cpe/BYU-Computing-Tutorials/wiki/TclVivado 3/10
28/9/22, 20:44 TclVivado · byu-cpe/BYU-Computing-Tutorials Wiki
NOTE: Vivado, when run, has the notion of a current directory where it is running from. You do an
ls from the Tcl console to see what files are in the current directory, a cd to change
directories, and a pwd to see what directory you are in. Keep that in mind as you work.
# Print the size statistics of an open Vivado design to the specified file.
# This may be useful to understand the size of designs being used for
# benchmark purposes.
close $fp
proc generate_cell_distribution_dictionary { } {
return $cell_dictionary
https://github.com/byu-cpe/BYU-Computing-Tutorials/wiki/TclVivado 4/10
28/9/22, 20:44 TclVivado · byu-cpe/BYU-Computing-Tutorials Wiki
There is a single parameter for the print_cell_statistics procedure but it is optional and has a
default value given ("cell_stats.txt"). The parameter is called filename.
...
...
close $fp
It shows how to get the current design, then get the property named TOP associated with it:
It shows how to set a variable with something and then later refer to it (with a $ sign in front):
...
It shows how to get all the cells in the design (the hierarchical flag says to traverse the hierarchy,
the -quiet flag says to not print the resulting list to the console):
Note how commands are wrapped in [ ... ] when they return something you then want to use like
in the example above.
If all you wanted was to see a list of cells in the design you could just do this and it would print
the list to the screen:
get_cells
If you wanted to assign those to a variable you would use the set command:
https://github.com/byu-cpe/BYU-Computing-Tutorials/wiki/TclVivado 5/10
28/9/22, 20:44 TclVivado · byu-cpe/BYU-Computing-Tutorials Wiki
There are similar command for getting all kinds of things: tiles, sites, ports, pins, pips, nets,
iiobanks, and bels. In each case, they will return a list.
You can filter what you get. Here is what get_cells returns, then after that, is another query but
asking for just cells that start with the letter 'c' in their name:
Vivado% get_cells
Vivado% get_cells c*
When you do a command like get_cells, you can specify you want all the cells inside some other
object. This is how you would get the
sites inside a specified tile:
There are lots of other filtering and modification options available - see the Xilinx Tcl reference
for more information.
Lists are used a lot in Tcl. The code fragment below shows how to loop across the elements of a
list:
https://github.com/byu-cpe/BYU-Computing-Tutorials/wiki/TclVivado 6/10
28/9/22, 20:44 TclVivado · byu-cpe/BYU-Computing-Tutorials Wiki
And, that code shows how to use other data structures such as a dictionary (dict).
Properties
Everything in Vivado has properties (cells, tiles sites, pins, ...). Above, we saw how to get the TOP
property associated with the current design. Here is an example of how to see all the properties
associated with a cell:
So, how to learn even what properties an object has? The command above is one way. There are
others which allow you to get the value of a specific property. One example would be:
https://github.com/byu-cpe/BYU-Computing-Tutorials/wiki/TclVivado 7/10
28/9/22, 20:44 TclVivado · byu-cpe/BYU-Computing-Tutorials Wiki
Filtering on Properties
You can filter on properties when you use a command like "get_cells". Here is one:
This will return all the pins whose direction is IN and whose name does NOT contain the
substring RESET in their NAME property.
You should also run the Vivado GUI and do some comparisons. Examples follow.
Cell Properties
Start the Vivado GUI (start_gui), click on the "Netlist Tab", expand list of cells, click on a cell,
and see the window below that opens to show you all there is to know about that cell.
In the Tcl Console figure out the Tcl commands to show you what the GUI is showing you.
That is, print out the various cell properties.
https://github.com/byu-cpe/BYU-Computing-Tutorials/wiki/TclVivado 8/10
28/9/22, 20:44 TclVivado · byu-cpe/BYU-Computing-Tutorials Wiki
Net Properties
Repeat the above but for the nets in the design.a
Device Exploration
Make sure you have done "Open Implementation" for a design. This will bring up a physical
view of the FPGA with your design mapped to it.
Click on the FPGA layout figure (right side of screen).
Whatever you clicked will show up where the cell properties window used to be. It will
probably be a clock region. Its properties will be displayed in the info window.
See how to access it and its properties using Tcl.
Now, zoom in and click on smaller things like tiles, sites, wires, LUTs, etc. In each case,
compare what the GUI shows in that info window with what you can query using Tcl.
https://github.com/byu-cpe/BYU-Computing-Tutorials/wiki/TclVivado 9/10
28/9/22, 20:44 TclVivado · byu-cpe/BYU-Computing-Tutorials Wiki
Zoom in and select an object graphically in the device view. Zoom and click until you have
selected a tile (you can tell what you have selected by looking in the properties pane to the
left of the device view window.
Assign what you selected to a variable using set myobj [get_selected_objects] .
Now, use Tcl commands to query that object's properties or to manipulate it some way
using the myobj variable you set it to.
Now, experiment with mixing graphical and Tcl ways of doing various things. When you are
trying to figure something out, this can be a very powerful way to operate. And, remember, if
you choose to run a complex Tcl script, you can always stop the GUI, run the script, then restart it
- this will make the script run WAY faster.
Pages 22
Home
https://github.com/byu-cpe/BYU-Computing-Tutorials.wiki.git
https://github.com/byu-cpe/BYU-Computing-Tutorials/wiki/TclVivado 10/10