libusb backend issue with Teensy HID device #443

Closed
opened 2022-08-14 07:54:57 -05:00 by mcuee · 8 comments
mcuee commented 2022-08-14 07:54:57 -05:00 (Migrated from github.com)

From here.
https://github.com/avrdudes/avrdude/blob/main/src/teensy.c#L126-L131

        if (pdata->hid_usage == 0)
        {
            // On Linux, libhidapi does not seem to return the HID usage from the report descriptor.
            // We try to infer the board from the part information, until somebody fixes libhidapi.
            // To use this workaround, the -F option is required.
            avrdude_message(MSG_INFO, "%s: WARNING: Cannot detect board type (HID usage is 0)\n", progname);

This seems to happen to the libusb backend but not hidraw backend.

From here. https://github.com/avrdudes/avrdude/blob/main/src/teensy.c#L126-L131 ``` if (pdata->hid_usage == 0) { // On Linux, libhidapi does not seem to return the HID usage from the report descriptor. // We try to infer the board from the part information, until somebody fixes libhidapi. // To use this workaround, the -F option is required. avrdude_message(MSG_INFO, "%s: WARNING: Cannot detect board type (HID usage is 0)\n", progname); ``` This seems to happen to the libusb backend but not hidraw backend.
mcuee commented 2022-08-14 08:00:00 -05:00 (Migrated from github.com)

You can see from the following results that HID usage reporting is not good for the libusb backend.

mcuee@UbuntuSwift3:~/build/hidapi/build$ ./hidtest/hidtest_libusb 
hidapi test/example tool. Compiled with hidapi version 0.13.0, runtime version 0.13.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 16c0 0486
  path: 3-1:1.0
  serial_number: (null)
  Manufacturer: (null)
  Product:      Teensyduino RawHID Device
  Release:      102
  Interface:    0
  Usage (page): 0x0 (0x0)

Device Found
  type: 16c0 0486
  path: 3-1:1.1
  serial_number: (null)
  Manufacturer: (null)
  Product:      Teensyduino RawHID Device
  Release:      102
  Interface:    1
  Usage (page): 0x0 (0x0)

unable to open device

mcuee@UbuntuSwift3:~/build/hidapi/build$ ./hidtest/hidtest_hidraw 
hidapi test/example tool. Compiled with hidapi version 0.13.0, runtime version 0.13.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 16c0 0486
  path: /dev/hidraw1
  serial_number: 
  Manufacturer: (null)
  Product:      Teensyduino RawHID Device
  Release:      102
  Interface:    0
  Usage (page): 0x200 (0xffab)

Device Found
  type: 16c0 0486
  path: /dev/hidraw4
  serial_number: 
  Manufacturer: (null)
  Product:      Teensyduino RawHID Device
  Release:      102
  Interface:    1
  Usage (page): 0x4 (0xffc9)

   ... skipped ...

unable to open device

mcuee@UbuntuSwift3:~/build/hidapi/build$ lsusb -vvv -d 16c0:0486

Bus 003 Device 025: ID 16c0:0486 Van Ooijen Technische Informatica Teensyduino RawHID
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x16c0 Van Ooijen Technische Informatica
  idProduct          0x0486 Teensyduino RawHID
  bcdDevice            1.02
  iManufacturer           0 
  iProduct                1 Teensyduino RawHID Device
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0049
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xc0
      Self Powered
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              2 Teensyduino RawHID
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      28
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x04  EP 4 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              3 Emulated Arduino Serial
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      33
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               2
can't get device qualifier: Resource temporarily unavailable
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0000
  (Bus Powered)


You can see from the following results that HID usage reporting is not good for the libusb backend. ``` mcuee@UbuntuSwift3:~/build/hidapi/build$ ./hidtest/hidtest_libusb hidapi test/example tool. Compiled with hidapi version 0.13.0, runtime version 0.13.0. Compile-time version matches runtime version of hidapi. Device Found type: 16c0 0486 path: 3-1:1.0 serial_number: (null) Manufacturer: (null) Product: Teensyduino RawHID Device Release: 102 Interface: 0 Usage (page): 0x0 (0x0) Device Found type: 16c0 0486 path: 3-1:1.1 serial_number: (null) Manufacturer: (null) Product: Teensyduino RawHID Device Release: 102 Interface: 1 Usage (page): 0x0 (0x0) unable to open device mcuee@UbuntuSwift3:~/build/hidapi/build$ ./hidtest/hidtest_hidraw hidapi test/example tool. Compiled with hidapi version 0.13.0, runtime version 0.13.0. Compile-time version matches runtime version of hidapi. Device Found type: 16c0 0486 path: /dev/hidraw1 serial_number: Manufacturer: (null) Product: Teensyduino RawHID Device Release: 102 Interface: 0 Usage (page): 0x200 (0xffab) Device Found type: 16c0 0486 path: /dev/hidraw4 serial_number: Manufacturer: (null) Product: Teensyduino RawHID Device Release: 102 Interface: 1 Usage (page): 0x4 (0xffc9) ... skipped ... unable to open device mcuee@UbuntuSwift3:~/build/hidapi/build$ lsusb -vvv -d 16c0:0486 Bus 003 Device 025: ID 16c0:0486 Van Ooijen Technische Informatica Teensyduino RawHID Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 0 bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x16c0 Van Ooijen Technische Informatica idProduct 0x0486 Teensyduino RawHID bcdDevice 1.02 iManufacturer 0 iProduct 1 Teensyduino RawHID Device iSerial 0 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 0x0049 bNumInterfaces 2 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xc0 Self Powered MaxPower 100mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 0 bInterfaceProtocol 0 iInterface 2 Teensyduino RawHID HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.11 bCountryCode 0 Not supported bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 28 Report Descriptors: ** UNAVAILABLE ** Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x83 EP 3 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x04 EP 4 OUT bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 0 bInterfaceProtocol 0 iInterface 3 Emulated Arduino Serial HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.11 bCountryCode 0 Not supported bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 33 Report Descriptors: ** UNAVAILABLE ** Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x02 EP 2 OUT bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0020 1x 32 bytes bInterval 2 can't get device qualifier: Resource temporarily unavailable can't get debug descriptor: Resource temporarily unavailable Device Status: 0x0000 (Bus Powered) ```
JoergAtGithub commented 2022-08-14 14:04:15 -05:00 (Migrated from github.com)

@mcuee Could you try, what usbhid-dump returns for this device?

@mcuee Could you try, what usbhid-dump returns for this device?
Youw commented 2022-08-14 14:12:18 -05:00 (Migrated from github.com)

This is a known and documented issue: github.com/libusb/hidapi@c3ae3d0b58/libusb/hid.c (L729)

As I mentioned here - now there is a workaround (ask for USAGE after the device is open).

This is a known and documented issue: https://github.com/libusb/hidapi/blob/c3ae3d0b582ba5e6b26af603aea37d988e7eda7b/libusb/hid.c#L729 As I mentioned [here](https://github.com/libusb/hidapi/pull/432#issuecomment-1214167047) - now there is a workaround (ask for USAGE after the device is open).
mcuee commented 2022-08-14 20:42:17 -05:00 (Migrated from github.com)

@Youw
In this case, should I close this issue as this is a known limitation and there is a workaround now?

For avrdude, I am suggesting to use the hidraw backend.
https://github.com/avrdudes/avrdude/issues/1065#issuecomment-1214373729

@Youw In this case, should I close this issue as this is a known limitation and there is a workaround now? For avrdude, I am suggesting to use the hidraw backend. https://github.com/avrdudes/avrdude/issues/1065#issuecomment-1214373729
Youw commented 2022-08-15 04:43:42 -05:00 (Migrated from github.com)

Lets close it after #438 is resolved - that's another related improvement.

Lets close it after #438 is resolved - that's another related improvement.
mcuee commented 2022-08-16 08:19:32 -05:00 (Migrated from github.com)

Yes I can confirm that #444 is good for #438 which can serve as the workaround for this issue (to ask for USAGE after the device is open).

mcuee@UbuntuSwift3:~/build/hidapi/build$ sudo ./hidtest/hidtest_libusb 
hidapi test/example tool. Compiled with hidapi version 0.13.0, runtime version 0.13.0.
Compile-time version matches runtime version of hidapi.

Device Found
  type: 046d c52b
  path: 3-3:1.0
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    0
  Usage (page): 0x0 (0x0)

Device Found
  type: 046d c52b
  path: 3-3:1.1
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    1
  Usage (page): 0x0 (0x0)

Device Found
  type: 046d c52b
  path: 3-3:1.2
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    2
  Usage (page): 0x0 (0x0)

Device Found
  type: 04d8 003f
  path: 3-2.3:1.0
  serial_number: (null)
  Manufacturer: Microchip Technology Inc.
  Product:      Simple HID Device Demo
  Release:      2
  Interface:    0
  Usage (page): 0x0 (0x0)

Device Found
  type: 16c0 0486
  path: 3-1:1.0
  serial_number: (null)
  Manufacturer: (null)
  Product:      Teensyduino RawHID Device
  Release:      102
  Interface:    0
  Usage (page): 0x0 (0x0)

Device Found
  type: 16c0 0486
  path: 3-1:1.1
  serial_number: (null)
  Manufacturer: (null)
  Product:      Teensyduino RawHID Device
  Release:      102
  Interface:    1
  Usage (page): 0x0 (0x0)

Manufacturer String: Microchip Technology Inc.
Product String: Simple HID Device Demo
Serial Number String: (1033) 
Device Found
  type: 04d8 003f
  path: 3-2.3:1.0
  serial_number: (null)
  Manufacturer: Microchip Technology Inc.
  Product:      Simple HID Device Demo
  Release:      2
  Interface:    0
  Usage (page): 0x1 (0xff00)

Indexed String 1: Microchip Technology Inc.
Unable to send a feature report.
Unable to get a feature report: hid_error is not implemented yet
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
read() timeout

When I change the test device to Teensy 2.0.

Unable to read manufacturer string
Manufacturer String: 
Product String: Teensyduino RawHID Device
Unable to read serial number string
Serial Number String: (0) 
Device Found
  type: 16c0 0486
  path: 3-1:1.0
  serial_number: (null)
  Manufacturer: (null)
  Product:      Teensyduino RawHID Device
  Release:      102
  Interface:    0
  Usage (page): 0x200 (0xffab)

Indexed String 1: Teensyduino RawHID Device
Feature Report
   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
read() timeout

When I changed the device to the Logitech USB receiver:

Manufacturer String: Logitech
Product String: USB Receiver
Serial Number String: (1033) 
Device Found
  type: 046d c52b
  path: 3-3:1.0
  serial_number: (null)
  Manufacturer: Logitech
  Product:      USB Receiver
  Release:      1203
  Interface:    0
  Usage (page): 0x6 (0x1)

Indexed String 1: Logitech
Unable to send a feature report.
Unable to get a feature report: hid_error is not implemented yet
Unable to write(): hid_error is not implemented yet
Unable to write()/2: hid_error is not implemented yet
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
waiting...
read() timeout


Yes I can confirm that #444 is good for #438 which can serve as the workaround for this issue (to ask for USAGE after the device is open). ``` mcuee@UbuntuSwift3:~/build/hidapi/build$ sudo ./hidtest/hidtest_libusb hidapi test/example tool. Compiled with hidapi version 0.13.0, runtime version 0.13.0. Compile-time version matches runtime version of hidapi. Device Found type: 046d c52b path: 3-3:1.0 serial_number: (null) Manufacturer: Logitech Product: USB Receiver Release: 1203 Interface: 0 Usage (page): 0x0 (0x0) Device Found type: 046d c52b path: 3-3:1.1 serial_number: (null) Manufacturer: Logitech Product: USB Receiver Release: 1203 Interface: 1 Usage (page): 0x0 (0x0) Device Found type: 046d c52b path: 3-3:1.2 serial_number: (null) Manufacturer: Logitech Product: USB Receiver Release: 1203 Interface: 2 Usage (page): 0x0 (0x0) Device Found type: 04d8 003f path: 3-2.3:1.0 serial_number: (null) Manufacturer: Microchip Technology Inc. Product: Simple HID Device Demo Release: 2 Interface: 0 Usage (page): 0x0 (0x0) Device Found type: 16c0 0486 path: 3-1:1.0 serial_number: (null) Manufacturer: (null) Product: Teensyduino RawHID Device Release: 102 Interface: 0 Usage (page): 0x0 (0x0) Device Found type: 16c0 0486 path: 3-1:1.1 serial_number: (null) Manufacturer: (null) Product: Teensyduino RawHID Device Release: 102 Interface: 1 Usage (page): 0x0 (0x0) Manufacturer String: Microchip Technology Inc. Product String: Simple HID Device Demo Serial Number String: (1033) Device Found type: 04d8 003f path: 3-2.3:1.0 serial_number: (null) Manufacturer: Microchip Technology Inc. Product: Simple HID Device Demo Release: 2 Interface: 0 Usage (page): 0x1 (0xff00) Indexed String 1: Microchip Technology Inc. Unable to send a feature report. Unable to get a feature report: hid_error is not implemented yet waiting... waiting... waiting... waiting... waiting... waiting... waiting... waiting... waiting... waiting... read() timeout ``` When I change the test device to Teensy 2.0. ``` Unable to read manufacturer string Manufacturer String: Product String: Teensyduino RawHID Device Unable to read serial number string Serial Number String: (0) Device Found type: 16c0 0486 path: 3-1:1.0 serial_number: (null) Manufacturer: (null) Product: Teensyduino RawHID Device Release: 102 Interface: 0 Usage (page): 0x200 (0xffab) Indexed String 1: Teensyduino RawHID Device Feature Report 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 waiting... waiting... waiting... waiting... waiting... waiting... waiting... waiting... waiting... waiting... read() timeout ``` When I changed the device to the Logitech USB receiver: ``` Manufacturer String: Logitech Product String: USB Receiver Serial Number String: (1033) Device Found type: 046d c52b path: 3-3:1.0 serial_number: (null) Manufacturer: Logitech Product: USB Receiver Release: 1203 Interface: 0 Usage (page): 0x6 (0x1) Indexed String 1: Logitech Unable to send a feature report. Unable to get a feature report: hid_error is not implemented yet Unable to write(): hid_error is not implemented yet Unable to write()/2: hid_error is not implemented yet waiting... waiting... waiting... waiting... waiting... waiting... waiting... waiting... waiting... waiting... read() timeout ```
Youw commented 2022-08-16 08:30:18 -05:00 (Migrated from github.com)

A workaround is possible, based on current master.

A [workaround](https://github.com/libusb/hidapi/issues/443#issuecomment-1214433164) is possible, based on current master.
mcuee commented 2022-08-16 08:33:50 -05:00 (Migrated from github.com)

A workaround is possible, based on current master.

Oh yes. Thanks for pointing that out. #432 makes the workaround possible, not #444.

avrdude probably will only use the workaround after 0.13 is released.

> A [workaround](https://github.com/libusb/hidapi/issues/443#issuecomment-1214433164) is possible, based on current master. Oh yes. Thanks for pointing that out. #432 makes the workaround possible, not #444. avrdude probably will only use the workaround after 0.13 is released.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi#443
No description provided.