Skip to content

Commit e67d4a2

Browse files
jetpaxdpgeorge
authored andcommitted
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 <[email protected]>
1 parent 50a5fe0 commit e67d4a2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

ports/esp32/machine_sdcard.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ static esp_err_t sdcard_ensure_card_init(sdcard_card_obj_t *self, bool force) {
166166

167167
esp_err_t err = sdmmc_card_init(&(self->host), &(self->card));
168168
if (err == ESP_OK) {
169+
// Ensure card's host structure has the correct slot after init
170+
self->card.host.slot = self->host.slot;
169171
self->flags |= SDCARD_CARD_FLAGS_CARD_INIT_DONE;
170172
} else {
171173
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
307309
else {
308310
sdmmc_host_t _temp_host = SDMMC_HOST_DEFAULT();
309311
_temp_host.max_freq_khz = freq / 1000;
312+
_temp_host.slot = slot_num;
310313
self->host = _temp_host;
311314
}
312315
#endif

0 commit comments

Comments
 (0)