Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix enumeration of USB devices without a short serial on Raspberry Pi 4 #160

Merged
merged 3 commits into from
Sep 27, 2024

Conversation

andber1
Copy link
Contributor

@andber1 andber1 commented Feb 19, 2024

This will fix the issue with USB devices that do not have a short serial and are not listed when using serialport::available_ports(). serial_number is an optional field in the UsbPortInfo struct and is not required to be available.

In my specifc case I have the USB device "USB-Serial_Controller" from "Prolific_Technology_Inc." (vid: 0x067b, pid: 0x2303). When connected to a Raspberry 4 it is not shown. This pull request fixes this.

Related to #113

Copy link
Contributor

@sirhcel sirhcel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your PR @andber1! It looks like the right thing to do here. We should not have detecting USB devices depending on optional properties.

src/posix/enumerate.rs Outdated Show resolved Hide resolved
@sirhcel
Copy link
Contributor

sirhcel commented Aug 30, 2024

I finally managed to set up a Raspberry Pi 4 to give this PR a check. I have no Prolific device at hand but a FTDI R2232 (without an external EEPROM and thereor) without a serial number. This device gets enumerated by the list_ports example just fine:

$ cargo run --example list_ports
[...]
Found 3 ports:
  /dev/ttyUSB1
    Type: USB
    VID:0403 PID:6010
     Serial Number:
      Manufacturer: FTDI
           Product: Dual RS232
[...]

I checked this with 18f5c2a. What do lsusb -v and udevadm info /dev/ttyUSBn report for the device in your case?

@andber1
Copy link
Contributor Author

andber1 commented Sep 8, 2024

@sirhcel Unfortunately I do not have a Raspberry 4 to hand now. I put the Prolific controller in a Raspberry 3 and it got listed, because it is a USB device and not a PCI device as on the Raspberry 4. Here are the requested outputs. Perhaps it will still help.

$ lsusb -v
[...]
Bus 001 Device 004: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port / Mobile Phone Data Cable
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x067b Prolific Technology, Inc.
  idProduct          0x2303 PL2303 Serial Port / Mobile Phone Data Cable
  bcdDevice            3.00
  iManufacturer           1 Prolific Technology Inc.
  iProduct                2 USB-Serial Controller
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0027
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x000a  1x 10 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
[...]
$ udevadm info /dev/ttyUSB0
P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1:1.0/ttyUSB0/tty/ttyUSB0
M: ttyUSB0
R: 0
U: tty
D: c 188:0
N: ttyUSB0
L: 0
S: serial/by-path/platform-3f980000.usb-usb-0:1:1.0-port0
S: serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0
E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1:1.0/ttyUSB0/tty/ttyUSB0
E: DEVNAME=/dev/ttyUSB0
E: MAJOR=188
E: MINOR=0
E: SUBSYSTEM=tty
E: USEC_INITIALIZED=561403310
E: ID_BUS=usb
E: ID_MODEL=USB-Serial_Controller
E: ID_MODEL_ENC=USB-Serial\x20Controller
E: ID_MODEL_ID=2303
E: ID_SERIAL=Prolific_Technology_Inc._USB-Serial_Controller
E: ID_VENDOR=Prolific_Technology_Inc.
E: ID_VENDOR_ENC=Prolific\x20Technology\x20Inc.
E: ID_VENDOR_ID=067b
E: ID_REVISION=0300
E: ID_TYPE=generic
E: ID_USB_MODEL=USB-Serial_Controller
E: ID_USB_MODEL_ENC=USB-Serial\x20Controller
E: ID_USB_MODEL_ID=2303
E: ID_USB_SERIAL=Prolific_Technology_Inc._USB-Serial_Controller
E: ID_USB_VENDOR=Prolific_Technology_Inc.
E: ID_USB_VENDOR_ENC=Prolific\x20Technology\x20Inc.
E: ID_USB_VENDOR_ID=067b
E: ID_USB_REVISION=0300
E: ID_USB_TYPE=generic
E: ID_USB_INTERFACES=:ff0000:
E: ID_USB_INTERFACE_NUM=00
E: ID_USB_DRIVER=pl2303
E: ID_VENDOR_FROM_DATABASE=Prolific Technology, Inc.
E: ID_MODEL_FROM_DATABASE=PL2303 Serial Port / Mobile Phone Data Cable
E: ID_PATH=platform-3f980000.usb-usb-0:1:1.0
E: ID_PATH_TAG=platform-3f980000_usb-usb-0_1_1_0
E: ID_MM_CANDIDATE=1
E: DEVLINKS=/dev/serial/by-path/platform-3f980000.usb-usb-0:1:1.0-port0 /dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0
E: TAGS=:systemd:
E: CURRENT_TAGS=:systemd:

@sirhcel
Copy link
Contributor

sirhcel commented Sep 27, 2024

Thank you very much for for looking up the device information @andber1! The device descriptor does not look special, udev reports in as a USB device and therefor ID_USB_SERIAL_SHORT does not matter.

I finally got a Prolific PL2303 device into my hands today and - well - it enumerate just fine in my setup:

$ cargo run --example list_ports
[...]
Found 2 ports:
  /dev/ttyUSB1
    Type: USB
    VID:067b PID:2303
     Serial Number:
      Manufacturer: Prolific Technology Inc.
           Product: USB-Serial Controller D
[...]

Now I see what I missed in #160 (comment) and what happens here as well: The device is actually reported as an USB device. 🤦

I also found device information seen on a Raspberry Pi 4 back in 2023 in #110 (comment). Looks like libudev changed how these devices are reported in my setup.

Nevertheless, your proposed changes are the right thing to do for older/different setups with a Raspberry Pi 4.

@sirhcel sirhcel merged commit f1b8ecf into serialport:main Sep 27, 2024
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants