MicroSD problem

mtaz78
Posts: 14
Joined: Thu Nov 23, 2023 3:32 pm

MicroSD problem

Postby mtaz78 » Tue Feb 13, 2024 3:48 pm

Hello everyone,
I'm trying to save an image from the ESP-KORVO-2's camera to the MicroSD inserted in the camera slot. The problem is that the board seems not to recognise the SD, and I get the error:

vfs_fat_sdmmc: host init failed (0x105).

I know for a fact that both the SD and the reader work perfectly (I saved an audio file to the SD). Do you have any advice? Thanks in advance.
Below you can find the code I'm using.

Code: Select all

static esp_err_t initi_sd_card(void)
{  
    sdmmc_host_t host = SDMMC_HOST_DEFAULT();
    sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
    esp_vfs_fat_sdmmc_mount_config_t mount_config = {
        .format_if_mount_failed = false,
        .max_files = 3,
    };
    sdmmc_card_t *card;
    esp_err_t err = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
    if (err != ESP_OK)
    {
        return err;
    }
    return ESP_OK;
}

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: MicroSD problem

Postby chegewara » Fri Feb 16, 2024 5:37 am

From code snippet it looks like you didnt assing sd card pins

Code: Select all

sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
https://github.com/espressif/esp-idf/bl ... #L143-L145

https://espressif-docs.readthedocs-host ... on-summary

mtaz78
Posts: 14
Joined: Thu Nov 23, 2023 3:32 pm

Re: MicroSD problem

Postby mtaz78 » Wed Feb 21, 2024 1:56 pm

Thank you for your response chegewara, I updated my code as you suggested:

Code: Select all

static esp_err_t initi_sd_card(void)
{  
    sdmmc_host_t host = SDMMC_HOST_DEFAULT();
    sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
    slot_config.clk = GPIO_NUM_15;
    slot_config.cmd = GPIO_NUM_7;
    slot_config.d0 = GPIO_NUM_4;
    esp_vfs_fat_sdmmc_mount_config_t mount_config = {
        .format_if_mount_failed = false,
        .max_files = 3,
    };
    sdmmc_card_t *card;
    esp_err_t err = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
    if (err != ESP_OK)
    {
        return err;
    }
    return ESP_OK;
}
Unfortunately, I always get the same error:
vfs_fat_sdmmc: host init failed (0x105)
Do you have any other advice for me?

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: MicroSD problem

Postby chegewara » Thu Feb 22, 2024 1:40 am

It seems to be this error:

Code: Select all

    err = (*host_config->init)();
    CHECK_EXECUTE_RESULT(err, "host init failed");
  
which is related to this part of code in your app

Code: Select all

sdmmc_host_t host = SDMMC_HOST_DEFAULT();
It may be that you need to change something in this configuration or there is hardware issue. I am just guessing now, since i dont have this exact devkit.

I think you should see if you find code with sdmmc in this repository, which is focusing on espressif devkits:
https://github.com/espressif/esp-bsp/tr ... r/examples

mtaz78
Posts: 14
Joined: Thu Nov 23, 2023 3:32 pm

Re: MicroSD problem

Postby mtaz78 » Thu Feb 22, 2024 10:31 am

Hi chegewara, thanks again for your help, I found some initializations in the link you provided, but nothing, I keep getting the same error. I would exclude an hardware issue, because with the example code https://github.com/espressif/esp-adf/tr ... ve_to_file it works and it saves an audio file into MicroSD without any problem. So I tried integrating the example code into my own, and the only thing I got was a slightly more explanatory error:
vfs_fat_sdmmc: host init failed (0x105).
SDCARD: Failed to initialize the card (261). Make sure SD card lines have pull-up resistors in place.
Here it is a snippet of the code I'm referring to:

Code: Select all

esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();
esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg);
audio_board_sdcard_init(set, SD_MODE_1_LINE);
You can find it here: https://github.com/espressif/esp-adf/bl ... ile.c#L136

A possible problem could be that I would like to use the SD to save a frame from the camera, if I initialise the SD first, the camera will not work and vice versa. The strange aspect is that they use completely different pins, so it is quite abnormal behaviour.

Thanks again for your help, have a good day.

ESP_rrtandler
Posts: 24
Joined: Wed May 31, 2023 6:54 pm

Re: MicroSD problem

Postby ESP_rrtandler » Mon Feb 26, 2024 4:22 pm

Hi mtaz78,
Please check the value of your

Code: Select all

slot_config.width
The default is 0 meaning maximum possible size of data bus, while your board uses only DATA0, so the correct value adopted to your use case should be 1.

mtaz78
Posts: 14
Joined: Thu Nov 23, 2023 3:32 pm

Re: MicroSD problem

Postby mtaz78 » Wed Feb 28, 2024 7:24 am

Hi ESP_rrtandler, thanks for your answer. Unfortunately, I have already tried changing that parameter, but the error remains. This is my code now

Code: Select all

sdmmc_host_t host = SDMMC_HOST_DEFAULT();
sdmmc_slot_config_t slot_config = {
        .clk = GPIO_NUM_15,
        .cmd = GPIO_NUM_7,
        .d0 = GPIO_NUM_4,
        .d1 = GPIO_NUM_NC,
        .d2 = GPIO_NUM_NC,
        .d3 = GPIO_NUM_NC,
        .d4 = GPIO_NUM_NC,
        .d5 = GPIO_NUM_NC,
        .d6 = GPIO_NUM_NC,
        .d7 = GPIO_NUM_NC,
        .cd = SDMMC_SLOT_NO_CD,
        .wp = SDMMC_SLOT_NO_WP,
        .width = 1,
        .flags = SDMMC_HOST_FLAG_1BIT,
    };
I have restricted the problem to the 'simultaneous' initialisation of the camera and the MicroSD. In fact if I call this functions

Code: Select all

 esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();
 esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg); 
and then initialise the MicroSD I have no problems, but then I get an error for initialising the camera and vice versa.

This is the error i got when i initialize the MicroSD first

Code: Select all

E (6217) s3 ll_cam: DMA interrupt allocation of camera failed
E (6223) cam_hal: cam_config(402): cam intr alloc failed
E (6229) camera: Camera config failed with error 0xffffffff

ESP_rrtandler
Posts: 24
Joined: Wed May 31, 2023 6:54 pm

Re: MicroSD problem

Postby ESP_rrtandler » Wed Feb 28, 2024 11:07 am

Hi mtaz78,

Please add following:

Code: Select all

esp_log_level_set("intr_alloc", ESP_LOG_VERBOSE);
Before initialisation code and run both initialisation combinations - sd first, then camera and vice versa. Please post log messages of both cases.

ESP_rrtandler
Posts: 24
Joined: Wed May 31, 2023 6:54 pm

Re: MicroSD problem

Postby ESP_rrtandler » Wed Feb 28, 2024 2:26 pm

@mtaz78 - Please also check whether you have Enabled PSRAM in menuconfig and set Flash and PSRAM frequiencies to 80MHz

Who is online

Users browsing this forum: No registered users and 80 guests