Skip to content

v2.1.5

Latest

Choose a tag to compare

@baorepo baorepo released this 24 Aug 01:03
2f1f609

Fixed

SD writes no longer corrupt the filesystem (#18, PR #19)

What was broken

sdWriteBytes() sent the 512-byte block with SPIClass::transfer(void*, size_t), which is in-place on the SAMD core — the buffer was overwritten with the 0xFF bytes received during the write. That buffer is the FatFs window (fs->win), still treated as a valid sector cache after disk_write returns, so every FAT and directory sector was destroyed in RAM right after being written and the garbage was written back on the next access to the same sector.

Symptoms users saw

  • Files with correct size but corrupted contents after append-heavy sessions (FR_OK all along — silent data corruption)
  • FR_DISK_ERR / FR_NO_FILE mid-session, files disappearing from the directory

Simple write-once examples did not trigger it, which is why the defect (introduced when the ESP32 writeBytes()-based path was ported to SAMD) went unnoticed for so long.

What changed

  • sdWriteBytes() now sends the block byte-by-byte (zero performance cost on SAMD — the core's block transfer is itself a per-byte loop; sdWriteSectors() is covered by the same change)
  • AcquireSPI(card, frequency) now uses its frequency argument, restoring the intended 400 kHz card initialization
  • Version bump to 2.1.5 (2.1.4 had shipped without one)

All users logging data to the microSD (esp. Wio Terminal) should upgrade.

Huge thanks to @ygCEO for the root-cause analysis, the controlled reproduction and the validated patch (#18).