Skip to content

Fix DWC2 DMA data toggle mismatch in IN-transfers - #3872

Open
runelauridsen wants to merge 1 commit into
hathach:masterfrom
runelauridsen:dwc2-pid-desync
Open

Fix DWC2 DMA data toggle mismatch in IN-transfers#3872
runelauridsen wants to merge 1 commit into
hathach:masterfrom
runelauridsen:dwc2-pid-desync

Conversation

@runelauridsen

Copy link
Copy Markdown

In the DWC2 driver, when an IN transfer completes in non-DMA mode, the driver correctly reads the updated pid and saves it to next_pid:

static bool handle_channel_in_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) {
  // ...
  if (hcint & HCINT_XFER_COMPLETE) {
    if (edpt->hcchar_bm.ep_num != 0) {
      edpt->next_pid = hctsiz.pid; // save pid (already toggled)
    }
  // ...
}

However, the handler for DMA mode (handle_channel_in_dma) was missing this logic. If the expected number of packets was not received, then for all subsequent transfers the driver would program the wrong DATA0/DATA1 pid for their initial packets.

With this patch the DMA handler now matches the non-DMA handler.

The issue was observed when interfacing with a LAN9500. After some time, ethernet frames would start missing their first 64 bytes, because the first USB packet in each transfer was discarded due to the DATA0/DATA1 mismatch.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@HiFiPhile

HiFiPhile commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Thank you, please add a ISO transfer guard: edpt->hcchar_bm.ep_type != HCCHAR_EPTYPE_ISOCHRONOUS

@HiFiPhile HiFiPhile left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

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.

3 participants