Skip to content

usb: device_next: save some flash and RAM #90791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jfischer-no
Copy link
Collaborator

Allow disabling of features that may not be needed. Exclude high-speed structures that the compiler cannot optimize if high-speed support is not enabled. Some of the if/endifs in CDC ACM are not worth it, as the resource savings are minimal.

The savings are about 1640B Flash and 1608B RAM (44892B/16240B vs 43252B/14632B) on frdm_k645f and 1944B Flash and 1752B RAM (54528B/15952B vs 52584B/14200B) on reel_board when built samples/subsys/usb/cdc_acm with options -DCONFIG_USBD_MSG_DEFERRED_MODE=n -DCONFIG_USBD_VREQ_SUPPORT=n -DCONFIG_USBD_BOS_SUPPORT=n.

Disabling it if not needed can save about 400 bytes of flash memory.

Signed-off-by: Johann Fischer <[email protected]>
Disabling it if not needed can save about 100 bytes of flash memory.

Signed-off-by: Johann Fischer <[email protected]>
Allowing message callback execution from the USBD thread saves about 800
bytes. For small devices, the option can be useful to reduce flash/RAM
usage, those with enough resources should not bother about it.

Signed-off-by: Johann Fischer <[email protected]>
@jfischer-no jfischer-no self-assigned this May 29, 2025
@jfischer-no jfischer-no added area: USB Universal Serial Bus Experimental Experimental features not enabled by default labels May 29, 2025
@github-actions github-actions bot added the area: Samples Samples label May 29, 2025
@github-actions github-actions bot requested review from kartben and nashif May 29, 2025 09:23
@@ -81,8 +81,15 @@ config USBD_MSG_SLAB_COUNT
help
Maximum number of USB device notification messages that can be queued.

config USBD_MSG_DEFERRED_MODE
bool "Execute message callback from system workqueue"
default y
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change is a step in the right direction, however I would prefer this to be default n.

Add Kconfig option to use dedicated workqueue in CDC ACM but use the
system work queue in CDC ACM by default.

Signed-off-by: Johann Fischer <[email protected]>
Disable high-speed descriptors when they are not in use saves 64 bytes
in flash/RAM. It is unlikely that it will scale well enough to be used
in all class implementations or to support a different speed.

Signed-off-by: Johann Fischer <[email protected]>
The required buffer is 128 bytes per instance on a full-speed device.
Use common (UDC) buffer, as this results in a smaller footprint.

Signed-off-by: Johann Fischer <[email protected]>
Disable the high-speed USB device descriptor if it is not in use.
Add checks to the code where the high-speed descriptor may be used.

Signed-off-by: Johann Fischer <[email protected]>
Do not add functions to the high-speed iterable section when high-speed
support is disabled.

Signed-off-by: Johann Fischer <[email protected]>
@jfischer-no jfischer-no force-pushed the pr-device_next-try-to-save-some-flash branch from c06c6ad to f4e9a24 Compare June 3, 2025 12:09
Copy link

sonarqubecloud bot commented Jun 3, 2025

@fabiobaltieri fabiobaltieri merged commit 703e2c5 into zephyrproject-rtos:main Jun 3, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Samples Samples area: USB Universal Serial Bus Experimental Experimental features not enabled by default
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants