Search code examples
tclxilinxvivado

Programming device in vivado using tcl


I am trying out programming my digilent FPGA through the vivado command line. After opening the hardware server I can program my device as follows...

program_hw_devices [get_hw_devices xc7a100t_0]

Then if I run puts [get_hw_devices xc7a100t_0] it outputs xc7a100t_0 which leads me to think that I should be able to just do something like program_hw_devices xc7a100t_0. This however fails and I get the following output.

ERROR: [Common 17-161] Invalid option value 'xc7a100t_0' specified for 'hw_device'.

I don't really understand what is wrong with this. I thought the two commands would be equivalent since I just passed it what was returned by get_hw_devices. Also I thought the type of everything in tcl was just a string. Does the output of [get_hw_devices xc7a100t_0] have some special type?


Solution

  • Looking at usage patterns, we see that the recommended usage is:

    program_hw_devices [lindex [get_hw_devices] 0]
    

    Given the text of the output of get_hw_devices is a “simple” word (no spaces or Tcl metacharacters), I suspect that the device tokens are actually special values that have non-trivial types hanging off the back end of their representation. We don't recommend that approach as it can lead to very weird error messages (such as the one you got), but given that it is so, you need to use exactly the pattern as described above so that you strip exactly one level of list-ness away.


    For future reference, the script at that link (which was supposedly working) was:

    # Connect to the Digilent Cable on localhost:3121
    
    connect_hw_server -url localhost:3121
    current_hw_target [get_hw_targets */xilinx_tcf/Digilent/12345]
    open_hw_target
    
    # Program and Refresh the XC7K325T Device
    
    current_hw_device [lindex [get_hw_devices] 0]
    refresh_hw_device -update_hw_probes false [lindex [get_hw_devices] 0]
    set_property PROGRAM.FILE {C:/design.bit} [lindex [get_hw_devices] 0]
    set_property PROBES.FILE {C:/design.ltx} [lindex [get_hw_devices] 0]
    
    program_hw_devices [lindex [get_hw_devices] 0]
    refresh_hw_device [lindex [get_hw_devices] 0]
    

    I would have written it more like this myself:

    # Connect to the Digilent Cable on localhost:3121
    connect_hw_server -url localhost:3121
    current_hw_target [get_hw_targets */xilinx_tcf/Digilent/12345]
    open_hw_target
    
    # Program and Refresh the XC7K325T Device
    set Device [lindex [get_hw_devices] 0]
    current_hw_device $Device
    refresh_hw_device -update_hw_probes false $Device
    set_property PROGRAM.FILE "C:/design.bit" $Device
    set_property PROBES.FILE "C:/design.ltx" $Device
    
    program_hw_devices $Device
    refresh_hw_device $Device
    

    so that I only do the list extraction once, but that's purely style; if one works, the other should as well.