Skip to content

Commit 3f13ada

Browse files
committed
Merge branch 'fix/sdmmc_probe_timing_retry' into 'master'
fix(sdmmc): Fix SDMMC slot switch timing related issue on ESP32-P4 Closes IDFCI-2328 See merge request espressif/esp-idf!32900
2 parents b8b845a + b263b9d commit 3f13ada

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

components/esp_driver_sdmmc/src/sdmmc_host.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static host_ctx_t s_host_ctx = {0};
9191
static void sdmmc_isr(void *arg);
9292
static void sdmmc_host_dma_init(void);
9393
static esp_err_t sdmmc_host_pullup_en_internal(int slot, int width);
94+
static bool sdmmc_host_slot_initialized(int slot);
9495
#if SOC_SDMMC_NUM_SLOTS >= 2
9596
static void sdmmc_host_change_to_slot(int slot);
9697
#endif
@@ -380,8 +381,16 @@ esp_err_t sdmmc_host_start_command(int slot, sdmmc_hw_cmd_t cmd, uint32_t arg)
380381
SLOT_CHECK(slot);
381382

382383
#if SOC_SDMMC_NUM_SLOTS >= 2
383-
// change the host settings to the appropriate slot before starting the transaction
384-
sdmmc_host_change_to_slot(slot);
384+
// Change the host settings to the appropriate slot before starting the transaction
385+
// If the slot is not initialized (slot_host_div not set) or already active, do nothing
386+
if (s_host_ctx.active_slot_num != slot) {
387+
s_host_ctx.active_slot_num = slot;
388+
if (sdmmc_host_slot_initialized(slot)) {
389+
sdmmc_host_change_to_slot(slot);
390+
} else {
391+
ESP_LOGD(TAG, "Slot %d is not initialized yet, skipping sdmmc_host_change_to_slot", slot);
392+
}
393+
}
385394
#endif
386395

387396
// if this isn't a clock update command, check the card detect status
@@ -808,12 +817,6 @@ static bool sdmmc_host_slot_initialized(int slot)
808817
#if SOC_SDMMC_NUM_SLOTS >= 2
809818
static void sdmmc_host_change_to_slot(int slot)
810819
{
811-
// If the slot is not initialized (slot_host_div not set) or already active, do nothing
812-
if (s_host_ctx.active_slot_num == slot || sdmmc_host_slot_initialized(slot) == false) {
813-
return;
814-
}
815-
s_host_ctx.active_slot_num = slot;
816-
817820
// Apply the appropriate saved host settings for the new slot before starting the transaction
818821
SDMMC_CLK_SRC_ATOMIC() {
819822
sdmmc_ll_set_clock_div(s_host_ctx.hal.dev, s_host_ctx.slot_ctx[slot].slot_host_div);

0 commit comments

Comments
 (0)