January 26, 2021

Xilinx Zynq - XC7Z010 - Vivado Constraints

First off, here are some links that may prove useful someday. Constraints files are where the rubber meets the road; in this case where a verilog model gets tied to real world pins and such. A constraints file (extension XDC) specifies the external connections to the FPGA and their characteristics.

Take the following two lines from the Numato tutorial:

set_property -dict { PACKAGE_PIN "N17" IOSTANDARD LVCMOS33 SLEW FAST} [get_ports { A }]; # IO_L21P_T3_DQS_14 Sch = SW3
set_property -dict { PACKAGE_PIN "M16" IOSTANDARD LVCMOS33 SLEW FAST} [get_ports { B }]; # IO_L24N_T3_RS0_15 Sch = LED7
If we can understand these two lines, we will be well on our way.

First of all, be advised that this is actually the Tcl language. If you have any familiarity with Tcl syntax, it will help you to generate proper XDC files. Secondly, we are going to use the ug903 user guide (69 pages) entitled "using constraints" to try to educate ourselves. It turns out that ug903 is pretty dismal as a reference as it mostly assumes a bunch of prior knowledge and is not the reference manual for XDC file format that I had hoped.

XDC stands for Xilinx Design Constraints. It is based on Synopsis Design Constraints, which doesn't help us at all since we are new to all of this, but as of 2012 it had been around for 20 years or so. There are timing constraints and physical constraints, and constraints can be separated into multiple files.

The syntax for a physical constraint (which is what we have above) is:

set_property property value object-list
I have discarded (and/or burned) all of my Tcl books, which I don't really regret, but let's hold our nose and examine the Tcl syntax in the above example lines.

Tcl short course

The hash (#) is the comment character -- so what is this cryptic IO_L24N_T3_RS0_15 that appears in the above comments? I have seen this kind of notation elsewhere, but never seen it explained. This is not Tcl mind you, just something that deserves to be mentioned.

Square brackets are not what you think -- they say to evaluate what is inside of them and replace them (and what is in them) with the result. So consider the following:

[get_ports { A }]
This says to call the "get_ports" function and pass "A" as an argument. The square brackets say to do it now and interpolate the result in place. Whatever comes back as the result of this serves as the "object-list" in some mysterious way.

Curly braces are not what you think either. They tend to group several things into one and act like a certain kind of quote that inhibits substitution within it -- but they seem to have uses that aren't described by this, such as the following with just one thing inside the braces.
Consider the following:

set_property -dict { PACKAGE_PIN "N17" IOSTANDARD LVCMOS33 SLEW FAST} [get_ports { A }]; # IO_L21P_T3_DQS_14 Sch = SW3
Here the -dict "switch" says that a dictionary of settings follows (as a single argument). The dictionary has (in this case) 3 property value pairs:
PACKAGE_PIN "N17"
IOSTANDARD LVCMOS33
SLEW FAST
Some people would do this with separate lines as follows:
set_property PACKAGE_PIN E15 [get_ports {GPIO_O[0]}]
set_property IOSTANDARD LVCMOS25 [get_ports {GPIO_O[0]}]

A Tcl list is just a bunch of things separated by spaces. So you can define a list like this:

set mylist {red green blue}
Allow me a short rant on "set". Tcl has no infix assignment like a = 1, you say "set a 1" instead. On top of that, Tcl is generally dealing with strings (so "a" here is not a numeric value, but a string "1"). If you want to do math, you do something like "set a [expr $a+1]" if you can believe it. Indeed, this would be "a++" in C or many other modern languages. The built in "expr" function handles infix notation in its arguments, without it we would have to do something like "set a [add $a 1]" with a variety of math operator words like "add".

Note also the use of the dollar sign. Without it, we are just dealing with the string "a", with it (as in $a) we are dealing with the value stored in the variable of name "a". I trip over this all the time. The bottom line is that Tcl has virtually no parser as we know it in modern languages, and it is up to you to help it along every step of the way.

One last thing (maybe) to mention is the semicolon. This ends a Tcl statement with authority. It is sort of optional, but may either be a good idea or essential if a pound sign introduces an online comment that follows.

The following looks like a pretty good one page summary of Tcl fundamentals:


Feedback? Questions? Drop me a line!

Tom's Computer Info / [email protected]