Skip to content

dwc2: submit SETUP on SETUP_DONE, handle v3.10a spurious RX_COMPLETE (STM32L476)#3669

Merged
hathach merged 5 commits into
masterfrom
dwc2-l476-setup
Jun 4, 2026
Merged

dwc2: submit SETUP on SETUP_DONE, handle v3.10a spurious RX_COMPLETE (STM32L476)#3669
hathach merged 5 commits into
masterfrom
dwc2-l476-setup

Conversation

@hathach

@hathach hathach commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Summary

follow up to #3634

Primary change: move the device-mode control SETUP event from the SETUP_RX RX-FIFO status to SETUP_DONE for all DWC2 cores. SETUP_DONE is the correct hand-off point — the core asserts DOEPINT.SetUp right 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 (RXFLVL PKTSTS 0x3) that is not a real OUT data completion, in two cases flagged on DOEPINT:

  • STPKTRX (Setup Packet Received) — pushed between SETUP_RX and SETUP_DONE of 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 a usbd_edpt_xfer assert, breaking enumeration.

Fix

Guarded by gsnpsid == DWC2_CORE_REV_3_10a, in the GRXSTS_PKTSTS_RX_COMPLETE case: drop the event when STPKTRX or STSPHSRX is set, and W1C-clear the flag so a latched STSPHSRX cannot block the core from emitting the next SETUP_DONE. usbd still 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: 0

Board Core Result
stm32l476disco v3.10a (fix target)
stm32f407disco stm32f4
stm32f723disco stm32f7
stm32h743nucleo stm32h7
espressif_p4_function_ev esp32p4
espressif_s3_devkitm esp32s3

Also 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

hathach and others added 4 commits June 3, 2026 21:44
…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>
Copilot AI review requested due to automatic review settings June 3, 2026 16:21
hathach referenced this pull request Jun 3, 2026
- 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>

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.

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_DONE and add a v3.10a-specific guard to drop spurious EP0 RX_COMPLETE words flagged by STPKTRX/STSPHSRX.
  • HIL: add stm32f407disco and stm32l476disco entries to test/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.

