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

[USB] Korg B2 Piano URB Transfer IN never finishes (IDFGH-14421) #15201

Open
3 tasks done
chipweinberger opened this issue Jan 14, 2025 · 9 comments
Open
3 tasks done
Labels
Status: Opened Issue is new Type: Bug bugs in IDF

Comments

@chipweinberger
Copy link
Contributor

chipweinberger commented Jan 14, 2025

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.1.4

Espressif SoC revision.

ESP32-S3

Operating System used.

macOS

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

Development Kit.

custom pcb

Power Supply used.

USB

What is the expected behavior?

I am the creator of Jamcorder.

I have over 300 devices out in the wild, and the large majority connect to and communicate with their piano just fine. They can send MIDI OUT (data sent to usb piano) no problem. However for a few pianos, MIDI IN (receiving data from usb piano) does not work.

  • Korg B2
  • Kawai MP 7

These devices work fine when plugged into a Windows or MacOS computer. So the problem is something related to the ESP32-S3.

Im calling usb_host_transfer_submit, but it just never calls the callback.

What is the actual behavior?

Im calling usb_host_transfer_submit on the MIDI IN, but it just never calls the callback.

Steps to reproduce.

  1. claim interface
  2. call usb_host_transfer_submit on USB IN endpoint

Debug Logs.

