USB Port Select for Open On-Chip Debugger

After having played around with the HiFive1 a bit using the Arduino IDE, I wanted to integrate it in my tool environment and leave the Arduino IDE behind. I understand the Open On-Chip Debugger is used not only for debugging but also to just load newly compiled and linked programs to the HiFive1. It appears to find the correct USB port automagically (likely by finding the one with VID 0x0403 and PID 0x6010), but what if there are more than one HiFive1-s attached? The Arduino IDE apparently ignores the selected USB port, and the Makefile that comes with the SDK does not include an option to select the USB port (pair). How do I tell openocd which USB port (pair) to use in cases where more than one HiFive1 boards are attached?

1 Like

I think probably no one has needed to do this so there isn’t support worked out for it in either the freedom-e-sdk scripts or the Arduino IDE.

However OpenOCD does have a way to specify it. You can set the ftdi_location property in a .cfg file and then use different .cfg files for each board and then invoke OpenOCD with the correct .cfg file using the -f argument.

1 Like

Thanks a bunch @bruce - that works for me - I can integrate this into my stuff! I looked at the OpenOCD manual but couldn’t find it - probably because I was just a tad overwhelmed as I haven’t read it cover-to-cover (yet). But now I know where to look.

Glad a guy with my hair color could help me out here :grinning:

1 Like

“None of the Above”?

1 Like

I’s not the amount that matters, it is the color that stems from spending enough time with all this stuff and ultimately puts you in a position to share all this knowledge acquired over decades :grinning::grinning:

So thanks again for sharing some of it with us here!

1 Like

Under (the Arduino-installed) .../sifive/hardware/riscv/1.0.2/freedom-e-sdk/bsp/tools there is a bash script, which does exactly what you recommended. I couldn’t find it in the regular SDK install. Here is what it does

#! /bin/bash -x
openocd -f ${2} \
    	-c "flash protect 0 64 last off; program ${1} verify; resume 0x20400000; exit" \
    	2>&1 | tee openocd_upload.log

in other words, it takes the loadable program as the first and the USB port as the second parameter - works exactly as you said :grinning:

1 Like

I’m trying to use two boards attached to my host PC and facing the same issue “Makefile that comes with the SDK does not include an option to select the USB port (pair)”.
Can you please guide me through?

Sorry - this project has long been concluded and the host I used at the time doesn’t even exist anymore :unamused:. So I am afraid, the little script I posted back then (which came with the Arduino installation, but could just as well be copied-and-pasted out of the post) is all I would be able to offer. The script is just a wrapper around openocd that allows to specify the USB port as a second parameter - not that I remember (it’s been five years), I just read the script again.

A good start for your further investigations could be the OpenOCD (Open On Chip Debugger), which is, as mentioned, what this script uses

Good luck!

1 Like

Hi @anshumantech you can specify the VID and PID of a USB device (preferrably ftdi-compatible) in your openocd script file like so

adapter driver ftdi
ftdi device_desc description-string
ftdi vid_pid id-string
ftdi layout_init 0x0b08 0x0b1b

where description-string and id-string, respectively, are something like

FTDI module UM232

0x0403 0x6014

Tag-Connect cable

0x0403 0x6014

Olimex cable

0x15ba 0x002a

For best results, use the Zadig program, open-source and freely downloadable, when dealing with USB devices and their drivers in the MS Windows environment. Tip: I find libusbK works well with almost every interface device. Note that you will see two interfaces when your USB device is the two-channel FT2232H part; presumably you would see four interfaces when you plug in an FT4232H part although I have never comfirmed this.

You can see a full stand-alone example in my github repo Demonstrating-AMO, especially the openocd script and toolchain make file.

1 Like

Thanks @pds

I guess i wont be able to use Zadig because I’m on Ubuntu OS.
Let me tell you my setup, I’m using two development boards of RISC-V each having FT2232 (for jtag and serial) on Ubuntu V16.04. Yes, i can see two USB interfaces as you stated above.
Issue: When i invoke make command to download code into one of RISC-V board (when both boards are connected to PC) it randomly selects anyone of the two boards and downloads the code into it, what I want is to have option to select the desired board each time while downloading code.
Following is the .cfg file found under /bdp/thirdparty/

ftdi_device_desc “Arty On-board FTDI interface”

adapter_khz 1000

interface ftdi

ftdi_vid_pid 0x0403 0x6010

ftdi_channel 0

ftdi_layout_init 0x0088 0x008b

reset_config none

debug_level 4

set _CHIPNAME riscv

jtag newtap $_CHIPNAME cpu -irlen 6; # -expected-id 0x0362d093


target create $_TARGETNAME.0 riscv -chain-position $_TARGETNAME

$_TARGETNAME.0 configure -work-area-phys 0x80000000 -work-area-size 10000 -work-area-backup 1

riscv use_bscan_tunnel 5 1


if {[ info exists pulse_srst]} {

ftdi_set_signal nSRST 0

ftdi_set_signal nSRST z



Even better being on Linux/Ubuntu @anshumantech devices are easier to work with because you can see them with tools like lsusb -t

OpenOCD lets you specify the USB endpoint with its configuration command

adapter usb location [<bus>-<port>[.<port>]...]

where bus and port are clearly discussed at StackOverflow and the relevant documentation is in the OpenOCD manual.

Note that interface is a deprecated term in OpenOCD jim-tcl; it’s replacement is adapter driver. For the ftdi drivers the device_desc is optional, you can specify more than one pair of vendor and product ID’s, up to eight, like so

ftdi_vid_pid 0x0403 0x6010 0x15ba 0x002a

Thanks @pds
will keep updated here.