Skip to content

Save 25 to 50 bytes of flash by storing "CircuitPython" once in the USB names - #11546

Merged
dhalbert merged 3 commits into
adafruit:mainfrom
mikeysklar:usb-name-prefix
Oct 10, 2026
Merged

dhalbert merged 3 commits into
adafruit:mainfrom
mikeysklar:usb-name-prefix

Conversation

@mikeysklar

@mikeysklar mikeysklar commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

What

The built-in USB names share one copy of "CircuitPython", saving 24 to 48 bytes of flash.

Why

Small boards like the Trinket M0 are nearly full.

The names a computer sees do not change.

Free flash, en_US main This PR
trinket_m0 2,468 2,492
circuitplayground_express 6,408 6,456
metro_m0_express 716 764
Tested Default names Custom names from boot.py
Trinket M0, macOS Same as main HID, MIDI: same as main
Metro M0 Express, Linux Same as main CDC, HID, MIDI: same as main

usb_audio and usb_video are unchanged, to keep names on boards that set their own.

Written with Claude Code, which ran the builds and hardware tests.

🤖 Generated with Claude Code

Each built-in USB interface name (CDC, Mass Storage, HID, MIDI, WebUSB)
stored its own copy of USB_INTERFACE_NAME. They now store only the part
after it, and usb_add_interface_name() marks the slot so the string
table builder puts USB_INTERFACE_NAME in front. Custom names set in
boot.py are passed through unchanged.

Free flash: trinket_m0 +24 B, circuitplayground_express and
metro_m0_express +48 B. Interface names seen by the host are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@mikeysklar mikeysklar changed the title Save flash by storing "CircuitPython" once in the USB names Save 25 to 50 bytes of flash by storing "CircuitPython" once in the USB names Oct 9, 2026

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks - some comments.

Comment thread supervisor/usb.h
Comment thread supervisor/usb.h Outdated
Comment thread shared-module/usb_hid/__init__.c Outdated
mikeysklar and others added 2 commits October 9, 2026 09:21
The default suffixes no longer start with a space, and the parameter is
renamed default_suffix. Saves another 8 bytes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Every little bit helps, and I think this is better code all around as well.

@dhalbert
dhalbert merged commit bce52f9 into adafruit:main Oct 10, 2026
322 of 326 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants