0

I have a couple of USB devices connected to my computer:

  1. An FT232 based USB-UART converter : Used to send and receive data between a microcontroller and the computer using the Serial protocol.
  2. A YDLidar TG15 : Used for mapping the environment. Product Page

I am running Lubuntu 22.04 LTS on a NUC.

I want to be able to assign the FT232-based device to dev/ttyUSB0 , and the YDLidar, which uses a cp210x serial converter, to dev/ttyUSB1 every time the computer boots up. The configuration I want is shown below:

$ sudo dmesg | grep tty
[    0.095479] printk: console [tty0] enabled
[    6.046918] usb 1-3: FTDI USB Serial Device converter now attached to ttyUSB0
[   57.282034] usb 1-4: cp210x converter now attached to ttyUSB1

I was able to follow some resources online such as this one, this one, and this one, which helped me to write a custom rule for my use-case, presented below.

$ cat /etc/udev/rules.d/34-usb-serial.rules 
# Assign FTDI chips to /dev/ttyFTDI
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK="ttyUSB0"
# Assign Silicon Labs UART converters to /dev/ttyUSB1
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK="ttyUSB1"

Problem:

  1. Even after triggering udevadm to reload the rules, it does not change the addresses after boot-up. I use
sudo udevadm control --reload-rules
sudo udevadm trigger

to reload the rules. This should load the rules, or complain if it cannot, right? However, when this substitution does not work, it does not throw any errors. It simply assigns the cp210x device as ttyUSB0 and the FTDI device as ttyUSB1. I can only know this when I do the sudo dmesg | grep tty once again.

  1. How do I use the udev rule that I wrote to properly assign these devices their appropriate IDs at boot-time?

P.S.: If there is any ambiguity about what is seen as "proper" in this context, I just want something that works in a robust fashion, while adhering as closely as possible to the "best practices" that are followed in editing these files.

Thanks in advance!

1 Answer 1

2

You may not be able to use SYMLINK="ttyUSB0" or SYMLINK="ttyUSB1" because they'll overlap with the standard names for the USB serial converter devices.

With a modern udev implementation, you cannot override the standard names, but you will be able to create additional symbolic links.

You should name your custom device nodes according to their purpose:

# FTDI serial converter for microcontroller
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="ttyUSBmc"

# Silicon Labs serial converter for LIDAR
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="ttyUSBlidar"

With these rules, the serial converters will get the actual device names /dev/ttyUSB0 and /dev/ttyUSB1 in whichever order they are detected on each boot, but /dev/ttyUSBmc will be a symbolic link that will always point to the FTDI serial converter, and /dev/ttyUSBlidar will always point to the Silicon Labs serial converter.

Also, after creating these udev rules, you should rebuild your initramfs file. It is possible that the drivers for the USB serial converters are loaded very early in the boot process, before the real root filesystem is mounted.

By updating your initramfs, you'll ensure that a copy of the udev rules you added will be present when even the earliest drivers are loading.

2
  • 1
    Hi telcoM, thanks for your response. Just so I understand you correctly, if I change my rules file to the one you posted on your answer, later on when I want to send/receive data, I should send to ttyUSBmc and ttyUSBlidar instead of ttyUSB0 and ttyUSB1, correct? For context, I have an executable which accepts the name of a serial device and baud rate passed in as command-line arguments.
    – ssarkar
    Oct 9, 2023 at 14:45
  • Yes, your understanding is correct.
    – telcoM
    Oct 9, 2023 at 14:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .