ESP32-ADF using the sd-card

Started by maushax, December 05, 2022, 10:43:37 PM

Previous topic - Next topic

maushax

Hello,
i am trying to use the esp-adf-rev.c board as an mp3-player that can be controlled over tcp. For now i would be happy if the sd-card example projects from the official esp-adf git repository are working but i don't know how to initialize the sd-card properly. I found configuration files for the board on the olimex dance radio project and added the board to the components so i think the pin configuration should be correct now.

Then I tried the "pipeline_play_sdcard_music" example but executing this:
    ESP_LOGI(TAG, "[ 1 ] Mount sdcard");
    // Initialize peripherals management
    esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();
    esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg);

    // Initialize SD Card peripheral
    audio_board_sdcard_init(set, SD_MODE_1_LINE);
i get the following error:

E (404) vfs_fat_sdmmc: slot init failed (0x103).
E (404) SDCARD: File system already mounted


 Is the standard configuration for the peripherals not suitable for the board? If so, i would be greatful if you can help me and give me some hints how to get the examples working  :)

Thank you for your help!

LubOlimex

I will see what we can do, on first looks it appears to be an SPI SD card (not 1-bit SDIO). Also even if the example was made for SPI SD card, maybe the pins have to be redefined to match the Olimex hardware (e.g. looking at the schematic HS_MISO is GPIO12, HS_MOSI is GPIO13, HS_SCK is GPIO14, SD_CS is GPIO21).
Technical support and documentation manager at Olimex

maushax

oh, i was not aware that the lyraT-boards don't even use SPI! So the peripheral default configuration can't be the right choice for the board.

I found another example in the esp-idf repo called "sdspi" that allows a configuration of pins in menuconfig so i changed them accordingly. Unfortunately it is still not working, i get the following error:

I (348) example: Initializing SD card
I (348) example: Using SPI peripheral
I (358) example: Mounting filesystem
I (358) gpio: GPIO[15]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
E (408) sdmmc_sd: sdmmc_init_sd_if_cond: send_if_cond (1) returned 0x108
E (408) vfs_fat_sdmmc: sdmmc_card_init failed (0x108).
I (408) gpio: GPIO[15]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
E (418) example: Failed to initialize the card (ESP_ERR_INVALID_RESPONSE). Make sure SD card lines have pull-up resistors in place.

LubOlimex

The error messages says something about gpio: GPIO[15] - and GPIO15 is not used for the SD card in the ESP32-ADF design. It seems the definitions are not correct, sometimes might be hard to find how to redefine the pins and some examples might not allow to do so via the code and you might need to edit the definitions in the library itself.
Technical support and documentation manager at Olimex

maushax

Well.. Thank you, now it's working! I misread the schematics.. mixed up HS_CS and SD_CS!

LubOlimex

Glad to help it would be really cool if you can share how exactly did you got it working, in case another person has similar issue. What code did you use and where did you edit the pins? Thanks for this.
Technical support and documentation manager at Olimex

maushax

#6
Sure,
to initialize the sd-card of the olimex-adf board you have to use an SPI-sd configuration. I used the code from the example file sdspi (located here: /esp/esp-adf/esp-idf/examples/storage/sd_card/sdspi/main/sd_card_example_main.c).

The SPI configuration has to be set like this:

    sdmmc_host_t host = SDSPI_HOST_DEFAULT();
    spi_bus_config_t bus_cfg = {
        .mosi_io_num = 13,
        .miso_io_num = 12,
        .sclk_io_num = 14,
        .quadwp_io_num = -1,
        .quadhd_io_num = -1,
        .max_transfer_sz = 4000,
    };
    ..
    ..
    sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
    slot_config.gpio_cs = 21;
    slot_config.host_id = host.slot;