SDMMC init failed.

ujurmsde
Posts: 73
Joined: Tue Jan 19, 2021 6:37 am

SDMMC init failed.

Postby ujurmsde » Fri Sep 19, 2025 11:26 am

I have a development board based on ESP32p4 and it has init issues with SD card.

I am following the following example inthere there is SD card init() function that is not being init properly.

https://github.com/espressif/esp-idf/bl ... der_main.c
The following is the function that I use for init() sd card.
The error that I get is the following.
E (488) vfs_fat_sdmmc: sdmmc_card_init failed (0x105).

Code: Select all

void start_sd_card(void) {

    esp_err_t err;
    esp_vfs_fat_sdmmc_mount_config_t mount_config = {
        .format_if_mount_failed = true,
        .max_files = 5,
        .allocation_unit_size = 8 * 1024,
    };

    printf("initialising SD card\n");

    spi_bus_config_t spi_cfg = {
        .miso_io_num = GPIO_NUM_39,
        .mosi_io_num = GPIO_NUM_40,
        .sclk_io_num = GPIO_NUM_43,
        .quadhd_io_num = -1,
        .quadwp_io_num = -1,
        .max_transfer_sz = 4000,
    };

    err = spi_bus_initialize(host.slot, &spi_cfg, SPI_DMA_CH_AUTO);

    if(err != ESP_OK) {
        printf("SPI device not init ok\n");
    }

    sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
    slot_config.gpio_cs = GPIO_NUM_41;
    slot_config.gpio_cd = GPIO_NUM_44;
    slot_config.host_id = host.slot;


    err = esp_vfs_fat_sdspi_mount(SD_MOUNT_POINT, &host, &slot_config, &mount_config, &card);
    if(err != ESP_OK) {
        printf("SD mount failed\n");
    }
}

adokitkat
Espressif staff
Espressif staff
Posts: 77
Joined: Thu Jun 22, 2023 12:50 pm

Re: SDMMC init failed.

Postby adokitkat » Tue Sep 23, 2025 2:58 pm

Hello.

Please check, if you have your GPIO pins correctly assigned. Also try to add this piece of code after "printf("initialising SD card\n");" line:

Code: Select all

#if CONFIG_EXAMPLE_SD_PWR_CTRL_LDO_INTERNAL_IO
    sd_pwr_ctrl_ldo_config_t ldo_config = {
        .ldo_chan_id = CONFIG_EXAMPLE_SD_PWR_CTRL_LDO_IO_ID,
    };
    sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;

    ret = sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle);
    if (ret != ESP_OK) {
        printf("Failed to create a new on-chip LDO power control driver\n");
        return;
    }
    host.pwr_ctrl_handle = pwr_ctrl_handle;
#endif
As well as this at after other header includes:

Code: Select all

#if SOC_SDMMC_IO_POWER_EXTERNAL
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
#endif
It is possible we need to update the example to include this code for ESP32-P4.

You can check this similar example to see it whole how SDSPI mount should work: https://github.com/espressif/esp-idf/bl ... ple_main.c

If it still doesn't work please share all of your code here, thank you.

20142796
Posts: 4
Joined: Tue Aug 26, 2025 11:39 am

Re: SDMMC init failed.

Postby 20142796 » Wed Sep 24, 2025 10:42 am

esp_err_t bsp_sdcard_mount(void)
{
const esp_vfs_fat_sdmmc_mount_config_t mount_config = {
#ifdef CONFIG_BSP_SD_FORMAT_ON_MOUNT_FAIL
.format_if_mount_failed = true,
#else
.format_if_mount_failed = false,
#endif
.max_files = 5,
.allocation_unit_size = 64 * 1024
};

sdmmc_host_t host = SDMMC_HOST_DEFAULT();
host.slot = SDMMC_HOST_SLOT_0;
host.max_freq_khz = SDMMC_FREQ_HIGHSPEED;

sd_pwr_ctrl_ldo_config_t ldo_config = {
.ldo_chan_id = 4,
};
sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;
esp_err_t ret = sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to create a new on-chip LDO power control driver");
return ret;
}
host.pwr_ctrl_handle = pwr_ctrl_handle;

const sdmmc_slot_config_t slot_config = {
/* SD card is connected to Slot 0 pins. Slot 0 uses IO MUX, so not specifying the pins here */
.cd = SDMMC_SLOT_NO_CD,
.wp = SDMMC_SLOT_NO_WP,
.width = 4,
.flags = 0,
};

return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, &host, &slot_config, &mount_config, &bsp_sdcard);
}

adokitkat
Espressif staff
Espressif staff
Posts: 77
Joined: Thu Jun 22, 2023 12:50 pm

Re: SDMMC init failed.

Postby adokitkat » Wed Sep 24, 2025 11:06 am

Which esp32p4 board do you use? Which idf version?

Also sorry I forgot to add something - since the code I sent was missing there is also appropriate Kconfig missing. So you also need to do something like this at the top so the code I sent before will be active:

Code: Select all

#if CONFIG_IDF_TARGET_ESP32P4
#define CONFIG_EXAMPLE_SD_PWR_CTRL_LDO_INTERNAL_IO 1
#define CONFIG_EXAMPLE_SD_PWR_CTRL_LDO_IO_ID 4
#endif
However check before if the board really uses LDO to power SD card (Espressifs devboard does).

If it still doesn't work can you plese try to build and flash this example to see if it works? https://github.com/espressif/esp-idf/tr ... card/sdspi

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], PerplexityBot, PetalBot, Semrush [Bot] and 4 guests