raspberrypi / pico-extras

BSD 3-Clause "New" or "Revised" License
480 stars 120 forks source link

usb_stream_helper requires the chunk buffer size to be a power of 2 #66

Open george-norton opened 1 year ago

george-norton commented 1 year ago

The asserts in the code indicate that that chunk_size must be a multiple of the usb packet size (64 bytes): https://github.com/raspberrypi/pico-extras/blob/e5b9cb45cc698bc28450e38fcb73e852c289e06f/src/rp2_common/usb_device/usb_stream_helper.c#L120

But in reality things break if the chunk_size is not also a power of 2 as the offset computation breaks down here: https://github.com/raspberrypi/pico-extras/blob/e5b9cb45cc698bc28450e38fcb73e852c289e06f/src/rp2_common/usb_device/usb_stream_helper.c#L12

For example, if the chunk_size is 192 bytes the offset will not be updated after the first packet is sent, and so the first packet gets sent twice.