Esp32S3 : Questions concerning SD Cards and MMC Cards

ThomasESP32
Posts: 229
Joined: Thu Jul 14, 2022 5:15 am

Esp32S3 : Questions concerning SD Cards and MMC Cards

Postby ThomasESP32 » Thu Oct 17, 2024 4:25 am

Good morning,

I need to use an Esp32S3 in order to dialog with an MMC Card or an SD Card (using the same pins).
Could you confirm that this is possible using the SPI mode with the two types of cards (Both type have an SPI Mode ??)

More questions please :
I saw that the MMC card could be used with an MMC Protocol and the SD Card with an SD Protocol, both different from SPI mode. Could you confirm please ?

Moreover, could you also confirm that the MMC and SD protocols are not the same ?

Conclusion :
Could you please confirm that if I manage to "speak" to the SD card using the SPI mode, I would be able to plug an MMC Card instead of the SD Card and it would be ok ? I would be able to exchange datas with the MMC card the same way ?

Please give me as much informations as possible concerning the SD and MMC cards/protocols (This is quite new for me).
Best regards,

Thank you for your help on this subject,

Thomas TRUILHE

ThomasESP32
Posts: 229
Joined: Thu Jul 14, 2022 5:15 am

Re: Esp32S3 : Questions concerning SD Cards and MMC Cards

Postby ThomasESP32 » Thu Oct 17, 2024 4:30 am

Or do you think that the MMC protocol is compatible with the SPI protocol (In 1 bit mode ??)

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Esp32S3 : Questions concerning SD Cards and MMC Cards

Postby MicroController » Thu Oct 17, 2024 9:21 am

All MMC and SD cards should support 1-bit SPI.
Getting your hands on actual MMC cards nowadays may be a challenge though.

pacucha42
Posts: 31
Joined: Fri Mar 29, 2019 12:56 pm

Re: Esp32S3 : Questions concerning SD Cards and MMC Cards

Postby pacucha42 » Thu Oct 17, 2024 12:53 pm

Unfortunately, eMMC chips can't be connected to ESP32* through SPI bus, only the chips with integrated SD host controller are capable of MMC communication (ESP32, ESP32S3 and ESP32P4). Eg ESP32C3 can't do: https://docs.espressif.com/projects/esp ... emmc-chips, whilst ESP32S3 is eMMC compatible: https://docs.espressif.com/projects/esp ... emmc-chips. The SDMMC driver-level API is the same for both SD and eMMC.

Also, check the example at https://github.com/espressif/esp-idf/tr ... orage/emmc (works only on S3, so you are safe). Hope this helps

ThomasESP32
Posts: 229
Joined: Thu Jul 14, 2022 5:15 am

Re: Esp32S3 : Questions concerning SD Cards and MMC Cards

Postby ThomasESP32 » Thu Oct 17, 2024 1:56 pm

Ok I have seen you example, thank you.
Using it, I managed to mount my SD Card using the following lines :

SDCard_MountCfg.format_if_mount_failed = true;
SDCard_MountCfg.max_files = SDCARD_MAX_FILE;
SDCard_MountCfg.allocation_unit_size = CONFIG_WL_SECTOR_SIZE;

// By default, SD card frequency is initialized to SDMMC_FREQ_DEFAULT (20MHz)
// For setting a specific frequency, use host.max_freq_khz (range 400kHz - 40MHz for SDMMC)
// Example: for fixed frequency of 10MHz, use host.max_freq_khz = 10000;
sdmmc_host_t host = SDMMC_HOST_DEFAULT(); // @suppress("Invalid arguments")

// This initializes the slot without card detect (CD) and write protect (WP) signals.
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); // @suppress("Invalid arguments")
slot_config.width = 1;
slot_config.clk = (gpio_num_t)PIN_NUM_CLK;
slot_config.cmd = (gpio_num_t)PIN_NUM_CMD;
slot_config.d0 = (gpio_num_t)PIN_NUM_DATA0;
slot_config.cd = (gpio_num_t)PIN_NUM_CS;

// Enable internal pullups on enabled pins. The internal pullups
// are insufficient however, please make sure 10k external pullups are
// connected on the bus. This is for debug / example purpose only.
slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP;

/* Initialisation de la SPI : */
err = esp_vfs_fat_sdmmc_mount(MOUNT_POINT_EXTFLASH, &host, &slot_config, &SDCard_MountCfg, &SDCard); // @suppress("Invalid arguments")


However, if I set the option SDCard_MountCfg.format_if_mount_failed to false, the firmware does not manage to mount the FileSystem.
I have to set it to true to mount the filesystem normally but the FileSystem is formatted each time that I start the firmware
so I loose all the files that are on it.

Do you have any idea why please ?

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Esp32S3 : Questions concerning SD Cards and MMC Cards

Postby MicroController » Thu Oct 17, 2024 2:21 pm


ThomasESP32
Posts: 229
Joined: Thu Jul 14, 2022 5:15 am

Re: Esp32S3 : Questions concerning SD Cards and MMC Cards

Postby ThomasESP32 » Thu Oct 17, 2024 2:57 pm

In fact I am looking for an example where the tinyusb driver is used with an SPI external SDCard.
Do you think this kind of example exists ?

Best regards,

pacucha42
Posts: 31
Joined: Fri Mar 29, 2019 12:56 pm

Re: Esp32S3 : Questions concerning SD Cards and MMC Cards

Postby pacucha42 » Thu Oct 17, 2024 3:15 pm

TinyUSB MSC example: https://github.com/espressif/esp-idf/tr ... e/tusb_msc
Not sure this would work with SDSPI
Last edited by pacucha42 on Thu Oct 17, 2024 3:39 pm, edited 1 time in total.

pacucha42
Posts: 31
Joined: Fri Mar 29, 2019 12:56 pm

Re: Esp32S3 : Questions concerning SD Cards and MMC Cards

Postby pacucha42 » Thu Oct 17, 2024 3:16 pm

ThomasESP32 wrote:
Thu Oct 17, 2024 1:56 pm
Ok I have seen you example, thank you.
Using it, I managed to mount my SD Card using the following lines :

...
Please, provide verbose logs.

Note 1: you are using SDCard_MountCfg.allocation_unit_size = CONFIG_WL_SECTOR_SIZE, which is technically ok, but philosophically unrelated. SD cards have own wear-levelling and don't care about IDF WL sector size (which works for SPI Flash only). 'allocation_unit_size' is slightly misleading name for the FAT cluster size, which must be integer multiple of the target media sector size. So, in this case it's fine, but it's sort of constant type exploitation

Note 2: if you need to connect SD card (not MMC), please, refer to example at https://github.com/espressif/esp-idf/tr ... card/sdmmc

ThomasESP32
Posts: 229
Joined: Thu Jul 14, 2022 5:15 am

Re: Esp32S3 : Questions concerning SD Cards and MMC Cards

Postby ThomasESP32 » Mon Oct 21, 2024 7:15 am

Good morning, using the example sdmmc,
I manage to mount my 2Go card and my 16Go card.
This is perfect. Thank you.

Who is online

Users browsing this forum: No registered users and 336 guests