Repository navigation
Codex/sd mass storage hotplug - #267
mkuettner97 wants to merge 10 commits into
Conversation
There was a problem hiding this comment.
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.
| #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 |
| /*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) |
Co-authored-by: DennisMoschina <45356478+DennisMoschina@users.noreply.github.com>
|
Build output available: |
|
Should we also migrate the non-FOTA prj.conf build to the new USB stack, or is USB MSC intended to be FOTA-only for now? |
…stabilize SD hotplug recovery
✅ Unit tests passed9 passed, 0 failed/error, 0 skipped — view workflow run
Download the |
Compiler warningsThe extended-warning build completed successfully. Application compiler warningsShow warnings |
CodeChecker static analysis (advisory)Note This report is informational. It does not block merging and does not change code. At a glance
Findings on changed linesNo non-style findings were reported on lines changed by this PR. Analyzer coverage
Complete-codebase summarySeverity: 1 high Complete-codebase findingsEach finding includes source context. The Show detailed findings with source context (1 of 1)HIGH —
|
|
Build output available: |
SD card can be remounted after removal (unmount) and can be mounted as a USB device.