Skip to content

usbd: disable xfer_isr path for ch32 usbfs/usbhs#3728

Open
HiFiPhile wants to merge 2 commits into
masterfrom
xfer_isr_fallback
Open

usbd: disable xfer_isr path for ch32 usbfs/usbhs#3728
HiFiPhile wants to merge 2 commits into
masterfrom
xfer_isr_fallback

Conversation

@HiFiPhile

Copy link
Copy Markdown
Collaborator

Disable xfer_isr path for ch32 usbfs/usbhs as extended processing time inside interrupt handler will lead to ISO data loss.

Added a note about ISO issue workaround, together with #3727 uac2_headset and uac2_speaker_fb examples works on CH32V305.

Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Copilot AI review requested due to automatic review settings June 23, 2026 12:36

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 disables the USBD xfer_isr callback path for WCH CH32 USBFS/USBHS targets to reduce ISR processing time (mitigating isochronous transfer corruption/data loss), and documents a partial workaround for the WCH ISO limitations.

Changes:

  • Add a TUP_USBD_XFER_ISR configuration knob (default on) and force it off for CH32 (WCH) MCU families in tusb_mcu.h.
  • Make xfer_isr optional/conditional across USBD core and class-driver declarations/registration.
  • Update the audio device class to re-arm transfers from xfer_cb when xfer_isr is disabled; add documentation notes for the CH32 ISO issue workaround.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/device/usbd.c Gates the xfer_isr dispatch path and class driver table initializers behind TUP_USBD_XFER_ISR.
src/device/usbd_pvt.h Makes the usbd_class_driver_t::xfer_isr callback conditional on TUP_USBD_XFER_ISR.
src/common/tusb_mcu.h Defines TUP_USBD_XFER_ISR (default 1) and forces it to 0 for WCH CH32 MCU families.
src/class/audio/audio_device.h Gates the audiod_xfer_isr prototype behind TUP_USBD_XFER_ISR.
src/class/audio/audio_device.c Refactors audio endpoint completion handling so transfers can be re-armed from task context when ISR path is disabled.
docs/reference/device_issues.rst Adds a “Partial workaround” section for the WCH CH32 isochronous endpoint corruption issue.
Comments suppressed due to low confidence (1)

src/class/audio/audio_device.c:554

  • audiod_tx_done() now runs in both ISR and task context (depending on the is_isr argument / TUP_USBD_XFER_ISR), but it still calls tud_audio_tx_done_isr(). This function is documented and named as ISR-only, so calling it from task context when TUP_USBD_XFER_ISR==0 is surprising for application code and can lead to incorrect assumptions about what is safe to do in the callback. At minimum, document this behavior near the call (or preferably update the public API docs / naming to reflect the actual context).

  // Call a weak callback here - a possibility for user to get informed former TX was completed and data gets now loaded into EP in buffer
  TU_VERIFY(tud_audio_tx_done_isr(rhport, n_bytes_sent, idx_audio_fct, audio->ep_in, audio->ep_in_alt));


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/reference/device_issues.rst
@claude

claude Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

1 similar comment
@claude

claude Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@github-actions

Copy link
Copy Markdown

Size Difference Report

Because TinyUSB code size varies by port and configuration, the metrics below represent the averaged totals across all example builds.

Note: If there is no change, only one value is shown.

Changes >1% in size

No entries.

