-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Use EP0 buffer directly if it's large enough #3352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: HiFiPhile <[email protected]>
Signed-off-by: HiFiPhile <[email protected]>
Signed-off-by: HiFiPhile <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes control transfer buffer management in TinyUSB by allowing device classes to use the EP0 buffer directly when it's large enough, avoiding unnecessary dedicated buffer allocations and memory copies. This improves memory efficiency on resource-constrained devices while maintaining the same functional behavior.
Key Changes
- Added
usbd_control_get_buffer()API to expose the EP0 buffer to device class implementations - Optimized control transfer path to skip unnecessary memory copies when the buffer is already the EP0 buffer
- Updated Audio and DFU device classes to conditionally use EP0 buffer instead of always allocating dedicated buffers
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/device/usbd_control.c | Added function to expose EP0 buffer and optimized copy operations to skip when buffer pointer matches EP0 buffer |
| src/device/usbd.h | Added declaration for usbd_control_get_buffer() function |
| src/class/dfu/dfu_device.c | Conditionally allocates transfer buffer only when larger than EP0, otherwise uses EP0 buffer directly via helper function |
| src/class/audio/audio_device.c | Conditionally allocates control buffer only when larger than EP0, uses EP0 buffer otherwise, and removes length cropping code that relied on dedicated buffer always existing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: HiFiPhile <[email protected]>
[Pa082]: undefinedbehavior: the order of volatile accesses is undefined in this E:\mcu\tinyusb\src\common\tusb_fifo.h Signed-off-by: HiFiPhile <[email protected]>
Signed-off-by: HiFiPhile <[email protected]>
|



This pull request improves how control transfer buffers are managed for both the Audio and DFU device classes. The main enhancement is to allow the use of the endpoint 0 buffer for control transfers when it is large enough, falling back to a dedicated buffer only when necessary.