esp-idf: TinyUSB OUT endpoint uses incorrect endpoint size (IDFGH-8673)
I’ve edited this issue to reflect the actual issue I’ve found and what the bug might be.
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.0-beta1-824-ga8ef7570ca
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
PowerShell
Development Kit.
ESP32-S3-WROOM-1 | Custom PCB & Official Devkit
Power Supply used.
USB
What is the expected behavior?
Each time the USB Device is sent an OUT interrupt report, the tud_hid_set_report_cb should be triggered.
What is the actual behavior?
The callback will be triggered once, then never again. (Confirmed other OUT reports are being sent to the device via Wireshark).
Steps to reproduce.
- Set up project from example: HID Example
- Use a custom descriptor with an IN and OUT endpoint. I will be using the default VID and PID here.
static const uint8_t gc_hid_configuration_descriptor[] = { // Configuration number, interface count, string index, total length, attribute, power in mA TUD_CONFIG_DESCRIPTOR(1, 1, 0, 41, TUSB_DESC_CONFIG_ATT_SELF_POWERED, 500), // Interface 9, TUSB_DESC_INTERFACE, 0x00, 0x00, 0x02, TUSB_CLASS_HID, 0x00, 0x00, 0x00, // HID Descriptor 9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0110), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(61), // Endpoint Descriptor 7, TUSB_DESC_ENDPOINT, 0x81, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(37), 1, // Endpoint Descriptor 7, TUSB_DESC_ENDPOINT, 0x02, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(5), 8, };
This descriptor has an OUT endpoint with a size of 5 bytes.
-
Insert functionality in tud_hid_set_report_cb which will be triggered under the conditions in TinyUSB for data received on the OUT endpoint
if (report_type == HID_REPORT_TYPE_INVALID && report_id == 0) { // Code here to demonstrate the issue. You can change or toggle LED color, as I have been doing, but I'll use a log statement to demonstrate. ESP_LOGI("OUT GOT", "Recieved OUT report: %X", (unsigned int) buffer[0]); }
-
I set up the Espressif driver with a Libusb driver through Zadig (I installed WinUSB) for further testing.
-
I used a python script to send an appropriate chunk of data. `import os import usb from usb.backend import libusb1 import time be = libusb1.get_backend()
brand = 0x303a #Expressif prod = 0x4004 #ESP32 S3
dev = usb.core.find(idVendor=brand, idProduct=prod, backend=be)
print(dev)
internum = 0 setting = 0 epnum = 0x1
startPayload = [0x11, 0x00, 0x00, 0x00, 0x00] tmp = dev.write(0x02, startPayload, timeout=1000)`
More Information.
The result is that the write times out.
The fix is to change the OUT size to 6 instead of 5. I believe this is a bug. Even with the report byte being part of the data (which is expected),
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 22 (7 by maintainers)
@chegewara I am late to the party. As roman-jam already pointed out, though I want to add a bit of explanation with control transfer. HID input/output report can be get/set via BOTH control endpoint and interrupt endpoint. In fact, interrupt endpoint is optional if it is not used often enough e.g in case of keyboard with output for LED indicator.
hope this helps
See the link to the code in question. When a transfer is completed from Host to Device, it calls this function and you can see the report type is set to HID_REPORT_TYPE_INVALID. This is how @hathach has decided to implement this. https://github.com/hathach/tinyusb/blob/52a9098b31d993d743ee31efe155b90c7ba5b21e/src/class/hid/hid_device.c#L412