Skip to content

Fix SPI SD card remount zombie state, MISO release clock, and USBSerial vprintf - #3082

Merged
bmorcelli merged 2 commits into
BruceDevices:devfrom
pingequalab:fix/sd-spi-remount-zombie
Nov 13, 2026
Merged

bmorcelli merged 2 commits into
BruceDevices:devfrom
pingequalab:fix/sd-spi-remount-zombie

Conversation

@pingequalab

@pingequalab pingequalab commented Nov 13, 2026 •

Copy link
Copy Markdown

Note: Follow-up PR #3092 submits the companion single-sector write (CMD24) busy-wait and 2x 0xFF sdWait() idle check in lib/HAL/sd_card/sd_diskio.cpp.

Summary

Fixes an unrecoverable SPI SD card zombie state after any transient read/command timeout, clocks a trailing 0xFF byte on CS deassertion so the SD card releases MISO on shared SPI buses, and fixes USBSerial::vprintf printing va_list stack pointers on CLI commands such as storage free sd.

Hardware Tested

  • Board: m5stack-sticks3 (v1.17 / 2b6ba4d) with external shared-SPI module (CC1101 + NRF24 + 32GB MicroSD sharing SCK=5, MISO=4, MOSI=6).
  • Applies to all SPI SD targets using lib/HAL/sd_card and USB-serial CLI targets using USBSerial.

Changes (fefc13b)

  • src/core/sd_functions.cpp: Call closeSdCard() and displayError("SD Read/Mount Error", true) when the second fs.exists(rootPath) fails for SD, resetting _pdrv to 0xFF so the next setupSdCard() performs a real SPI re-initialization (160 SCK + CMD0).
  • lib/HAL/sd_card/sd_diskio.cpp: Clock one trailing 0xFF byte after pulling ssPin HIGH in sdDeselectCard() so the card releases DAT0/MISO to Hi-Z on shared SPI buses.
  • src/core/serial_commands/storage_commands.cpp: Unmount via closeSdCard() and report an error if SD.totalBytes() == 0, and guard freeBytes against unsigned underflow.
  • src/core/USBSerial/USBSerial.h: Forward va_list to out->vprintf(fmt, args) instead of out->printf(fmt, args).

Verification

  • Build: pio run -e m5stack-sticks3 -> SUCCESS.
  • On-device verification: storage free sd accurately formats 64-bit capacities (31702614016 Bytes on 32GB MicroSD), and 10 rounds of CC1101 / NRF24 / SD Card switching confirm hot-remount recovery without ESP.restart().

pr3y and others added 2 commits November 12, 2026 23:25
1.17!!! B)
…, fix vprintf

Verified build: pio run -e m5stack-sticks3 (exit 0)
@bmorcelli
bmorcelli changed the base branch from main to dev November 13, 2026 11:34
@bmorcelli
bmorcelli merged commit 97de7f8 into BruceDevices:dev Nov 13, 2026
@pingequalab pingequalab changed the title Fix SPI SD card remount zombie state, MISO release clock, and USBSerial vprintf Fix SPI SD card remount zombie state, shared-SPI MISO/busy timing, and USBSerial vprintf Nov 14, 2026
@pingequalab pingequalab changed the title Fix SPI SD card remount zombie state, shared-SPI MISO/busy timing, and USBSerial vprintf Fix SPI SD card remount zombie state, MISO release clock, and USBSerial vprintf Nov 14, 2026
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.

3 participants