//
// These logs are not that useful
//

 [0;32mI (43627) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (43755) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (43879) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (44003) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (44127) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (44251) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (44375) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (44503) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (44627) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (44755) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (44879) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (45003) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (45127) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (45235) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45251) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (45295) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45307) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45307) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45311) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45311) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45315) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45315) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45319) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45319) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45323) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45323) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45339) pd usbh: [client task] NEW_DEV! addr: 1 [0m
 [0;32mI (45339) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (45343) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45343) pd usbh: [openSingleDevice] usb_host_device_open(0x3c3b5da0, usbAddress: 1, ..) [0m
 [0;32mI (45347) pd usbh: [openSingleDevice] deviceHandle 0x3c2923e0 [0m
 [0;32mI (45347) pd midi usb: usb_midi_device_open() [0m
 [0;32mI (45347) pd usbh [device]: usb_host_device_info(dev: 0x3c2923e0) [0m
 [0;32mI (45351) pd usbh [device]: usb_host_get_device_descriptor(dev:0x3c2923e0) [0m
Device descriptor:
Length: 18
Descriptor type: 0x01 (Device)
USB version: 0x0200 (2.0.0)
Device class: 0x00 (Generic Device)
Device subclass: 0x00 ()
Device protocol: 0x00
EP0 max packet size: 64
VID: 0x0944
PID: 0x020f
Revision number: 1.0.4
iManufacturer: 1
iProduct: 2
iSerialNumber: 0
Num Configurations: 1

 [0;32mI (45363) pd usbh [device]: getStringDescriptor(idx: 1) [0m
 [0;32mI (45367) pd usbh: usb_host_transfer_submit_control(client: 0x3c3b5da0, transfer: 0x3c3b5d60) [0m
 [0;32mI (45371) pd usbh: clientEventsTransferCallback, transfer:0x3c3b5d60 [0m
 [0;32mI (45375) pd usbh: clientEventsTransferCallback, transfer:0x3c3b5d60 (got mutex) [0m
 [0;32mI (45379) pd usbh: clientEventsTransferCallback, transfer:0x3c3b5d60 (set bit) [0m
 [0;32mI (45379) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (45371) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45371) pd usbh: wait for xfer [0m
 [0;32mI (45383) pd usbh: xfer complete [0m

manufacturer: '	�'

 [0;32mI (45387) pd usbh [device]: getStringDescriptor(idx: 2) [0m
 [0;32mI (45391) pd usbh: usb_host_transfer_submit_control(client: 0x3c3b5da0, transfer: 0x3c3b5d60) [0m
 [0;32mI (45403) pd usbh: clientEventsTransferCallback, transfer:0x3c3b5d60 [0m
 [0;32mI (45407) pd usbh: clientEventsTransferCallback, transfer:0x3c3b5d60 (got mutex) [0m
 [0;32mI (45407) pd usbh: clientEventsTransferCallback, transfer:0x3c3b5d60 (set bit) [0m
 [0;32mI (45411) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (45411) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45411) pd usbh: wait for xfer [0m
 [0;32mI (45415) pd usbh: xfer complete [0m

product: '	�'

 [0;32mI (45419) pd usbh [device]: getConfigDescriptor(idx: 0) [0m
 [0;32mI (45423) pd usbh [device]: using cached configuration! [0m
 [0;32mI (45423) pd usbh [device]: wTotalLength 378 [0m
 [0;32mI (45427) pd usbh [device]: configuration descriptor (378 bytes): [0m
 [0;32mI (45427) pd usbh [device]: 09 02 7a 01 05 01 00 c0 00 09 04 00 00 00 01 01  [0m
 [0;32mI (45431) pd usbh [device]: 00 00 0a 24 01 00 01 3c 00 02 01 02 0c 24 02 01  [0m
 [0;32mI (45435) pd usbh [device]: 01 01 00 02 03 00 00 02 08 24 06 05 01 01 03 00  [0m
 [0;32mI (45439) pd usbh [device]: 09 24 03 02 01 03 00 05 02 0c 24 02 03 03 06 00  [0m
 [0;32mI (45439) pd usbh [device]: 02 03 00 00 02 09 24 03 04 01 01 00 03 02 09 04  [0m
 [0;32mI (45439) pd usbh [device]: 01 00 00 01 02 00 06 09 04 01 01 02 01 02 00 06  [0m
 [0;32mI (45439) pd usbh [device]: 07 24 01 01 00 01 00 0b 24 02 01 02 03 18 01 80  [0m
 [0;32mI (45439) pd usbh [device]: bb 00 09 05 01 05 26 01 01 00 81 07 25 01 01 00  [0m
 [0;32mI (45439) pd usbh [device]: 00 00 09 05 81 01 03 00 01 03 00 09 04 01 02 02  [0m
 [0;32mI (45439) pd usbh [device]: 01 02 00 06 07 24 01 01 00 01 00 0b 24 02 01 02  [0m
 [0;32mI (45439) pd usbh [device]: 02 10 01 80 bb 00 09 05 01 05 c4 00 01 00 81 07  [0m
 [0;32mI (45439) pd usbh [device]: 25 01 01 00 00 00 09 05 81 01 03 00 01 03 00 09  [0m
 [0;32mI (45439) pd usbh [device]: 04 02 00 00 01 02 00 05 09 04 02 01 01 01 02 00  [0m
 [0;32mI (45439) pd usbh [device]: 05 07 24 01 04 00 01 00 0b 24 02 01 02 03 18 01  [0m
 [0;32mI (45467) pd usbh [device]: 80 bb 00 09 05 83 05 26 01 01 00 00 07 25 01 01  [0m
 [0;32mI (45471) pd usbh [device]: 00 00 00 09 04 02 02 01 01 02 00 05 07 24 01 04  [0m
 [0;32mI (45471) pd usbh [device]: 00 01 00 0b 24 02 01 02 02 10 01 80 bb 00 09 05  [0m
 [0;32mI (45475) pd usbh [device]: 83 05 c4 00 01 00 00 07 25 01 01 00 00 00 09 04  [0m
 [0;32mI (45479) pd usbh [device]: 03 00 00 01 01 00 00 09 24 01 00 01 09 00 01 04  [0m
 [0;32mI (45479) pd usbh [device]: 09 04 04 00 02 01 03 00 00 07 24 01 00 01 25 00  [0m
 [0;32mI (45483) pd usbh [device]: 06 24 02 01 10 03 09 24 03 02 40 01 10 01 00 09  [0m
 [0;32mI (45487) pd usbh [device]: 24 03 01 30 01 20 01 04 06 24 02 02 20 00 09 05  [0m
 [0;32mI (45487) pd usbh [device]: 02 02 40 00 00 00 00 05 25 01 01 10 09 05 82 02  [0m
 [0;32mI (45491) pd usbh [device]: 40 00 00 00 00 05 25 01 01 30  [0m
Configuration:
Length: 9
Descriptor type: 0x02 (Config)
Total Length: 378
bNumInterfaces: 5
bConfigurationValue: 1
iConfiguration (string): 0
bmAttributes: 0xc0
bMaxPower: 0 mA

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 0
bAlternateSetting: 0
bNumEndpoints: 0
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x01 (Audio Control)
bInterfaceProtocol: 0x00
iInterface (string): 0

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 1
bAlternateSetting: 0
bNumEndpoints: 0
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x02 (Audio Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 6

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 1
 [0;32mI (45523) zlib: compressed 7165 to 3605 bytes in 0.083 seconds [0m
bAlternateSetting: 1
bNumEndpoints: 2
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x02 (Audio Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 6

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x01 (addr: 1 Dir: Out)
bmAttributes: 0x05 (Iso)
wMaxPacketSize: 294
bInterval: 1 ms

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x81 (addr: 1 Dir: In)
bmAttributes: 0x01 (Iso)
wMaxPacketSize: 3
bInterval: 1 ms

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 1
bAlternateSetting: 2
bNumEndpoints: 2
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x02 (Audio Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 6

Endpoint:
Length: 9
 [0;32mI (45555) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x01 (addr: 1 Dir: Out)
bmAttributes: 0x05 (Iso)
wMaxPacketSize: 196
bInterval: 1 ms
Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x81 (addr: 1 Dir: In)
bmAttributes: 0x01 (Iso)
wMaxPacketSize: 3
bInterval: 1 ms
Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 2
bAlternateSetting: 0
bNumEndpoints: 0
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x02 (Audio Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 5

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 2
bAlternateSetting: 1
bNumEndpoints: 1
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x02 (Audio Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 5

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x83 (addr: 3 Dir: In)
bmAttributes: 0x05 (Iso)
wMaxPacketSize: 294
bInterval: 1 ms

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 2
bAlternateSetting: 2
bNumEndpoints: 1
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x02 (Audio Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 5

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x83 (addr: 3 Dir: In)
bmAttributes: 0x05 (Iso)
wMaxPacketSize: 196
bInterval: 1 ms

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 3
bAlternateSetting: 0
bNumEndpoints: 0
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x01 (Audio Control)
bInterfaceProtocol: 0x00
iInterface (string): 0

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 4
bAlternateSetting: 0
bNumEndpoints: 2
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x03 (Midi Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 0

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x02 (addr: 2 Dir: Out)
bmAttributes: 0x02 (Bulk)
wMaxPacketSize: 64
bInterval: 0 ms

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x82 (addr: 2 Dir: In)
bmAttributes: 0x02 (Bulk)
wMaxPacketSize: 64
bInterval: 0 ms


Configuration:
Length: 9
Descriptor type: 0x02 (Config)
Total Length: 378
bNumInterfaces: 5
bConfigurationValue: 1
iConfiguration (string): 0
bmAttributes: 0xc0
bMaxPower: 0 mA

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 0
bAlternateSetting: 0
bNumEndpoints: 0
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x01 (Audio Control)
bInterfaceProtocol: 0x00
iInterface (string): 0

Audio Control Interface:
bLength: 10
bDescriptorType: 0x24 (CS Interface)
bDescriptorSubtype: 0x1 (Header)
bcdADC: 0x0100 (AC Spec Rev 1.0.0)
wTotalLength: 60
bInCollection: 2
baInterfaceNr[0]: 1
baInterfaceNr[1]: 2

Interface (Class Specified):
Length: 12
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x02 
Interface Subclass: 0x01 (Audio Control)
Interface Class: 0x01 (Audio)

Interface (Class Specified):
Length: 8
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x06 
Interface Subclass: 0x01 (Audio Control)
Interface Class: 0x01 (Audio)

 [0;32mI (45683) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m

Interface (Class Specified):
Length: 9
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x03 
Interface Subclass: 0x01 (Audio Control)
Interface Class: 0x01 (Audio)

Interface (Class Specified):
Length: 12
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x02 
Interface Subclass: 0x01 (Audio Control)
Interface Class: 0x01 (Audio)

Interface (Class Specified):
Length: 9
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x03 
Interface Subclass: 0x01 (Audio Control)
Interface Class: 0x01 (Audio)

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 1
bAlternateSetting: 0
bNumEndpoints: 0
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x02 (Audio Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 6

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 1
bAlternateSetting: 1
bNumEndpoints: 2
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x02 (Audio Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 6

Interface (Class Specified):
Length: 7
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x01 
Interface Subclass: 0x02 (Audio Streaming)
Interface Class: 0x01 (CDC Communications)

Interface (Class Specified):
Length: 11
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x02 
Interface Subclass: 0x02 (Audio Streaming)
Interface Class: 0x01 (CDC Communications)

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x01 (addr: 1 Dir: Out)
bmAttributes: 0x05 (Iso)
wMaxPacketSize: 294
bInterval: 1 ms

Endpoint (Class Specified):
Length: 7
Descriptor type: 0x25 (CS Endpoint)
Descriptor Subtype: 0x01 
Interface Class: 0x01 (CDC Communications)
Interface Subclass: 0x02 (Audio Streaming)

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x81 (addr: 1 Dir: In)
bmAttributes: 0x01 (Iso)
wMaxPacketSize: 3
bInterval: 1 ms

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 1
bAlternateSetting: 2
bNumEndpoints: 2
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x02 (Audio Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 6

Interface (Class Specified):
Length: 7
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x01 
Interface Subclass: 0x02 (Audio Streaming)
Interface Class: 0x01 (CDC Communications)

Interface (Class Specified):
Length: 11
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x02 
Interface Subclass: 0x02 (Audio Streaming)
Interface Class: 0x01 (CDC Communications)

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x01 (addr: 1 Dir: Out)
bmAttributes: 0x05 (Iso)
wMaxPacketSize: 196
bInterval: 1 ms

Endpoint (Class Specified):
Length: 7
Descriptor type: 0x25 (CS Endpoint)
Descriptor Subtype: 0x01 
Interface Class: 0x01 (CDC Communications)
Interface Subclass: 0x02 (Audio Streaming)

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x81 (addr: 1 Dir: In)
bmAttributes: 0x01 (Iso)
wMaxPacketSize: 3
bInterval: 1 ms

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 2
bAlternateSetting: 0
bNumEndpoints: 0
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x02 (Audio Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 5

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 2
bAlternateSetting: 1
bNumEndpoints: 1
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x02 (Audio Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 5

Interface (Class Specified):
Length: 7
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x01 
Interface Subclass: 0x02 (Audio Streaming)
Interface Class: 0x01 (CDC Communications)

Interface (Class Specified):
Length: 11
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x02 
Interface Subclass: 0x02 (Audio Streaming)
Interface Class: 0x01 (CDC Communications)

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x83 (addr: 3 Dir: In)
bmAttributes: 0x05 (Iso)
wMaxPacketSize: 294
bInterval: 1 ms

Endpoint (Class Specified):
Length: 7
Descriptor type: 0x25 (CS Endpoint)
Descriptor Subtype: 0x01 
Interface Class: 0x01 (CDC Communications)
Interface Subclass: 0x02 (Audio Streaming)

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 2
bAlternateSetting: 2
bNumEndpoints: 1
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x02 (Audio Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 5

Interface (Class Specified):
Length: 7
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x01 
Interface Subclass: 0x02 (Audio Streaming)
Interface Class: 0x01 (CDC Communications)
 [0;32mI (45811) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m

Interface (Class Specified):
Length: 11
Descriptor type: 0x24 (CS Interface)
Descriptor Subtype: 0x02 
Interface Subclass: 0x02 (Audio Streaming)
Interface Class: 0x01 (CDC Communications)

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x83 (addr: 3 Dir: In)
bmAttributes: 0x05 (Iso)
wMaxPacketSize: 196
bInterval: 1 ms

Endpoint (Class Specified):
Length: 7
Descriptor type: 0x25 (CS Endpoint)
Descriptor Subtype: 0x01 
Interface Class: 0x01 (CDC Communications)
Interface Subclass: 0x02 (Audio Streaming)

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 3
bAlternateSetting: 0
bNumEndpoints: 0
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x01 (Audio Control)
bInterfaceProtocol: 0x00
iInterface (string): 0

Audio Control Interface:
bLength: 9
bDescriptorType: 0x24 (CS Interface)
bDescriptorSubtype: 0x1 (Header)
bcdADC: 0x0100 (AC Spec Rev 1.0.0)
wTotalLength: 9
bInCollection: 1
baInterfaceNr[0]: 4

Interface:
Length: 9
Descriptor type: 4 (Interface)
bInterfaceNumber: 4
bAlternateSetting: 0
bNumEndpoints: 2
bInterfaceClass: 0x01 (Audio)
bInterfaceSubclass: 0x03 (Midi Streaming)
bInterfaceProtocol: 0x00
iInterface (string): 0

Midi MS Interface:
bLength: 7
bDescriptorType: 0x24 (CS Interface)
bDescriptorSubtype: 0x1 (MS Header)
bcdMSC: 0x0100 (Midi Revision 1.0.0)
wTotalLength: 37

Midi Jack IN Interface:
bLength: 6
bDescriptorType: 0x24 (CS Interface)
bDescriptorSubtype: 0x2 (Midi IN Jack)
bJackType: 0x1 (Embedded)
bJackID: 16
iJack: 3

Midi Jack OUT Interface:
bLength: 9
bDescriptorType: 0x24 (CS Interface)
bDescriptorSubtype: 0x3 (Midi OUT Jack)
bJackType: 0x2 (External)
bJackID: 64
bNrInputPins: 1
 [0] BaSourceID: 16
 [0] BaSourcePin: 1
iJack: 0

Midi Jack OUT Interface:
bLength: 9
bDescriptorType: 0x24 (CS Interface)
bDescriptorSubtype: 0x3 (Midi OUT Jack)
bJackType: 0x1 (Embedded)
bJackID: 48
bNrInputPins: 1
 [0] BaSourceID: 32
 [0] BaSourcePin: 1
iJack: 4

Midi Jack IN Interface:
bLength: 6
bDescriptorType: 0x24 (CS Interface)
bDescriptorSubtype: 0x2 (Midi IN Jack)
bJackType: 0x2 (External)
bJackID: 32
iJack: 0

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x02 (addr: 2 Dir: Out)
bmAttributes: 0x02 (Bulk)
wMaxPacketSize: 64
bInterval: 0 ms

Midi Bulk Endpoint:
bLength: 5
bDescriptorType: 0x25 (CS Endpoint)
bDescriptorSubtype: 0x1 (MS General)
bNumEmbMIDIJack: 1
 [0] BaAssocJackID: 16

Endpoint:
Length: 9
Descriptor type: 5 (Endpoint)
bEndpointAddress: 0x82 (addr: 2 Dir: In)
bmAttributes: 0x02 (Bulk)
wMaxPacketSize: 64
bInterval: 0 ms

Midi Bulk Endpoint:
bLength: 5
bDescriptorType: 0x25 (CS Endpoint)
bDescriptorSubtype: 0x1 (MS General)
bNumEmbMIDIJack: 1
 [0] BaAssocJackID: 48

 [0;32mI (45883) pd midi usb: midi interfaces found: 1 [0m
 [0;32mI (45883) pd midi usb: Found midi 1.0 endpoint. [0m
 [0;32mI (45883) pd usbh [device]: setActiveConfigValue(idx: 1) [0m
 [0;32mI (45887) pd usbh: usb_host_transfer_submit_control(client: 0x3c3b5da0, transfer: 0x3c3b5d60) [0m
 [0;32mI (45887) pd usbh: clientEventsTransferCallback, transfer:0x3c3b5d60 [0m
 [0;32mI (45891) pd usbh: clientEventsTransferCallback, transfer:0x3c3b5d60 (got mutex) [0m
 [0;32mI (45891) pd usbh: clientEventsTransferCallback, transfer:0x3c3b5d60 (set bit) [0m
 [0;32mI (45895) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (45895) pd usbh: [host task] usb_host_lib_handle_events() [0m
 [0;32mI (45887) pd usbh: wait for xfer [0m
 [0;32mI (45899) pd usbh: xfer complete [0m
 [0;32mI (46019) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (46143) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (46267) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (46391) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (46399) pd usbh: usb_host_interface_claim(0x3c3b5da0, deviceHandle:0x3c2923e0 bInterfaceNumber: 4 bAlternateSetting: 0) [0m
 [0;32mI (46403) pd midi usb: epAddrIn: 130 [0m
 [0;32mI (46403) pd midi usb IN: xTaskCreate xferInTask_loop [0m
 [0;32mI (46407) pd midi usb IN: xferInTask_loop started [0m
 [0;32mI (46407) pd midi usb: epAddrOut: 2 [0m
 [0;32mI (46407) pd midi usb OUT: xTaskCreate midi_usb_tx_task [0m
 [0;32mI (46411) pd midi usb OUT: allocate msg queue: 44000 bytes [0m
 [0;32mI (46423) pd midi usb OUT: USB OUT task started [0m
 [0;32mI (46427) pd buzz: USB Device Inserted Sound [0m
 [0;32mI (46515) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (46643) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (46771) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (46895) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (47019) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (47027) pd usbh: wait for all devices to close... [0m
 [0;32mI (47143) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (47267) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (47391) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (47515) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (47639) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (47767) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (47891) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (48015) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (48139) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (48263) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (48387) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (48511) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (48635) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (48763) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (48887) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (49011) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (49135) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (49259) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (49383) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (49407) pd midi usb IN: xferFromEndpoint-start [0m
 [0;32mI (49407) pd usbh [device]: xferFromEndpoint 130 maxPkt 64 len 1024 deviceHandle 0x3c2923e0 [0m
 [0;32mI (49411) pd usbh: usb_host_transfer_submit(client: 0x3c3b5da0, transfer: 0x3c3b5d60) [0m
 [0;32mI (49411) pd usbh: wait for xfer [0m
 [0;32mI (49507) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (49631) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (49755) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (49879) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (50003) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (50127) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (50251) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (50375) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (50499) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (50623) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (50751) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (50875) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (50999) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (51123) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (51247) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (51371) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (51495) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (51619) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (51743) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (51867) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (51991) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (52115) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (52239) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (52363) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (52487) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (52611) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (52739) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (52863) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (52987) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (53111) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (53235) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (53359) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (53483) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (53607) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (53735) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (53859) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (53983) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (54107) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (54231) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (54355) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (54479) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (54603) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (54727) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (54851) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (54915) pd usbh: xfer complete [0m
 [0;32mI (54915) pd midi usb IN: xferFromEndpoint-end [0m
 [0;33mW (54935) pd issues: RAISE - [Midi Usb Rx] Transfer Failure | None [0m
 [0;31mE (54935) : e1 : [pd usbh] USB TRANSFER FAILED - xEventGroupWaitBits timed out
e2 : [pd usbh [device]] pd_usbh_service_submitTransferAndWait() failed.
e3 : [pd midi usb IN] xfer IN task: xferFromEndpoint() timedout
 [0m
 [0;32mI (54975) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (55003) pd xtrans: header: Content-Encoding: deflate [0m
 [0;31mE (55043) pd midi usb IN: USB task failure. stopping xferInTask_loop() until replugged [0m
 [0;32mI (55047) pd midi usb IN: xferInTask_loop ended. wait for usb replug. [0m
 [0;32mI (55231) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (55255) pd usbh: cancelAllTransfers() [0m
 [0;32mI (55255) pd usbh: closeAllDevices() [0m
 [0;33mW (55271) pd usbh: [close device] closing, dev_hdl: 0x3c2923e0 [0m
 [0;32mI (55271) pd usbh: [close device] unblocking usb transfer 3 [0m
 [0;32mI (55275) pd usbh: usb_host_interface_release(0x3c3b5da0, device: 0x3c2923e0, bInterfaceNumber: 4 [0m
 [0;31mE (55295) : e1 : [pd usbh] usb_host_interface_release() failed ESP_ERR_INVALID_STATE
e2 : [pd usbh] pd_usbh_service_releaseInterface() bInterfaceNumber: 4, failed
e3 : [pd usbh] closeDevice() dev_hdl: 0x3c2923e0 failed

 [0;32mI (55359) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (55611) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (55867) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (55995) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (56119) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (56243) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (56367) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (56491) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (56615) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (56743) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (56867) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (56991) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (57115) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (57239) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (57363) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (57487) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (57611) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (57739) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (57863) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (57987) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (58111) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (58235) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (58359) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (58483) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (58607) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (58735) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (58859) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (58983) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (59107) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (59231) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (59355) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (60727) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (60855) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (60979) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (61103) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (61227) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (61351) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (61475) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (61599) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m
 [0;32mI (61727) pd usbh: [client task] usb_host_client_handle_events(client:0x3c3b5da0) [0m

More Information.

No response

@chipweinberger chipweinberger added the Type: Bug bugs in IDF label Jan 14, 2025
@github-actions github-actions bot changed the title [USB] Korg B2 Piano URB Transfer IN never finishes [USB] Korg B2 Piano URB Transfer IN never finishes (IDFGH-14421) Jan 14, 2025
@espressif-bot espressif-bot added the Status: Opened Issue is new label Jan 14, 2025
@chipweinberger
Copy link
Contributor Author

chipweinberger commented Jan 14, 2025

The diff which broke Korg B2 support was this change. (Edit: I was wrong, see new comment below)

This change was made to support a OYAYO Folding piano, which did not like having its configuration descriptor downloaded multiple times. Again, all these pianos work fine with Windows & MacOS, and they all have a single Configuration Descriptor.

There's something specific to the ESP32-S3 causing them to misbehave.

Before:

// submits control transfer
xesp_usb_config_descriptor_t* pd_usbh_device_getConfigDescriptor(pd_usbh_device_t usbhDevice, uint8_t configIdx, pd_error_t *error)
{
    pd_err_unset(error);

    xesp_usb_config_descriptor_t* parsed = NULL;

    // allocations
    pd_usb_transfer_t* transfer = pd_usbh_service_takeTransfer();
    {
        ESP_LOGI(TAG, "getConfigDescriptor(idx: %" PRIu8 ")", configIdx);

        USB_SETUP_PACKET_INIT_GET_CONFIG_DESC((usb_setup_packet_t *)transfer->val->data_buffer,
                                                configIdx,
                                                CONFIG_USB_HOST_CONTROL_TRANSFER_MAX_SIZE);

        transfer->val->num_bytes = CONFIG_USB_HOST_CONTROL_TRANSFER_MAX_SIZE + sizeof(usb_setup_packet_t);
        transfer->val->flags = 0;
        transfer->val->device_handle = usbhDevice.deviceHandleB;
        transfer->val->bEndpointAddress = 0;
        transfer->val->status = USB_TRANSFER_STATUS_ERROR;
        transfer->val->timeout_ms = 500;
        transfer->val->context = 0;
        
        eTry(,pd_usbh_service_submitTransferAndWait,(transfer, error));

        uint32_t length = transfer->val->actual_num_bytes - sizeof(usb_setup_packet_t);
        uint8_t* configDesc = transfer->val->data_buffer + sizeof(usb_setup_packet_t);

        // parse
        parsed = xesp_usbh_parse_config(configDesc, length, error);
        if (!parsed) {
            eFail("failed to parse config descriptor");
            goto end;
        }

        pd_err_success(error);
    }
end:
    pd_usbh_service_giveTransfer(transfer);
    eOnFail(return NULL);
    return parsed;
}

After:

// submits control transfer
xesp_usb_config_descriptor_t* pd_usbh_device_getConfigDescriptor(pd_usbh_device_t usbhDevice, uint8_t configIdx, pd_error_t *error)
{
    pd_err_unset(error);

    // allocations
    xesp_usb_config_descriptor_t* parsed = NULL;
    {
        ESP_LOGI(TAG, "getConfigDescriptor(idx: %" PRIu8 ")", configIdx);

        // read
        const usb_config_desc_t* desc;
        sTry(esp_err_t err =,usb_host_get_active_config_descriptor,(usbhDevice.deviceHandleB, &desc));

        // parse
        eTry(parsed =,xesp_usbh_parse_config,((uint8_t*) desc, desc->wTotalLength, error));

        pd_err_success(error);
    }
end:
    eOnFail(return NULL);
    return parsed;
}

@peter-marcisovsky
Copy link
Collaborator

Hi @chipweinberger

Thanks for the report.

  1. Does the USB MIDI Device work on Linux?
  2. Can you please enable debug logs in menuconfig Component Config -> Log -> Log Level -> Default log verbosity, run usb_host_lib example with your MIDI Device connected to the esp32s3 and share the output log? This way we can see if the device was enumerated correctly by the USB Host.

@roma-jam
Copy link
Collaborator

roma-jam commented Jan 14, 2025

Hi @chipweinberger,

Im calling usb_host_transfer_submit, but it just never calls the callback.

When you schedule the IN transfer, the callback should be called after the data is received by the hardware. Does that mean that literally, you pressed any piano keys and no data appears on the usb? And the same logic works without problem (you can get the callback) on other MIDI-devices, am I right?

Is there any specific class-related configuration should be done with some class requests, to setup the device regarding sending back the data?

Maybe, Wireshark log from attaching device to Win could help (especially, class specific requests sequence during initialization of the MIDI class driver on the Host side).

UPD: Could you also specify what does mean OYAYO Folding piano, which did not like having its configuration descriptor downloaded multiple times?
Apparently, it is worth it to check the Wireshark log, specifically SetConfguration() request.
During the USB Host Library it is a part of enumeration process by default (with possibility to change the index via enum_filter_cb() ), so set Verbosity level is enough.

If some devices requires specific index, it might be filtered during the enumeration callback by VID/PID of the device.

@chipweinberger
Copy link
Contributor Author

Does the USB MIDI Device work on Linux?

I'll check.

Can you please enable debug logs in menuconfig Component Config -> Log -> Log Level -> Default log verbosity, run usb_host_lib example with your MIDI Device connected to the esp32s3 and share the output log? This way we can see if the device was enumerated correctly by the USB Host.

Will do.

When you schedule the IN transfer, the callback should be called after the data is received by the hardware. Does that mean that literally, you pressed any piano keys and no data appears on the usb? And the same logic works without problem (you can get the callback) on other MIDI-devices, am I right?

Correct.

Maybe, Wireshark log from attaching device to Win could help (especially, class specific requests sequence during initialization of the MIDI class driver on the Host side).

Sure, I can provide that.

UPD: Could you also specify what does mean OYAYO Folding piano, which did not like having its configuration descriptor downloaded multiple times?

I'm not sure exactly, but the diff I posted fixed it. The descriptors were grabbed (a) automatically by esp-idf & (b) again by my code, and (b) was not working. I expected maybe their firmware was bugged, so I played with it.

Apparently, it is worth it to check the Wireshark log, specifically SetConfguration() request.
During the USB Host Library it is a part of enumeration process by default (with possibility to change the index via enum_filter_cb() ), so set Verbosity level is enough.

Ah I did not realize this. My code also calls SetConfguration. So it's getting called twice.

@chipweinberger
Copy link
Contributor Author

chipweinberger commented Jan 14, 2025

So I've found the actual issue! 🎉🎉🎉

In my latest firmware update, I added additional print statement during usb parsing -- ironically to aide in debugging USB issues. I use custom parsing code, since my code was written before esp-idf's.

xesp_usb_config_descriptor_t* xesp_usbh_parse_config(uint8_t *data, uint32_t length, pd_error_t* error) {
     ...
    usb_util_print_cfg(config); // causes an issue
    ...
}

xesp_usb_intf_descriptor_t* xesp_usbh_parse_intf(uint8_t *data, uint32_t length, pd_error_t* error) {
     ...
    usb_util_print_intf(intf); // causes an issue
    ...
}

xesp_usb_ep_descriptor_t* xesp_usbh_parse_ep(uint8_t *data, uint32_t length, pd_error_t* error) {
     ...
    usb_util_print_ep(ep); // causes an issue
    ...
}

these print functions are just simple utils. They don't recurse or anything like that. All 3 are just like this:

void usb_util_print_cfg(const usb_config_desc_t* data){
    printf2("Configuration:\n");
    if (!data) {printf2("NULL\n\n"); return;}
    printf2("bLength: %d\n", data->bLength);
    printf2("bDescriptorType: 0x%02x (%s)\n", data->bDescriptorType, usb_descriptor_type_str(data->bDescriptorType));
    printf2("wTotalLength: %d\n", data->wTotalLength);
    printf2("bNumInterfaces: %d\n", data->bNumInterfaces);
    printf2("bConfigurationValue: %d\n", data->bConfigurationValue);
    printf2("iConfiguration (string): %d\n", data->iConfiguration);
    printf2("bmAttributes: 0x%02x\n", data->bmAttributes);
    printf2("bMaxPower: %d mA\n\n", data->bMaxPower * 2);
}

For whatever reason, perhaps timing related, these USB devices do not like this. It's a bit surprising, but also extremely reproducible.

I will close this issue.

@peter-marcisovsky @roma-jam, I'm you'd like to understand the underlying mechanism of failure more. Unfortunately, I don't have time or a need to dig deeper right now. But the offending device is a Korg B2. This one.

@chipweinberger
Copy link
Contributor Author

chipweinberger commented Jan 15, 2025

So I spoke too soon, this issue is back when using a 'production' device with Bluetooth and Wifi enabled.

I'm not sure if BLE & Wifi is related, but it seems like anything like that could affect timing.

Especially, I have a BLE message pd_alerts_push(PD_ALERT_USB_STATE) in my clientEventsCallback

static void clientEventsCallback(const usb_host_client_event_msg_t *event, void *arg)
{
    if (event->event == USB_HOST_CLIENT_EVENT_NEW_DEV)
    {
        // COMMENTED OUT - the extra time needed to send this bluetooth alert 
        // causes the KORG B2 piano to not initialize properly
        //pd_alerts_push(PD_ALERT_USB_STATE);

        //A new device has been enumerated and added to the USB Host Library

        ESP_LOGI(TAG, "[client task] NEW_DEV! addr: %" PRIu8 "", event->new_dev.address);

        bool success = xQueueSend(xDeviceConnectedEvents, &event->new_dev.address, portMAX_DELAY);

        if (!success)
        {
            pd_raise_uie_e2("usbhQueue",TAG, "[client task] xQueueSend NEW DEV failed");
        }
    }
    else if (event->event == USB_HOST_CLIENT_EVENT_DEV_GONE)
    {
        // A device opened by the client is now gone
        usb_device_handle_t deviceHandle = event->dev_gone.dev_hdl;

        ESP_LOGW(TAG, "[client task] DEV_GONE dev_hdl: %p", deviceHandle);

        pd_error_t errorBase;
        pd_error_t* error = &errorBase;
        pd_err_init_lite(error);

        closeDeviceBase(pd_usbh_device_create(deviceHandle), true /*isDeviceGone*/, error);

        if (is_fail(error)){
            pd_raise_uie_e2("usbhClose",TAG, "[client task] usb_host_device_close() failed");
        }
    }
    else
    {
        // raise issue
        pd_raise_uie_e2("usbhUnknown", TAG, "[client task] unknown event %" PRIu32 "", event->event);
    }
}

@chipweinberger
Copy link
Contributor Author

chipweinberger commented Jan 15, 2025

In summary, Im not sure if there is anything in esp-idf that needs to change / should change to avoid issues like this.

@roma-jam
Copy link
Collaborator

Hi @chipweinberger

USB_HOST_CLIENT_EVENT_NEW_DEV and USB_HOST_CLIENT_EVENT_DEV_GONE are called within usbh_process(), which is in its own turn is inside the usb_host_lib_handle_events() call.

Calling any other things such as pd_alerts_push(PD_ALERT_USB_STATE); means literally that you call that logic within the task, which handles the USB (where you call usb_host_lib_handle_events()).

If there will be anything, that requires time, the USB will be waiting for these logic to end to proceed handle the USB events.

So, if you don't want any other tasks affect USB, you should keep them out of the task, which handles USB.

@chipweinberger
Copy link
Contributor Author

chipweinberger commented Jan 15, 2025

Yes, it makes sense.

However, the usb_util_print_cfg call causing issues before was not in the usbh_process(). It was just in my PD_PRIORITY_MIDI_USB_OPEN_TASK, which is responsible for opening the device, parsing the configuration, and calling SET_CONFIGURATION.

Notably, I also have PD_PRIORITY_USB_CLIENT_EVENTS_TASK > PD_PRIORITY_USB_HOST_TASK. Is this expected?

#define PD_PRIORITY_USB_CLIENT_EVENTS_TASK 21
#define PD_PRIORITY_USB_HOST_TASK 20
#define PD_PRIORITY_MIDI_USB_OPEN_TASK 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

4 participants