我正在使用mspdebug
编程器连接到设备。
mspdebug
仅当我使用时才会连接到设备sudo mspdebug
。如果我不使用sudo
,mspdebug
则无法找到该设备。
如何在不需要的情况下连接到设备sudo
?
我特别想要连接的设备列于此处:
$ lsusb
Bus 001 Device 018: ID 2047:0013 Texas Instruments MSP Tools Driver
我有这些udev
规则/etc/udev/rules.d/46-TI_launchpad.rules
:
ATTR{idVendor}=="0451", ATTR{idProduct}=="f432", MODE="0660", GROUP="plugdev"
ATTR{idVendor}=="2047", ATTR{idProduct}=="0013", MODE="0660", GROUP="plugdev"
我在plugdev
群组中:
$ id $USER
uid=1000(earthishome) gid=1000(earthishome) groups=1000(earthishome),10(wheel),977(pkg-build),1001(plugdev),974(vboxusers),1003(docker)
编辑1
追踪设备
插入设备时,会创建两个 tty:ttyACM0
和ttyACM1
:
$ udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
KERNEL[21580.524390] add /devices/pci0000:00/0000:00:14.0/usb1/1-2 (usb)
KERNEL[21580.527712] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)
KERNEL[21580.528138] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/tty/ttyACM0 (tty)
KERNEL[21580.528301] bind /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)
KERNEL[21580.528453] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.1 (usb)
KERNEL[21580.528623] bind /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.1 (usb)
KERNEL[21580.528892] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2 (usb)
KERNEL[21580.529451] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/tty/ttyACM1 (tty)
KERNEL[21580.529600] bind /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2 (usb)
KERNEL[21580.529746] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.3 (usb)
KERNEL[21580.529892] bind /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.3 (usb)
KERNEL[21580.530075] bind /devices/pci0000:00/0000:00:14.0/usb1/1-2 (usb)
UDEV [21580.563378] add /devices/pci0000:00/0000:00:14.0/usb1/1-2 (usb)
UDEV [21580.570495] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)
UDEV [21580.572104] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.1 (usb)
UDEV [21580.573582] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.3 (usb)
UDEV [21580.573663] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2 (usb)
UDEV [21580.577042] bind /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.1 (usb)
UDEV [21580.578987] bind /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.3 (usb)
UDEV [21580.579357] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/tty/ttyACM0 (tty)
UDEV [21580.580712] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/tty/ttyACM1 (tty)
UDEV [21580.585516] bind /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)
UDEV [21580.585592] bind /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2 (usb)
UDEV [21580.596329] bind /devices/pci0000:00/0000:00:14.0/usb1/1-2 (usb)
使用strace
尝试打开时出现“权限被拒绝”错误/dev/ttyACM0
,但运行时不会发生strace sudo mspdebug tilib
。
$ strace mspdebug tilib
openat(AT_FDCWD, "/dev/ttyACM0", O_RDWR|O_NOCTTY|O_NONBLOCK) = -1 EACCES (Permission denied)
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=5000000}, NULL) = 0
openat(AT_FDCWD, "/dev/ttyACM0", O_RDWR|O_NOCTTY|O_NONBLOCK) = -1 EACCES (Permission denied)
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=5000000}, NULL) = 0
openat(AT_FDCWD, "/dev/ttyACM0", O_RDWR|O_NOCTTY|O_NONBLOCK) = -1 EACCES (Permission denied)
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=5000000}, NULL) = 0
openat(AT_FDCWD, "/dev/ttyACM0", O_RDWR|O_NOCTTY|O_NONBLOCK) = -1 EACCES (Permission denied)
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=5000000}, NULL) = 0
使用 udevadm 查找设备及其父设备
$ udevadm info --attribute-walk /dev/ttyACM0
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/tty/ttyACM0':
KERNEL=="ttyACM0"
SUBSYSTEM=="tty"
DRIVER==""
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0':
KERNELS=="1-2:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="cdc_acm"
ATTRS{iad_bFunctionSubClass}=="02"
ATTRS{bmCapabilities}=="2"
ATTRS{interface}=="MSP Debug Interface"
ATTRS{bInterfaceClass}=="02"
ATTRS{authorized}=="1"
ATTRS{bInterfaceNumber}=="00"
ATTRS{iad_bFunctionClass}=="02"
ATTRS{iad_bFunctionProtocol}=="01"
ATTRS{bAlternateSetting}==" 0"
ATTRS{supports_autosuspend}=="1"
ATTRS{iad_bFirstInterface}=="00"
ATTRS{bInterfaceSubClass}=="02"
ATTRS{bNumEndpoints}=="01"
ATTRS{bInterfaceProtocol}=="01"
ATTRS{iad_bInterfaceCount}=="02"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-2':
KERNELS=="1-2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{busnum}=="1"
ATTRS{authorized}=="1"
ATTRS{bMaxPacketSize0}=="8"
ATTRS{devnum}=="14"
ATTRS{bmAttributes}=="80"
ATTRS{rx_lanes}=="1"
ATTRS{serial}=="B1443A5106001800"
ATTRS{bcdDevice}=="0200"
ATTRS{bMaxPower}=="100mA"
ATTRS{product}=="MSP Tools Driver"
ATTRS{idVendor}=="2047"
ATTRS{bDeviceSubClass}=="02"
ATTRS{speed}=="12"
ATTRS{removable}=="removable"
ATTRS{urbnum}=="140"
ATTRS{devpath}=="2"
ATTRS{bDeviceClass}=="ef"
ATTRS{bNumInterfaces}==" 4"
ATTRS{tx_lanes}=="1"
ATTRS{ltm_capable}=="no"
ATTRS{idProduct}=="0013"
ATTRS{configuration}=="MSP430 USB"
ATTRS{maxchild}=="0"
ATTRS{bDeviceProtocol}=="01"
ATTRS{quirks}=="0x0"
ATTRS{bNumConfigurations}=="1"
ATTRS{manufacturer}=="Texas Instruments"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{version}==" 2.00"
ATTRS{bConfigurationValue}=="1"
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1':
KERNELS=="usb1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{authorized_default}=="1"
ATTRS{idVendor}=="1d6b"
ATTRS{speed}=="480"
ATTRS{bDeviceProtocol}=="01"
ATTRS{serial}=="0000:00:14.0"
ATTRS{devnum}=="1"
ATTRS{devpath}=="0"
ATTRS{bMaxPower}=="0mA"
ATTRS{ltm_capable}=="no"
ATTRS{version}==" 2.00"
ATTRS{rx_lanes}=="1"
ATTRS{busnum}=="1"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{urbnum}=="268"
ATTRS{bmAttributes}=="e0"
ATTRS{bDeviceClass}=="09"
ATTRS{bcdDevice}=="0506"
ATTRS{interface_authorized_default}=="1"
ATTRS{configuration}==""
ATTRS{bConfigurationValue}=="1"
ATTRS{bNumConfigurations}=="1"
ATTRS{quirks}=="0x0"
ATTRS{manufacturer}=="Linux 5.6.19-300.fc32.x86_64 xhci-hcd"
ATTRS{bNumInterfaces}==" 1"
ATTRS{idProduct}=="0002"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{authorized}=="1"
ATTRS{maxchild}=="12"
ATTRS{removable}=="unknown"
ATTRS{tx_lanes}=="1"
ATTRS{product}=="xHCI Host Controller"
looking at parent device '/devices/pci0000:00/0000:00:14.0':
KERNELS=="0000:00:14.0"
SUBSYSTEMS=="pci"
DRIVERS=="xhci_hcd"
ATTRS{device}=="0x9d2f"
ATTRS{dbc}=="disabled"
ATTRS{irq}=="126"
ATTRS{consistent_dma_mask_bits}=="64"
ATTRS{driver_override}=="(null)"
ATTRS{subsystem_device}=="0x082a"
ATTRS{dma_mask_bits}=="64"
ATTRS{class}=="0x0c0330"
ATTRS{subsystem_vendor}=="0x1028"
ATTRS{vendor}=="0x8086"
ATTRS{enable}=="1"
ATTRS{local_cpulist}=="0-7"
ATTRS{ari_enabled}=="0"
ATTRS{d3cold_allowed}=="1"
ATTRS{revision}=="0x21"
ATTRS{broken_parity_status}=="0"
ATTRS{local_cpus}=="ff"
ATTRS{msi_bus}=="1"
ATTRS{numa_node}=="-1"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
编辑2
感谢评论中的故障排除提示,我能够解决这个问题。
总长DR
有两件事需要改变:
将文件从 移动
46-TI_launchpad.rules
到94-TI_launchpad.rules
规则中改为如下
ATTR
所示:ATTRS
ATTRS {idVendor}==“2047”,ATTRS {idProduct}==“0013”,MODE =“0660”,GROUP =“plugdev”
细节
正如 Artem S. Tashkinov 和 meuh 所指出的那样,该规则正在被后来的规则所覆盖。在 90 年代重命名文件可确保它将运行到最后,并且不会被早期规则覆盖。
正如 dirkt 建议的那样,使用udevadm info -a
打印整个设备链。从设备链来看,实际设备本身并没有属性idVendor
和idProduct
定义;这些属性在父设备中定义。为了匹配这些属性,ATTR
必须更改为ATTRS
匹配父设备中的属性。
答案1
由于问题评论中的故障排除提示,我能够解决这个问题。
总长DR
有两件事需要改变:
- 将文件从 移动
46-TI_launchpad.rules
到94-TI_launchpad.rules
- 规则中改为如下
ATTR
所示:ATTRS
ATTRS{idVendor}=="2047", ATTRS{idProduct}=="0013", MODE="0660", GROUP="plugdev"
细节
正如 Artem S. Tashkinov 和 meuh 所指出的,46 规则正在被后来的规则覆盖。在 90 年代重命名文件可确保它将运行到最后,并且不会被早期规则覆盖。
正如 dirkt 建议的那样,使用udevadm info -a
打印整个设备链。从设备链来看,实际设备本身并没有属性idVendor
和idProduct
定义;这些属性在父设备中定义。为了匹配父设备中的属性,ATTR
必须更改为ATTRS
.