motor_controller: migrate to the new USB device stack - #74
Merged
Conversation
CONFIG_USB_DEVICE_STACK now carries `select DEPRECATED`, and the whole legacy
stack -- usb_device.c, usb_descriptor.c, usb_transfer.c and the SoC's bossa.c
-- is built from __deprecated APIs. Under twister's -Werror every one of those
is fatal, so `west twister -T applications/motor_controller` could not build
this app at all. Nothing in the app caused it and nothing in the app could
suppress it.
src/usb.c already carried a complete port to the new stack, dead behind
`#if defined(CONFIG_USB_DEVICE_STACK_NEXT)` with the Kconfig commented out in
prj.conf. Enabling it needed one API fix: usbd_register_all_classes() has since
gained a fourth `blocklist` argument.
Two things the new stack does not bring with it:
1. BOSSA 1200-baud touch reset. soc/atmel/sam0/common/bossa.c hangs off
CDC_ACM_DTE_RATE_CALLBACK_SUPPORT, a legacy-only symbol, so under the new
stack BOOTLOADER_BOSSA_DEVICE_NAME is unsatisfiable and the file compiles to
nothing. Without a replacement, bossac could no longer put the board into
its bootloader and every `west flash` would need a manual double-tap of
reset. It is reimplemented in usb.c off USBD_MSG_CDC_ACM_LINE_CODING, using
the same magic value and SRAM location as bossa.c.
2. Room. The new stack costs ~13 KB more flash and ~3.2 KB more RAM than the
legacy one, on a part that was already at 98.89% flash and 99.51% RAM --
160 bytes of RAM free. Making it fit meant giving things up:
- kernel/device/i2c shells and the thread instrumentation they pull in
(INIT_STACKS, THREAD_MONITOR, THREAD_STACK_INFO): ~7.5 KB flash. Note
these default to y once SHELL is on, so they need an explicit =n.
- SHELL_HELP, SHELL_HISTORY, SHELL_TAB: help strings and line-editing
conveniences. Every command still works.
- DYNAMIXEL_LOG_LEVEL_DBG: debug log strings, better set locally.
- LV_Z_VDB_SIZE 10% -> 5% (~3.2 KB RAM). Still ~13 display lines per
flush; costs redraw cycles, not correctness.
Result: 99.67% flash (788 B free), 96.78% RAM -- RAM is now healthier than
before, flash considerably tighter. This app has no room left.
USBD_CDC_ACM_LOG_LEVEL must be OFF rather than ERR: cdc_acm_uart0 is
zephyr,shell-uart, and with SHELL_LOG_BACKEND the driver would log over the
transport it is logging about. usbd_cdc_acm.c makes that a hard #warning.
Two pre-existing problems surfaced on the way, both fixed here:
- tests.yaml had no platform_allow, so twister fanned out over ~60 platforms
this board-specific app was never meant to build on and reported their
missing-devicetree-node failures as its own.
- debug.conf set CONFIG_DEBUG_OPTIMIZATIONS=y (-Os -> -Og), which adds ~56 KB
to a 99%-full image. Verified against main: it overflows by 56,040 B there
too, so this config has never linked -- it only looked green because twister
aborted on the USB deprecation first. Dropped, with the reasoning recorded:
the normal build already compiles -gdwarf-4, so gdb has full symbols at -Os.
Verified: `west twister -T applications/motor_controller` builds both the
default and debug configurations, 0 failed / 0 errored. Not runtime-verified --
no hardware available, so neither USB enumeration nor the 1200-baud reset has
been exercised on a board.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Fixes
west twister -T applications/motor_controller, which could not build this app at all.Root cause
CONFIG_USB_DEVICE_STACKnow carriesselect DEPRECATED, and the entire legacy stack —usb_device.c,usb_descriptor.c,usb_transfer.c, plus the SoC'sbossa.c— is built from__deprecatedAPIs. Under twister's-Werrorevery one is fatal. Nothing in the app caused it; nothing in the app could suppress it.src/usb.calready carried a complete port to the new stack, dead behind#if defined(CONFIG_USB_DEVICE_STACK_NEXT)with the Kconfig commented out. Enabling it needed one API fix:usbd_register_all_classes()has since gained a fourthblocklistargument.BOSSA 1200-baud reset, reimplemented
soc/atmel/sam0/common/bossa.changs offCDC_ACM_DTE_RATE_CALLBACK_SUPPORT, a legacy-only symbol, so under the new stackBOOTLOADER_BOSSA_DEVICE_NAMEis unsatisfiable and the file compiles to nothing. Without a replacement,west flashwould need a manual double-tap of reset every time. It is reimplemented inusb.coffUSBD_MSG_CDC_ACM_LINE_CODING, using the same magic value and SRAM location asbossa.c.What was given up to make it fit
The new stack costs ~13 KB more flash and ~3.2 KB more RAM, on a part already at 98.89% flash / 99.51% RAM — 160 bytes of RAM free.
INIT_STACKS,THREAD_MONITOR,THREAD_STACK_INFOSHELL_HELP,SHELL_HISTORY,SHELL_TABDYNAMIXEL_LOG_LEVEL_DBGLV_Z_VDB_SIZE10% → 5%yonceSHELLis on — deleting the lines is a no-op, they need an explicit=n. That cost me a build to discover and is called out inprj.conf.main)RAM is healthier than before; flash is considerably tighter. This app has no room left — anything added from here needs something removed.
Also:
USBD_CDC_ACM_LOG_LEVELmust beOFF, notERR.cdc_acm_uart0iszephyr,shell-uart, so withSHELL_LOG_BACKENDthe driver would log over the transport it is logging about;usbd_cdc_acm.cmakes that a hard#warning.Two pre-existing problems surfaced and fixed
tests.yamlhad noplatform_allow, so twister fanned out over ~60 platforms this board-specific app was never meant to build on, reporting their missing-devicetree-node failures as its own. 64 configs → 2.debug.confsetCONFIG_DEBUG_OPTIMIZATIONS=y(-Os→-Og), which adds ~56 KB to a 99%-full image. Verified againstmain: it overflows by 56,040 B there too — this config has never linked on any revision; it only looked green because twister aborted on the USB deprecation first. Dropped, with reasoning recorded: the normal build already compiles-gdwarf-4, so gdb has full symbols at-Os.Verification
Not runtime-verified — no hardware available to this session. Neither USB enumeration nor the reimplemented 1200-baud reset has been exercised on a board. If the reset path is wrong,
west flashneeds a manual double-tap until it's fixed; recoverable, but worth checking first thing.🤖 Generated with Claude Code