Not in fact any relation to the famous large Greek meal of the same name.

Wednesday, 4 January 2012

Giving An FTDI Serial Port A Persistent Device Node

There are plenty of perfectly good reasons why one might have several FTDI USB-to-serial adaptors attached to the same PC at the same time. Anyone who does, though, will notice that they’re a royal pain, because every time you unplug and replug one, it gets a different /dev/ttyUSBn device node.

Fortunately, there’s a way to use udev to set up unchanging aliases for those ever-changing device nodes. This is done by setting up a udev rule for each FTDI adaptor that you care about, that picks it out by serial number and gives it a custom symlink.

Some of the details are here, but just to sew it all together, here’s what you need to do.

  • First attach your FTDI adaptor, making sure all others are unplugged.

  • ls /dev/ttyUSB*
    — only one should be listed.
  • udevadm info --name=/dev/ttyUSB0 --attribute-walk
    — (using the ttyUSB number listed in the previous step) should dump a huge list of attributes
  • udevadm info --name=/dev/ttyUSB0 --attribute-walk | grep serial
    — will list only a few lines, such as the following —
    SUBSYSTEMS=="usb-serial"
    ATTRS{serial}=="XR00U1BU"
    ATTRS{serial}=="000000000000"
    ATTRS{serial}=="0000:00:1d.7"
  • The first ATTRS line is the one we’re interested in. That’s the USB serial number of the FTDI adaptor. (The subsequent lines are the USB serial number of an intermediate hub, and the PCI address of the USB controller.)
  • Now you need to go and find the udev rules directory: in a standard udev install, that’s /etc/udev/rules.d. In that directory, make a file called 99-local.rules (you’ll need to be root), and add a line like the following (and it must be all on one line; this blog might show it split) —
    KERNEL=="ttyUSB?", ATTRS{serial}=="XR00U1BU", SYMLINK+="ftdiDUINO", MODE="0666"
  • (An earlier version of this page suggested the name 10-local.rules, which with modern versions of udev is checked too early in the process; using 99-local.rules makes it work with any version of udev.)
  • Obviously the ATTRS clause must match the one your adaptor listed above. The SYMLINK clause can be anything (that doesn’t clash with any other device), so name it after the thing it’s plugged into at the other end.
  • Unplug and replug your FTDI adaptor. Whatever ttyUSB number it gets, the symlink /dev/ftdiDUINO will be pointing to it.
  • Oh yes, that udev rule also makes the device node world-writable. So you won’t need to be root to issue
    miniterm.py /dev/ftdiDUINO 115200

About Me

Cambridge, United Kingdom
Waits for audience applause ... not a sossinge.
CC0 To the extent possible under law, the author of this work has waived all copyright and related or neighboring rights to this work.