Skip to content

Conversation

@HiFiPhile
Copy link
Collaborator

Describe the PR
Add dcd_configure to configure dwc2 IN EP double buffer.

Although the gain is minimal as bandwidth limit is close (29MB/s vs 31MB/s). My PC's host controller only does 8 transfer per msof which yields a maximum throughput of 32MB/s.

Signed-off-by: HiFiPhile <[email protected]>
Copilot AI review requested due to automatic review settings November 21, 2025 15:54

// TX FIFO empty level for interrupt is complete empty
uint32_t gahbcfg = dwc2->gahbcfg;
gahbcfg |= GAHBCFG_TX_FIFO_EPMTY_LVL;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think there is no need to set FIFO level to complete empty in any case ?

Copy link
Contributor

Copilot AI left a comment

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 adds a new configuration API (dcd_configure) to dynamically configure DWC2 device controller behavior, specifically enabling double buffering for IN endpoints to improve throughput. The implementation replaces the previous hardcoded TX FIFO empty level configuration with a configurable double buffering approach.

Key changes:

  • New public API tud_configure() to configure device stack behavior before initialization
  • DWC2-specific configuration structure to specify which IN endpoints should be double buffered
  • FIFO allocation logic updated to support double buffering based on configuration

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/device/usbd.h Adds new configuration API types and tud_configure() function declaration
src/device/usbd.c Implements tud_configure() as a passthrough to dcd_configure() with weak default implementation
src/device/dcd.h Declares dcd_configure() for device controller drivers to implement
src/portable/synopsys/dwc2/dcd_dwc2.c Implements dcd_configure() for DWC2 and updates FIFO allocation logic to support double buffering; removes hardcoded TX FIFO empty level setting

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

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

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 any section

No entries.

Changes <1% in all sections

File .rodata .text .data .bss Total
dcd_dwc2.c 25 4126 ➙ 4154 (+28, +0.7%) 0 261 ➙ 263 (+2, +0.8%) 4411 ➙ 4441 (+30, +0.7%)
SUM 25 4126 ➙ 4154 (+28, +0.7%) 0 261 ➙ 263 (+2, +0.8%) 4411 ➙ 4441 (+30, +0.7%)
No changes
File .rodata .text .data .bss Total
audio_device.c 0 2809 1228 1739 4542
cdc_device.c 16 1437 22 698 2134
cdc_host.c 487 6643 15 1612 8438
dcd_ch32_usbfs.c 0 1472 0 2444 3916
dcd_ch32_usbhs.c 0 1648 0 448 2096
dcd_ci_fs.c 0 1925 0 1290 3215
dcd_ci_hs.c 0 1725 0 1152 2493
dcd_da146xx.c 0 3067 0 144 3211
dcd_eptri.c 0 2270 0 259 2529
dcd_khci.c 0 1953 0 1290 3243
dcd_lpc17_40.c 0 1470 0 648 1794
dcd_lpc_ip3511.c 0 1463 0 264 1639
dcd_mm32f327x_otg.c 0 1478 0 1290 2768
dcd_msp430x5xx.c 0 1796 0 176 1972
dcd_musb.c 0 2228 0 160 2388
dcd_nrf5x.c 0 2919 0 292 3211
dcd_nuc120.c 0 1093 0 78 1171
dcd_nuc121.c 0 1167 0 101 1268
dcd_nuc505.c 0 0 1529 157 1686
dcd_rp2040.c 20 736 580 1029 2365
dcd_rusb2.c 0 2966 0 156 3122
dcd_samd.c 0 1032 0 266 1298
dcd_samg.c 0 1319 0 72 1391
dcd_stm32_fsdev.c 3 3126 0 291 3418
dfu_device.c 28 741 712 174 915
dfu_rt_device.c 0 157 134 0 156
dwc2_common.c 29 781 0 0 797
ecm_rndis_device.c 0 1037 1 2272 3310
ehci.c 0 2651 0 5970 8622
hcd_ch32_usbfs.c 0 2484 0 498 2982
hcd_ci_hs.c 0 229 0 0 229
hcd_dwc2.c 32 4898 0 512 5442
hcd_khci.c 0 2442 0 449 2891
hcd_musb.c 0 3073 0 157 3230
hcd_pio_usb.c 0 262 240 0 502
hcd_rp2040.c 73 936 420 512 1941
hcd_rusb2.c 0 2965 0 246 3211
hcd_samd.c 0 2220 0 324 2544
hid_device.c 44 1119 997 117 1235
hid_host.c 0 1171 0 1286 2456
hub.c 8 1236 8 31 1270
midi_device.c 0 1220 1079 619 1836
midi_host.c 7 1402 7 3978 5383
msc_device.c 108 2508 2274 544 3052
msc_host.c 0 1583 0 404 1987
mtp_device.c 22 1621 1385 585 2214
ncm_device.c 28 1503 1408 5961 7478
ohci.c 0 1942 0 2414 4356
rp2040_usb.c 70 124 574 4 772
rusb2_common.c 0 0 16 0 16
tusb.c 0 616 524 3 617
tusb_fifo.c 0 893 536 0 888
typec_stm32.c 8 820 2 12 842
usbc.c 2 408 16 166 592
usbd.c 57 3323 92 273 3658
usbd_control.c 0 523 474 79 601
usbh.c 57 4364 61 962 5406
usbtmc_device.c 24 2169 71 287 2488
vendor_device.c 0 697 590 477 1173
video_device.c 6 4399 1851 476 4866
SUM 1129 106259 16846 45848 155266

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 4, 2025

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