Altera Quartus II and Tcl

Altera Quartus II has acomplete  implementation, with many extra Tcl commands. To allow easy access, they are organised into Tcl packages which must be imported when needed.
Altera Quartus II provides a Tcl console, so you can type in commands, or source (read in) Tcl commands from an external file, directly from the Quartus II GUI.
As a first step, and if you are learnign Tcl, you could let Quartus helps you. It has a powerful feature which can get you started by creating a project file of settings for you, once you've set you project. You can then complete the script to suit your needs.

Let Quartus generates the project settings Tcl file for you. Here's how:
Project > Generate Tcl File for Project...
A dialogue box will pop up allowing you to store the Tcl file. Let's use the our counter example project



# Quartus II: Generate Tcl File for Project

# File: counter.tcl
# Generated on: Sun Mar 17 09:17:37 2013

# Load Quartus II Tcl Project package
package require ::quartus::project

set need_to_close_project 0
set make_assignments 1

# Check that the right project is open
if {[is_project_open]} {
if {[string compare $quartus(project) "counter"]} {
  puts "Project counter is not open"
  set make_assignments 0
}
} else {
# Only open if not already open
if {[project_exists counter]} {
  project_open -revision counter counter
} else {
  project_new -revision counter counter
}
set need_to_close_project 1
}

# Make assignments
if {$make_assignments} {
set_global_assignment -name FAMILY "Cyclone V"
set_global_assignment -name DEVICE 5CSXFC6D6F31C8
set_global_assignment -name ORIGINAL_QUARTUS_VERSION 12.1
set_global_assignment -name PROJECT_CREATION_TIME_DATE "12:30:13  MARCH 16, 2013"
set_global_assignment -name LAST_QUARTUS_VERSION 12.1
set_global_assignment -name PROJECT_OUTPUT_DIRECTORY output_files
set_global_assignment -name ERROR_CHECK_FREQUENCY_DIVISOR 256
set_global_assignment -name MIN_CORE_JUNCTION_TEMP 0
set_global_assignment -name MAX_CORE_JUNCTION_TEMP 85
set_global_assignment -name EDA_DESIGN_ENTRY_SYNTHESIS_TOOL "Design Compiler"
set_global_assignment -name EDA_INPUT_VCC_NAME VDD -section_id eda_design_synthesis
set_global_assignment -name EDA_LMF_FILE altsyn.lmf -section_id eda_design_synthesis
set_global_assignment -name EDA_INPUT_DATA_FORMAT EDIF -section_id eda_design_synthesis
set_global_assignment -name EDA_SIMULATION_TOOL "ModelSim-Altera (VHDL)"
set_global_assignment -name EDA_OUTPUT_DATA_FORMAT VHDL -section_id eda_simulation
set_global_assignment -name VHDL_FILE src/counter.vhd
set_global_assignment -name PARTITION_NETLIST_TYPE SOURCE -section_id Top
set_global_assignment -name PARTITION_FITTER_PRESERVATION_LEVEL PLACEMENT_AND_ROUTING -section_id Top
set_global_assignment -name PARTITION_COLOR 16764057 -section_id Top
set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top
set_parameter -name maxcount 10
set_parameter -name nbits 4

# Commit assignments
export_assignments

# Close project
if {$need_to_close_project} {
  project_close
}
}



To compile the design use the Quartus execute_flow Tcl command and  import the Quartus II ::quartus::flow package at the top of the script.

# Quartus II: Generate Tcl File for Project
# File: counter.tcl
# Generated on: Sun Mar 17 09:17:37 2013
# Load Quartus II Tcl Project package
package require ::quartus::project

# Add the next line to get the execute_flow command
package require ::quartus::flow

# ...

# ...cutted code here... 

# ...

  execute_flow -compile
  # Close project
  if {$need_to_close_project} {
    project_close
  }
}

 

To run the script you can put it in the project directory and use the source command as above from the GUI (source counter.tcl), rr you can run it from the command line as follows:
Open a shell (Linux) or a cmd prompt (Windows, the Windows PowerShell would be a better option)
Change directory and go where you saved your Tcl file and type:

 

quartus_sh -t counter.tcl



If you can't find the quartus_sh command you should add the bin (or bin64) Quartus II installation directory to your PATH system variable

Copyright 2018 Campera Electronic Systems Srl | All rights reserved | P.IVA 01780710495