pico-extras
pico-extras copied to clipboard
usb_stream_helper requires the chunk buffer size to be a power of 2
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.