I found a resource on Automatic Script Execution so I know how to create a .tcl script that executes when compilation is complete. I'd like to know what needs to be in that .tcl script to automatically program the generated .sof file. I found this snippet but it doesn't seem to do what I want. Can anybody offer advice?

qexec quartus_pgm.exe -m jtag -c 1 -o "p;output_files\filename.sof"

It takes a little bit more to get it working than that. The following template should work:

set module [lindex $quartus(args) 0]
set revision [lindex $quartus(args) 2]

if {[string match "quartus_asm" $module]} {

    #Commands which are run after the Quartus Assembler
    post_message "Running TCL after Quartus Assembler"

    #Use Chain file to program sof.
    qexec "quartus_pgm ProgramSof.cdf"

Place the template in a TCL script file of whatever name you choose, e.g. PostModule.tcl, then in your projects .qsf file, and the following line:

set_global_assignment -name POST_MODULE_SCRIPT_FILE quartus_sh:PostModule.tcl

The line in the .qsf file will instruct Quartus to run the TCL script each time a module (e.g. fitter, assembler, timequest, etc.) finishes running.

In the script we get the current module that is being run, and can also get the corresponding project revision. Then we check whether the current module is the one that we want to run the script after - in this case Quartus Assembler (quartus_asm).

Any commands you put within that if statement are now executed every time that the Quartus Assembler finishes.

The simplest way to achieve the programming is to use a chain file. If you open the Quartus programmer and set up everything - programming hardware, sof filename, device list, and so on. Then save that file as something like "ProgramSof.cdf". The template above will then execute the Quartus programmer using that chain file which will use all the settings you have saved.

You can also change the command to do it entirely via command line switches rather than a chain file, however if you are going to do this you need to specify the programming cable name, the devices in the JTAG chain if there is more than one (e.g. many dev kits have MAX V supervisors in the chain with the main FPGA), and so forth. It is easier to simply save a chain file and then if you need to change any settings you can just edit that chain file.

  • \$\begingroup\$ Thanks for the answer but the template isn't working for me. I know it's running because I put a post_message outside of the if statement and it worked, but the post_message inside isn't printing. On top of that, this answer doesn't provide information about the actual programming command, which is the biggest piece I'm missing. Can you provide more details? Thanks! \$\endgroup\$ – Dillon Nichols Jun 23 '17 at 14:17
  • \$\begingroup\$ @DillonNichols it's possible the module name is wrong - I think asm is assembler. You could also try quartus_sta which is the timing analysis step run after the assembler. In terms of the exact programming string, that is entirely dependent on what FPGA family you have and what programmer you are using, neither of which you've specified. The command you gave in the question seems reasonable at first glance, I assumed the problem you were having was getting it to execute from the TCL script. \$\endgroup\$ – Tom Carpenter Jun 23 '17 at 15:49
  • \$\begingroup\$ Also, what version of Quartus are you using? \$\endgroup\$ – Tom Carpenter Jun 23 '17 at 15:50
  • \$\begingroup\$ In fact the template works fine for me. I get "Running TCL after Quartus Assembler" printed whenever Quartus Assembler finishes. \$\endgroup\$ – Tom Carpenter Jun 23 '17 at 16:08
  • \$\begingroup\$ @DillonNichols I've added to the template a line for getting the TCL script to run the programmer using a Quartus programmer chain file. The template works perfectly for me. \$\endgroup\$ – Tom Carpenter Jun 23 '17 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.