Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/portable/synopsys/dwc2/hcd_dwc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,14 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t*
if (bus_info.speed == TUSB_SPEED_HIGH) {
edpt->uframe_interval = 1u << (desc_ep->bInterval - 1);
} else {
edpt->uframe_interval = desc_ep->bInterval << 3;
// USB 2.0 §5.7.4 / §9.6.6: a low-speed interrupt bInterval is 10..255 frames. Mice and
// keyboards ship 1, which re-arms from its own NAK halt and holds the preamble bus. The
// host may poll slower than the endpoint asks, so raise a short interval to the minimum.
uint8_t binterval = desc_ep->bInterval;
if (bus_info.speed == TUSB_SPEED_LOW && binterval < 10) {
binterval = 10;
}
edpt->uframe_interval = (uint32_t) binterval << 3;
Comment on lines +853 to +856

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Received packets get overwritten

Clamping bInterval=1 changes how partially completed IN transfers retry. An app can use tuh_edpt_xfer() to request 16 bytes from an 8-byte low-speed interrupt endpoint. If the first packet succeeds and the next gets a NAK, channel_xfer_in_retry() now frees the channel instead of keeping it.

The next attempt clears xferred_bytes and restarts with the original buffer and length. Later packets therefore overwrite bytes already received. Preserve the received bytes and remaining length before moving these transfers onto the slower retry path.

Knowledge Base Used: USB controller drivers

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/portable/synopsys/dwc2/hcd_dwc2.c
Line: 853-856

Comment:
**Received packets get overwritten**

Clamping `bInterval=1` changes how partially completed IN transfers retry. An app can use `tuh_edpt_xfer()` to request 16 bytes from an 8-byte low-speed interrupt endpoint. If the first packet succeeds and the next gets a NAK, `channel_xfer_in_retry()` now frees the channel instead of keeping it.

The next attempt clears `xferred_bytes` and restarts with the original buffer and length. Later packets therefore overwrite bytes already received. Preserve the received bytes and remaining length before moving these transfers onto the slower retry path.

**Knowledge Base Used:** [USB controller drivers](https://app.greptile.com/-/switch-tenant?tenant=tinyusb&next=%2Fcustom-context%2Fknowledge-base%2Fhathach%2Ftinyusb%2F-%2Fdocs%2Fusb-controller-drivers.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code

}
break;

Expand Down
Loading