summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjetpax <jep@alphabetiq.com>2025-12-15 19:41:05 -0800
committerDamien George <damien@micropython.org>2025-12-18 11:49:19 +1100
commite67d4a2a777f09215cdda928ec259696b86fcb81 (patch)
treee1a276292dd590b1a14465435c6c6341ae7ebbca
parent50a5fe0020cc8d16fd9b4c108bd992209cb041f6 (diff)
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 <jep@alphabetiq.com>
-rw-r--r--ports/esp32/machine_sdcard.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/ports/esp32/machine_sdcard.c b/ports/esp32/machine_sdcard.c
index 0f8bd8446..4785a7254 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