Skip to content

Make storage.disable_usb_drive() work on zephyr-cp - #11901

Merged
dhalbert merged 3 commits into
adafruit:mainfrom
mikeysklar:zephyr-disable-usb-drive
Nov 18, 2026
Merged

dhalbert merged 3 commits into
adafruit:mainfrom
mikeysklar:zephyr-disable-usb-drive

Conversation

@mikeysklar

Copy link
Copy Markdown
Collaborator

What

storage.disable_usb_drive() in boot.py now hides the CIRCUITPY drive on Zephyr boards.

Why

Before, it raised RuntimeError: Cannot change USB devices now, even in boot.py.

So code could not get write access to CIRCUITPY.

Dependencies

Stacked on #11900 (the Metro CH32V4x7 boards). Only the last commit is new.

Fixes #11531.

Testing

boot.py calls storage.disable_usb_drive(), then the board is reset from the REPL.

Step Metro CH32V407 Metro CH32V467 Pico 2 Pico Feather nRF52840
Drive shows by default pass pass pass pass pass
Drive gone after boot.py, REPL still up pass pass pass pass pass
Code can write a file while the drive is off pass pass pass pass pass
Drive back after removing boot.py pass pass pass pass pass

Code and testing by Claude, reviewed by me.

Zephyr always registered the MSC class and always reported media, so
storage.disable_usb_drive() had no effect. Skip MSC registration and
report no media when storage_usb_enabled() is false, and pass the MSC
flags from the build script. Add a tusb.h shim so shared storage code
can ask whether USB is connected, and helpers for the CIRCUITPY lock.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikeysklar
mikeysklar force-pushed the zephyr-disable-usb-drive branch from e2071c4 to fd5ad8e Compare November 18, 2026 01:03

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The PR has CH32V407 files in it which I think are extraneous. Was this stacked?

@mikeysklar

Copy link
Copy Markdown
Collaborator Author

Yes, it is stacked on #11900. The CH32V407 files will drop out once #11900 merges.

@mikeysklar
mikeysklar requested a review from dhalbert November 18, 2026 16:48
@mikeysklar

Copy link
Copy Markdown
Collaborator Author

The Read the Docs failure is a cancelled build, not a docs error.

@dhalbert

Copy link
Copy Markdown
Collaborator

The Read the Docs failure is a cancelled build, not a docs error.

This keeps coming up, not sure why. It may be because we are auto-cancelling builds that are unneeded when a later PR merges and can cancel this one. That is something we turned on recently.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks. There are printk()s in the code for various error conditions. Did you leave them there deliberately?

@mikeysklar

Copy link
Copy Markdown
Collaborator Author

I'll look into the docs build issue and clean up those stray printk's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mikeysklar

mikeysklar commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

Removed the four in this PR's diff.

The other printk()s in usb.c were already in main, so I left them.

@mikeysklar
mikeysklar requested a review from dhalbert November 18, 2026 17:37
@dhalbert
dhalbert merged commit 15f9a04 into adafruit:main Nov 18, 2026
63 checks passed
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.

zephyr-cp: CIRCUITPY_USB_MSC is off, so storage USB drive control is missing

2 participants