Fix some -Wconversion warnings#3601
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
.gitignorefor.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.
Size Difference ReportBecause 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 sizeNo entries. Changes <1% in size
No changes
|
|
| 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% |
ee3452c to
a6dcc3f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.