1

I'm completely new to tcl and am trying to understand how to script the command "adapter usb location" in openOCD.

From the openOCD manual, the command has this description: openOCD manual

I want to point it to the port with the red arrow below: lsusb -t

Thanks.

AJbotic
  • 75
  • 1
  • 6
  • 1
    The OpenOCD docs could definitely stand to be a little clearer here. In particular, the format of IDs (when not strictly “only use manufactured ones from the commands over there”) needs to be very clearly stated, whereas it's obvious that the authors of OpenOCD thought that it was too obvious to bother with. Alas. – Donal Fellows Sep 24 '19 at 08:59

1 Answers1

1

It's not 100% clear, but I would expect (from that snippet of documentation) a bus location to be a dotted “path” something like:

1-6

where the values are:

  • 1 — Bus ID
  • 6 — Port ID

Which would result in a call to the command being done like this:

adapter usb location 1-6

When there's a more complex structure involved (internally because of chained hubs) such as with the item above the one you pointed at, I'd instead expect:

1-5.3

Notice that there are is a sequence of port IDs (5.3) in there to represent the structure. The resulting call would then be:

adapter usb location 1-5.3

Now for the caveats!

I can't tell what the actual format of those IDs is. They might just be numbers, or they might have some textual prefix (e.g., bus1-port6). Those text prefixes, if present, might contain a space (or other metacharacter) which will be deeply annoying to use if true. You should be able to run adapter usb location without any other arguments to see what the current location is; be aware though that it might return the empty string (or give an error) if there is no current location. I welcome feedback on this, as that information appears to be not present in any online documentation I can find (and I don't have things installed so I can't just check).

I also have no idea what (if anything) to do with the device and interface IDs.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • Thanks for the suggestions. I've attempted what you suggested. Trying on a dev machine with the same hardware setup but the port numbers are different than the image in the original post, I used "adapter usb location 1-2" for bus 01, port 2. The error returned is " unable to open ftdi device with vid 0403, pid 6010, description '*', serial '*' at bus location '1-2' ". Next I try running "adapter usb location" and get back "adapter usb location: (null)". – AJbotic Sep 24 '19 at 14:56
  • I was misinterpreting the nesting of the ports when observing the results from lsusb -t. This answer is correct and there were no anomalous characters expected. Thank you. – AJbotic Sep 24 '19 at 16:55
  • I can confirm this worked for me. My adapter location was quite a bit longer: `1-1.4.5.2` for lsusb's Bus 1, Port 1, Port 4, Port 5, Port 2 (hub on a raspberry pi). Tips: I ended up putting the `adapter usb location
    ` inside my stlink.cfg file, as adding it via `-c` wasn't working. Don't include leading zeroes.
    – ArtHare Oct 11 '22 at 15:41