# USB Port Select for Open On-Chip Debugger

**URL:** <https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214>\
**Category:** HiFive1 Rev B\
**Created:** [April 8, 2019, 1:10am UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214 "2019-04-08T01:10:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ekkehard](https://avatars.discourse-cdn.com/v4/letter/e/d6d6ee/32.png) [@Ekkehard](https://forums.sifive.com/u/Ekkehard)\
**Post date:** [April 8, 2019, 1:10am UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214/1 "2019-04-08T01:10:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bruce](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/bruce/32/452_2.png) [@bruce](https://forums.sifive.com/u/bruce)\
**Post date:** [April 8, 2019, 6:14pm UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214/2 "2019-04-08T18:14:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ekkehard](https://avatars.discourse-cdn.com/v4/letter/e/d6d6ee/32.png) [@Ekkehard](https://forums.sifive.com/u/Ekkehard)\
**Post date:** [April 8, 2019, 6:40pm UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214/3 "2019-04-08T18:40:22Z")

</div>

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 😀

---

<div class="post-metadata">

**Author:** ![bruce](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/bruce/32/452_2.png) [@bruce](https://forums.sifive.com/u/bruce)\
**Post date:** [April 8, 2019, 8:32pm UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214/4 "2019-04-08T20:32:44Z")

</div>

“None of the Above”?

---

<div class="post-metadata">

**Author:** ![Ekkehard](https://avatars.discourse-cdn.com/v4/letter/e/d6d6ee/32.png) [@Ekkehard](https://forums.sifive.com/u/Ekkehard)\
**Post date:** [April 8, 2019, 9:01pm UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214/5 "2019-04-08T21:01:03Z")

</div>

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 😀😀

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

---

<div class="post-metadata">

**Author:** ![Ekkehard](https://avatars.discourse-cdn.com/v4/letter/e/d6d6ee/32.png) [@Ekkehard](https://forums.sifive.com/u/Ekkehard)\
**Post date:** [April 9, 2019, 11:09pm UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214/6 "2019-04-09T23:09:48Z")

</div>

Under (the Arduino-installed) `.../sifive/hardware/riscv/1.0.2/freedom-e-sdk/bsp/tools` there is a bash script `openocd_upload.sh`, 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 😀

---

<div class="post-metadata">

**Author:** ![anshumantech](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@anshumantech](https://forums.sifive.com/u/anshumantech)\
**Post date:** [December 14, 2023, 6:09am UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214/7 "2023-12-14T06:09:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Ekkehard](https://avatars.discourse-cdn.com/v4/letter/e/d6d6ee/32.png) [@Ekkehard](https://forums.sifive.com/u/Ekkehard)\
**Post date:** [December 14, 2023, 8:38pm UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214/8 "2023-12-14T20:38:48Z")

</div>

Sorry - this project has long been concluded and the host I used at the time doesn’t even exist anymore 😒. 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

[https://openocd.org/pages/documentation.html](https://openocd.org/pages/documentation.html)

Good luck!

---

<div class="post-metadata">

**Author:** ![pds](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pds](https://forums.sifive.com/u/pds)\
**Post date:** [December 16, 2023, 7:07pm UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214/9 "2023-12-16T19:07:44Z")

</div>

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

```auto
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

```auto
UM232H-B
0x0403 0x6014

```

Tag-Connect cable

```auto
C232HD-DDHSP-0
0x0403 0x6014

```

Olimex cable

```auto
Olimex OpenOCD JTAG ARM-USB-TINY-H
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](https://github.com/psherman42/Demonstrating-AMO), especially the `riscv.mk` openocd script and toolchain make file.

---

<div class="post-metadata">

**Author:** ![anshumantech](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@anshumantech](https://forums.sifive.com/u/anshumantech)\
**Post date:** [December 18, 2023, 12:17pm UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214/10 "2023-12-18T12:17:28Z")

</div>

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

set \_TARGETNAME $\_CHIPNAME.cpu

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

init

if {[info exists pulse\_srst]} {

ftdi\_set\_signal nSRST 0

ftdi\_set\_signal nSRST z

}

halt

---

<div class="post-metadata">

**Author:** ![pds](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@pds](https://forums.sifive.com/u/pds)\
**Post date:** [December 18, 2023, 6:27pm UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214/11 "2023-12-18T18:27:27Z")

</div>

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

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

```

where _bus_ and _port_ are clearly discussed at [StackOverflow](https://stackoverflow.com/questions/58072009/how-to-interpret-tcl-command-in-openocd-manual) and the relevant documentation is in the [OpenOCD manual](https://openocd.org/doc/html/Debug-Adapter-Configuration.html).

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

```auto
ftdi_vid_pid 0x0403 0x6010 0x15ba 0x002a

```

---

<div class="post-metadata">

**Author:** ![anshumantech](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@anshumantech](https://forums.sifive.com/u/anshumantech)\
**Post date:** [December 20, 2023, 6:51am UTC](https://forums.sifive.com/t/usb-port-select-for-open-on-chip-debugger/2214/12 "2023-12-20T06:51:38Z")

</div>

Thanks @pds  
will keep updated here.
