fix(sdmmc): Fix SDMMC slot switch timing related issue on ESP32-P4

This commit is contained in:
Adam Múdry
2024-08-16 13:11:50 +02:00
committed by BOT
parent 6773164b6a
commit 1e04e7cdbb

View File

@ -103,6 +103,7 @@ DRAM_DMA_ALIGNED_ATTR static sdmmc_desc_t s_dma_desc[SDMMC_DMA_DESC_CNT];
static void sdmmc_isr(void *arg);
static void sdmmc_host_dma_init(void);
static esp_err_t sdmmc_host_pullup_en_internal(int slot, int width);
static bool sdmmc_host_slot_initialized(int slot);
#if SOC_SDMMC_NUM_SLOTS >= 2
static void sdmmc_host_change_to_slot(int slot);
#endif
@ -392,8 +393,16 @@ esp_err_t sdmmc_host_start_command(int slot, sdmmc_hw_cmd_t cmd, uint32_t arg)
SLOT_CHECK(slot);
#if SOC_SDMMC_NUM_SLOTS >= 2
// change the host settings to the appropriate slot before starting the transaction
// Change the host settings to the appropriate slot before starting the transaction
// If the slot is not initialized (slot_host_div not set) or already active, do nothing
if (s_host_ctx.active_slot_num != slot) {
s_host_ctx.active_slot_num = slot;
if (sdmmc_host_slot_initialized(slot)) {
sdmmc_host_change_to_slot(slot);
} else {
ESP_LOGD(TAG, "Slot %d is not initialized yet, skipping sdmmc_host_change_to_slot", slot);
}
}
#endif
// if this isn't a clock update command, check the card detect status
@ -830,12 +839,6 @@ static bool sdmmc_host_slot_initialized(int slot)
#if SOC_SDMMC_NUM_SLOTS >= 2
static void sdmmc_host_change_to_slot(int slot)
{
// If the slot is not initialized (slot_host_div not set) or already active, do nothing
if (s_host_ctx.active_slot_num == slot || sdmmc_host_slot_initialized(slot) == false) {
return;
}
s_host_ctx.active_slot_num = slot;
// Apply the appropriate saved host settings for the new slot before starting the transaction
SDMMC_CLK_SRC_ATOMIC() {
sdmmc_ll_set_clock_div(s_host_ctx.hal.dev, s_host_ctx.slot_ctx[slot].slot_host_div);