stlink-org/stlink

STLinkv3: UDEV rules in Debian not matching STLINK-V3MINIE

Ryanf55 opened this issue · 1 comments

Related Issues

#966

Description

In order to allow developers to isolate and target your respective issue, please take some time to select the check boxes below and fill out each of the following items appropriate to your specific problem.

  • Programmer/board type: STLINK-V3MINIE https://store.cuav.net/shop/cuav-c-adb/
  • Operating system an version: Linux Ubuntu 22.04.3
  • stlink tools version and/or git commit hash: Installed v1.7.0 debian, however reading docs from develop on 3e18d9d3b73ac954fca6ccc8419ce21dd65bd96f
  • stlink commandline tool name: N/A, just want the udev rules
  • Target chip (and board, if applicable): STM32H753 on Pixhawk 6X

Steps to reproduce

  1. Obtain a Ubuntu 22 computer and STLINk V3
  2. Install the latest debian from this repo: https://github.com/stlink-org/stlink#installation
  3. Verify with the FAQ the udev files are installed under the right directory: https://github.com/stlink-org/stlink/blob/develop/doc/tutorial.md#a-verify-if-udev-rules-are-set-correctly-by-dave-hylands
  4. Observe they are not in the right spot:
$ sudo dpkg -L stlink  | grep udev
/lib/udev
/lib/udev/rules.d
/lib/udev/rules.d/49-stlinkv1.rules
/lib/udev/rules.d/49-stlinkv2-1.rules
/lib/udev/rules.d/49-stlinkv2.rules
/lib/udev/rules.d/49-stlinkv3.rules

Commandline output:

Here is behavior with my STLink V3 connected via USB to my computer. The STM32H473 is not connected.

$ openocd --file Tools/debug/openocd-h7.cfg 
Open On-Chip Debugger 0.12.0+dev-g9fcf33da8 (2023-11-15-23:04)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 1800 kHz
Error: libusb_open() failed with LIBUSB_ERROR_ACCESS
Error: open failed

Now, you can run as root, and see it gets passed the LIBUSB_ERROR_ACCESS error, hinting to me the USB device did not have right permissions

$ sudo openocd --file Tools/debug/openocd-h7.cfg 
[sudo] password for ryan: 
Open On-Chip Debugger 0.12.0+dev-g9fcf33da8 (2023-11-15-23:04)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 1800 kHz
Info : STLINK V3J8M3 (API v3) VID:PID 0483:3754
Info : Target voltage: 0.001603
Error: target voltage may be too low for reliable debugging
Error: init mode failed (unable to connect to the target)
$ lsusb | grep STLINK
Bus 001 Device 038: ID 0483:3754 STMicroelectronics STLINK-V3

Note below permissions are NOT 0666 as explained in the FAQ.

$ ls -l /dev/bus/usb/001/038
crw-rw-r-- 1 root root 189, 37 Nov 16 08:01 /dev/bus/usb/001/038

Expected/description:

I would expect udev rules to be installed into the right directory such that I do not need to run my debugger as root.

Currently, in the debian, they are installed in /lib/udev, but the FAQ says they need to be in /etc/udev/rules.d/

Doing some further research with man udev, it seems the new directory is OK, however, it doesn't seem to help. Checking the rules, I found it was missing the specific rule for my device (0483:3754). Adding this solved it:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3754", \
    MODE:="0666", \
    SYMLINK+="stlinkv3_%n"