USB Descriptor Data transfer is limited to 256 bytes
Summary
There is a bug in machine.sendDescriptorData() that prevents HID Report Descriptors larger than 256 bytes from being transferred correctly.
Current code:
https://github.com/tinygo-org/tinygo/blob/dev/src/machine/usb.go#L329
data = data[:min(len(data), len(udd_ep_control_cache_buffer), int(maxLen))]
I believe this should instead be: <- bad idea
data = data[:min(len(data), int(maxLen))]
unused udd_ep_control_cache_buffer on RP2040/2340 only
Reason
sendUSBPacket() already splits the transfer into USB endpoint-sized packets (64 bytes for EP0), so the size of udd_ep_control_cache_buffer should not limit the total transfer length.
As long as udd_ep_control_cache_buffer is at least one endpoint packet in size (64 bytes), larger descriptors can be transmitted correctly over multiple packets.
The current implementation unintentionally limits the maximum transferable descriptor size to the size of udd_ep_control_cache_buffer (currently 256 bytes).
Impact
Because of this, HID Report Descriptors larger than 256 bytes cannot be sent successfully.
USB Descriptor Data transfer is limited to 256 bytes
Summary
There is a bug in
machine.sendDescriptorData()that prevents HID Report Descriptors larger than 256 bytes from being transferred correctly.Current code:
https://github.com/tinygo-org/tinygo/blob/dev/src/machine/usb.go#L329
I believe this should instead be:<- bad ideaunused udd_ep_control_cache_buffer on RP2040/2340 only
Reason
sendUSBPacket()already splits the transfer into USB endpoint-sized packets (64 bytes for EP0), so the size ofudd_ep_control_cache_buffershould not limit the total transfer length.As long as
udd_ep_control_cache_bufferis at least one endpoint packet in size (64 bytes), larger descriptors can be transmitted correctly over multiple packets.The current implementation unintentionally limits the maximum transferable descriptor size to the size of
udd_ep_control_cache_buffer(currently 256 bytes).Impact
Because of this, HID Report Descriptors larger than 256 bytes cannot be sent successfully.