Skip to content

itsybitsy_m4 - USB stack depends on code optimization #821

@FraFrieFa

Description

@FraFrieFa

Description:
I've encountered an issue with the usb_serial example in the itsybitsy_m4 crate. When building the example in isolation (i.e., outside of the full atsamd workspace), the firmware compiles successfully, but the device fails to enumerate as a CDC ACM device unless the following build options are set:

  • lto = true
  • opt-level = "s"

Without these settings, the USB functionality does not work as expected.


Steps to Reproduce:

  1. Clone the atsamd repository containing the itsybitsy_m4 crate.
  2. Copy the itsybitsy_m4 folder to a standalone location (thus losing the workspace context and the top-level Cargo.toml).
  3. Build the usb_serial example in release without modifying any build profile settings.
  4. Flash the resulting firmware onto an ItsyBitsy M4 board.
  5. Observe that the board does not register as a CDC ACM device.

Expected Behavior:
The USB serial example should enumerate correctly as a CDC ACM device regardless of the build configuration, or at least the need for these specific build settings should be clearly documented to make USB device implementations easier for users of the crate.


Observed Behavior:
The device only enumerates as a CDC ACM device when building with:

[profile.release]
lto = true
opt-level = "s"

Comments:

  • Might be a deeper problem in the rust USB stack
  • Optimization level 0 or missing lto = true lead to unstable USB enumeration after multiple attempts

Environment

NixOS channel nixos:24.11, rustup

$ rustc --version
rustc 1.85.0 (4d91de4e4 2025-02-17)

$ cargo --version
cargo 1.85.0 (d73d2caf9 2024-12-31)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions