Two SD Cards in SDIO Mode

obscenity
Posts: 1
Joined: Mon Jan 20, 2025 5:44 pm

Two SD Cards in SDIO Mode

Postby obscenity » Mon Jan 20, 2025 5:53 pm

Hello! I'm wondering if it's possible to hook up two SD cards to my Arduino Nano ESP32-S3 at the same time? I've wired it up to try but no matter what I do I can only get one to run at a time. I've tried a variety of different code combinations but this is my latest. It's failing with the following error:

Code: Select all

␛[0;32mI (820) sdcard_copy: SD card on Slot 0 mounted successfully␛[0m
␛[0;32mI (820) sdcard_copy: Mounting SD card on Slot 1␛[0m
␛[0;31mE (820) vfs_fat_sdmmc: host init failed (0x103).␛[0m
␛[0;31mE (820) sdcard_copy: Failed to mount SD card on Slot 1 (ESP_ERR_INVALID_STATE)␛[0m
␛[0;32mI (830) main_task: Returned from app_main()␛[0m

Code: Select all

#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "driver/sdmmc_host.h"
#include "esp_log.h"

static const char *TAG = "sdcard_copy";

#define MOUNT_POINT_SLOT0 "/sdcard0"
#define MOUNT_POINT_SLOT1 "/sdcard1"

// GPIO configuration for Slot 0
#define SLOT0_CLK GPIO_NUM_1
#define SLOT0_CMD GPIO_NUM_2
#define SLOT0_D0 GPIO_NUM_3
#define SLOT0_D1 GPIO_NUM_4
#define SLOT0_D2 GPIO_NUM_14
#define SLOT0_D3 GPIO_NUM_13

// GPIO configuration for Slot 1
#define SLOT1_CLK GPIO_NUM_9
#define SLOT1_CMD GPIO_NUM_10
#define SLOT1_D0 GPIO_NUM_8
#define SLOT1_D1 GPIO_NUM_5
#define SLOT1_D2 GPIO_NUM_6
#define SLOT1_D3 GPIO_NUM_7

void app_main() {
    ESP_LOGI(TAG, "errorTag");
    esp_err_t ret;

    sdmmc_host_t host = SDMMC_HOST_DEFAULT();
    host.max_freq_khz = SDMMC_FREQ_PROBING; 

    // Configure Slot 0
    // sdmmc_host_t host0 = SDMMC_HOST_DEFAULT();
    // host0.slot = SDMMC_HOST_SLOT_1;

    sdmmc_slot_config_t slot_config0 = SDMMC_SLOT_CONFIG_DEFAULT();
    slot_config0.clk = SLOT0_CLK;
    slot_config0.cmd = SLOT0_CMD;
    slot_config0.d0 = SLOT0_D0;
    slot_config0.d1 = SLOT0_D1;
    slot_config0.d2 = SLOT0_D2;
    slot_config0.d3 = SLOT0_D3;
    slot_config0.gpio_wp = -1;        // Disable Write Protect
    slot_config0.gpio_cd = -1; 

    slot_config0.flags = true;
    slot_config0.width = 4;

    // Configure Slot 1
    // sdmmc_host_t host1 = SDMMC_HOST_DEFAULT();
    // host1.slot = SDMMC_HOST_SLOT_0;

    sdmmc_slot_config_t slot_config1 = SDMMC_SLOT_CONFIG_DEFAULT();
    slot_config1.clk = SLOT1_CLK;
    slot_config1.cmd = SLOT1_CMD;
    slot_config1.d0 = SLOT1_D0;
    slot_config1.d1 = SLOT1_D1;
    slot_config1.d2 = SLOT1_D2;
    slot_config1.d3 = SLOT1_D3;
    slot_config1.gpio_wp = -1;        // Disable Write Protect
    slot_config1.gpio_cd = -1; 

    slot_config1.flags = true;
    slot_config1.width = 4;

    // Common FAT filesystem configuration
    esp_vfs_fat_sdmmc_mount_config_t mount_config = {
        .format_if_mount_failed = false,
        .max_files = 5,
        .allocation_unit_size = 16 * 1024
    };

    sdmmc_card_t *card0;
    sdmmc_card_t *card1;

    // // Mount SD card on Slot 0
    ESP_LOGI(TAG, "Mounting SD card on Slot 0");
    ret = esp_vfs_fat_sdmmc_mount(MOUNT_POINT_SLOT0, &host, &slot_config0, &mount_config, &card0);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Failed to mount SD card on Slot 0 (%s)", esp_err_to_name(ret));
        return;
    }
    ESP_LOGI(TAG, "SD card on Slot 0 mounted successfully");

    // Mount SD card on Slot 1
    ESP_LOGI(TAG, "Mounting SD card on Slot 1");
    ret = esp_vfs_fat_sdmmc_mount(MOUNT_POINT_SLOT1, &host, &slot_config1, &mount_config, &card1);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Failed to mount SD card on Slot 1 (%s)", esp_err_to_name(ret));
        // esp_vfs_fat_sdmmc_unmount(MOUNT_POINT_SLOT0, card0);
        return;
    }
    ESP_LOGI(TAG, "SD card on Slot 1 mounted successfully");
}




My SD Card reader modules have the 10k resistors built in. I've verified that they (and the cards) both work individually. But the second slot config always fails. I'm wondering if the pins I have it connected to just don't support SDIO? If that's the case i'm not sure how I'd be able to move things around to make it all work.

Thanks!

ESP_adokitkat
Posts: 55
Joined: Thu Jun 22, 2023 12:50 pm

Re: Two SD Cards in SDIO Mode

Postby ESP_adokitkat » Sun Jan 26, 2025 8:57 pm

Hello. What version of ESP-IDF do you use? Concurrent use of 2 SDMMC devices is available from ESP-IDF v5.4 (there also is a backport created for v5.3 but it wasn't merged yet). I think it shouldn't matter if it's SDIO, if it doesn't work it probably is a bug...

Can you please share what SD cards are you using?
Could you also please share your log with debug log level enabled?

Thank you.

Edit: I found another bug in sdmmc driver, but it shouldn't prevent you from mounting both cards. It works for me.

Who is online

Users browsing this forum: No registered users and 36 guests