ESP32 SD Card in MMC-mode

JSchaef
Posts: 13
Joined: Fri Jan 25, 2019 8:39 am

ESP32 SD Card in MMC-mode

Postby JSchaef » Tue Feb 19, 2019 1:23 pm

Hi,
when I try to use SD-Card in MMC-mode it is working only, when I use 1-line SD-mode.
When I use 4-lines, it failes.

Code: Select all

//#define SDCARD_USE_SPI 1

void xSdCardInit()
{
#ifdef SDCARD_USE_SPI
   ESP_LOGI(TAG, "Using SPI peripheral");

   sdmmc_host_t host = SDSPI_HOST_DEFAULT();
   sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
   slot_config.gpio_miso = 2;
   slot_config.gpio_mosi = 15;
   slot_config.gpio_sck  = 14;
   slot_config.gpio_cs = 13;
#else // SDCARD_USE_SPI
   ESP_LOGI("xSDCard", "Using SDMMC peripheral");
   sdmmc_host_t host = SDMMC_HOST_DEFAULT();
   //host.max_freq_khz = 19000;
   sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
   // To use 1-line SD mode, uncomment the following line:
   slot_config.width = 1;

   // GPIOs 15, 2, 4, 12, 13 should have external 10k pull-ups.
   // Internal pull-ups are not sufficient. However, enabling internal pull-ups
   // does make a difference some boards, so we do that here.
   gpio_set_pull_mode(15, GPIO_PULLUP_ONLY);     // CMD, needed in 4- and 1- line modes
   gpio_set_pull_mode(2, GPIO_PULLUP_ONLY);      // D0, needed in 4- and 1-line modes
   gpio_set_pull_mode(4, GPIO_PULLUP_ONLY);      // D1, needed in 4-line mode only
   gpio_set_pull_mode(12, GPIO_PULLUP_ONLY);     // D2, needed in 4-line mode only
   gpio_set_pull_mode(13, GPIO_PULLUP_ONLY);   // D3, needed in 4- and 1-line modes
   //gpio_set_pull_mode(14, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes
#endif // SDCARD_USE_SPI

	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* card;
   esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sd", &host, &slot_config, &mount_config, &card);

   if(ret != ESP_OK)
   {
      if(ret == ESP_FAIL)
      {
         ESP_LOGE("xSDCard",
            "Failed to mount filesystem. "
               "If you want the card to be formatted, set format_if_mount_failed = true.");
      }
      else
      {
         ESP_LOGE("xSDCard",
            "Failed to initialize the card (%s). "
               "Make sure SD card lines have pull-up resistors in place.",
            esp_err_to_name(ret));
      }
   }
   
   sdmmc_card_print_info(stdout, card);
}
The message in 1-line mode is:
I (89) xSDCard: Using SDMMC peripheral
Name: SA16G
Type: SDHC/SDXC
Speed: 20 MHz
Size: 14772MB
In 4-lines mode it is:
I (90) xSDCard: Using SDMMC peripheral
I (90) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
E (120) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x109
E (120) diskio_sdmmc: sdmmc_read_blocks failed (265)
W (120) vfs_fat_sdmmc: failed to mount card (1)
E (130) xSDCard: Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true.
Name: SA16G
Type: SDHC/SDXC
Speed: 20 MHz
Size: 14772MB
But the card is also recognized by ESP32, but no access to filesystem is possible.

What is wrong?

Regards
Jorg

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: ESP32 SD Card in MMC-mode

Postby ESP_igrr » Tue Feb 19, 2019 1:35 pm

0x109 is CRC error. Usually this means either signal integrity (interference/long wiring/etc) issue or voltage levels issue. Try reducing clock frequency to 400kHz. If it doesn't help, check if all the pull-up resistors are in place. Use oscilloscope to scope the signals and see whether they look okay.

JSchaef
Posts: 13
Joined: Fri Jan 25, 2019 8:39 am

Re: ESP32 SD Card in MMC-mode

Postby JSchaef » Tue Feb 19, 2019 1:41 pm

Hi ESP_igrr,
thank you for your reply.
I used the recomended pullups GPIO14, GPIO15, GPIO2, GPIO4, GPIO12, GPIO13, each 10k.

I will see with an oscilloscope how the signals are.
Is it only the CLK (GPIO14)-line, where I have to pay attention for?

Regards
Jorg

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: ESP32 SD Card in MMC-mode

Postby ESP_igrr » Tue Feb 19, 2019 2:42 pm

Most likely it's something with D1-D3 lines, since CLK/CMD/D0 are used in 1-line mode and you don't observe issues there.

Keep in mind that there may be a pull-down on GPIO12, depending on the development board. If it is present, it may be conflicting with your external pull-up.

JSchaef
Posts: 13
Joined: Fri Jan 25, 2019 8:39 am

Re: ESP32 SD Card in MMC-mode

Postby JSchaef » Wed Feb 20, 2019 3:21 pm

Hello ESP_igrr,

I didn't have time to see the signals with an oscilloscope.

But are the recommended 10k-pullups sufficient?
In other forums I read about 100k-pullups (also in SD-Card forum).
I know, that when one use higher pullups then the edges in the signals look like more an "edge" than a "curve" - especially when frequency increases.
Is the 10k really the recommondation of Espressif?

Regards
Jorg

Who is online

Users browsing this forum: No registered users and 177 guests