Skip to content

Codex/sd mass storage hotplug - #267

Open
mkuettner97 wants to merge 6 commits into
mainfrom
codex/sd-mass-storage-hotplug
Open

Codex/sd mass storage hotplug#267
mkuettner97 wants to merge 6 commits into
mainfrom
codex/sd-mass-storage-hotplug

Conversation

@mkuettner97

Copy link
Copy Markdown
Collaborator

SD card can be remounted after removal (unmount) and can be mounted as a USB device.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves SD-card hotplug robustness (safe teardown + remount) and enables exposing the SD card over USB mass storage by switching the FOTA build to Zephyr’s next-generation USB device stack.

Changes:

  • Add dedicated, preemptible work queues for SD-card lifecycle operations and sensor configuration to avoid blocking cooperative/system workqueues during long SD operations.
  • Refactor SD logger teardown coordination (park writer thread, abort recording on removal) and make unmount resilient when media disappears mid-write.
  • Introduce an MSC helper module and update build/Kconfig/CMake + prj configs to support next-gen USB MSC and reduce SD command retry/timeout delays after removal.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
unicast_server/main.cpp Switch USB init to next-gen stack path and add MSC LUN + SD MSC init hook.
src/SensorManager/SensorManager.cpp Move sensor config application work onto a dedicated preemptible workqueue.
src/SensorManager/Kconfig Add Kconfig knobs for sensor config workqueue prio/stack.
src/SD_Card/SDLogger/SDLogger.h Add abort_recording() API for card-removal handling.
src/SD_Card/SDLogger/SDLogger.cpp Rework writer/teardown coordination (park handshake), removal abort path, and flush semantics.
src/SD_Card/SD_Card_Manager/SD_Card_Manager.h Minor formatting-only change.
src/SD_Card/SD_Card_Manager/SD_Card_Manager.cpp Add dedicated SD lifecycle workqueue; robust unmount/remount sequencing; disk deinit + load-switch release changes.
src/SD_Card/MassStorage/SDMassStorage.h New interface for syncing USB MSC media with SD presence.
src/SD_Card/MassStorage/SDMassStorage.cpp New implementation: init/deinit disk ref for MSC, shell status command.
src/SD_Card/MassStorage/CMakeLists.txt Build MSC helper only when next-gen USB + MSC class enabled.
src/Battery/PowerManager.cpp Keep SD + level shifter powered for USB MSC sessions (runtime PM gets).
prj.conf Reduce SD data timeout / retry count to bound card-removal teardown latency.
prj_fota.conf Switch to USB_DEVICE_STACK_NEXT + enable MSC class; adjust SD timeouts/retries.
Kconfig Pull in Zephyr sample-usbd Kconfig for next-gen USB init helpers.
include/openearable_common.h Document sd_msg semantics/order for removal vs unmount.
CMakeLists.txt Add MassStorage include/subdir; include Zephyr USB sample common.cmake when next-gen USB enabled.
CLAUDE.md New repository guidance doc (architecture + build/testing notes).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread unicast_server/main.cpp
Comment on lines +55 to +66
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
#include <zephyr/storage/disk_access.h>
#include <zephyr/usb/usbd.h>
#include <zephyr/usb/class/usbd_msc.h>
extern "C" {
#include <sample_usbd.h>
}

USBD_DEFINE_MSC_LUN(sd, "SD", "OpenEarable", "SD Card", "1.00");
#else
#include <zephyr/usb/usb_device.h>
#endif
Comment thread unicast_server/main.cpp
Comment on lines 81 to +85
/*sdcard_manager.init();

sdcard_manager.mount();*/

/* STEP 5.5 - Enable USB */
if (IS_ENABLED(CONFIG_USB_DEVICE_STACK)) {
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
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