Codex/sd mass storage hotplug - #267
Open
mkuettner97 wants to merge 6 commits into
Open
Conversation
mkuettner97
requested review from
DennisMoschina and
TobiasRoeddiger
and
a lite review from Copilot
August 13, 2026 11:42
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.
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 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SD card can be remounted after removal (unmount) and can be mounted as a USB device.