From e67d4a2a777f09215cdda928ec259696b86fcb81 Mon Sep 17 00:00:00 2001 From: jetpax Date: Mon, 15 Dec 2025 19:41:05 -0800 Subject: [PATCH] esp32/machine_sdcard: Fix SDMMC slot assignment for non-default slots. The SDMMC_HOST_DEFAULT() macro sets slot to SDMMC_HOST_SLOT_1, but this was not being overridden when the user specified a different slot number. This caused SDMMC initialization to fail on chips like ESP32-P4 when trying to use slot 0. This commit ensures the slot number passed to the SDCard constructor is properly assigned to the host configuration structure. Tested on ESP32-P4 with SD card on slot 0. Signed-off-by: jetpax --- ports/esp32/machine_sdcard.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/esp32/machine_sdcard.c b/ports/esp32/machine_sdcard.c index 0f8bd84469..4785a7254a 100644 --- a/ports/esp32/machine_sdcard.c +++ b/ports/esp32/machine_sdcard.c @@ -166,6 +166,8 @@ static esp_err_t sdcard_ensure_card_init(sdcard_card_obj_t *self, bool force) { esp_err_t err = sdmmc_card_init(&(self->host), &(self->card)); if (err == ESP_OK) { + // Ensure card's host structure has the correct slot after init + self->card.host.slot = self->host.slot; self->flags |= SDCARD_CARD_FLAGS_CARD_INIT_DONE; } else { self->flags &= ~SDCARD_CARD_FLAGS_CARD_INIT_DONE; @@ -307,6 +309,7 @@ static mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args else { sdmmc_host_t _temp_host = SDMMC_HOST_DEFAULT(); _temp_host.max_freq_khz = freq / 1000; + _temp_host.slot = slot_num; self->host = _temp_host; } #endif