some time ago i found out a way to add udev rules for AVR programmers. while i barely ever use AVRs nowadays, the udev part becomes handy over and over again. :)
recently at work we had a few helper RasPi boards connected a test env, with loads of other TTY-to-USB adapters. it was a mess, as after a reboot one could never tell which device is which. it was time to clean it up, and Chris pointed me to a neat fact, that RasPi Pico chips actually have a unique serial number to them. that insight was enough to make unique links for each serial device, so that instead of /dev/ttuACM3 you could have /dev/my_foobar_device.
first just check device properties with:
udevadm info --name=/dev/ttyACM3 --attribute-walk
then create udev rule in, say /etc/udev/rules.d/50-foobar.rules file:
SUBSYSTEM=="tty", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0005", ATTRS{serial}=="1234567890AB", \
SYMLINK+="my_foobar_device"
note that the rule is specific to a particular board / µC, as it has a serial number.
then make the change live:
udevadm control --reload-rules
udevadm trigger
…and enjoy new symlink! :)
to make things more fun, we had one device that reported 4 serial devices (e.g. /dev/ttyUSB0 to /dev/ttyUSB3), but we needed to name / link those differently, to make it readable. serial is available inside tty while bInterfaceNumber is in usb.
the bad news is that udev does not have built-in support for more than 1 SUBSYSTEM(S) match. the good news is that this can be worked around with labels. let's say we want 3rd of 4 (i.e. number 2):
# 1st part
SUBSYSTEM=="tty", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0005", ATTRS{serial}=="1234567890AB", \
GOTO="second_match"
GOTO="no_match"
# 2nd part
LABEL="second_match"
SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="02" \
SYMLINK+="my_device"
# no match - this rule does not apply
LABEL="no_match"
and voila – now we can have /dev/ttyUSB2 of our device, differentiated by serial, linked as /dev/my_device.
while this problem could also be addressed by SYMLINK+=“my_device_%n” and have just 4 linked devices, one would still need to remember which-is-which.