Comment thread test/hil/tinyusb.json
Comment on lines +346 to +349
{
"name": "stm32f407disco",
"uid": "30001A000647313332353735",
"tests": {
Comment thread src/portable/synopsys/dwc2/dcd_dwc2.c Outdated
case GRXSTS_PKTSTS_SETUP_DONE:
// Setup packet done:
case GRXSTS_PKTSTS_SETUP_DONE: {
// Pop this word cause Setup interrupt
Comment thread src/portable/synopsys/dwc2/dcd_dwc2.c Outdated

case GRXSTS_PKTSTS_RX_COMPLETE: {
// Out packet done
// Pop this word cause xfer complete interrupt
Comment thread src/portable/synopsys/dwc2/dcd_dwc2.c Outdated
if (dir == TUSB_DIR_IN) {
handle_epin_slave(rhport, epnum, intr.diepint_bm);
} else {
// epout is handled in rxflv
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

TinyUSB Average Code Size Metrics

File .text .rodata .data .bss size %
ehci.c 2763 0 0 6274 7783 4.4%
midi2_host.c 1802 0 0 5921 7723 4.3%
cdc_host.c 6381 487 15 985 7579 4.3%
usbh.c 4967 57 82 1161 6233 3.5%
ncm_device.c 1757 28 815 4354 6124 3.4%
hcd_dwc2.c 5015 25 1 513 5554 3.1%
midi_host.c 1341 7 7 3635 4979 2.8%
video_device.c 4443 5 1235 479 4914 2.8%
audio_device.c 2896 0 1259 1625 4515 2.5%
dcd_dwc2.c 4223 19 0 265 4507 2.5%
ohci.c 1925 0 0 2503 4428 2.5%
dcd_ch32_usbfs.c 1582 0 0 2444 4026 2.3%
usbd.c 3519 58 91 355 3936 2.2%
ecm_rndis_device.c 1059 0 1 2759 3818 2.1%
hcd_stm32_fsdev.c 3257 0 1 420 3678 2.1%
dcd_ft9xx.c 3284 0 0 172 3456 1.9%
msc_device.c 2517 108 2281 806 3323 1.9%
dcd_khci.c 1952 0 0 1290 3242 1.8%
dcd_nrf5x.c 2939 0 0 292 3231 1.8%
hcd_musb.c 3071 0 0 157 3228 1.8%
midi2_device.c 2634 52 1175 566 3222 1.8%
dcd_ci_fs.c 1924 0 0 1290 3214 1.8%
dcd_da146xx.c 3067 0 0 144 3211 1.8%
hcd_rusb2.c 2923 0 0 245 3168 1.8%
dcd_rusb2.c 2918 0 0 156 3074 1.7%
hcd_ch32_usbfs.c 2491 0 0 502 2993 1.7%
hcd_khci.c 2443 0 0 454 2897 1.6%
dcd_stm32_fsdev.c 2558 0 0 291 2849 1.6%
dcd_mm32f327x_otg.c 1477 0 0 1290 2767 1.6%
usbtmc_device.c 2196 24 68 316 2544 1.4%
hcd_samd.c 2220 0 0 324 2544 1.4%
dcd_ci_hs.c 1756 0 0 1344 2534 1.4%
dcd_eptri.c 2273 0 0 259 2532 1.4%
hid_host.c 1241 0 0 1251 2492 1.4%
dcd_musb.c 2225 0 0 171 2396 1.3%
dcd_ch32_usbhs.c 1892 0 0 481 2373 1.3%
hcd_rp2040.c 1996 17 4 321 2338 1.3%
mtp_device.c 1717 22 743 588 2312 1.3%
dcd_rp2040.c 840 0 764 653 2257 1.3%
msc_host.c 1636 0 0 394 2030 1.1%
dcd_msp430x5xx.c 1801 0 0 176 1977 1.1%
cdc_device.c 1239 16 1092 735 1972 1.1%
dcd_lpc17_40.c 1481 0 0 648 1805 1.0%
midi_device.c 1151 0 1007 624 1773 1.0%
dcd_nuc505.c 0 0 1533 157 1690 1.0%
dcd_lpc_ip3511.c 1463 0 0 264 1683 0.9%
hub.c 1384 8 8 30 1418 0.8%
printer_device.c 830 0 706 566 1394 0.8%
dcd_samg.c 1322 0 0 72 1394 0.8%
dcd_samd.c 1036 0 0 266 1302 0.7%
dcd_nuc121.c 1170 0 0 101 1270 0.7%
hid_device.c 1125 44 997 119 1244 0.7%
vendor_device.c 641 0 534 565 1204 0.7%
dcd_nuc120.c 1096 0 0 78 1174 0.7%
rp2040_usb.c 386 35 619 11 1051 0.6%
dfu_device.c 777 28 712 138 914 0.5%
tusb_fifo.c 854 0 486 0 849 0.5%
typec_stm32.c 820 8 2 12 842 0.5%
dwc2_common.c 603 22 0 0 615 0.3%
usbc.c 420 2 20 166 608 0.3%
hcd_pio_usb.c 262 0 240 0 502 0.3%
tusb.c 455 0 387 3 457 0.3%
hcd_ci_hs.c 181 0 0 0 181 0.1%
fsdev_common.c 180 0 0 0 180 0.1%
rusb2_common.c 160 0 16 0 176 0.1%
dfu_rt_device.c 157 0 134 0 157 0.1%
TOTAL 124114 1072 17035 52181 177856 100.0%
Input files
  • cmake-build/cmake-build-adafruit_clue/metrics.json
  • cmake-build/cmake-build-apard32690/metrics.json
  • cmake-build/cmake-build-at32f403a_weact_blackpill/metrics.json
  • cmake-build/cmake-build-at_start_f402/metrics.json
  • cmake-build/cmake-build-at_start_f413/metrics.json
  • cmake-build/cmake-build-at_start_f415/metrics.json
  • cmake-build/cmake-build-at_start_f423/metrics.json
  • cmake-build/cmake-build-at_start_f425/metrics.json
  • cmake-build/cmake-build-at_start_f435/metrics.json
  • cmake-build/cmake-build-at_start_f455/metrics.json
  • cmake-build/cmake-build-b_g474e_dpow1/metrics.json
  • cmake-build/cmake-build-b_u585i_iot2a/metrics.json
  • cmake-build/cmake-build-ch32f205r-r0/metrics.json
  • cmake-build/cmake-build-ch32v103c_bluepill/metrics.json
  • cmake-build/cmake-build-ch32v203c_r0_1v0/metrics.json
  • cmake-build/cmake-build-ch32v307v_r1_1v0/metrics.json
  • cmake-build/cmake-build-cynthion_d11/metrics.json
  • cmake-build/cmake-build-da14695_dk_usb/metrics.json
  • cmake-build/cmake-build-double_m33_express/metrics.json
  • cmake-build/cmake-build-ea4088_quickstart/metrics.json
  • cmake-build/cmake-build-ea4357/metrics.json
  • cmake-build/cmake-build-ek_tm4c123gxl/metrics.json
  • cmake-build/cmake-build-feather_stm32f405/metrics.json
  • cmake-build/cmake-build-fomu/metrics.json
  • cmake-build/cmake-build-frdm_k32l2a4s/metrics.json
  • cmake-build/cmake-build-frdm_k64f/metrics.json
  • cmake-build/cmake-build-frdm_kl25z/metrics.json
  • cmake-build/cmake-build-frdm_mcxa153/metrics.json
  • cmake-build/cmake-build-frdm_rw612/metrics.json
  • cmake-build/cmake-build-hpm6750evk2/metrics.json
  • cmake-build/cmake-build-lpcxpresso11u37/metrics.json
  • cmake-build/cmake-build-lpcxpresso1347/metrics.json
  • cmake-build/cmake-build-lpcxpresso1549/metrics.json
  • cmake-build/cmake-build-lpcxpresso1769/metrics.json
  • cmake-build/cmake-build-lpcxpresso18s37/metrics.json
  • cmake-build/cmake-build-lpcxpresso51u68/metrics.json
  • cmake-build/cmake-build-lpcxpresso54114/metrics.json
  • cmake-build/cmake-build-metro_m0_express/metrics.json
  • cmake-build/cmake-build-metro_m4_express/metrics.json
  • cmake-build/cmake-build-metro_m7_1011/metrics.json
  • cmake-build/cmake-build-mm32f327x_mb39/metrics.json
  • cmake-build/cmake-build-mm900evxb/metrics.json
  • cmake-build/cmake-build-msp_exp430f5529lp/metrics.json
  • cmake-build/cmake-build-msp_exp432e401y/metrics.json
  • cmake-build/cmake-build-nutiny_nuc126v/metrics.json
  • cmake-build/cmake-build-nutiny_sdk_nuc120/metrics.json
  • cmake-build/cmake-build-nutiny_sdk_nuc121/metrics.json
  • cmake-build/cmake-build-nutiny_sdk_nuc505/metrics.json
  • cmake-build/cmake-build-portenta_c33/metrics.json
  • cmake-build/cmake-build-raspberry_pi_pico/metrics.json
  • cmake-build/cmake-build-raspberrypi_cm4/metrics.json
  • cmake-build/cmake-build-raspberrypi_zero/metrics.json
  • cmake-build/cmake-build-samg55_xplained/metrics.json
  • cmake-build/cmake-build-sipeed_longan_nano/metrics.json
  • cmake-build/cmake-build-stlinkv3mini/metrics.json
  • cmake-build/cmake-build-stm32c071nucleo/metrics.json
  • cmake-build/cmake-build-stm32f070rbnucleo/metrics.json
  • cmake-build/cmake-build-stm32f103_bluepill/metrics.json
  • cmake-build/cmake-build-stm32f207nucleo/metrics.json
  • cmake-build/cmake-build-stm32f303disco/metrics.json
  • cmake-build/cmake-build-stm32g0b1nucleo/metrics.json
  • cmake-build/cmake-build-stm32h503nucleo/metrics.json
  • cmake-build/cmake-build-stm32h743eval/metrics.json
  • cmake-build/cmake-build-stm32h7s3nucleo/metrics.json
  • cmake-build/cmake-build-stm32l052dap52/metrics.json
  • cmake-build/cmake-build-stm32l412nucleo/metrics.json
  • cmake-build/cmake-build-stm32n6570dk/metrics.json
  • cmake-build/cmake-build-stm32u083cdk/metrics.json
  • cmake-build/cmake-build-stm32wb55nucleo/metrics.json
  • cmake-build/cmake-build-stm32wba_nucleo/metrics.json
  • cmake-build/cmake-build-xmc4500_relax/metrics.json

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

Top 10 targets by memory change (%) (out of 2345 targets) View Project Dashboard →

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>
@HiFiPhile

Copy link
Copy Markdown
Collaborator

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.

@hathach

hathach commented Jun 4, 2026

Copy link
Copy Markdown
Owner Author

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 hathach left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

@hathach hathach merged commit 35d67a2 into master Jun 4, 2026
424 of 426 checks passed
@hathach hathach deleted the dwc2-l476-setup branch June 4, 2026 02:16
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