USB allocation rework and simplification #963
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Our current USB Subsystem has a few issues with buffer allocation. This PR attempts to fix them.
Issues
Addressing the issues
To address (1), I have now added in some feature flags for the HAL, which allows the user to set the global USB endpoint allocation buffer to either 1KB, 2KB, 4KB or 8KB. 2KB remains the default to maintain compatibility (The 2KB feature flag is not required to compile the crate)
To address 2 and 3, and to simplify the USB buffer allocation method, This global buffer is now divided equally by 16 (Number of endpoints on our chips), rather than attempting to be split dynamically, it is also stored in a structure that is 4 byte aligned, to simplify the allocation process.
This PR also makes the USB connection more stable under high loads, since we now utilize the multi-packet RX/TX feature properly, which allows a user to send large bulk data, and the hardware will send it over smaller USB packets, before generating an interrupt once sending is complete. Before, we were limited by the USB packet size to the endpoint buffer size, meaning realistically, an interrupt was generated every 64 bytes being sent or received.
Old implementation
New implementation
usb-buffer-1kusb-buffer-2k(Default)usb-buffer-4kusb-buffer-8k