Skip to content

Conversation

@HiFiPhile
Copy link
Collaborator

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.

Copilot AI review requested due to automatic review settings November 20, 2025 23:52
Copilot finished reviewing on behalf of HiFiPhile November 20, 2025 23:57
Copy link
Contributor

Copilot AI left a 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]>
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants