Skip to content

Fix some -Wconversion warnings#3601

Merged
hathach merged 1 commit into
masterfrom
fix-conversion-warnings
Apr 23, 2026
Merged

Fix some -Wconversion warnings#3601
hathach merged 1 commit into
masterfrom
fix-conversion-warnings

Conversation

@hathach
Copy link
Copy Markdown
Owner

@hathach hathach commented Apr 16, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 16, 2026 17:11
Copy link
Copy Markdown
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 aims to reduce/eliminate -Wconversion / -Wsign-conversion warnings across multiple MCU/USB controller ports by making narrowing/bitwise operations explicit (casts, unsigned literals) and, in a few cases, suppressing warnings originating from vendor headers.

Changes:

  • Add explicit casts for arithmetic/bitfield operations that intentionally narrow (e.g., tu_div_ceil() results, register bitfields, endpoint IDs).
  • Replace signed shift literals with unsigned variants (1u, 0x11u, etc.) to avoid sign-conversion warnings in register manipulation.
  • Add GCC diagnostic suppression blocks around vendor headers in select ports/boards; update .gitignore for .worktrees.

Reviewed changes

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

Show a summary per file
File Description
src/portable/synopsys/dwc2/dcd_dwc2.c Add explicit casts for FIFO sizing and packet count calculations.
src/portable/st/stm32_fsdev/fsdev_common.h Use unsigned shift literals in bit-clearing helpers.
src/portable/st/stm32_fsdev/fsdev_common.c Cast tu_div_ceil() results to uint8_t for PMA block encoding.
src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c Add explicit casts for PMA address values and endpoint index usage.
src/portable/renesas/rusb2/dcd_rusb2.c Make endpoint/register width conversions explicit; tighten ep_addr to uint8_t.
src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c Add casts for endpoint-id math and buffer fields to avoid narrowing warnings.
src/portable/nxp/lpc17_40/dcd_lpc17_40.c Cast arithmetic results to uint8_t where the API expects 8-bit values.
src/portable/nuvoton/nuc505/dcd_nuc505.c Suppress conversion warnings from vendor header; fix buffer size type/arithmetics.
src/portable/nuvoton/nuc121/dcd_nuc121.c Suppress conversion warnings from vendor header; add casts for register reads and sizes.
src/portable/nuvoton/nuc120/dcd_nuc120.c Fix size type/arithmetics and cast register reads to uint16_t.
src/portable/nordic/nrf5x/dcd_nrf5x.c Suppress conversion warnings from nrfx headers; cast register value before tu_edpt_dir().
src/portable/microchip/samg/dcd_samg.c Use unsigned shift literals when toggling endpoint reset bits.
src/portable/mentor/musb/musb_type.h Cast endpoint index to the register’s 8-bit width.
src/portable/mentor/musb/dcd_musb.c Add explicit casts for FIFO sizing/control bits; widen TX/RX interrupt snapshot types.
src/portable/dialog/da146xx/dcd_da146xx.c Use unsigned masks/shifts and cast register reads/writes to appropriate widths.
src/portable/chipidea/ci_fs/dcd_ci_fs.c Align interrupt/status variable types with 8-bit CI FS register definitions.
src/common/tusb_fifo.c Add explicit casts for word-aligned byte counts and odd-byte calculations.
hw/bsp/tm4c/family.c Use unsigned shift literal for UART control bit manipulation.
hw/bsp/samg/family.c Wrap vendor includes with additional conversion-warning suppression.
hw/bsp/samd2x_l2x/family.c Use unsigned shift literals in GCLK init masks.
hw/bsp/samd11/family.c Add conversion-warning suppression for vendor HAL includes; use unsigned shift literals.
hw/bsp/mm32/family.c Use unsigned shift literals for RCC register bit manipulation.
hw/bsp/board.c Adjust RTT logging syscall to avoid int narrowing in call site.
.gitignore Ignore .worktrees.

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

Comment thread hw/bsp/board.c
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 16, 2026

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 .bss size % diff
dcd_dwc2.c 4237 ➙ 4241 (+4) 19 265 4521 ➙ 4524 (+3) +0.1%
dcd_rusb2.c 2919 ➙ 2915 (-4) 0 156 3075 ➙ 3071 (-4) -0.1%
TOTAL 7156 19 421 7596 ➙ 7595 (-1) -0.0%
No changes
file .text .rodata .data .bss size % diff
audio_device.c 2896 0 1259 1625 4515 +0.0%
cdc_device.c 1253 16 1106 684 1935 +0.0%
cdc_host.c 6381 487 15 985 7579 +0.0%
dcd_ch32_usbfs.c 1473 0 0 2444 3917 +0.0%
dcd_ch32_usbhs.c 1469 0 0 448 1917 +0.0%
dcd_ci_fs.c 1925 0 0 1290 3215 +0.0%
dcd_ci_hs.c 1759 0 0 1344 2538 +0.0%
dcd_da146xx.c 3067 0 0 144 3211 +0.0%
dcd_eptri.c 2271 0 0 259 2530 +0.0%
dcd_ft9xx.c 3276 0 0 172 3448 +0.0%
dcd_khci.c 1953 0 0 1290 3243 +0.0%
dcd_lpc17_40.c 1474 0 0 648 1798 +0.0%
dcd_lpc_ip3511.c 1463 0 0 264 1683 +0.0%
dcd_mm32f327x_otg.c 1478 0 0 1290 2768 +0.0%
dcd_msp430x5xx.c 1798 0 0 176 1974 +0.0%
dcd_musb.c 2445 0 0 160 2605 +0.0%
dcd_nrf5x.c 2918 0 0 292 3210 +0.0%
dcd_nuc120.c 1094 0 0 78 1172 +0.0%
dcd_nuc121.c 1168 0 0 101 1269 +0.0%
dcd_nuc505.c 0 0 1531 157 1688 +0.0%
dcd_rp2040.c 842 0 764 653 2259 +0.0%
dcd_samd.c 1034 0 0 266 1300 +0.0%
dcd_samg.c 1320 0 0 72 1392 +0.0%
dcd_stm32_fsdev.c 2558 0 0 291 2849 +0.0%
dfu_device.c 777 28 712 140 916 +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 1037 0 1 2858 3896 +0.0%
ehci.c 2763 0 0 6043 7597 +0.0%
fsdev_common.c 180 0 0 0 180 +0.0%
hcd_ch32_usbfs.c 2485 0 0 498 2983 +0.0%
hcd_ci_hs.c 184 0 0 0 184 +0.0%
hcd_dwc2.c 5007 25 1 513 5545 +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 2000 17 4 321 2342 +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 3287 0 1 420 3708 +0.0%
hid_device.c 1125 44 997 119 1244 +0.0%
hid_host.c 1240 0 0 1251 2491 +0.0%
hub.c 1384 8 8 30 1418 +0.0%
midi_device.c 1151 0 1007 624 1773 +0.0%
midi_host.c 1341 7 7 3635 4979 +0.0%
msc_device.c 2525 108 2286 547 3071 +0.0%
msc_host.c 1587 0 0 394 1982 +0.0%
mtp_device.c 1696 22 735 588 2292 +0.0%
ncm_device.c 1538 28 718 5843 7395 +0.0%
ohci.c 1940 0 0 2414 4353 +0.0%
printer_device.c 830 0 706 566 1394 +0.0%
rp2040_usb.c 369 35 644 11 1059 +0.0%
rusb2_common.c 160 0 16 0 176 +0.0%
tusb.c 451 0 383 3 453 +0.0%
tusb_fifo.c 846 0 480 0 841 +0.0%
typec_stm32.c 820 8 2 12 842 +0.0%
usbc.c 420 2 20 166 608 +0.0%
usbd.c 3224 57 88 275 3564 +0.0%
usbd_control.c 538 0 484 79 616 +0.0%
usbh.c 4652 55 99 1034 5807 +0.0%
usbtmc_device.c 2196 24 68 316 2544 +0.0%
vendor_device.c 641 0 534 565 1204 +0.0%
video_device.c 4443 5 1235 479 4914 +0.0%
TOTAL 111832 998 16285 46052 159493 +0.0%

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 16, 2026

MemBrowse Memory Report

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

target .text .rodata .data .bss total % diff
portenta_c33/mtp 18,676 → 18,660 (-16) 18,676 → 18,660 (-16) -0.1%
portenta_c33/dfu_runtime 10,796 → 10,792 (-4) 10,796 → 10,792 (-4) -0.0%
portenta_c33/hid_generic_inout 11,780 → 11,776 (-4) 11,780 → 11,776 (-4) -0.0%
b_u585i_iot2a/hid_generic_inout 23,504 → 23,512 (+8) 24,544 → 24,552 (+8) +0.0%
at_start_f435/dfu_runtime 11,556 → 11,560 (+4) 12,552 → 12,556 (+4) +0.0%
portenta_c33/hid_multiple_interface 12,616 → 12,612 (-4) 12,616 → 12,612 (-4) -0.0%
portenta_c33/hid_boot_interface 12,632 → 12,628 (-4) 12,632 → 12,628 (-4) -0.0%
portenta_c33/hid_composite 12,840 → 12,836 (-4) 12,840 → 12,836 (-4) -0.0%
stm32f207nucleo/dfu_runtime 12,068 → 12,072 (+4) 12,892 → 12,896 (+4) +0.0%
portenta_c33/midi_test 13,048 → 13,044 (-4) 13,048 → 13,044 (-4) -0.0%

@hathach hathach force-pushed the fix-conversion-warnings branch from ee3452c to a6dcc3f Compare April 17, 2026 03:16
@hathach hathach merged commit 0d1c090 into master Apr 23, 2026
512 of 517 checks passed
@hathach hathach deleted the fix-conversion-warnings branch April 23, 2026 08:35
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