-
Notifications
You must be signed in to change notification settings - Fork 882
Description
Problem
MCUboot's Zephyr USB serial recovery and USB DFU features currently use the legacy USB_DEVICE_STACK API, which has been deprecated in Zephyr and is scheduled for removal in Zephyr v4.5.0.
Current Impact (Zephyr v4.3.0)
Building MCUboot with USB features enabled generates numerous deprecation warnings:
warning: 'usb_enable' is deprecated [-Wdeprecated-declarations]
warning: 'usb_disable' is deprecated [-Wdeprecated-declarations]
warning: 'usb_dc_ep_write' is deprecated [-Wdeprecated-declarations]
warning: 'usb_dc_ep_read' is deprecated [-Wdeprecated-declarations]
... (50+ similar warnings from zephyr/subsys/usb/device/)
These warnings occur throughout Zephyr's USB subsystem code when compiling MCUboot with:
- CONFIG_BOOT_SERIAL_CDC_ACM=y (USB serial recovery)
- CONFIG_BOOT_USB_DFU_WAIT=y (USB DFU mode)
Timeline
- Zephyr v4.3.0 (current): Legacy USB stack deprecated, warnings generated
- Zephyr v4.5.0 (upcoming): Legacy USB stack will be removed entirely
- Result: MCUboot's USB features will break unless migrated
Workaround Currently in Place
Zephyr has a temporary workaround that prevents the new stack from being used with MCUboot:
boards/common/usb/Kconfig.cdc_acm_serial.defconfig
config USB_DEVICE_STACK_NEXT
default y if !MCUBOOT # Explicitly disabled when MCUboot is present
This confirms the Zephyr team is aware of the incompatibility but cannot fix it directly since MCUboot is a separate project.
Proposed Solution
Migrate MCUboot's USB implementation to use the new USB_DEVICE_STACK_NEXT API.
API Changes Required
Files to modify:
- boot/zephyr/main.c - 3 locations using usb_enable() / usb_disable()
- boot/zephyr/serial_adapter.c - 1 location using usb_enable()
Legacy API:
usb_enable(NULL);
usb_disable();
New API:
struct usbd_context uds_ctx = / context */;
usbd_init(uds_ctx);
usbd_enable(uds_ctx);
usbd_disable(uds_ctx);
Device Tree Changes
The new stack requires USB device context definition via device tree:
USBD_DEVICE_DEFINE(mcuboot_usbd,
DEVICE_DT_GET(DT_NODELABEL(zephyr_udc0)),
VENDOR_ID,
PRODUCT_ID);
CDC-ACM configuration also moves from Kconfig to device tree.
Kconfig Changes
Replace:
CONFIG_USB_DEVICE_STACK=y
With:
CONFIG_USB_DEVICE_STACK_NEXT=y
CONFIG_USBD_CDC_ACM_CLASS=y
Estimated Scope
- Lines of code: ~50-100 modifications
- Complexity: Low to moderate (mostly mechanical API replacement)
- Testing required: Critical - must verify USB serial recovery and DFU work on multiple platforms
References
- USB device next follow-up zephyrproject-rtos/zephyr#95649
- Planned USB device/host support rework/enhancements zephyrproject-rtos/zephyr#42066
- usb: device_next: implement USB DFU class for the new device support zephyrproject-rtos/zephyr#79794 - Shows precedent for migrating USB classes
- https://docs.zephyrproject.org/latest/connectivity/usb/device/usb_device.html
- https://docs.zephyrproject.org/latest/connectivity/usb/device_next/api/usbd.html
Hardware Tested
I can test and validate this migration on:
- nRF5340 (nrfx_usbd controller with UDC support)
Volunteers
I'm willing to contribute this migration if the maintainers would accept the PR. Please advise on:
- Whether this migration is desired
- Any specific requirements or constraints
- Testing expectations beyond nRF5340