ESP32 SD Card in MMC-mode
Posted: 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.
The message in 1-line mode is:
What is wrong?
Regards
Jorg
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);
}
In 4-lines mode it is:I (89) xSDCard: Using SDMMC peripheral
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.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
What is wrong?
Regards
Jorg