Skip to content

Conversation

@HiFiPhile
Copy link
Collaborator

Found a RA4M2-EK from no where, turns out compatible with ra4m3_ek...

Signed-off-by: HiFiPhile <[email protected]>
Copilot AI review requested due to automatic review settings December 11, 2025 22:20
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 fixes a FIFO write bug in the RUSB2 USB device controller driver and enables dedicated hardware FIFO support. The fix addresses data corruption issues that could occur when writing from a circular buffer (tu_fifo) that wraps around, ensuring proper 16-bit alignment for hardware FIFO writes.

Key changes:

  • Enables CFG_TUD_EDPT_DEDICATED_HWFIFO for RUSB2, indicating the hardware has dedicated FIFOs for each endpoint
  • Refactors pipe_write_packet_ff to handle wrapped buffer writes with proper alignment by ensuring only the final write operation can have an odd byte count
  • When the linear portion of a wrapped buffer has odd length, creates a "glue" buffer combining the last byte of the linear portion with the first byte of the wrapped portion to maintain 16-bit alignment

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/tusb_option.h Enables CFG_TUD_EDPT_DEDICATED_HWFIFO for RUSB2 (tested on RA4M2-EK hardware)
src/portable/renesas/rusb2/dcd_rusb2.c Fixes pipe_write_packet_ff to properly handle wrapped FIFO writes with 16-bit alignment requirements

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

@github-actions
Copy link

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 .bss size % diff
dcd_rusb2.c 2966 ➙ 3076 (+110) 156 3122 ➙ 3232 (+110) +3.5%
TOTAL 2966 ➙ 3076 (+110) 156 3122 ➙ 3232 (+110) +3.5%

Changes <1% in size

file .text .rodata .data .bss size % diff
audio_device.c 2803 0 1228 1689 ➙ 1687 (-2) 4487 ➙ 4484 (-3) -0.1%
cdc_device.c 1393 16 21 674 ➙ 656 (-18) 2066 ➙ 2047 (-19) -0.9%
midi_device.c 1180 0 1047 600 ➙ 584 (-16) 1778 ➙ 1762 (-16) -0.9%
tusb_fifo.c 933 ➙ 935 (+2) 0 536 0 927 ➙ 929 (+2) +0.2%
vendor_device.c 661 0 562 458 ➙ 456 (-2) 1118 ➙ 1116 (-2) -0.2%
TOTAL 6970 ➙ 6972 (+2) 16 3394 3421 ➙ 3383 (-38) 10376 ➙ 10338 (-38) -0.4%
No changes
file .text .rodata .data .bss size % diff
cdc_host.c 6625 487 15 1624 8433 +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 4159 25 0 261 4444 +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_samd.c 1032 0 0 266 1298 +0.0%
dcd_samg.c 1319 0 0 72 1391 +0.0%
dcd_stm32_fsdev.c 3149 3 0 291 3441 +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_dwc2.c 4898 32 0 512 5442 +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%
hid_host.c 1189 0 0 1286 2475 +0.0%
hub.c 1236 8 8 31 1270 +0.0%
midi_host.c 1390 7 7 4010 5403 +0.0%
msc_device.c 2508 108 2274 544 3052 +0.0%
msc_host.c 1584 0 0 404 1988 +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%
tusb.c 516 0 441 3 517 +0.0%
typec_stm32.c 820 8 2 12 842 +0.0%
usbc.c 408 2 16 166 592 +0.0%
usbd.c 3338 ➙ 3339 (+1) 57 92 273 3674 +0.0%
usbd_control.c 523 0 474 79 601 +0.0%
usbh.c 4364 57 61 962 5406 +0.0%
usbtmc_device.c 2169 24 71 287 2488 +0.0%
video_device.c 4399 6 1851 476 4866 +0.0%
TOTAL 100324 ➙ 100325 (+1) 1138 13308 42464 145990 +0.0%

Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

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

great, I kind of guess why we have issue with fifo read, that force us to do byte read previously and skip 32-bit access for highspeed Though I don't really remember it, will test this assumption out later on.

@hathach hathach merged commit 3a4d02b into master Dec 13, 2025
163 checks passed
@hathach hathach deleted the rusb2_fifo_fix branch December 13, 2025 02:03
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