tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

hcd: add stm32_fsdev driver

Open HiFiPhile opened this issue 1 month ago • 2 comments

Describe the PR Add stm32_fsdev HCD mode support, host mode works pretty like device mode with 8 bidirectional channels.

  • Static buffer allocation, 64*2 bytes per channel (IN+OUT) (no ISO support)
  • Dynamic channel allocation like dwc2
  • No interrupt transfer scheduler, transfer will be retried on each frame if NAKed
  • Add deinit to DCD/HCD

Tested on Nucleo-C071RB (put on both STLINK and USB power jumper):

  • Hub is tested with Keyboard + Disk
    • Hub plug-in result a strange hardfault (power ??) so it's plugged on startup
    • Sometimes device unplug result a assert in config_test_unit_ready_complete and hub stop working

Also tested on STM32H573I-DK

Example Result Note
device_info OK Keyboard/Disk
bare_api OK Keyboard/Disk
cdc_msc_hid OK Keyboard/Disk
cdc_msc_hid_freertos OK Keyboard/Disk
msc_file_explorer OK File copy at 100KB/s

HiFiPhile avatar Nov 24 '25 22:11 HiFiPhile

brilliant as usual, unfortunately, I got an sore throat and running nose. I will test this out later on when getting better.

hathach avatar Nov 25 '25 04:11 hathach

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

file .text .rodata .data .bss size % diff
cdc_host.c 6614 ➙ 6511 (-103) 487 15 1624 ➙ 1418 (-206) 8422 ➙ 8173 (-249) -3.0%
dcd_stm32_fsdev.c 3149 ➙ 2494 (-655) 3 ➙ 0 (-3) 0 291 3442 ➙ 2785 (-657) -19.1%
fsdev_common.c 0 ➙ 622 (+622) 0 0 0 0 ➙ 622 (+622) n/a
hcd_stm32_fsdev.c 0 ➙ 3258 (+3258) 0 0 ➙ 1 (+1) 0 ➙ 420 (+420) 0 ➙ 3679 (+3679) n/a
midi_host.c 1340 ➙ 1335 (-5) 7 7 4010 ➙ 3471 (-539) 5353 ➙ 4810 (-543) -10.1%
msc_host.c 1590 ➙ 1571 (-19) 0 0 404 ➙ 403 (-1) 1994 ➙ 1974 (-20) -1.0%
TOTAL 12693 ➙ 15791 (+3098) 497 ➙ 494 (-3) 22 ➙ 23 (+1) 6329 ➙ 6003 (-326) 19211 ➙ 22043 (+2832) +14.7%

Changes <1% in size

file .text .rodata .data .bss size % diff
hcd_dwc2.c 4898 ➙ 4880 (-18) 32 ➙ 30 (-2) 0 512 5442 ➙ 5422 (-20) -0.4%
hid_host.c 1194 ➙ 1190 (-4) 0 0 1286 ➙ 1306 (+20) 2480 ➙ 2495 (+15) +0.6%
hub.c 1239 ➙ 1227 (-12) 8 8 31 ➙ 30 (-1) 1274 ➙ 1262 (-12) -0.9%
tusb.c 416 ➙ 419 (+3) 0 361 3 418 ➙ 421 (+3) +0.7%
tusb_fifo.c 902 ➙ 898 (-4) 0 525 0 896 ➙ 892 (-4) -0.4%
usbh.c 4314 ➙ 4286 (-28) 57 ➙ 60 (+3) 61 ➙ 60 (-1) 962 ➙ 966 (+4) 5356 ➙ 5339 (-17) -0.3%
TOTAL 12963 ➙ 12900 (-63) 97 ➙ 98 (+1) 955 ➙ 954 (-1) 2794 ➙ 2817 (+23) 15866 ➙ 15831 (-35) -0.2%
No changes
file .text .rodata .data .bss size % diff
audio_device.c 2859 0 1250 1687 4540 +0.0%
cdc_device.c 1332 16 20 656 1986 +0.0%
dcd_ch32_usbfs.c 1472 0 0 2444 3916 +0.0%
dcd_ch32_usbhs.c 1648 0 0 448 2096 +0.0%
dcd_ci_fs.c 1925 0 0 1290 3215 +0.0%
dcd_ci_hs.c 1725 0 0 1152 2493 +0.0%
dcd_da146xx.c 3067 0 0 144 3211 +0.0%
dcd_dwc2.c 4188 25 0 263 4474 +0.0%
dcd_eptri.c 2270 0 0 259 2529 +0.0%
dcd_khci.c 1953 0 0 1290 3243 +0.0%
dcd_lpc17_40.c 1470 0 0 648 1794 +0.0%
dcd_lpc_ip3511.c 1463 0 0 264 1639 +0.0%
dcd_mm32f327x_otg.c 1478 0 0 1290 2768 +0.0%
dcd_msp430x5xx.c 1796 0 0 176 1972 +0.0%
dcd_musb.c 2228 0 0 160 2388 +0.0%
dcd_nrf5x.c 2919 0 0 292 3211 +0.0%
dcd_nuc120.c 1093 0 0 78 1171 +0.0%
dcd_nuc121.c 1167 0 0 101 1268 +0.0%
dcd_nuc505.c 0 0 1529 157 1686 +0.0%
dcd_rp2040.c 736 20 580 1029 2365 +0.0%
dcd_rusb2.c 3076 0 0 156 3232 +0.0%
dcd_samd.c 1032 0 0 266 1298 +0.0%
dcd_samg.c 1319 0 0 72 1391 +0.0%
dfu_device.c 741 28 712 174 915 +0.0%
dfu_rt_device.c 157 0 134 0 156 +0.0%
dwc2_common.c 781 29 0 0 797 +0.0%
ecm_rndis_device.c 1037 0 1 2272 3310 +0.0%
ehci.c 2651 0 0 5970 8622 +0.0%
hcd_ch32_usbfs.c 2484 0 0 498 2982 +0.0%
hcd_ci_hs.c 229 0 0 0 229 +0.0%
hcd_khci.c 2442 0 0 449 2891 +0.0%
hcd_musb.c 3073 0 0 157 3230 +0.0%
hcd_pio_usb.c 262 0 240 0 502 +0.0%
hcd_rp2040.c 936 73 420 512 1941 +0.0%
hcd_rusb2.c 2965 0 0 246 3211 +0.0%
hcd_samd.c 2220 0 0 324 2544 +0.0%
hid_device.c 1119 44 997 117 1235 +0.0%
midi_device.c 1129 0 991 584 1711 +0.0%
msc_device.c 2508 108 2274 544 3052 +0.0%
mtp_device.c 1622 22 1385 585 2215 +0.0%
ncm_device.c 1503 28 1408 5961 7478 +0.0%
ohci.c 1942 0 0 2414 4356 +0.0%
rp2040_usb.c 124 70 574 4 772 +0.0%
rusb2_common.c 0 0 16 0 16 +0.0%
typec_stm32.c 820 8 2 12 842 +0.0%
usbc.c 408 2 16 166 592 +0.0%
usbd.c 3167 57 88 276 3505 +0.0%
usbd_control.c 523 0 474 79 601 +0.0%
usbtmc_device.c 2169 24 71 287 2488 +0.0%
vendor_device.c 609 0 514 456 1064 +0.0%
video_device.c 4399 6 1851 476 4866 +0.0%
TOTAL 84236 560 15547 36885 124009 +0.0%

github-actions[bot] avatar Dec 13 '25 08:12 github-actions[bot]