Skip to content
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

usb: device: next: increased RAM and flash footprint with "device_next" USB stack #83309

Open
henrikbrixandersen opened this issue Dec 22, 2024 · 3 comments
Assignees
Labels
area: USB Universal Serial Bus Enhancement Changes/Updates/Additions to existing features Experimental Experimental features not enabled by default

Comments

@henrikbrixandersen
Copy link
Member

henrikbrixandersen commented Dec 22, 2024

Is your enhancement proposal related to a problem? Please describe.
The device_next USB stack comes with a significant increase in both RAM and flash footprint compared to the "legacy" stack. The impact is especially hard on smaller USB MCUs with e.g. 16k RAM and 64k flash (smaller STM32 parts) where the increase can prevent existing firmware applications from switching to the new stack.

Describe the solution you'd like
While the design and implementation of the device_next is much superior to the "legacy" stack, it would be nice if the RAM and flash footprint could be reduced to be more friendly towards more resource constrained MCUs.

Describe alternatives you've considered
None.

Additional context
As an example, the samples/subsys/usb/hid-mouse/ sample compiled for the frdm_k64f board increases significantly in RAM and flash footprint when built for the device_next stack, but the problem is not limited to this sample/board.

$ west build -b frdm_k64f/mk64f12 samples/subsys/usb/hid-mouse
...
Memory region         Used Size  Region Size  %age Used
           FLASH:       41016 B         1 MB      3.91%
             RAM:       12760 B       192 KB      6.49%
           SRAML:          0 GB        64 KB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%
$ west build -b frdm_k64f/mk64f12 samples/subsys/usb/hid-mouse/ -- -DCONF_FILE=usbd_next_prj.conf -DEXTRA_DTC_OVERLAY_FILE=usbd_next.overlay
...
Memory region         Used Size  Region Size  %age Used
           FLASH:       54792 B         1 MB      5.23%
             RAM:       15480 B       192 KB      7.87%
           SRAML:          0 GB        64 KB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%
@henrikbrixandersen henrikbrixandersen added Enhancement Changes/Updates/Additions to existing features area: USB Universal Serial Bus Experimental Experimental features not enabled by default labels Dec 22, 2024
@henrikbrixandersen
Copy link
Member Author

henrikbrixandersen commented Dec 22, 2024

These are the numbers when building the same sample with logging disabled:

$ west build -b frdm_k64f/mk64f12 samples/subsys/usb/hid-mouse -- -DCONFIG_LOG=n
...
Memory region         Used Size  Region Size  %age Used
           FLASH:       27288 B         1 MB      2.60%
             RAM:       10648 B       192 KB      5.42%
           SRAML:          0 GB        64 KB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%
$ west build -b frdm_k64f/mk64f12 samples/subsys/usb/hid-mouse/ -- -DCONF_FILE=usbd_next_prj.conf -DEXTRA_DTC_OVERLAY_FILE=usbd_next.overlay -DCONFIG_LOG=n
...
Memory region         Used Size  Region Size  %age Used
           FLASH:       37016 B         1 MB      3.53%
             RAM:       13368 B       192 KB      6.80%
           SRAML:          0 GB        64 KB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%

@henrikbrixandersen
Copy link
Member Author

Numbers for the nrf54h20dk/nrf54h20/cpuapp:

west build -b nrf54h20dk/nrf54h20/cpuapp samples/subsys/usb/hid-mouse/ -- -DCONFIG_LOG=n
...
Memory region         Used Size  Region Size  %age Used
           FLASH:       44052 B       248 KB     17.35%
             RAM:       11232 B       256 KB      4.28%
   DMA_RAM3x_APP:           2 B         4 KB      0.05%
        IDT_LIST:          0 GB        32 KB      0.00%
west build -b nrf54h20dk/nrf54h20/cpuapp samples/subsys/usb/hid-mouse/ -- -DCONF_FILE=usbd_next_prj.conf -DEXTRA_DTC_OVERLAY_FILE=usbd_next.overlay -DCONFIG_LOG=
...
Memory region         Used Size  Region Size  %age Used
           FLASH:       60564 B       248 KB     23.85%
             RAM:       17992 B       256 KB      6.86%
   DMA_RAM3x_APP:           2 B         4 KB      0.05%
        IDT_LIST:          0 GB        32 KB      0.00%

@dleach02
Copy link
Member

dleach02 commented Jan 8, 2025

@henrikbrixandersen @jfischer-no

Some number crunching on the frdm_k64f.

First thing I did was to add to the usbd_next_prj.conf CONFIG_INPUT_MODE_SYNCHRONOUS so that it is in alignment with the default prj.confg. It caused some minor differences that initially confused me.

Key differences between new and legacy:

  • Kernel .text is 762 bytes larger due to inclusion of mem_slab.c, mempool.c, and msg_q.c
  • Drivers module .text/.rodata is +3260, .data/.bss is smaller. New model has udc_common.c and udc_kinetis.c while old model only has usb_dc_kinetis.c. The .text/.rodata increase mostly comes from the udc_common.c
  • The libsubsys__usb__device has a bunch of files added to support usbd. The legacy only has core.c but some of what I think are comparable files in legacy are actually compiled into section libzephyr.a. But if I compare the two sections relevant USB files the new model .text/.rodata is +6738 and .data/.bss is +1665
  • libapp.a module is larger in the new model due to the inclusion of sample_usbd_init.c, which the legacy doesn't have. This adds +831 to .text/.rodata and 354 to .data

Overall, on the frdm_k64, the new model .text/.rodata is +11609 and .data/.bss is +3168.

Attached are the spreadsheets I generated for the two target builds for your pleasure and digging.

usb_legacy.xlsx
usb_new.xlsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: USB Universal Serial Bus Enhancement Changes/Updates/Additions to existing features Experimental Experimental features not enabled by default
Projects
None yet
Development

No branches or pull requests

3 participants