Changes <1% in size
file .text .rodata .data .bss size % diff
audio_device.c 2890 ➙ 2892 (+2) 0 1259 1623 4508 ➙ 4510 (+2) +0.0%
usbd.c 3530 ➙ 3518 (-12) 57 90 355 3948 ➙ 3936 (-12) -0.3%
TOTAL 6420 ➙ 6410 (-10) 57 1349 1978 8456 ➙ 8446 (-10) -0.1%
No changes
file .text .rodata .data .bss size % diff
cdc_device.c 1236 16 1092 728 1963 +0.0%
cdc_host.c 6399 487 15 971 7594 +0.0%
dcd_ch32_usbfs.c 1659 0 0 2444 4103 +0.0%
dcd_ch32_usbhs.c 1892 0 0 481 2373 +0.0%
dcd_ci_fs.c 1924 0 0 1290 3214 +0.0%
dcd_ci_hs.c 1756 0 0 1344 2534 +0.0%
dcd_da146xx.c 3067 0 0 144 3211 +0.0%
dcd_dwc2.c 4223 19 0 265 4506 +0.0%
dcd_eptri.c 2273 0 0 259 2532 +0.0%
dcd_ft9xx.c 3284 0 0 172 3456 +0.0%
dcd_khci.c 1952 0 0 1290 3242 +0.0%
dcd_lpc17_40.c 1481 0 0 648 1805 +0.0%
dcd_lpc_ip3511.c 1463 0 0 264 1683 +0.0%
dcd_mm32f327x_otg.c 1477 0 0 1290 2767 +0.0%
dcd_msp430x5xx.c 1801 0 0 176 1977 +0.0%
dcd_musb.c 2595 0 0 179 2773 +0.0%
dcd_nrf5x.c 2939 0 0 292 3231 +0.0%
dcd_nuc120.c 1096 0 0 78 1174 +0.0%
dcd_nuc121.c 1170 0 0 101 1270 +0.0%
dcd_nuc505.c 0 0 1533 157 1690 +0.0%
dcd_rp2040.c 840 0 764 653 2257 +0.0%
dcd_rusb2.c 2918 0 0 156 3074 +0.0%
dcd_samd.c 1036 0 0 266 1302 +0.0%
dcd_samg.c 1322 0 0 72 1394 +0.0%
dcd_stm32_fsdev.c 2534 0 0 291 2825 +0.0%
dfu_device.c 776 28 712 136 912 +0.0%
dfu_rt_device.c 157 0 134 0 157 +0.0%
dwc2_common.c 603 22 0 0 615 +0.0%
ecm_rndis_device.c 1059 0 1 2759 3818 +0.0%
ehci.c 2763 0 0 6274 7783 +0.0%
fsdev_common.c 180 0 0 0 180 +0.0%
hcd_ch32_usbfs.c 2491 0 0 502 2993 +0.0%
hcd_ci_hs.c 181 0 0 0 181 +0.0%
hcd_dwc2.c 5070 25 1 545 5640 +0.0%
hcd_khci.c 2443 0 0 454 2897 +0.0%
hcd_musb.c 3071 0 0 157 3228 +0.0%
hcd_pio_usb.c 262 0 240 0 502 +0.0%
hcd_rp2040.c 1996 17 4 321 2338 +0.0%
hcd_rusb2.c 2923 0 0 245 3168 +0.0%
hcd_samd.c 2220 0 0 324 2544 +0.0%
hcd_stm32_fsdev.c 3248 0 1 420 3670 +0.0%
hid_device.c 1123 44 997 119 1242 +0.0%
hid_host.c 1241 0 0 1270 2511 +0.0%
hub.c 1384 8 8 30 1419 +0.0%
midi2_device.c 2628 52 1175 561 3211 +0.0%
midi2_host.c 1802 0 0 5921 7723 +0.0%
midi_device.c 1149 0 1007 619 1765 +0.0%
midi_host.c 1339 7 7 3538 4880 +0.0%
msc_device.c 2513 108 2281 804 3318 +0.0%
msc_host.c 1633 0 0 395 2028 +0.0%
mtp_device.c 1713 22 743 589 2309 +0.0%
ncm_device.c 1761 28 819 4393 6167 +0.0%
ohci.c 1925 0 0 2503 4428 +0.0%
printer_device.c 828 0 706 560 1387 +0.0%
rp2040_usb.c 386 35 619 11 1051 +0.0%
rusb2_common.c 160 0 16 0 176 +0.0%
tusb.c 455 0 387 3 457 +0.0%
tusb_fifo.c 855 0 486 0 850 +0.0%
typec_stm32.c 820 8 2 12 842 +0.0%
usbc.c 420 2 20 166 608 +0.0%
usbh.c 4967 57 82 1165 6238 +0.0%
usbtmc_device.c 2194 24 68 313 2539 +0.0%
vendor_device.c 639 0 534 559 1197 +0.0%
video_device.c 4433 5 1235 480 4905 +0.0%
TOTAL 118148 1014 15689 50159 169827 +0.0%

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown

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

hfp-iar

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 630k/406k MSC 812k/757k
stm32f746disco ✅ CDC 12.2M/7.8M MSC 15.1M/30.4M
stm32f746disco-DMA ✅ CDC 12.5M/10.4M MSC 15.7M/31.2M
lpcxpresso43s67 ✅ CDC 10.1M/10.1M MSC 21.7M/25.1M

Legend: ✅ pass · ❌ fail · ⚪ skipped · blank not run

hfp.json

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 632k/397k MSC 817k/791k
stm32f746disco ✅ CDC 13.6M/10.4M MSC 15.2M/30.3M
stm32f746disco-DMA ✅ CDC 13.7M/9.5M MSC 15.7M/30.5M
lpcxpresso43s67 ✅ CDC 12.9M/11.9M MSC 29.9M/32.7M

Legend: ✅ pass · ❌ fail · ⚪ skipped · blank not run

tinyusb.json

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 768k/800k MSC 912k/1M
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 472k/494k MSC 474k/560k
max32666fthr ✅ CDC 7M/14.2M MSC 16.3M/17.4M
metro_m4_express ✅ CDC 548k/641k MSC 631k/546k
mimxrt1015_evk ✅ CDC 17.4M/10.4M MSC 27.1M/22.6M
mimxrt1064_evk ✅ CDC 18.1M/12M MSC 28.6M/23.1M rd 1365KB/s
lpcxpresso11u37 ✅ CDC 423k/334k MSC 486k/571k
ra4m1_ek ✅ CDC 543k/444k MSC 645k/587k
raspberry_pi_pico ✅ CDC 508k/514k MSC 526k/534k rd 62KB/s rd 62KB/s
raspberry_pi_pico_w rd 1106KB/s rd 1022KB/s
raspberry_pi_pico2 rd 1108KB/s rd 1022KB/s
adafruit_fruit_jam ✅ CDC 557k/524k MSC 533k/524k rd 62KB/s rd 62KB/s
stm32f072disco ✅ CDC 423k/350k MSC 635k/489k
stm32f407disco ✅ CDC 534k/500k MSC 706k/975k
stm32f723disco ✅ CDC 775k/852k MSC 1M/1M rd 18078KB/s rd 4096KB/s
stm32f723disco-DMA ✅ CDC 847k/754k MSC 1M/969k rd 20164KB/s rd 4096KB/s
stm32h743nucleo ✅ CDC 787k/957k MSC 971k/1M
stm32h743nucleo-DMA ✅ CDC 833k/780k MSC 821k/870k
stm32g0b1nucleo ✅ CDC 467k/499k MSC 522k/587k
stm32l476disco ✅ CDC 593k/481k MSC 680k/942k
stm32u083nucleo ✅ CDC 575k/530k MSC 672k/567k
nanoch32v203-fsdev ✅ CDC 976k/607k MSC 1M/1M
nanoch32v203-usbfs ✅ CDC 965k/575k MSC 1.1M/1.1M
ch32v103r_r1_1v0
ch582m_evt ✅ CDC 236k/228k MSC 495k/514k

Legend: ✅ pass · ❌ fail · ⚪ skipped · blank not run

@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

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

target .text .rodata .data .bss total % diff
ch32v103c_bluepill/printer_to_cdc 11,908 → 11,628 (-280) 12,268 → 11,988 (-280) -2.3%
ch582m_evt/printer_to_cdc 9,032 → 8,760 (-272) 12,568 → 12,296 (-272) -2.2%
ch32v103c_bluepill/webusb_serial 12,248 → 11,980 (-268) 12,664 → 12,396 (-268) -2.1%
ch32v103c_bluepill/dfu_runtime 8,556 → 8,368 (-188) 8,924 → 8,736 (-188) -2.1%
ch32v307v_r1_1v0/printer_to_cdc 13,308 → 13,024 (-284) 13,796 → 13,512 (-284) -2.1%
ch32v203c_r0_1v0/printer_to_cdc 14,036 → 13,756 (-280) 14,332 → 14,052 (-280) -2.0%
ch32v307v_r1_1v0/dfu_runtime 9,380 → 9,188 (-192) 9,876 → 9,684 (-192) -1.9%
ch582m_evt/webusb_serial 9,464 → 9,212 (-252) 13,048 → 12,796 (-252) -1.9%
ch32v307v_r1_1v0/webusb_serial 13,528 → 13,260 (-268) 14,072 → 13,804 (-268) -1.9%
ch32v103c_bluepill/cdc_msc_throughput 13,956 → 13,688 (-268) 14,316 → 14,048 (-268) -1.9%

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