tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

Allow more endpoint packet sizes for SAMD

Open maddyaby opened this issue 3 years ago • 1 comments

Tested on SAMD51 in an audio application with ISO OUT endpoint - we can allow more packet sizes by checking that the set size value is greater than the requested packet size instead of exactly the same.

maddyaby avatar Jun 17 '22 23:06 maddyaby

I see that a == was changed to >=. I'm not so familiar with SAMD, but I figure this could cause issues with INT IN endpoints:

  1. Class defines INT IN endpoint with wMaxPacketSize=10
  2. Driver sets hardware to use wMaxPacketSize=16
  3. Class starts transfer of 25 bytes.
  4. Peripheral transmits packet of size 10 which would confuse the host since it expects a max packet size of 10 bytes.

pigrew avatar Jun 30 '22 04:06 pigrew

I see that a == was changed to >=. I'm not so familiar with SAMD, but I figure this could cause issues with INT IN endpoints:

  1. Class defines INT IN endpoint with wMaxPacketSize=10
  2. Driver sets hardware to use wMaxPacketSize=16
  3. Class starts transfer of 25 bytes.
  4. Peripheral transmits packet of size 10 which would confuse the host since it expects a max packet size of 10 bytes.

Thank you @pigrew for reviewing, this is SAMD port specific. SAMD endppoint can only have endpoint with power of two size i.e 8/16/.../512/1023. Therefore normally application on SAMD must take this into account and must define endpoint size accordingly. The use case here is for ISO endpoint which will have arbitrary depending on constant data rate e.g audio with 44.1 Mhz may have endpoint of 131 bytes while 48Mh would be 150 bytes. Normally ISO endpoint will only send 1 packet per constant interval, which is handle by audio driver, which make sure that it send data at constant rate. Of course for other use-case such as HID, SAMD user should only stick with power of two size. Hopefully this explanation make sense to you.

image

hathach avatar Oct 19 '22 15:10 hathach