Skip to content

fix(dwc2): defer EP0 buffer advance until DMA completion#3772

Open
tore-espressif wants to merge 1 commit into
hathach:masterfrom
espressif:fix/ep0_buf_alignment
Open

fix(dwc2): defer EP0 buffer advance until DMA completion#3772
tore-espressif wants to merge 1 commit into
hathach:masterfrom
espressif:fix/ep0_buf_alignment

Conversation

@tore-espressif

Copy link
Copy Markdown
Contributor

edpt_schedule_packets() advanced xfer->buffer when scheduling EP0 IN DMA, and EP0 OUT completion invalidated cache at that already-advanced pointer. Short control OUT transfers (e.g. 7 bytes) then skipped the start of the buffer and broke class drivers.

Track scheduled EP0 packet size in ep0_xact_bytes[]. Invalidate and advance the buffer only on transfer complete, then schedule the next EP0 chunk. EP0 IN advances by ep0_xact_bytes before rescheduling.

Fixes #3295

edpt_schedule_packets() advanced xfer->buffer when scheduling EP0 IN
DMA, and EP0 OUT completion invalidated cache at that already-advanced
pointer. Short control OUT transfers (e.g. 7 bytes) then skipped the
start of the buffer and broke class drivers.

Track scheduled EP0 packet size in ep0_xact_bytes[]. Invalidate and
advance the buffer only on transfer complete, then schedule the next
EP0 chunk. EP0 IN advances by ep0_xact_bytes before rescheduling.

Bug introduced in hathach#3295
@hathach

hathach commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Yeah I fixed this exact bug while doing usbtest, which I have been trying to get it merge for the last few days.

@github-actions

Copy link
Copy Markdown

Hardware-in-the-loop (HIL) Test Report

hfp.json

✅ 39 passed · ❌ 13 failed · ⚪ 0 skipped · blank not run

Board cdc_dual_ports cdc_msc dfu cdc_msc_throughput audio_test_freertos dfu_runtime cdc_msc_freertos hid_boot_interface msc_dual_lun hid_generic_inout printer_to_cdc midi_test mtp
stm32l412nucleo ✅ CDC 608k/392k MSC 844k/814k
stm32f746disco ✅ CDC 13.7M/10.5M MSC 15.6M/30.6M
stm32f746disco-DMA ✅ CDC 14.3M/10.3M MSC 15.7M/31.3M
lpcxpresso43s67

tinyusb.json

✅ 333 passed · ❌ 6 failed · ⚪ 11 skipped · blank not run

Board cdc_dual_ports cdc_msc dfu cdc_msc_throughput audio_test_freertos dfu_runtime cdc_msc_freertos hid_boot_interface msc_dual_lun hid_generic_inout printer_to_cdc midi_test mtp host_info_to_device_cdc cdc_msc_hid msc_file_explorer msc_file_explorer_freertos device_info hid_composite_freertos
ek_tm4c123gxl ✅ CDC 519k/528k MSC 535k/511k
espressif_p4_function_ev rd 409KB/s
espressif_p4_function_ev-DMA rd 409KB/s
espressif_s3_devkitm rd 409KB/s
espressif_s3_devkitm-DMA rd 409KB/s
feather_nrf52840_express ✅ CDC 498k/568k MSC 585k/521k
max32666fthr ✅ CDC 7M/14.3M MSC 16.9M/21.3M
metro_m4_express ✅ CDC 518k/519k MSC 566k/560k
mimxrt1015_evk ✅ CDC 12M/9.1M MSC 23.5M/13.8M
mimxrt1064_evk ✅ CDC 8.2M/6.3M MSC 20M/23.1M rd 1365KB/s rd 1365KB/s
lpcxpresso11u37 ✅ CDC 447k/324k MSC 542k/591k
ra4m1_ek ✅ CDC 635k/459k MSC 602k/626k
raspberry_pi_pico ✅ CDC 579k/579k MSC 596k/550k
raspberry_pi_pico_w rd 1108KB/s rd 1022KB/s
raspberry_pi_pico2 rd 1110KB/s rd 1022KB/s
adafruit_fruit_jam ✅ CDC 523k/596k MSC 610k/633k rd 62KB/s rd 62KB/s
stm32f072disco ✅ CDC 488k/318k MSC 532k/552k
stm32f407disco ✅ CDC 942k/511k MSC 1M/575k
stm32f723disco ✅ CDC 509k/524k MSC 519k/514k rd 15887KB/s rd 4002KB/s
stm32f723disco-DMA ✅ CDC 507k/511k MSC 511k/511k rd 15420KB/s rd 4096KB/s
stm32h743nucleo ✅ CDC 651k/633k MSC 620k/521k
stm32h743nucleo-DMA ✅ CDC 654k/525k MSC 546k/511k
stm32g0b1nucleo ✅ CDC 507k/511k MSC 519k/516k
stm32l476disco ✅ CDC 544k/487k MSC 384k/639k
stm32u083nucleo ✅ CDC 508k/509k MSC 594k/538k
nanoch32v203-fsdev ✅ CDC 508k/511k MSC 511k/511k
nanoch32v203-usbfs
ch32v103r_r1_1v0 ✅ CDC 144k/436k MSC 627k/618k
ch582m_evt ✅ CDC 230k/209k MSC 438k/379k

@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

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

target .text .rodata .data .bss total % diff
raspberrypi_zero/dynamic_configuration 61,420 → 61,448 (+28) 939 → 5,007 (+4,068) 62,359 → 66,455 (+4,096) +6.6%
xmc4500_relax/hid_composite 740 → 748 (+8) 796 → 804 (+8) +1.0%
xmc4500_relax/hid_generic_inout 876 → 884 (+8) 932 → 940 (+8) +0.9%
xmc4500_relax/webusb_serial 1,044 → 1,052 (+8) 1,100 → 1,108 (+8) +0.7%
xmc4500_relax/dfu_runtime 12,048 → 12,112 (+64) 24,148 → 24,276 (+128) +0.5%
xmc4500_relax/audio_test_multi_rate 15,296 → 15,360 (+64) 2,608 → 2,616 (+8) 33,348 → 33,484 (+136) +0.4%
xmc4500_relax/video_capture_2ch 16,924 → 16,988 (+64) 38,040 → 38,168 (+128) +0.3%
xmc4500_relax/msc_dual_lun 14,916 → 14,980 (+64) 46,268 → 46,396 (+128) +0.3%
xmc4500_relax/midi2_device 1,240 → 1,248 (+8) 3,036 → 3,044 (+8) +0.3%
xmc4500_relax/cdc_msc 17,420 → 17,484 (+64) 1,448 → 1,456 (+8) 52,788 → 52,924 (+136) +0.3%

@hathach

hathach commented Jul 16, 2026

Copy link
Copy Markdown
Owner

it is detected when doing usbtest suite 59f02a1

@hathach

hathach commented Jul 17, 2026

Copy link
Copy Markdown
Owner

this should be fixed with #3758, please check if current master work for you.

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