Ug Qps Scripting 683325 666985
Ug Qps Scripting 683325 666985
Contents
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
2
Contents
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
3
683325 | 2018.09.24
Send Feedback
The command-line executables are completely interchangeable with the Intel Quartus
Prime GUI, allowing you to use the exact combination of tools that best suits your
needs.
You can group Intel Quartus Prime executable files into a script, batch file, or a
makefile to automate design flows. These scripting capabilities facilitate the
integration of Intel Quartus Prime software and other EDA synthesis, simulation, and
verification software. Automatic design flows can perform on multiple computers
simultaneously and easily archive and restore projects.
Command-line executables reduce the amount of memory required during each step
in the design flow. Since each executable targets only one step in the design flow, the
executables themselves are relatively compact, both in file size and the amount of
memory used during processing. This memory usage reduction improves performance,
and is particularly beneficial in design environments where heavy usage of computing
resources results in reduced memory availability.
Related Information
About Command-Line Executables
in Intel Quartus Prime Help
If installed, the tutorial design is located in the <Intel Quartus Prime directory>/
qdesigns/fir_filter directory.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
1. Command Line Scripting
683325 | 2018.09.24
a. With the first instruction you create a new Intel Quartus Prime project named
filtref, set the top-level file as filtref.bdf, set Cyclone® V as the target
device family, and perform logic synthesis and technology mapping on the
design files.
b. The second command performs place and route by fitting the filtref project
into the specified device, and directs the Fitter to pack sequential and
combinational functions into single logic cells to reduce device resource usage.
c. The third command creates a device programming image for the filtref
project.
d. The last line performs basic timing analysis on the filtref project using the
Intel Quartus Prime Timing Analyzer, reporting worst-case setup slack, worst-
case hold slack, and other measurements.
4. Create a batch file or script file with the commands, like the UNIX shell script
below:
#!/bin/sh
PROJECT=filtref
TOP_LEVEL_FILE=filtref.bdf
FAMILY="Cyclone V"
PART=EP3C10F256C8
PACKING_OPTION=minimize_area
quartus_map $PROJECT --source=$TOP_LEVEL_FILE --family=$FAMILY
quartus_fit $PROJECT --part=$PART --pack_register=$PACKING_OPTION
quartus_asm $PROJECT
quartus_sta $PROJECT
Related Information
Intel Quartus Prime Scripting Reference Manual
To use the Intel Quartus Prime Command-Line and Tcl API Help browser, type the
following command:
quartus_sh --qhelp
This command starts the Intel Quartus Prime Command-Line and Tcl API Help browser,
a viewer for information about the Intel Quartus Prime Command-Line executables
and Tcl API.
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
5
1. Command Line Scripting
683325 | 2018.09.24
Use the -h option with any of the Intel Quartus Prime Command-Line executables to
get a description and list of supported options. Use the --help=<option name>
option for detailed information about each option.
Figure 1. Intel Quartus Prime Command-Line and Tcl API Help Browser
To make assignments to an individual entity you can use the Intel Quartus Prime Tcl
scripting API. On existing projects, you can also open the project in the Intel Quartus
Prime GUI, change the assignment, and close the project. The changed assignment is
updated in the .qsf. Any command-line executables that are run after this update
use the updated assignment.
Related Information
• Tcl Scripting on page 18
• Intel Quartus Prime Settings File (.qsf) Definition
in Intel Quartus Prime Help
• Intel Quartus Prime Standard Edition Settings File Reference Manual
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
6
1. Command Line Scripting
683325 | 2018.09.24
The .qsf file contains all the project-wide and entity-level assignments and settings
for the current revision for the project. The compiler database contains the result of
the last compilation in the /db directory, and reflects the assignments at the moment
when the project was compiled. Updated assignments first appear in the compiler
database and later in the .qsf file.
Command-line options override any conflicting assignments in the .qsf file or the
compiler database files. To specify whether the .qsf or compiler database files take
precedence for any assignments not specified in the command-line, use the option --
read_settings_files.
Any assignment not specified as a command-line option or found in the .qsf file or
compiler database file is set to its default value.
The example assumes that a project named fir_filter exists, and that the analysis and
synthesis step has been performed.
quartus_fit fir_filter --pack_register=off
quartus_sta fir_filter
mv fir_filter_sta.rpt fir_filter_1_sta.rpt
quartus_fit fir_filter --pack_register=minimize_area --
write_settings_files=off
quartus_sta fir_filter
mv fir_filter_sta.rpt fir_filter_2_sta.rpt
The third command uses the UNIX mv command to copy the report file output from
quartus_sta to a file with a new name, so that the results are not overwritten by
subsequent timing analysis.
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
7
1. Command Line Scripting
683325 | 2018.09.24
The fourth command runs quartus_fit a second time, and directs it to attempt to
pack logic into registers to reduce device resource usage. With the --
write_settings_files=off option, the command-line executable does not update
the .qsf to reflect the changed register packing setting. Instead, only the compiler
database files reflect the changed setting. If the --write_settings_files=off
option is not specified, the command-line executable updates the .qsf to reflect the
register packing setting.
The fifth command reruns timing analysis, and the sixth command renames the report
file, so that it is not overwritten by subsequent timing analysis.
In this example, the quartus_asm executable does not read or write settings files:
quartus_map filtref --source=filtref --part=EP3C10F256C8
quartus_fit filtref --pack_register=off --read_settings_files=off
quartus_asm filtref --read_settings_files=off --write_settings_files=off
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
8
1. Command Line Scripting
683325 | 2018.09.24
Quartus Shell
quartus_sh
Power
Analyzer
EDA Netlist Writer quartus_pow
quartus_eda Assembler
quartus_asm
Use the quartus_sh executable with the --flow option to perform a complete
compilation flow with a single command. The --flow option supports the smart
recompile feature and efficiently sets command-line arguments for each executable in
the flow.
The following example runs compilation, timing analysis, and programming file
generation with a single command:
quartus_sh --flow compile filtref
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
9
1. Command Line Scripting
683325 | 2018.09.24
Report file names contain the revision name and the short-form name of the
executable that generated the report file, in the format
<revision>.<executable>.rpt. For example, using the quartus_fit executable
to place and route a project with the revision name design_top generates a report
file named design_top.fit.rpt. Similarly, using the quartus_sta executable to
perform timing analysis on a project with the revision name fir_filter generates a
report file named fir_filter.sta.rpt.
Related Information
• Text-Format Report File (.rpt) Definition
in Intel Quartus Prime Help
• ::quartus::report
in Intel Quartus Prime Help
To set up a new project and apply individual constraints, such as pin location
assignments and timing requirements, you must use a Tcl script or the Intel Quartus
Prime GUI.
Command-line executables are very useful for working with existing projects, for
making common global settings, and for performing common operations. For more
flexibility in a flow, use a Tcl script. Additionally, Tcl scripts simplify passing data
between different stages of the design flow.
For example, you can create a UNIX shell script to run a third-party synthesis
software, place-and-route the design in the Intel Quartus Prime software, and
generate output netlists for other simulation software.
This script shows a script that synthesizes a design with the Synopsys* Synplify
®
software, simulates the design using the Mentor Graphics* ModelSim software, and
then compiles the design targeting a Cyclone V device.
#!/bin/sh
# Run synthesis first.
# This example assumes you use Synplify software
synplify -batch synthesize.tcl
# If your Quartus Prime project exists already, you can just
# recompile the design.
# You can also use the script described in a later example to
# create a new project from scratch
quartus_sh --flow compile myproject
# Use the quartus_sta executable to do fast and slow-model
# timing analysis
quartus_sta myproject --model=slow
quartus_sta myproject --model=fast
# Use the quartus_eda executable to write out a gate-level
# Verilog simulation netlist for ModelSim
quartus_eda my_project --simulation --tool=modelsim --format=verilog
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
10
1. Command Line Scripting
683325 | 2018.09.24
The example creates a project with a Tcl script and applies project constraints using
the tutorial design files in the <Intel Quartus Prime installation directory>/
qdesigns/fir_filter/ directory.
project_new filtref -overwrite
# Assign family, device, and top-level file
set_global_assignment -name FAMILY Cyclone
set_global_assignment -name DEVICE EP1C12F256C6
set_global_assignment -name BDF_FILE filtref.bdf
# Assign pins
set_location_assignment -to clk Pin_28
set_location_assignment -to clkx2 Pin_29
set_location_assignment -to d[0] Pin_139
set_location_assignment -to d[1] Pin_140
#
project_close
Save the script in a file called setup_proj.tcl and type the commands illustrated in
the example at a command prompt to create the design, apply constraints, compile
the design, and perform fast-corner and slow-corner timing analysis. Timing analysis
results are saved in two files, filtref_sta_1.rpt and filtref_sta_2.rpt.
quartus_sh -t setup_proj.tcl
quartus_map filtref
quartus_fit filtref
quartus_asm filtref
quartus_sta filtref --model=fast --export_settings=off
mv filtref_sta.rpt filtref_sta_1.rpt
quartus_sta filtref --export_settings=off
mv filtref_sta.rpt filtref_sta_2.rpt
Type the following commands to create the design, apply constraints, and compile the
design, without performing timing analysis:
quartus_sh -t setup_proj.tcl
quartus_sh --flow compile filtref
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
11
1. Command Line Scripting
683325 | 2018.09.24
The script checks the exit code of the quartus_map executable to determine whether
there is an error during the syntax check. Files with syntax errors are added to the
FILES_WITH_ERRORS variable, and when all files are checked, the script prints a
message indicating syntax errors.
When options are not specified, the executable uses the project database values. If
not specified in the project database, the executable uses the Intel Quartus Prime
software default values. For example, the fir_filter project is set to target the Cyclone
device family, so it is not necessary to specify the --family option.
#!/bin/sh
FILES_WITH_ERRORS=""
# Iterate over each file with a .bdf or .v extension
for filename in `ls *.bdf *.v`
do
# Perform a syntax check on the specified file
quartus_map fir_filter --analyze_file=$filename
# If the exit code is non-zero, the file has a syntax error
if [ $? -ne 0 ]
then
FILES_WITH_ERRORS="$FILES_WITH_ERRORS $filename"
fi
done
if [ -z "$FILES_WITH_ERRORS" ]
then
echo "All files passed the syntax check"
exit 0
else
echo "There were syntax errors in the following file(s)"
echo $FILES_WITH_ERRORS
exit 1
fi
The --part option causes quartus_map to target a device. To create the project and
synthesize it using the netlist optimizations described above, type the command
shown in this example at a command prompt.
quartus_map top --source=top.edf --enable_register_retiming=on
--enable_wysiwyg_resynthesis=on --part=EP3C10F256C8
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
12
1. Command Line Scripting
683325 | 2018.09.24
Use the --archive or --restore options for quartus_sh as appropriate. Type the
command shown in the example at a command prompt to archive your project.
quartus_sh --archive <project name>
The archive file is automatically named <project name>.qar. If you want to use a
different name, type the command with the -output option as shown in example the
example.
quartus_sh --archive <project name> -output <filename>
To restore a project archive, type the command shown in the example at a command
prompt.
quartus_sh --restore <archive name>
The command restores the project archive to the current directory and overwrites
existing files.
Related Information
Managing Intel Quartus Prime Projects
The example shows the commands for a DOS batch file for this example. With a DOS
batch file, you can specify the project name and the revision name once for both
commands. To create the DOS batch file, paste the following lines into a file called
update_memory.bat.
quartus_cdb --update_mif %1 --rev=%2
quartus_asm %1 --rev=%2
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
13
1. Command Line Scripting
683325 | 2018.09.24
To run the batch file, type the following command at a command prompt:
update_memory.bat <project name> <revision name>
To create an option file that turns on compression, type the following command at a
command prompt:
quartus_cpf -w <filename>.opt
This interactive command guides you through some questions, then creates an option
file based on your answers. Use --option to cause quartus_cpf to use the option
file. For example, the following command creates a compressed .pof that targets an
EPCS64 device:
quartus_cpf --convert --option=<filename>.opt --device=EPCS64 <file>.sof
<file>.pof
Alternatively, you can use the Convert Programming Files utility in the Intel Quartus
Prime software GUI to create a Conversion Setup File (.cof). Configure any options
you want, including compression, then save the conversion setup. Use the following
command to run the conversion setup you specified.
quartus_cpf --convert <file>.cof
To attempt to fit the project called top as quickly as possible, type the command
shown at a command prompt.
quartus_fit top --effort=fast --one_fit_attempt=on
Because the top-level entity in the project does not have the same name as the
project, you must specify the revision name for the top-level entity with the --rev
option. The --seed option specifies the seeds to use for fitting.
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
14
1. Command Line Scripting
683325 | 2018.09.24
A seed is a parameter that affects the random initial placement of the Intel Quartus
Prime Fitter. Varying the seed can result in better performance for some designs.
After each fitting attempt, the script creates new directories for the results of each
fitting attempt and copies the complete project to the new directory so that the results
are available for viewing and debugging after the script has completed.
#!/bin/sh
ERROR_SEEDS=""
quartus_map fir_filter --rev=filtref
# Iterate over a number of seeds
for seed in 1 2 3 4 5
do
echo "Starting fit with seed=$seed"
# Perform a fitting attempt with the specified seed
quartus_fit fir_filter --seed=$seed --rev=filtref
# If the exit-code is non-zero, the fitting attempt was
# successful, so copy the project to a new directory
if [ $? -eq 0 ]
then
mkdir ../fir_filter-seed_$seed
mkdir ../fir_filter-seed_$seed/db
cp * ../fir_filter-seed_$seed
cp db/* ../fir_filter-seed_$seed/db
else
ERROR_SEEDS="$ERROR_SEEDS $seed"
fi
done
if [ -z "$ERROR_SEEDS" ]
then
echo "Seed sweeping was successful"
exit 0
else
echo "There were errors with the following seed(s)"
echo $ERROR_SEEDS
exit 1
fi
Tip: Use Design Space Explorer II (DSE) included with the Intel Quartus Prime software
script (by typing quartus_dse at a command prompt) to improve design
performance by performing automated seed sweeping.
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
15
1. Command Line Scripting
683325 | 2018.09.24
Tip: The QFlow script is located in the <Intel Quartus Prime directory>/
common/tcl/apps/qflow/ directory.
2015.05.04 15.0.0 Remove descriptions of makefile support that was removed from
software in 14.0.
November 2009 9.1.0 Updated Table 2–1 to add quartus_jli and quartus_jbcc executables
and descriptions, and other minor updates throughout document.
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
16
1. Command Line Scripting
683325 | 2018.09.24
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
17
683325 | 2018.09.24
Send Feedback
2. Tcl Scripting
You can use Tcl scripts to control the Intel Quartus Prime software and to perform a
wide range of functions, such as compiling a design or scripting common tasks.
Tcl scripts also facilitate project or assignment migration. For example, when designing
in different projects with the same prototype or development board, you can write a
script to automate reassignment of pin locations in each new project. The Intel
Quartus Prime software can also generate a Tcl script based on all the current
assignments in the project, which aids in switching assignments to another project.
The Intel Quartus Prime software Tcl commands follow the EDA industry Tcl application
programming interface (API) standards for command-line options. This simplifies
learning and using Tcl commands. If you encounter an error with a command
argument, the Tcl interpreter includes help information showing correct usage.
This chapter includes sample Tcl scripts for automating tasks in the Intel Quartus
Prime software. You can modify these example scripts for use with your own designs.
You can find more Tcl scripts in the Design Examples section of the Support area on
the Altera website.
Related Information
Tcl Design Examples
With Tcl, you can work seamlessly across most development platforms. Synopsys,
Mentor Graphics, and Intel software products support the Tcl language.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
2. Tcl Scripting
683325 | 2018.09.24
By combining Tcl commands and Intel Quartus Prime API functions, you can create
your own procedures and automate your design flow. Run Intel Quartus Prime
software in batch mode, or execute individual Tcl commands interactively in the Intel
Quartus Prime Tcl shell.
Intel Quartus Prime software supports Tcl/Tk version 8.5, supplied by the Tcl
DeveloperXchange.
chip_planner Identify and modify resource usage and routing with the Chip Editor
device Get device and family information from the device database
fif Contains the set of Tcl functions for using the Fault Injection File (FIF) Driver
flow Compile a project, run command-line executables, and other common flows
incremental compilation Manipulate design partitions and Logic Lock (Standard) regions, and settings related to incremental
compilation
insystem_source_probe Interact with the In-System Sources and Probes tool in an Intel device
logic_analyzer_interface Query and modify the Logic Analyzer Interface output pin state
misc Perform miscellaneous tasks such as enabling natural bus naming, package loading, and message
posting
partial_reconfiguration Contain the set of Tcl functions for performing partial reconfiguration
project Create and manage projects and revisions, make any project assignments including timing
assignments
sta Contain the set of Tcl functions for obtaining advanced information from the Timing Analyzer
synthesis_report Contain the set of Tcl functions for the Dynamic Synthesis Report tool
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
19
2. Tcl Scripting
683325 | 2018.09.24
Run your scripts with executables that include the packages you use in the scripts. For
example, to use commands in the sdc_ext package, you must use the quartus_sta
executable because quartus_sta is the only executable with support for the
sdc_ext package.
The following command prints lists of the packages loaded or available to load for an
executable, to the console:
For example, type the following command to list the packages loaded or available to
load by the quartus_fit executable:
quartus_fit --tcl_eval help
Related Information
Command Line Scripting on page 4
• This command opens the Intel Quartus Prime Command-Line and Tcl API help
browser, which documents all commands and options in the Intel Quartus Prime
Tcl API. At a system command prompt, access the Intel Quartus Prime Tcl API Help
by typing:
quartus_sh --qhelp
• The Tcl API Help can be accessed from the Tcl console as well. At a Tcl prompt,
type
help
to access the help information. The output is:
tcl> help
-------------------------------------------------------------------------
----------------------------------
Available Intel Quartus Prime Tcl Packages:
----------------------------------
Loaded Not Loaded
------------------ ----------------------------------
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
20
2. Tcl Scripting
683325 | 2018.09.24
::quartus::device ::quartus::external_memif_toolkit
::quartus::misc ::quartus::iptclgen
::quartus::project ::quartus::design
::quartus::rtm
::quartus::partial_reconfiguration
::quartus::report
::quartus::names
::quartus::incremental_compilation
::quartus::flow
The Tcl console provides help options that display specific information:
Table 5. Help Options Available in the Intel Quartus Prime Tcl Environment
Help Command Description
help -tcl Explains how to load Tcl packages and access command-line
help.
help -pkg <package_name -[-version <version number>] Displays help commands of the Intel Quartus Prime package
that you specify, including the list of available Tcl
commands.
• If you do not specify -version, the Intel Quartus Prime
software loads the latest version of the package.
• If the package is not loaded, the Intel Quartus Prime
software displays the help for the latest version of the
package.
Examples:
package require ::quartus::<package name>[<version>] Loads a specific version of an Intel Quartus Prime Tcl
package. If you do not specify -version, the Intel Quartus
Prime software loads the latest version of the package.
Example:
load_package <package name> [-version <version number>] Allows you to alternate between different versions of the
same package.
Example:
continued...
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
21
2. Tcl Scripting
683325 | 2018.09.24
help -cmd <command_name> Displays the complete help text for an Intel Quartus Prime
-[-version <version>] Tcl command. If you do not specify -version, the Intel
Quartus Prime software loads the latest version of the
or package.
<command_name> -long_help Examples:
project_open -long_help
help -quartus To view help on the predefined global Tcl array that contains
project information and information about the Intel Quartus
Prime executable that is currently running.
quartus_sh --qhelp Launches the Tk viewer for Intel Quartus Prime command-
line help and display help for the command-line executables
and Tcl API packages.
"TimeQuestInfo"
Tcl array that contains delay model information and speed
grade information of a Timing Analyzer design that is
currently running.
The Tcl API help is also available in Intel Quartus Prime online help. Search for the
command or package name to find details about that command or package.
--script=<script file> [<script args>] Run the specified Tcl script with optional arguments.
-t <script file> [<script args>] Run the specified Tcl script with optional arguments. The -t option is the
short form of the --script option.
-s Open the executable in the interactive Tcl shell mode. The -s option is the
short form of the --shell option.
--tcl_eval <tcl command> Evaluate the remaining command-line arguments as Tcl commands. For
example, the following command displays help for the project package:
quartus_sh --tcl_eval help -pkg project
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
22
2. Tcl Scripting
683325 | 2018.09.24
For example, to run a script called myscript.tcl with one argument, Stratix®,
type the following command at a system command prompt:
quartus_sh -t myscript.tcl Stratix
quartus_sta -s
Commands you type in the Tcl shell are interpreted when you press Enter. To run a Tcl
script in the interactive shell type:
source <script name>
For example, the following command runs the Tcl command that prints out the
commands available in the project package.
quartus_sh --tcl_eval help -pkg project
Note: Some shell commands such as cd, ls, and others can be run in the Tcl Console
window, with the Tcl exec command. However, for best results, run shell commands
and Intel Quartus Prime executables from a system command prompt outside of the
Intel Quartus Prime software GUI.
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
23
2. Tcl Scripting
683325 | 2018.09.24
Tcl messages appear in the System tab (Messages window). Errors and messages
written to stdout and stderr also are shown in the Intel Quartus Prime Tcl Console
window.
Typically, EDA tools include their own script interpreters that extend core language
functionality with tool-specific commands. For example, the Intel Quartus Prime Tcl
interpreter supports all core Tcl commands, and adds numerous commands specific to
the Intel Quartus Prime software. You can include commands in one Tcl script to run
another script, which allows you to combine or chain together scripts to control
different tools. Because scripts for different tools must be executed with different Tcl
interpreters, it is difficult to pass information between the scripts unless one script
writes information into a file and another script reads it.
Within the Intel Quartus Prime software, you can perform many different operations in
a design flow (such as synthesis, fitting, and timing analysis) from a single script,
making it easy to maintain global state information and pass data between the
operations. However, there are some limitations on the operations you can perform in
a single script due to the various packages supported by each executable.
There are no limitations on running flows from any executable. Flows include
operations found in
Processing ➤ Start in the Intel Quartus Prime GUI, and are also documented as
options for the execute_flow Tcl command. If you can make settings in the Intel
Quartus Prime software and run a flow to get your desired result, you can make the
same settings and run the same flow in a Tcl script.
Click Project ➤ Generate Tcl File for Project to automatically generate a .tcl file
containing your assignments. You can source this file to recreate your project, and you
can add other commands to this file, such as commands for compiling the design. This
file is a good starting point to learn about project management and assignment
commands.
To commit the assignments you create or modify to the .qsf file, you use the
export_assignments or project_close commands. However, when you run the
execute_flow command, Intel Quartus Prime software automatically commits the
assignment changes to the .qsf file. To prevent this behavior, specify the -
dont_export_assignments logic option.
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
24
2. Tcl Scripting
683325 | 2018.09.24
The following example creates a project, makes assignments, and compiles the
design. The example uses the fir_filter tutorial design files in the qdesigns
installation directory. Run this script in the fir_filter directory, with the
quartus_sh executable.
load_package flow
# Create the project and overwrite any settings
# files that exist
project_new fir_filter -revision filtref -overwrite
# Set the device, the name of the top-level BDF,
# and the name of the top-level entity
set_global_assignment -name FAMILY Cyclone
set_global_assignment -name DEVICE EP1C6F256C6
set_global_assignment -name BDF_FILE filtref.bdf
set_global_assignment -name TOP_LEVEL_ENTITY filtref
# Add other pin assignments here
set_location_assignment -to clk Pin_G1
# compile the project
execute_flow -compile
project_close
Related Information
• Intel Quartus Prime Standard Edition Settings File Reference Manual
• Interactive Shell Mode on page 23
Use the flow package instead of system calls to run Intel Quartus Prime executables
from scripts or from the Intel Quartus Prime Tcl Console.
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
25
2. Tcl Scripting
683325 | 2018.09.24
2.7. Reporting
You can extract information from the Compilation Report to evaluate results. The Intel
Quartus Prime Tcl API provides easy access to report data so you do not have to write
scripts to parse the text report files.
If you know the exact report cell or cells you want to access, use the
get_report_panel_data command and specify the row and column names (or x
and y coordinates) and the name of the appropriate report panel. You can often
search for data in a report panel. To do this, use a loop that reads the report one row
at a time with the get_report_panel_row command.
Column headings in report panels are in row 0. If you use a loop that reads the report
one row at a time, start with row 1 to skip column headings. The
get_number_of_rows command returns the number of rows in the report panel,
including the column heading row. Since the number of rows includes the column
heading row, continue your loop if the loop index is less than the number of rows.
Report panels are hierarchically arranged and each level of hierarchy is denoted by the
string “||“ in the panel name. For example, the name of the Fitter Settings report
panel is Fitter||Fitter Settings because it is in the Fitter folder. Panels at
the highest hierarchy level do not use the “||” string. For example, the Flow Settings
report panel is named Flow Settings.
The following Tcl code prints a list of all report panel names in your project. You can
run this code with any executable that includes support for the report package.
The following Tcl code shows a simple way to create a .csv file with data from the
Fitter panel in a report.
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
26
2. Tcl Scripting
683325 | 2018.09.24
You can modify the script to use command-line arguments to pass in the name of the
project, report panel, and output file to use. You can run this script example with any
executable that supports the report package.
The Intel Quartus Prime software includes comprehensive Tcl APIs and SDC extensions
for the Timing Analyzer in the sta, and sdc_ext packages. The Intel Quartus Prime
software also includes a tdc package that obtains information from the Timing
Analyzer.
Related Information
Intel Quartus Prime Standard Edition Settings File Reference Manual
The following three global assignments control when a script is run automatically:
• PRE_FLOW_SCRIPT_FILE —before a flow starts
• POST_MODULE_SCRIPT_FILE —after a module finishes
• POST_FLOW_SCRIPT_FILE —after a flow finishes
A module is another term for an Intel Quartus Prime executable that performs one
step in a flow. For example, two modules are Analysis and Synthesis (quartus_map),
and timing analysis (quartus_sta).
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
27
2. Tcl Scripting
683325 | 2018.09.24
A flow is a series of modules that the Intel Quartus Prime software runs with
predefined options. For example, compiling a design is a flow that typically consists of
the following steps (performed by the indicated module):
1. Analysis and Synthesis (quartus_map)
2. Fitter (quartus_fit)
3. Assembler (quartus_asm)
4. Timing Analyzer (quartus_sta)
Other flows are described in the help for the execute_flow Tcl command. In
addition, many commands in the Processing menu of the Intel Quartus Prime GUI
correspond to this design flow.
The first argument passed in the argv variable (or quartus(args) variable) is the
name of the flow or module being executed, depending on the assignment you use.
The second argument is the name of the project and the third argument is the name
of the revision.
The last process, current project, and current revision are passed to the script by the
Intel Quartus Prime software and can be accessed by the following commands:
set process [lindex $quartus(args) 0]
set project [lindex $quartus(args) 1]
set revision [lindex $quartus(args) 2]
When you compile your project, the PRE_FLOW_SCRIPT_FILE assignment causes the
following command to be run before compilation begins:
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
28
2. Tcl Scripting
683325 | 2018.09.24
Next, the Intel Quartus Prime software starts compilation with analysis and synthesis,
performed by the quartus_map executable. After the Analysis and Synthesis finishes,
the POST_MODULE_SCRIPT_FILE assignment causes the following command to run:
Then, the Intel Quartus Prime software continues compilation with the Fitter,
performed by the quartus_fit executable. After the Fitter finishes, the
POST_MODULE_SCRIPT_FILE assignment runs the following command:
Corresponding commands are run after the other stages of the compilation. When the
compilation is over, the POST_FLOW_SCRIPT_FILE assignment runs the following
command:
For example, if you want a script to run only after timing analysis, use a conditional
test like the following example. It checks the flow or module name passed as the first
argument to the script and executes code when the module is quartus_sta.
Related Information
• The post_message Command on page 31
• Automating Script Execution on page 27
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
29
2. Tcl Scripting
683325 | 2018.09.24
The Intel Quartus Prime software defaults to natural bus naming. You can turn off
natural bus naming with the disable_natural_bus_naming command. For more
information about natural bus naming, type the following at an Intel Quartus Prime Tcl
prompt:
enable_natural_bus_naming -h
You can use any of the following abbreviations of the -revision option:
• -r
• -re
• -rev
• -revi
• -revis
• -revisio
You can use an extremely short option such as -r because in the case of the
project_open command no other option starts with the letter r. However, the
report_timing command includes the options -recovery and -removal. You
cannot use -r or -re to shorten either of those options, because the abbreviation is
not unique.
There are two Intel Quartus Prime Tcl commands for working with collections,
foreach_in_collection and get_collection_size. Use the set command to
assign a collection ID to a variable.
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
30
2. Tcl Scripting
683325 | 2018.09.24
foreach_in_collection Example
set all_instance_assignments [get_all_instance_assignments -name *]
foreach_in_collection asgn $all_instance_assignments {
# Information about each assignment is
# returned in a list. For information
# about the list elements, refer to Help
# for the get-all-instance-assignments command.
set to [lindex $asgn 2]
set name [lindex $asgn 3]
set value [lindex $asgn 4]
puts "Assignment to $to: $name = $value"
}
Related Information
foreach_in_collection (::quartus::misc)
In Intel Quartus Prime Help
get_collection_size Example
set all_global_assignments [get_all_global_assignments -name *]
set num_global_assignments [get_collection_size $all_global_assignments]
puts "There are $num_global_assignments global assignments in your project"
If you do not specify a type, Intel Quartus Prime software defaults to info.
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
31
2. Tcl Scripting
683325 | 2018.09.24
With the Intel Quartus Prime software in Windows, you can color code messages
displayed at the system command prompt with the post_message command. Add
the following line to your quartus2.ini file:
DISPLAY_COMMAND_LINE_MESSAGES_IN_COLOR = on
The following Tcl example prints all the arguments in the quartus(args) variable:
set i 0
foreach arg $quartus(args) {
puts "The value at index $i is $arg"
incr i
}
If you copy the script in the previous example to a file named print_args.tcl, it
displays the following output when you type the following at a command prompt.
quartus_sh -t print_args.tcl my_project 100MHz
The value at index 0 is my_project
The value at index 1 is 100MHz
cmdline Package
package require cmdline
variable ::argv0 $::quartus(args)
set options {
{ "project.arg" "" "Project name" }
{ "frequency.arg" "" "Frequency" }
}
set usage "You need to specify options and values"
array set optshash [::cmdline::getoptions ::argv $options $usage]
puts "The project name is $optshash(project)"
puts "The frequency is $optshash(frequency)"
If you save those commands in a Tcl script called print_cmd_args.tcl you see the
following output when you type the following command at a command prompt.
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
32
2. Tcl Scripting
683325 | 2018.09.24
Virtually all Intel Quartus Prime Tcl scripts must open a project. You can open a
project, and you can optionally specify a revision name with code like the following
example. The example checks whether the specified project exists. If it does, the
example opens the current revision, or the revision you specify.
If you do not require this flexibility or error checking, you can use just the
project_open command.
help -quartus
2.11. The Intel Quartus Prime Tcl Shell in Interactive Mode Example
This section presents how to make project assignments and then compile the finite
impulse response (FIR) filter tutorial project with the quartus_sh interactive shell.
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
33
2. Tcl Scripting
683325 | 2018.09.24
This example assumes you already have the fir_filter tutorial design files in a
project directory.
1. To run the interactive Tcl shell, type the following at the system command prompt:
quartus_sh -s
Note: • If the project file and project name are the same, the Intel Quartus
Prime software gives the revision the same name as the project.
• If a .qpf file for this project already exists, the Intel Quartus Prime
software will display an error stating that the project already exists.
Because the revision named filtref matches the top-level file, all design files
are automatically picked up from the hierarchy tree.
3. Set a global assignment for the device:
To learn more about assignment names that you can use with the -name option,
refer to Intel Quartus Prime Help.
Note: For assignment values that contain spaces, enclose the value in quotation
marks.
4. To compile a design, use the ::quartus::flow package, which properly exports
the new project assignments and compiles the design with the proper sequence of
the command-line executables. First, load the package:
load_package flow
It returns:
1.1
5. To perform a full compilation of the FIR filter design, use the execute_flow
command with the -compile option:
execute_flow -compile
This command compiles the FIR filter tutorial project, exporting the project
assignments and running quartus_map, quartus_fit, quartus_asm, and
quartus_sta. This sequence of events is the same as selecting Processing ➤
Start Compilation in the Intel Quartus Prime GUI.
6. When you are finished with a project, close it with the project_close
command.
7. To exit the interactive Tcl shell, type exit at a Tcl prompt.
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
34
2. Tcl Scripting
683325 | 2018.09.24
To include other directories in the path searched by the tclsh shell, set the
QUARTUS_INIT_PATH environment variable before running the tclsh shell. Directories
in the QUARTUS_INIT_PATH environment variable are searched by the tclsh shell
when you execute a system command.
Tcl commands are executed immediately as they are typed in an interactive Tcl shell.
You can also create scripts (including the examples in this chapter) in files and run
them with the Intel Quartus Prime executables or with the tclsh shell.
Use double quotation marks to group the words hello and world as one argument.
Double quotation marks allow substitutions to occur in the group. Substitutions can be
simple variable substitutions, or the result of running a nested command. Use curly
braces {} for grouping when you want to prevent substitutions.
2.13.2. Variables
Assign a value to a variable with the set command. You do not have to declare a
variable before using it. Tcl variable names are case-sensitive.
set a 1
To access the contents of a variable, use a dollar sign (“$”) before the variable name.
The following example prints "Hello world" in a different way.
set a Hello
set b world
puts "$a $b"
2.13.3. Substitutions
Tcl performs three types of substitution:
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
35
2. Tcl Scripting
683325 | 2018.09.24
puts "This is a\
$ special character and line continuation"
2.13.4. Arithmetic
Use the expr command to perform arithmetic calculations. Use curly braces (“{ }”)
to group the arguments of this command for greater efficiency and numeric precision.
set a 5
set b [expr { $a + sqrt(2) }]
The Intel Quartus Prime software supports all standard Tcl boolean and arithmetic
operators, such as && (AND), || (OR), ! (NOT), and comparison operators such as <
(less than), > (greater than), and == (equal to).
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
36
2. Tcl Scripting
683325 | 2018.09.24
2.13.5. Lists
A Tcl list is a series of values. Supported list operations include creating lists,
appending lists, extracting list elements, computing the length of a list, sorting a list,
and more.
set a { 1 2 3 }
You can use the lindex command to extract information at a specific index in a list.
Indexes are zero-based. You can use the index end to specify the last element in the
list, or the index end-<n> to count from the end of the list. For example, to print the
second element (at index 1) in the list stored in a use the following code.
puts [lindex $a 1]
The lappend command appends elements to a list. If a list does not already exist, the
list you specify is created. The list variable name is not specified with a dollar sign
(“$”).
lappend a 4 5 6
2.13.6. Arrays
Arrays are similar to lists except that they use a string-based index. Tcl arrays are
implemented as hash tables. You can create arrays by setting each element
individually or with the array set command.
To set an element with an index of Mon to a value of Monday in an array called days,
use the following command:
set days(Mon) Monday
The array set command requires a list of index/value pairs. This example sets the
array called days:
array set days { Sun Sunday Mon Monday Tue Tuesday \
Wed Wednesday Thu Thursday Fri Friday Sat Saturday }
Use the array names command to get a list of all the indexes in a particular array.
The index values are not returned in any specified order. The following example is one
way to iterate over all the values in an array.
foreach day [array names days] {
puts "The abbreviation $day corresponds to the day\
name $days($day)"
}
Arrays are a very flexible way of storing information in a Tcl script and are a good way
to build complex data structures.
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
37
2. Tcl Scripting
683325 | 2018.09.24
If-Then-Else Structure
if { $a > 0 } {
puts "The value is positive"
} elseif { $a < 0 } {
puts "The value is negative"
} else {
puts "The value is zero"
}
The following example uses a for loop to print each element in a list.
For Loop
set a { 1 2 3 }
for { set i 0 } { $i < [llength $a] } { incr i } {
puts "The list element at index $i is [lindex $a $i]"
}
The following example uses a foreach loop to print each element in a list.
foreach Loop
set a { 1 2 3 }
foreach element $a {
puts "The list element is $element"
}
The following example uses a while loop to print each element in a list.
while Loop
set a { 1 2 3 }
set i 0
while { $i < [llength $a] } {
puts "The list element at index $i is [lindex $a $i]"
incr i
}
You do not have to use the expr command in boolean expressions in control structure
commands because they invoke the expr command automatically.
2.13.8. Procedures
Use the proc command to define a Tcl procedure (known as a subroutine or function
in other scripting and programming languages). The scope of variables in a procedure
is local to the procedure. If the procedure returns a value, use the return command
to return the value from the procedure. The following example defines a procedure
that multiplies two numbers and returns the result.
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
38
2. Tcl Scripting
683325 | 2018.09.24
Simple Procedure
proc multiply { x y } {
set product [expr { $x * $y }]
return $product
}
The following example shows how to use the multiply procedure in your code. You
must define a procedure before your script calls it.
Using a Procedure
proc multiply { x y } {
set product [expr { $x * $y }]
return $product
}
set a 1
set b 2
puts [multiply $a $b]
Define procedures near the beginning of a script. If you want to access global
variables in a procedure, use the global command in each procedure that uses a
global variable.
To open a file, use the open command; to close a file, use the close command.
When you open a file, specify its name and the mode in which to open it. If you do not
specify a mode, Tcl defaults to read mode. To write to a file, specify w for write mode.
Tcl supports other modes, including appending to existing files and reading from and
writing to the same file.
The open command returns a file handle to use for read or write access. You can use
the puts command to write to a file by specifying a file handle.
Write to a File
set output [open myfile.txt w]
puts $output "This text is written to the file."
close $output
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
39
2. Tcl Scripting
683325 | 2018.09.24
You can read a file one line at a time with the gets command. The following example
uses the gets command to read each line of the file and then prints it out with its line
number.
Tcl uses the hash or pound character (#) to begin comments. The # character must
begin a comment. If you prefer to include comments on the same line as a command,
be sure to terminate the command with a semicolon before the # character. The
following example is a valid line of code that includes a set command and a
comment.
set a 1;# Initializes a
Without the semicolon, the command is invalid because the set command does not
terminate until the new line after the comment.
The Tcl interpreter counts curly braces inside comments, which can lead to errors that
are difficult to track down. The following example causes an error because of
unbalanced curly braces.
# if { $x > 0 } {
if { $y > 0 } {
# code here
}
• Brent B. Welch and Ken Jones, and Jeffery Hobbs, Practical Programming in Tcl
and Tk (Upper Saddle River: Prentice Hall, 2003)
• John Ousterhout and Ken Jones, Tcl and the Tk Toolkit (Boston: Addison-Wesley
Professional, 2009)
• Mark Harrison and Michael McLennan, Effective Tcl/Tk Programming: Writing
Better Programs in Tcl and Tk (Boston: Addison-Wesley Professional, 1997)
Intel Quartus Prime Standard Edition User Guide: Scripting Send Feedback
40
2. Tcl Scripting
683325 | 2018.09.24
Related Information
www.tcl.tk
Tcl Developer Xchange
November 2008 8.1.0 Changed to 8½” × 11” page size. No change to content.
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
41
683325 | 2018.09.24
Send Feedback
Related Information
• Intel Quartus Prime Standard Edition User Guide: Getting Started
Introduces the basic features, files, and design flow of the Intel Quartus Prime
Standard Edition software, including managing Intel Quartus Prime Standard
Edition projects and IP, initial design planning considerations, and project
migration from previous software versions.
• Intel Quartus Prime Standard Edition User Guide: Platform Designer
Describes creating and optimizing systems using Platform Designer (Standard),
a system integration tool that simplifies integrating customized IP cores in your
project. Platform Designer (Standard) automatically generates interconnect
logic to connect intellectual property (IP) functions and subsystems.
• Intel Quartus Prime Standard Edition User Guide: Design Recommendations
Describes best design practices for designing FPGAs with the Intel Quartus
Prime Standard Edition software. HDL coding styles and synchronous design
practices can significantly impact design performance. Following recommended
HDL coding styles ensures that Intel Quartus Prime Standard Edition synthesis
optimally implements your design in hardware.
• Intel Quartus Prime Standard Edition User Guide: Design Compilation
Describes set up, running, and optimization for all stages of the Intel Quartus
Prime Standard Edition Compiler. The Compiler synthesizes, places, and routes
your design before generating a device programming file.
• Intel Quartus Prime Standard Edition User Guide: Design Optimization
Describes Intel Quartus Prime Standard Edition settings, tools, and techniques
that you can use to achieve the highest design performance in Intel FPGAs.
Techniques include optimizing the design netlist, addressing critical chains that
limit retiming and timing closure, and optimization of device resource usage.
• Intel Quartus Prime Standard Edition User Guide: Programmer
Describes operation of the Intel Quartus Prime Standard Edition Programmer,
which allows you to configure Intel FPGA devices, and program CPLD and
configuration devices, via connection with an Intel FPGA download cable.
• Intel Quartus Prime Standard Edition User Guide: Partial Reconfiguration
Describes Partial Reconfiguration, an advanced design flow that allows you to
reconfigure a portion of the FPGA dynamically, while the remaining FPGA
design continues to function. Define multiple personas for a particular design
region, without impacting operation in other areas.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
A. Intel Quartus Prime Standard Edition User Guides
683325 | 2018.09.24
Send Feedback Intel Quartus Prime Standard Edition User Guide: Scripting
43