[PATCH] usb: common: Detect USB storage media with "miscellaneous" USB devices

Christian Kohlschütter christian at kohlschutter.com
Sat Oct 1 12:34:18 CEST 2022


> On 1. Oct 2022, at 00:58, Christian Kohlschütter <christian at kohlschutter.com> wrote:
> 
> On 1. Oct 2022, at 00:21, Christian Kohlschütter <christian at kohlschutter.com> wrote:
>> 
>>>> See https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_msc/src/usb_descriptors.c for an example of such a device. It has one mass storage device and one CDC.
>>>> Changing the device class to 0x00 breaks support on Linux and macOS (I didn't try Windows).
>>> 
>>> The question is -- does the aforementioned device conform to the USB-IF specification ? I think it does not, but luckily it could be fixed in software on the tinyusb side.
>> 
>> I'm not familiar enough with the available USB specs to say what is "right" but I think the problem is that "fixing" it by changing the device class breaks support on major operating systems.
> 
> OK, looking through the tinyUSB example source code [1] and USB docs [2], it looks like the reason why changing the device class from 0xEF (misc) to 0x00 is that the combination deviceClass:0xEF + deviceSubClass:0x02 + deviceProtocol:0x01 indicates the presence of an "Interface Association Descriptor":
> 
>    // Use Interface Association Descriptor (IAD) for CDC
>    // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
>    .bDeviceClass = TUSB_CLASS_MISC,
>    .bDeviceSubClass = MISC_SUBCLASS_COMMON,
>    .bDeviceProtocol = MISC_PROTOCOL_IAD,
> 
> So yeah, it looks like it has to be like that.
> 
> [1] https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_msc/src/usb_descriptors.c
> [2] https://www.usb.org/defined-class-codes

More insights:

According to [3], setting all three values (class/subclass/protocol) to zero (0x00/0x00/0x00) may also indicate a composite device (and I can confirm it working as well, so that could be a workaround if you can control the USB device's software stack). However  this approach seems to require the device to have exactly one USB configuration. This may limit the utility of such a device.

Moreover, for many real-world devices, like the ESP32, the documentation calls for 0xEF/0x02/0x01 [4].

[3] https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/enumeration-of-the-composite-parent-device
[4] https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/peripherals/usb_device.html



More information about the U-Boot mailing list