dwc2: submit SETUP on SETUP_DONE, handle v3.10a spurious RX_COMPLETE (STM32L476)#3669
Conversation
…LETE on core v3.10a (STM32L476)
DWC2 core rev 3.10a pushes an extra EP0 RX_COMPLETE (RXFLVL PKTSTS 0x3)
that is not a real OUT data completion, in two cases flagged on DOEPINT:
- STPKTRX (Setup Packet Received): between SETUP_RX and SETUP_DONE
- STSPHSRX (Status Phase Received, control write): after the OUT data
stage when the host starts the IN status phase
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- GRXSTSP register has internal FIFO, receiving events won't mix up (STATUS OUT & next SETUP) - Improve efficiency, remove 2nd IRQ overhead Signed-off-by: HiFiPhile <admin@hifiphile.com>
There was a problem hiding this comment.
Pull request overview
This PR adjusts the DWC2 device controller’s EP0 control transfer handling by reporting SETUP at SETUP_DONE (instead of SETUP_RX) and adds a DWC2 core rev 3.10a (STM32L476-class) workaround to ignore spurious EP0 RX_COMPLETE conditions that can otherwise double-count control-OUT completions. It also updates HIL board configuration and includes small formatting/comment-only cleanup in unrelated areas.
Changes:
- DWC2: emit device-mode SETUP events on
SETUP_DONEand add a v3.10a-specific guard to drop spurious EP0RX_COMPLETEwords flagged bySTPKTRX/STSPHSRX. - HIL: add
stm32f407discoandstm32l476discoentries totest/hil/tinyusb.json. - Minor cleanups: brace-style tweak in MTP class code; comment-out CMake target folder properties; add a commented JLink option line for stm32f769disco.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
test/hil/tinyusb.json |
Adds STM32F407 Disco and STM32L476 Disco HIL configurations. |
src/portable/synopsys/dwc2/dcd_dwc2.c |
Moves SETUP notification to SETUP_DONE and applies a v3.10a RX_COMPLETE quirk filter; small comment tweaks. |
src/class/mtp/mtp_device.c |
Brace/comment clarification for OUT completion logic in the MTP transfer callback. |
hw/bsp/stm32f7/boards/stm32f769disco/board.cmake |
Adds a commented example JLINK_OPTION line. |
hw/bsp/family_support.cmake |
Comments out unused CMake target folder properties. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| "name": "stm32f407disco", | ||
| "uid": "30001A000647313332353735", | ||
| "tests": { |
| case GRXSTS_PKTSTS_SETUP_DONE: | ||
| // Setup packet done: | ||
| case GRXSTS_PKTSTS_SETUP_DONE: { | ||
| // Pop this word cause Setup interrupt |
|
|
||
| case GRXSTS_PKTSTS_RX_COMPLETE: { | ||
| // Out packet done | ||
| // Pop this word cause xfer complete interrupt |
| if (dir == TUSB_DIR_IN) { | ||
| handle_epin_slave(rhport, epnum, intr.diepint_bm); | ||
| } else { | ||
| // epout is handled in rxflv |
TinyUSB Average Code Size Metrics
Input files
|
|
| target | .text | .rodata | .data | .bss | total | % diff |
|---|---|---|---|---|---|---|
| xmc4500_relax/hid_generic_inout | 12,900 → 12,964 (+64) | — | — | — | 25,852 → 25,980 (+128) | +0.5% |
| xmc4500_relax/hid_multiple_interface | 13,712 → 13,776 (+64) | — | — | — | 27,476 → 27,604 (+128) | +0.5% |
| sipeed_longan_nano/dfu_runtime | 12,556 → 12,616 (+60) | 590 → 594 (+4) | — | — | 13,814 → 13,878 (+64) | +0.5% |
| xmc4500_relax/printer_to_cdc | 14,968 → 15,032 (+64) | — | — | — | 29,984 → 30,112 (+128) | +0.4% |
| xmc4500_relax/audio_test | 15,060 → 15,124 (+64) | — | — | — | 30,192 → 30,320 (+128) | +0.4% |
| sipeed_longan_nano/hid_composite | 14,692 → 14,756 (+64) | — | — | — | 16,102 → 16,166 (+64) | +0.4% |
| xmc4500_relax/cdc_msc_throughput | 17,096 → 17,160 (+64) | — | — | — | 34,240 → 34,368 (+128) | +0.4% |
| sipeed_longan_nano/audio_test | 16,412 → 16,476 (+64) | — | — | — | 17,566 → 17,630 (+64) | +0.4% |
| sipeed_longan_nano/audio_test_multi_rate | 16,732 → 16,796 (+64) | — | — | — | 17,866 → 17,930 (+64) | +0.4% |
| sipeed_longan_nano/midi_test | 15,130 → 15,192 (+62) | 510 → 506 (-4) | — | — | 16,308 → 16,366 (+58) | +0.4% |
… dedup) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
How did you find out DOEPINT STUP need to cleared to allow RXSTSP SETUP_DONE fire again ? I read back and forth the guide but didn't find it. |
It is undocumented, I just guess and try it out. The L476 is troublesome, even though I fixed it once, I kind of forgot/mis-interprete it this time again and take quite a bit of trial. :) |
hathach
left a comment
There was a problem hiding this comment.
f723 host cdc failed is pre-PR issue. The hil test need a few re-run possibly due to over current to usb when multiple boards are active. I saw this happen when a couple of imxrt running especially 1064. Will try to add external power to make it more reliable.
Summary
follow up to #3634
Primary change: move the device-mode control SETUP event from the
SETUP_RXRX-FIFO status toSETUP_DONEfor all DWC2 cores.SETUP_DONEis the correct hand-off point — the core assertsDOEPINT.SetUpright after the Setup-Stage-Done word is popped, so the 8-byte packet is final (no more back-to-back SETUPs).This exposed a DWC2 core rev 3.10a (e.g. STM32L476) quirk: the core emits an extra EP0
RX_COMPLETE(RXFLVLPKTSTS0x3) that is not a real OUT data completion, in two cases flagged onDOEPINT:STPKTRX(Setup Packet Received) — pushed betweenSETUP_RXandSETUP_DONEof every control transfer.STSPHSRX(Status Phase Received, control write) — pushed after the OUT data stage when the host starts the IN status phase.Acting on these double-counted control-OUT completions (e.g.
SET_LINE_CODING) and tripped ausbd_edpt_xferassert, breaking enumeration.Fix
Guarded by
gsnpsid == DWC2_CORE_REV_3_10a, in theGRXSTS_PKTSTS_RX_COMPLETEcase: drop the event whenSTPKTRXorSTSPHSRXis set, and W1C-clear the flag so a latchedSTSPHSRXcannot block the core from emitting the nextSETUP_DONE.usbdstill handles the real OUT data and queues the IN status ZLP itself (the core does not auto-complete the control-write status). The guard makes the workaround inert on all non-3.10a cores.HIL validation — full device suite,
Total failed: 0Also bundled in this branch
test/hil/tinyusb.json: add STM32F407 / STM32L476 disco HIL board configs.src/class/mtp/mtp_device.c: brace-style cleanup.hw/bsp/family_support.cmake: comment out unused target folder properties.🤖 Generated with Claude Code