![无法打开 USB 端口](https://linux22.com/image/1016983/%E6%97%A0%E6%B3%95%E6%89%93%E5%BC%80%20USB%20%E7%AB%AF%E5%8F%A3.png)
我有一台单板计算机,其 JTAG 端口由 FTDI 硬件提供服务,但它无法连接到开发系统 (Xilinx Vivado),我正在尝试诊断问题。 尽管我暂时将权限设置为 777,但命令sudo lsusb -v -D /dev/ttyUSB0
仍报告。我运行了连接和未连接电缆的情况,以确保我看到的是正确的设备,以下是我得到的结果(序列号被我混淆了):Cannot open /dev/ttyUSB0
sudo usb-devices
T: Bus=01 Lev=03 Prnt=04 Port=01 Cnt=01 Dev#= 9 Spd=480 MxCh= 0
D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=0403 ProdID=6014 Rev=09.00
S: Manufacturer=Digilent
S: Product=Digilent USB Device
S: SerialNumber=000000000000
C: #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr=0mA
I: If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=ftdi_sio
我正在运行全新安装的 18.04.2,昨天刚刚更新到 18.04.4;重新安装是因为想解决这个问题,我想确保过时的软件不是导致问题的原因。
我认为 Vivado 无法看到该设备可能与 lsusb 等常用系统工具无法打开该设备有关。如能提供任何帮助,我们将不胜感激。
答案1
好的,它与主编号无关,正如我所想。如果返回的指针为NULL Cannot open /dev/ttyUSB0
,则打印消息。此函数依次调用返回 USB 设备列表及其总线和设备编号,这些编号是使用 和提取并与连接的。您可以使用它来检查它(我使用了今天的主提交 c92f1962892d709cb9bad3aac2440932dd9684f6 来自dump_one_device()
get_usb_device()
libusb_get_device_list()
libusb_get_bus_number()
libusb_get_device_address()
"/dev/bus/usb"
gdb
https://github.com/gregkh/usbutils):
$ gdb --args ./lsusb -vD /dev/ttyUSB0
Reading symbols from ./lsusb...done.
(gdb) break usbutils/usbmisc.c:134
Breakpoint 1 at 0x40b827: file usbmisc.c, line 134.
(gdb) run
Starting program: /media/data/usbutils/lsusb -vD /dev/ttyUSB0
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff6d44700 (LWP 4621)]
Thread 1 "lsusb" hit Breakpoint 1, get_usb_device (ctx=<optimized out>, path=path@entry=0x7fffffffddab "/dev/ttyUSB0") at usbmisc.c:134
134 if (!strcmp(device_path, absolute_path)) {
(gdb) print device_path
$1 = "/dev/bus/usb/002/002", '\000' <repeats 4076 times>
(gdb) continue
Continuing.
Thread 1 "lsusb" hit Breakpoint 1, get_usb_device (ctx=<optimized out>, path=path@entry=0x7fffffffddab "/dev/ttyUSB0") at usbmisc.c:134
134 if (!strcmp(device_path, absolute_path)) {
(gdb) print device_path
$2 = "/dev/bus/usb/002/001", '\000' <repeats 4076 times>
(gdb) continue
Continuing.
Thread 1 "lsusb" hit Breakpoint 1, get_usb_device (ctx=<optimized out>, path=path@entry=0x7fffffffddab "/dev/ttyUSB0") at usbmisc.c:134
134 if (!strcmp(device_path, absolute_path)) {
(gdb) print device_path
$3 = "/dev/bus/usb/001/002", '\000' <repeats 4076 times>
(gdb) continue
Continuing.
Thread 1 "lsusb" hit Breakpoint 1, get_usb_device (ctx=<optimized out>, path=path@entry=0x7fffffffddab "/dev/ttyUSB0") at usbmisc.c:134
134 if (!strcmp(device_path, absolute_path)) {
(gdb) print device_path
$4 = "/dev/bus/usb/001/001", '\000' <repeats 4076 times>
(...)
依此类推,直到device_path
等于输入参数。当然/dev/ttyUSB0
永远不会匹配。
您还可以更改为 /dev/bus/usb 并传递相对设备地址,这很好:
$ cd /dev/bus/usb/
$ lsusb -D 001/001
Device: ID 1d6b:0002 Linux Foundation 2.0 root hub
(...)