pico-extras icon indicating copy to clipboard operation
pico-extras copied to clipboard

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

Open george-norton opened this issue 2 years ago • 0 comments

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.

george-norton avatar May 24 '23 15:05 george-norton