Skip to content

boot: zephyr: migrate CDC ACM serial recovery to USB_DEVICE_STACK_NEXT#2635

Open
JayToltTech wants to merge 1 commit intomcu-tools:mainfrom
Tolt-Technologies:feat/cdc-acm-usbd-next
Open

boot: zephyr: migrate CDC ACM serial recovery to USB_DEVICE_STACK_NEXT#2635
JayToltTech wants to merge 1 commit intomcu-tools:mainfrom
Tolt-Technologies:feat/cdc-acm-usbd-next

Conversation

@JayToltTech
Copy link

@JayToltTech JayToltTech commented Feb 19, 2026

Summary

  • Replace the legacy USB device stack with USB_DEVICE_STACK_NEXT for CDC-ACM serial recovery
  • Initialize USB lazily in boot_uart_fifo_init() only when serial recovery is triggered, avoiding interference with application USB on normal boots
  • Add self-contained USBD CDC ACM module (usbd_cdc_serial.c/.h) with configurable USB descriptors (VID, PID, manufacturer, product, self-powered, max power) via new Kconfig options
  • Feed the watchdog while waiting for USB host connection to prevent timeout before the serial recovery loop is reached
  • Enlarge nrf52840 boot partitions to accommodate the larger USB stack
  • Remove stale legacy USB Kconfig options from board configs
  • Add flash-saving options (disable BOS, vendor requests, deferred messages) to recovery conf files

Supersedes #2634 (narrowed scope to CDC-ACM only, removed unrelated logging/SWO changes).

Builds on the approach from #2346 with key improvements:

  • Lazy USB init instead of CDC_ACM_SERIAL_INITIALIZE_AT_BOOT
  • Watchdog feeding during USB host wait
  • Dongle partition overlay for the larger USB stack
  • Direct context accessor instead of fragile STRUCT_SECTION_GET index

Test plan

  • Build nrf52840dk with usb_cdc_acm_log_recovery.conf (92.49% flash)
  • Build nrf52840dongle with usb_cdc_acm_recovery.conf (99.71% flash)
  • Functional test: enter serial recovery, upload image via mcumgr over USB CDC-ACM
  • Verify normal boot path does not initialize USB

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request migrates CDC ACM serial recovery from the legacy USB device stack to the new USB_DEVICE_STACK_NEXT in MCUboot. The key improvement is lazy USB initialization - USB is only initialized when serial recovery is actually triggered, avoiding interference with application USB on normal boots.

Changes:

  • Adds self-contained USB CDC ACM module with configurable descriptors via Kconfig
  • Implements lazy USB initialization in serial recovery path with watchdog feeding during USB host wait
  • Enlarges nrf52840 boot partitions (64KB → 72KB) to accommodate larger USB stack
  • Removes legacy USB stack configuration options from board files

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
docs/readme-zephyr.md Documents new Kconfig options for USB descriptor configuration
boot/zephyr/usbd_cdc_serial.h Header for new USB CDC ACM module
boot/zephyr/usbd_cdc_serial.c Self-contained USB stack setup with lazy initialization
boot/zephyr/usb_cdc_acm_recovery.conf Adds product string override and flash-saving options
boot/zephyr/usb_cdc_acm_log_recovery.conf Same configuration for logging variant
boot/zephyr/serial_adapter.c Updates to use new USB module with lazy init and watchdog feeding
boot/zephyr/main.c Adds USB cleanup on boot with -EALREADY handling for lazy init
boot/zephyr/boards/nrf52840dongle_nrf52840_big.overlay New overlay with enlarged boot partition for dongle
boot/zephyr/boards/nrf52840dongle_nrf52840.conf Removes legacy USB stack config options
boot/zephyr/boards/nrf52840_big.overlay Enlarges boot partition from 64KB to 72KB
boot/zephyr/Kconfig.serial_recovery Adds new Kconfig options for USB descriptor customization
boot/zephyr/CMakeLists.txt Conditionally compiles usbd_cdc_serial.c
boot/zephyr/sample.yaml Updates test configuration to use new overlay for dongle

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Replace the legacy USB device stack with USB_DEVICE_STACK_NEXT for
CDC-ACM serial recovery. USB is initialized lazily in
boot_uart_fifo_init() only when serial recovery is triggered, avoiding
interference with application USB on normal boots.

Add self-contained USBD CDC ACM module (usbd_cdc_serial.c/.h) that
manages device context, descriptors, and configuration registration.
Expose configurable USB descriptors (VID, PID, manufacturer, product,
self-powered, max power) through new Kconfig options under
BOOT_SERIAL_CDC_ACM.

Feed the watchdog while waiting for USB host connection to prevent
hardware watchdog timeout before the serial recovery loop is reached.

Update nrf52840 board files: enlarge boot partitions for the larger
USB stack, remove stale legacy USB Kconfig options, and add flash-
saving options (disable BOS, vendor requests, deferred messages).

Signed-off-by: Jay Beavers <jay@tolttechnologies.com>
@JayToltTech JayToltTech force-pushed the feat/cdc-acm-usbd-next branch from 1bdfcc1 to 41b043d Compare February 19, 2026 04:04
@henrikbrixandersen
Copy link
Contributor

Same as with #2346, we cannot merge this without also migrating the USB DFU support the device_next. Otherwise, you will have a mix of dependencies, some of the MCUBoot code depending on the legacy stack, other on the new stack.

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

Comments