From 8f3604018cd37d6c0dc9e0ef5a5958176bead41f Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Wed, 15 Jul 2026 00:10:30 +0200 Subject: [PATCH] Fix for SD card --- Devices/cyd-2432s024c/cyd,2432s024c.dts | 3 ++- .../elecrow,crowpanel-advance-35.dts | 3 ++- .../elecrow,crowpanel-basic-35.dts | 3 ++- Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts | 3 ++- Devices/m5stack-cardputer/m5stack,cardputer.dts | 3 ++- .../platform-esp32/bindings/espressif,esp32-spi.yaml | 8 ++++++++ .../platform-esp32/include/tactility/drivers/esp32_spi.h | 8 ++++++++ Platforms/platform-esp32/source/drivers/esp32_spi.cpp | 5 +++-- 8 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Devices/cyd-2432s024c/cyd,2432s024c.dts b/Devices/cyd-2432s024c/cyd,2432s024c.dts index a082d5136..ee3049995 100644 --- a/Devices/cyd-2432s024c/cyd,2432s024c.dts +++ b/Devices/cyd-2432s024c/cyd,2432s024c.dts @@ -74,7 +74,8 @@ pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - + miso-pull-up; + sdcard@0 { compatible = "espressif,esp32-sdspi"; frequency-khz = <20000>; diff --git a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts index d4b106b86..e6f6cf168 100644 --- a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts +++ b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts @@ -81,7 +81,8 @@ pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; - + miso-pull-up; + sdcard@0 { compatible = "espressif,esp32-sdspi"; frequency-khz = <20000>; diff --git a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts index 764b11c67..e7f888b5e 100644 --- a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts +++ b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts @@ -77,7 +77,8 @@ pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - + miso-pull-up; + sdcard@0 { compatible = "espressif,esp32-sdspi"; frequency-khz = <20000>; diff --git a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts index 535dd0ebd..a00145083 100644 --- a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts +++ b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts @@ -122,7 +122,8 @@ pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; - + miso-pull-up; + sdcard@0 { compatible = "espressif,esp32-sdspi"; status = "disabled"; diff --git a/Devices/m5stack-cardputer/m5stack,cardputer.dts b/Devices/m5stack-cardputer/m5stack,cardputer.dts index 90e7383e7..cc34fca94 100644 --- a/Devices/m5stack-cardputer/m5stack,cardputer.dts +++ b/Devices/m5stack-cardputer/m5stack,cardputer.dts @@ -104,7 +104,8 @@ pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; - + miso-pull-up; + sdcard@0 { compatible = "espressif,esp32-sdspi"; frequency-khz = <20000>; diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml index 95e16a878..10abdd7b6 100644 --- a/Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml +++ b/Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml @@ -41,3 +41,11 @@ properties: element-type: "struct GpioPinSpec" default: "{ }" description: Null-terminated array of chip select GPIO pin specs for peripherals on this bus + miso-pull-up: + type: boolean + default: false + description: > + Enables a weak internal pull-up on MISO, which floats between transactions/while another + device on the bus is selected. Helps some SPI peripherals (a garbled/invalid response on + CMD8/if_cond has been observed for SD-over-SPI on some boards) but has been observed to + break others (prevents the SD card from responding to CMD0 at all) - opt in per board. diff --git a/Platforms/platform-esp32/include/tactility/drivers/esp32_spi.h b/Platforms/platform-esp32/include/tactility/drivers/esp32_spi.h index c49051fae..3645deff4 100644 --- a/Platforms/platform-esp32/include/tactility/drivers/esp32_spi.h +++ b/Platforms/platform-esp32/include/tactility/drivers/esp32_spi.h @@ -27,6 +27,14 @@ struct Esp32SpiConfig { struct GpioPinSpec* cs_gpios; /** The item count of cs_gpios */ uint8_t cs_gpios_count; + /** + * Enables a weak internal pull-up on MISO, which floats between transactions/while + * another device on the bus is selected. Helps some SPI peripherals (a garbled/invalid + * response on CMD8/if_cond has been observed for SD-over-SPI on some boards) but has been + * observed to break others (e.g. prevents the SD card from responding to CMD0 at all on + * some boards) - opt in per board rather than defaulting it on for everyone. + */ + bool miso_pull_up; }; /** diff --git a/Platforms/platform-esp32/source/drivers/esp32_spi.cpp b/Platforms/platform-esp32/source/drivers/esp32_spi.cpp index 711540b3f..721d7892e 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_spi.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_spi.cpp @@ -129,8 +129,9 @@ static error_t start(Device* device) { // MISO is only actively driven by the selected slave; between commands (and briefly during // slave selection/response) it floats, which can be read as spurious bits. A weak pull-up // costs nothing against an actively-driven line and avoids that, e.g. on SD-over-SPI this - // shows up as CMD8/if_cond failing with a garbled/invalid response. - if (data->miso_descriptor != nullptr) { + // shows up as CMD8/if_cond failing with a garbled/invalid response. Opt-in per board though: + // it's been observed to instead prevent an SD card from responding to CMD0 at all elsewhere. + if (data->miso_descriptor != nullptr && dts_config->miso_pull_up) { gpio_descriptor_set_flags(data->miso_descriptor, GPIO_FLAG_DIRECTION_INPUT | GPIO_FLAG_PULL_UP); }