Fix for SD card

This commit is contained in:
Ken Van Hoeylandt 2026-07-15 00:10:30 +02:00
parent 594e85b1d7
commit 8f3604018c
8 changed files with 29 additions and 7 deletions

View File

@ -74,7 +74,8 @@
pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
miso-pull-up;
sdcard@0 { sdcard@0 {
compatible = "espressif,esp32-sdspi"; compatible = "espressif,esp32-sdspi";
frequency-khz = <20000>; frequency-khz = <20000>;

View File

@ -81,7 +81,8 @@
pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>;
pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>;
pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>;
miso-pull-up;
sdcard@0 { sdcard@0 {
compatible = "espressif,esp32-sdspi"; compatible = "espressif,esp32-sdspi";
frequency-khz = <20000>; frequency-khz = <20000>;

View File

@ -77,7 +77,8 @@
pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
miso-pull-up;
sdcard@0 { sdcard@0 {
compatible = "espressif,esp32-sdspi"; compatible = "espressif,esp32-sdspi";
frequency-khz = <20000>; frequency-khz = <20000>;

View File

@ -122,7 +122,8 @@
pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>;
pin-miso = <&gpio0 39 GPIO_FLAG_NONE>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>;
pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
miso-pull-up;
sdcard@0 { sdcard@0 {
compatible = "espressif,esp32-sdspi"; compatible = "espressif,esp32-sdspi";
status = "disabled"; status = "disabled";

View File

@ -104,7 +104,8 @@
pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>;
pin-miso = <&gpio0 39 GPIO_FLAG_NONE>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>;
pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
miso-pull-up;
sdcard@0 { sdcard@0 {
compatible = "espressif,esp32-sdspi"; compatible = "espressif,esp32-sdspi";
frequency-khz = <20000>; frequency-khz = <20000>;

View File

@ -41,3 +41,11 @@ properties:
element-type: "struct GpioPinSpec" element-type: "struct GpioPinSpec"
default: "{ }" default: "{ }"
description: Null-terminated array of chip select GPIO pin specs for peripherals on this bus 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.

View File

@ -27,6 +27,14 @@ struct Esp32SpiConfig {
struct GpioPinSpec* cs_gpios; struct GpioPinSpec* cs_gpios;
/** The item count of cs_gpios */ /** The item count of cs_gpios */
uint8_t cs_gpios_count; 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;
}; };
/** /**

View File

@ -129,8 +129,9 @@ static error_t start(Device* device) {
// MISO is only actively driven by the selected slave; between commands (and briefly during // 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 // 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 // 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. // shows up as CMD8/if_cond failing with a garbled/invalid response. Opt-in per board though:
if (data->miso_descriptor != nullptr) { // 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); gpio_descriptor_set_flags(data->miso_descriptor, GPIO_FLAG_DIRECTION_INPUT | GPIO_FLAG_PULL_UP);
} }