Skip to content

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

Open

Description

@dhalbert

Claude wrote this, with edits by @dhalbert. These are notes for whoever works on this later.

Problem

zephyr-cp presents CIRCUITPY over USB with its own MSC code in ports/zephyr-cp/supervisor/usb.c. Its build never defines CIRCUITPY_USB_MSC, so the USB parts of storage are compiled out. This causes several problems:

  • disable_usb_drive(), unsafe_disable_usb_drive(), and enable_usb_drive() always raise RuntimeError: Cannot change USB devices now.
  • remount() is allowed while the host has write access. It should raise "Cannot remount path when visible via USB." instead.
  • remount() clears the block device lock that USB took. zephyr-cp's locked[0] stays true, so USB never takes the lock again.
  • Nothing releases locked[], so the lock is not dropped on eject or unmount.

Seen on a Feather nRF52840 running zephyr-cp built from 314c0be.

What is needed

  • Define CIRCUITPY_USB_MSC for zephyr-cp when USB is enabled.
  • Implement LUN enabling and disabling: report CIRCUITPY not ready when storage_usb_enabled() is false.
  • Provide usb_msc_release_circuitpy_lock(), usb_msc_holds_lock(), and usb_msc_remount(), as supervisor/shared/usb/usb_msc_flash.c does (the first two are added in Make storage.unsafe_disable_usb_drive() reversible #11530).

Zephyr USB MSC support

Unfortunately, some features are missing from Zephyr USB MSC that we need. Checked in adafruit/zephyr at a4d81519a1, subsys/usb/device_next/class/usbd_msc_scsi.c:

  • LUN not ready: possible. There is no API for it. But TEST UNIT READY, READ, and WRITE all answer "medium not present" when the disk's status is not DISK_STATUS_OK (L425, L749, L803). zephyr-cp's _zephyr_disk_status() can return DISK_STATUS_NOMEDIA while the drive is disabled.
  • Read-only to the host: not supported. MODE SENSE always reports no write protection (L600). DISK_STATUS_WR_PROTECT is treated as medium not present. So when CIRCUITPY is writable by Python, as after remount("/", readonly=False) in boot.py, the drive disappears from the host instead of appearing read-only. This needs a Zephyr change.
  • Eject: no notification. START STOP UNIT is handled inside the class and does not call the disk driver (L610). zephyr-cp cannot release its lock when the host ejects the drive.

Activity

  1. added this to the 11.0.0 milestone on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions