ESP32-S3, problem with usb_host_interface_claim() - ESP_ERR_NOT_SUPPORTED

marbalon
Posts: 23
Joined: Wed Dec 20, 2017 11:02 am

ESP32-S3, problem with usb_host_interface_claim() - ESP_ERR_NOT_SUPPORTED

Postby marbalon » Tue Nov 15, 2022 3:36 pm

Hi,

I have a custom board with ESP32-S3. It is working as USB host for USB POS printers. Everything is working fine for most of the printers I used but I have a problem with only one but have node idea why. Everything is working fine, until I'm trying to call usb_host_interface_claim, and this function returns error 0x0106 ESP_ERR_NOT_SUPPORTED.

Does anyone have an idea why this can happened? I need to send data to one of the endpoints of this printer but can't sort out this problem.

I tested on ESP-IDF 4.4 and 5.0 and it the same problem. Just to test on the 5.0 I used example usb_host_lib with few lines added to action_get_str_desc() function:

Code: Select all

err = usb_host_interface_claim(driver_obj->client_hdl,
                                driver_obj->dev_hdl,
                                0, 0);

    if (err != ESP_OK)
    {
        ESP_LOGE(TAG, "usb_host_interface_claim(): 0x%04X", err);
    }    
    else
    {
        ESP_LOGI(TAG, "usb_host_interface_claim(): OK");
    }
And the output is like this for this printer:

Code: Select all

I (313) DAEMON: Installing USB Host Library
I (353) CLASS: Registering Client
I (823) CLASS: Opening device at address 1
I (823) CLASS: Getting device information
I (823) CLASS:  Full speed
I (823) CLASS:  bConfigurationValue 1
I (823) CLASS: Getting device descriptor
*** Device descriptor ***
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0x0
bDeviceSubClass 0x0
bDeviceProtocol 0x0
bMaxPacketSize0 64
idVendor 0x403
idProduct 0x6001
bcdDevice 6.00
iManufacturer 1
iProduct 2
iSerialNumber 3
bNumConfigurations 1
I (853) CLASS: Getting config descriptor
*** Configuration descriptor ***
bLength 9
bDescriptorType 2
wTotalLength 32
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
bMaxPower 0mA
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 0
        bAlternateSetting 0
        bNumEndpoints 2
        bInterfaceClass 0xff
        bInterfaceSubClass 0xff
        bInterfaceProtocol 0xff
        iInterface 2
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x81   EP 1 IN
                bmAttributes 0x2        BULK
                wMaxPacketSize 512
                bInterval 0
                *** Endpoint descriptor ***
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x2    EP 2 OUT
                bmAttributes 0x2        BULK
                wMaxPacketSize 512
                bInterval 0
I (923) CLASS: Getting Manufacturer string descriptor
OXHOO
I (92
I (923) CLASS: Getting Product string descriptor
TP90
I (933) CLASS: Getting Serial Number string descriptor
FT9MNX5O
E (943) CLASS: usb_host_interface_claim(): 0x0106

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32-S3, problem with usb_host_interface_claim() - ESP_ERR_NOT_SUPPORTED

Postby chegewara » Tue Nov 15, 2022 6:45 pm

Either this device does not support full speed or you should check alternative configuration:

Code: Select all

wMaxPacketSize 512
For full speed max size is 64 bytes.

marbalon
Posts: 23
Joined: Wed Dec 20, 2017 11:02 am

Re: ESP32-S3, problem with usb_host_interface_claim() - ESP_ERR_NOT_SUPPORTED

Postby marbalon » Wed Nov 16, 2022 9:59 am

In the logs above the printer was in the Virtual Com Port mode. Here is the log when the printer is in default USB mode.

Code: Select all

I (353) CLASS: Registering Client
I (823) CLASS: Opening device at address 1
I (823) CLASS: Getting device information
I (823) CLASS:  Full speed
I (823) CLASS:  bConfigurationValue 1
I (823) CLASS: Getting device descriptor
*** Device descriptor ***
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0x2
bDeviceSubClass 0x0
bDeviceProtocol 0x0
bMaxPacketSize0 64
idVendor 0x20d1
idProduct 0x7007
bcdDevice 3.00
iManufacturer 1
iProduct 2
iSerialNumber 3
bNumConfigurations 1
I (853) CLASS: Getting config descriptor
*** Configuration descriptor ***
bLength 9
bDescriptorType 2
wTotalLength 32
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
bMaxPower 0mA
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 0
        bAlternateSetting 0
        bNumEndpoints 2
        bInterfaceClass 0x7
        bInterfaceSubClass 0x1
        bInterfaceProtocol 0x2
        iInterface 0
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x81   EP 1 IN
                bmAttributes 0x2        BULK
                wMaxPacketSize 512
                bInterval 0
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x2    EP 2 OUT
                bmAttributes 0x2        BULK
                wMaxPacketSize 512
                bInterval 0
I (923) CLASS: Getting Manufacturer string descriptor
OXHOO

I (923) CLASS: Getting Product string descriptor
TP90
I (933) CLASS: Getting Serial Number string descriptor
TP900021190243
But the same device on the Windows machine in the USBTreeView looks like here, and there is "Device Qualifier Descriptor (for Full-Speed)" where endpints are fine, but how to get the same on ESP32?

Code: Select all

    =========================== USB Port2 ===========================

Connection Status        : 0x01 (Device is connected)
Port Chain               : 1-1-2
Properties               : 0x01
 IsUserConnectable       : yes
 PortIsDebugCapable      : no
 PortHasMultiCompanions  : no
 PortConnectorIsTypeC    : no
ConnectionIndex          : 0x02 (Port 2)
CompanionIndex           : 0
 CompanionHubSymLnk      : USB#VID_0BDA&PID_0411#5&202ecbb1&0&17#{f18a0e88-c30c-11d0-8815-00a0c906bed8}
 CompanionPortNumber     : 0x02 (Port 2)
 -> CompanionPortChain   : 1-17-2

      ========================== Summary =========================
Vendor ID                : 0x20D1 (Dascom Europe GmbH)
Product ID               : 0x7007
USB Version              : 2.00
Port maximum Speed       : High-Speed (Companion Port 1-17-2 supports SuperSpeed)
Device maximum Speed     : High-Speed
Device Connection Speed  : High-Speed
Self powered             : no
Demanded Current         : 0 mA
Used Endpoints           : 3

      ======================== USB Device ========================

        +++++++++++++++++ Device Information ++++++++++++++++++
Device Description       : Uniwersalna drukarka USB
Device Path 1            : \\?\USB#VID_20D1&PID_7007#TP900021190243#{a5dcbf10-6530-11d2-901f-00c04fb951ed} (GUID_DEVINTERFACE_USB_DEVICE)
Device Path 2            : \\?\USB#VID_20D1&PID_7007#TP900021190243#{28d78fad-5a12-11d1-ae5b-0000f803a8c2} (GUID_DEVINTERFACE_USBPRINT)
Device Path 3            : \\?\USB#VID_20D1&PID_7007#TP900021190243#{a6782bce-4376-4de2-8096-70aa9e8fed19}
Kernel Name              : \Device\USBPDO-11
Device ID                : USB\VID_20D1&PID_7007\TP900021190243
Hardware IDs             : USB\VID_20D1&PID_7007&REV_0300 USB\VID_20D1&PID_7007
Driver KeyName           : {36fc9e60-c465-11cf-8056-444553540000}\0038 (GUID_DEVCLASS_USB)
Driver                   : \SystemRoot\System32\drivers\usbprint.sys (Version: 10.0.19041.2193  Date: 2022-11-10)
Driver Inf               : C:\WINDOWS\inf\usbprint.inf
Legacy BusType           : PNPBus
Class                    : USB
Class GUID               : {36fc9e60-c465-11cf-8056-444553540000} (GUID_DEVCLASS_USB)
Service                  : usbprint
Enumerator               : USB
Location Info            : Port_#0002.Hub_#0003
Location IDs             : PCIROOT(0)#PCI(1400)#USBROOT(0)#USB(1)#USB(2), ACPI(_SB_)#ACPI(PCI0)#ACPI(XHC_)#ACPI(RHUB)#ACPI(HS01)#USB(2)
Container ID             : {8e740817-c4c7-58e9-96cb-14565946798e}
Manufacturer Info        : Microsoft
Capabilities             : 0x94 (Removable, UniqueID, SurpriseRemovalOK)
Status                   : 0x0180600A (DN_DRIVER_LOADED, DN_STARTED, DN_DISABLEABLE, DN_REMOVABLE, DN_NT_ENUMERATOR, DN_NT_DRIVER)
Problem Code             : 0
Address                  : 2
HcDisableSelectiveSuspend: 0
EnableSelectiveSuspend   : 0
SelectiveSuspendEnabled  : 0
EnhancedPowerMgmtEnabled : 0
IdleInWorkingState       : 0
WakeFromSleepState       : 0
Power State              : D0 (supported: D0, D2, D3, wake from D0, wake from D2)
 Child Device 1          : TP90
  Device ID              : USBPRINT\OXHOOTP90\8&1DCEC2F3&1&USB004
  Class                  : Printer
  Driver KeyName         : {4d36e979-e325-11ce-bfc1-08002be10318}\0002 (GUID_DEVCLASS_PRINTER)
   Child Device 1        : TP90 (Lokalna kolejka wydruku)
    Device ID            : SWD\PRINTENUM\{A0F5260A-08A6-4011-8DA9-D186DD450FA4}
    Class                : PrintQueue
    Driver KeyName       : {1ed2bbf9-11f0-4084-b21f-ad83a8e6dcdc}\0014 (GUID_DEVCLASS_PRINTQUEUE)

        +++++++++++++++++ Registry USB Flags +++++++++++++++++
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\usbflags\20D170070300
 osvc                    : REG_BINARY 00 00

        ---------------- Connection Information ---------------
Connection Index         : 0x02 (Port 2)
Connection Status        : 0x01 (DeviceConnected)
Current Config Value     : 0x01 (Configuration 1)
Device Address           : 0x12 (18)
Is Hub                   : 0x00 (no)
Device Bus Speed         : 0x02 (High-Speed)
Number Of Open Pipes     : 0x02 (2 pipes to data endpoints)
Pipe[0]                  : EndpointID=1  Direction=IN   ScheduleOffset=0  Type=Bulk  wMaxPacketSize=512  bInterval=0
Pipe[1]                  : EndpointID=2  Direction=OUT  ScheduleOffset=0  Type=Bulk  wMaxPacketSize=512  bInterval=0
Data (HexDump)           : 02 00 00 00 12 01 00 02 02 00 00 40 D1 20 07 70   ...........@. .p
                           00 03 01 02 03 01 01 02 00 12 00 02 00 00 00 01   ................
                           00 00 00 07 05 81 02 00 02 00 00 00 00 00 07 05   ................
                           02 02 00 02 00 00 00 00 00                        .........

        --------------- Connection Information V2 -------------
Connection Index         : 0x02 (2)
Length                   : 0x10 (16 bytes)
SupportedUsbProtocols    : 0x03
 Usb110                  : 1 (yes, port supports USB 1.1)
 Usb200                  : 1 (yes, port supports USB 2.0)
 Usb300                  : 0 (no, port not supports USB 3.0) -> but Companion Port 1-17-2 does
 ReservedMBZ             : 0x00
Flags                    : 0x00
 DevIsOpAtSsOrHigher     : 0 (Device is not operating at SuperSpeed or higher)
 DevIsSsCapOrHigher      : 0 (Device is not SuperSpeed capable or higher)
 DevIsOpAtSsPlusOrHigher : 0 (Device is not operating at SuperSpeedPlus or higher)
 DevIsSsPlusCapOrHigher  : 0 (Device is not SuperSpeedPlus capable or higher)
 ReservedMBZ             : 0x00
Data (HexDump)           : 02 00 00 00 10 00 00 00 03 00 00 00 00 00 00 00   ................

    ---------------------- Device Descriptor ----------------------
bLength                  : 0x12 (18 bytes)
bDescriptorType          : 0x01 (Device Descriptor)
bcdUSB                   : 0x200 (USB Version 2.00)
bDeviceClass             : 0x02 (Communications and CDC Control)
bDeviceSubClass          : 0x00
bDeviceProtocol          : 0x00 (No class specific protocol required)
bMaxPacketSize0          : 0x40 (64 bytes)
idVendor                 : 0x20D1 (Dascom Europe GmbH)
idProduct                : 0x7007
bcdDevice                : 0x0300
iManufacturer            : 0x01 (String Descriptor 1)
 Language 0x0409         : "OXHOO"
iProduct                 : 0x02 (String Descriptor 2)
 Language 0x0409         : "TP90"
iSerialNumber            : 0x03 (String Descriptor 3)
 Language 0x0409         : "TP900021190243"
bNumConfigurations       : 0x01 (1 Configuration)
Data (HexDump)           : 12 01 00 02 02 00 00 40 D1 20 07 70 00 03 01 02   .......@. .p....
                           03 01                                             ..

    ------------------ Configuration Descriptor -------------------
bLength                  : 0x09 (9 bytes)
bDescriptorType          : 0x02 (Configuration Descriptor)
wTotalLength             : 0x0020 (32 bytes)
bNumInterfaces           : 0x01 (1 Interface)
bConfigurationValue      : 0x01 (Configuration 1)
iConfiguration           : 0x00 (No String Descriptor)
bmAttributes             : 0x80
 D7: Reserved, set 1     : 0x01
 D6: Self Powered        : 0x00 (no)
 D5: Remote Wakeup       : 0x00 (no)
 D4..0: Reserved, set 0  : 0x00
MaxPower                 : 0x00 (0 mA)
Data (HexDump)           : 09 02 20 00 01 01 00 80 00 09 04 00 00 02 07 01   .. .............
                           02 00 07 05 81 02 00 02 00 07 05 02 02 00 02 00   ................

        ---------------- Interface Descriptor -----------------
bLength                  : 0x09 (9 bytes)
bDescriptorType          : 0x04 (Interface Descriptor)
bInterfaceNumber         : 0x00 (Interface 0)
bAlternateSetting        : 0x00
bNumEndpoints            : 0x02 (2 Endpoints)
bInterfaceClass          : 0x07 (Printer)
bInterfaceSubClass       : 0x01
bInterfaceProtocol       : 0x02
iInterface               : 0x00 (No String Descriptor)
Data (HexDump)           : 09 04 00 00 02 07 01 02 00                        .........

        ----------------- Endpoint Descriptor -----------------
bLength                  : 0x07 (7 bytes)
bDescriptorType          : 0x05 (Endpoint Descriptor)
bEndpointAddress         : 0x81 (Direction=IN EndpointID=1)
bmAttributes             : 0x02 (TransferType=Bulk)
wMaxPacketSize           : 0x0200 (max 512 bytes)
bInterval                : 0x00 (never NAKs)
Data (HexDump)           : 07 05 81 02 00 02 00                              .......

        ----------------- Endpoint Descriptor -----------------
bLength                  : 0x07 (7 bytes)
bDescriptorType          : 0x05 (Endpoint Descriptor)
bEndpointAddress         : 0x02 (Direction=OUT EndpointID=2)
bmAttributes             : 0x02 (TransferType=Bulk)
wMaxPacketSize           : 0x0200 (max 512 bytes)
bInterval                : 0x00 (never NAKs)
Data (HexDump)           : 07 05 02 02 00 02 00                              .......

    --------- Device Qualifier Descriptor (for Full-Speed) --------
bLength                  : 0x0A (10 bytes)
bDescriptorType          : 0x06 (Device_qualifier Descriptor)
bcdUSB                   : 0x200 (USB Version 2.00)
bDeviceClass             : 0x00 (defined by the interface descriptors)
bDeviceSubClass          : 0x00
bDeviceProtocol          : 0x00
bMaxPacketSize0          : 0x40 (64 Bytes)
bNumConfigurations       : 0x01 (1 other-speed configuration)
bReserved                : 0x00
Data (HexDump)           : 0A 06 00 02 00 00 00 40 01 00                     .......@..

    ------------------ Configuration Descriptor -------------------
bLength                  : 0x09 (9 bytes)
bDescriptorType          : 0x02 (Configuration Descriptor)
wTotalLength             : 0x0020 (32 bytes)
bNumInterfaces           : 0x01 (1 Interface)
bConfigurationValue      : 0x01 (Configuration 1)
iConfiguration           : 0x00 (No String Descriptor)
bmAttributes             : 0x80
 D7: Reserved, set 1     : 0x01
 D6: Self Powered        : 0x00 (no)
 D5: Remote Wakeup       : 0x00 (no)
 D4..0: Reserved, set 0  : 0x00
MaxPower                 : 0x00 (0 mA)
Data (HexDump)           : 09 02 20 00 01 01 00 80 00 09 04 00 00 02 FF 00   .. .............
                           00 00 07 05 81 02 40 00 00 07 05 02 02 40 00 00   ......@......@..

        ---------------- Interface Descriptor -----------------
bLength                  : 0x09 (9 bytes)
bDescriptorType          : 0x04 (Interface Descriptor)
bInterfaceNumber         : 0x00 (Interface 0)
bAlternateSetting        : 0x00
bNumEndpoints            : 0x02 (2 Endpoints)
bInterfaceClass          : 0xFF (Vendor Specific)
bInterfaceSubClass       : 0x00
bInterfaceProtocol       : 0x00
iInterface               : 0x00 (No String Descriptor)
Data (HexDump)           : 09 04 00 00 02 FF 00 00 00                        .........

        ----------------- Endpoint Descriptor -----------------
bLength                  : 0x07 (7 bytes)
bDescriptorType          : 0x05 (Endpoint Descriptor)
bEndpointAddress         : 0x81 (Direction=IN EndpointID=1)
bmAttributes             : 0x02 (TransferType=Bulk)
wMaxPacketSize           : 0x0040 (64 bytes)
bInterval                : 0x00 (ignored)
Data (HexDump)           : 07 05 81 02 40 00 00                              ....@..

        ----------------- Endpoint Descriptor -----------------
bLength                  : 0x07 (7 bytes)
bDescriptorType          : 0x05 (Endpoint Descriptor)
bEndpointAddress         : 0x02 (Direction=OUT EndpointID=2)
bmAttributes             : 0x02 (TransferType=Bulk)
wMaxPacketSize           : 0x0040 (64 bytes)
bInterval                : 0x00 (ignored)
Data (HexDump)           : 07 05 02 02 40 00 00                              ....@..

      -------------------- String Descriptors -------------------
             ------ String Descriptor 0 ------
bLength                  : 0x04 (4 bytes)
bDescriptorType          : 0x03 (String Descriptor)
Language ID[0]           : 0x0409 (English - United States)
Data (HexDump)           : 04 03 09 04                                       ....
             ------ String Descriptor 1 ------
bLength                  : 0x0C (12 bytes)
bDescriptorType          : 0x03 (String Descriptor)
Language 0x0409          : "OXHOO"
Data (HexDump)           : 0C 03 4F 00 58 00 48 00 4F 00 4F 00               ..O.X.H.O.O.
             ------ String Descriptor 2 ------
bLength                  : 0x0A (10 bytes)
bDescriptorType          : 0x03 (String Descriptor)
Language 0x0409          : "TP90"
Data (HexDump)           : 0A 03 54 00 50 00 39 00 30 00                     ..T.P.9.0.
             ------ String Descriptor 3 ------
bLength                  : 0x1E (30 bytes)
bDescriptorType          : 0x03 (String Descriptor)
Language 0x0409          : "TP900021190243"
Data (HexDump)           : 1E 03 54 00 50 00 39 00 30 00 30 00 30 00 32 00   ..T.P.9.0.0.0.2.
                           31 00 31 00 39 00 30 00 32 00 34 00 33 00         1.1.9.0.2.4.3.

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: ESP32-S3, problem with usb_host_interface_claim() - ESP_ERR_NOT_SUPPORTED

Postby ESP_Dazz » Wed Nov 16, 2022 11:24 am

@marbalon Devices are supposed to return the valid descriptors corresponding to their current speed. So, if your high-speed capable device is connected to an FS only Host, then the device should only return FS descriptors. Quote from USB2.0 specification section "9.2.6.6 Speed Dependent Descriptors":
A high-speed capable device responds with descriptor information that is valid for the current operating speed. For example, when a device is asked for configuration descriptors, it only returns those for the current operating speed (e.g., full speed). However, there must be a way to determine the capabilities for both high- and full-speed operation.
The qualifier descriptors are used by a device to report the configuration information of their other operating speeds. In other words, a device is currently operating in HS will have qualifier descriptors for FS.

marbalon
Posts: 23
Joined: Wed Dec 20, 2017 11:02 am

Re: ESP32-S3, problem with usb_host_interface_claim() - ESP_ERR_NOT_SUPPORTED

Postby marbalon » Wed Nov 16, 2022 2:34 pm

@ESP_Dazz, thanks for your response.

Do you think it is an option from the host side to "tell" the device "we are FS only" and thanks to this we can get FS descriptors?

What is strange if you look inside logs from USBTreeView is that this device provides a full list of HS and FS descriptors on PC.

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: ESP32-S3, problem with usb_host_interface_claim() - ESP_ERR_NOT_SUPPORTED

Postby ESP_Dazz » Wed Nov 16, 2022 4:33 pm

marbalon wrote: Do you think it is an option from the host side to "tell" the device "we are FS only" and thanks to this we can get FS descriptors?
USB2.0 actually operates on the opposite logic. All HS capable devices start out as FS by default. The device must indicate to the host/hub the need to switch to HS by sending a "K-chirp" during the reset (more details here). A HS capable host/hub will respond to the "k-chirp" with a "kj-chirp" thus indicating to the device that the bus has now switched over from FS to HS.

However, FS only host/hubs (such as the ESP) will simply ignore the initial "k-chirp", so the connected device should never enter HS as it won't receive the "kj-chirp" response.

I don't think the device your using is operating in HS to begin with. If it was, no packets would be sent/received during enumeration due to the differing bit rates (i.e., 12MHz vs 480MHz).
marbalon wrote: What is strange if you look inside logs from USBTreeView is that this device provides a full list of HS and FS descriptors on PC.
What I guess is happening is that your device is actually operating in FS, but for some reason is returning the HS configuration descriptors during enumeration. Most devices store all of their configuration descriptors (both FS and HS) in ROM somewhere. So maybe the device indexed to the wrong copy of the descriptors when responding to the enumeration control transfer.

To test if the device is simply returning the wrong descriptor, we can actually try overwrite the "wMaxPacketSize" entry by software so that the host stack goes an allocates a 64 MPS pipe instead of returning an error.

In your class driver, once the device has connected (and before claiming any interfaces):
  • Open the device using usb_host_device_open() and get the device's active configuration descriptor using usb_host_get_active_config_descriptor(). The host stack basically stores a copy of the device's currently active configuration descriptor in memory.
  • Use the various usb_parse_...() functions in usb_helpers.h to traverse the configuration descriptor until you get a pointer to the individual endpoint descriptors (interface 0, EP 1 IN and EP 2 OUT in the case of your device).
  • Cast the EP descriptor pointers to a non-const version of usb_ep_desc_t and simply overwrite the wMaxPacketSize to 64
  • Now when you go to claim an interface, the host stack simply read the modified configuration descriptor and think the MPS is 64.
In theory, if your device is truly operating in FS (using the FS EP descriptors listed in the qualifer), then there shouldn't be an issue.
What you could try forcing the IDF host stack to allocate a pipe with MPS=64 regardless.

marbalon
Posts: 23
Joined: Wed Dec 20, 2017 11:02 am

Re: ESP32-S3, problem with usb_host_interface_claim() - ESP_ERR_NOT_SUPPORTED

Postby marbalon » Thu Nov 17, 2022 8:50 am

I tried to do this before but in a different place in function pipe_alloc_check_args(), but then writing 64 bytes each time failed. But now I'm added few lines like below and it is working! Thank your very much!

Code: Select all

    ESP_ERROR_CHECK(usb_host_get_active_config_descriptor(driver_obj->dev_hdl, &config_desc));

    // fix wMaxPacketSize
    int off = 0;
    uint16_t wTotalLength = config_desc->wTotalLength;
    const usb_standard_desc_t *next_desc = (const usb_standard_desc_t *)config_desc;
    if (next_desc)
    {
        do
        {
            if (next_desc->bDescriptorType == USB_B_DESCRIPTOR_TYPE_ENDPOINT)
            {
                usb_ep_desc_t *mod_desc = (usb_ep_desc_t *)next_desc;
                if (mod_desc->wMaxPacketSize > 64)
                {
                    ESP_LOGW(TAG, "EP 0x%02X with wrong wMaxPacketSize %d - fixed to 64", mod_desc->bEndpointAddress, mod_desc->wMaxPacketSize);
                    mod_desc->wMaxPacketSize = 64;
                }
            }

            next_desc = usb_parse_next_descriptor(next_desc, wTotalLength, &off);

        } while (next_desc != NULL);
    }
Edit.
Maybe it is worth adding this smart solution somewhere in esp-idf. I know it is a bug in the device implementation, but this can save a lot of time in case someone has a similar issue.

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: ESP32-S3, problem with usb_host_interface_claim() - ESP_ERR_NOT_SUPPORTED

Postby ESP_Dazz » Mon Nov 21, 2022 9:03 am

@marbalon In theory we could add this workaround, but the way I would prefer implementing this as follows:
  • Integrate this workaround into the hub driver (i.e., where enumeration is handled) so that users don't need to handle this in their class drivers
  • Make it an optional workaround via menuconfig
  • Have the hub driver enumeration check if entries in an EP descriptor are sane for the current speed, fetch the qualifier descriptors if they exist, and print an error if sane values aren't available.
I'll add this feature request to our internal feature request list.

marbalon
Posts: 23
Joined: Wed Dec 20, 2017 11:02 am

Re: ESP32-S3, problem with usb_host_interface_claim() - ESP_ERR_NOT_SUPPORTED

Postby marbalon » Tue Nov 22, 2022 9:48 am

ESP_Dazz wrote:
Mon Nov 21, 2022 9:03 am
@marbalon In theory we could add this workaround, but the way I would prefer implementing this as follows:
  • Integrate this workaround into the hub driver (i.e., where enumeration is handled) so that users don't need to handle this in their class drivers
  • Make it an optional workaround via menuconfig
  • Have the hub driver enumeration check if entries in an EP descriptor are sane for the current speed, fetch the qualifier descriptors if they exist, and print an error if sane values aren't available.
I'll add this feature request to our internal feature request list.
Sounds like a good plan! Thanks again for help.

Who is online

Users browsing this forum: abbas1375, Baidu [Spider] and 94 guests