From b89928663948a93690d5e2c90ba83772aff20967 Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sat, 11 Jul 2026 11:14:15 +0200 Subject: [PATCH] feat(sd): reformat a fresh card on mount failure in the spike MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flip format_if_mount_failed to true so a fresh exFAT/unformatted bench card is reformatted to FAT on the device instead of failing — no Mac-side prep for the spike. Fires only on a filesystem mount failure, not the CMD59 protocol rejection. The real persistence module must keep this false. --- firmware/src/bin/sd_fat.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/firmware/src/bin/sd_fat.rs b/firmware/src/bin/sd_fat.rs index 44f8a12..cddb734 100644 --- a/firmware/src/bin/sd_fat.rs +++ b/firmware/src/bin/sd_fat.rs @@ -189,11 +189,16 @@ fn mount_sd() -> Result<*mut sys::sdmmc_card_t> { slot.gpio_wp = -1; slot.gpio_int = -1; - // 4) Mount config. format_if_mount_failed = false is load-bearing: a mount - // hiccup must never reformat (and wipe) the user's card. allocation size - // only matters when formatting, which we've disabled. + // 4) Mount config. format_if_mount_failed = true here (spike only): a fresh + // bench card that's exFAT or unformatted gets reformatted to FAT on the + // device instead of failing, so no Mac-side prep is needed. This fires + // only on a *filesystem* mount failure, not on the earlier CMD59 protocol + // rejection (that still bails with the actionable message below). + // The real persistence module MUST keep this false — it must never wipe + // the user's card on a transient mount hiccup. allocation_unit_size is + // used when formatting, so the 16 KiB below now applies. let mount = sys::esp_vfs_fat_mount_config_t { - format_if_mount_failed: false, + format_if_mount_failed: true, max_files: 4, allocation_unit_size: 16 * 1024, disk_status_check_enable: false,