Issues with the SD SPI interface

NRollo
Posts: 21
Joined: Fri Jan 22, 2021 1:04 pm

Issues with the SD SPI interface

Postby NRollo » Mon Oct 18, 2021 11:15 am

I seem to have two issues with the SD SPI host interface.

#1:
Setting the clock speed on the SPI interface with the

Code: Select all

host.max_freq_khz
does not seem to have any effect, when measuring the SPI clock it's either 400 khz or 20 Mhz.
What is the correct way of changing the SPI clock to e.g. 10 Mhz?

#2:
Sporatic errors occur when running the ESP32 on 240 Mhz (no problems on 160 Mhz) SPI running @20 Mhz in both cases:
E (7064555) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x108
E (7074555) diskio_sdmmc: sdmmc_read_blocks failed (264)


The SD SPI initialization code:

Code: Select all

esp_vfs_fat_sdmmc_mount_config_t mount_config = {
        .format_if_mount_failed = false,
        .max_files = 10,
        .allocation_unit_size = 16 * 1024
    };

    sdmmc_host_t host = SDSPI_HOST_DEFAULT();
    // Not sure if this makes any difference but now its done
    host.flags |= SDMMC_HOST_FLAG_1BIT;
    
    spi_bus_config_t bus_cfg = {
        .mosi_io_num = PIN_NUM_MOSI,
        .miso_io_num = PIN_NUM_MISO,
        .sclk_io_num = PIN_NUM_CLK,
        .quadwp_io_num = -1,
        .quadhd_io_num = -1,
        .max_transfer_sz = 4000,
    };

    ret = spi_bus_initialize(host.slot, &bus_cfg, 1);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Failed to initialize bus.");
        return (1);
    }

    sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
    slot_config.gpio_cs = PIN_NUM_CS;
    slot_config.host_id = host.slot;

    ret = esp_vfs_fat_sdspi_mount("/sdcard", &host, &slot_config, &mount_config, &card);
Debugging the code I have found that the error occur in the 'sdmmc_cmd.c' module when returning from the function

Code: Select all

esp_err_t err = (*card->host.do_transaction)(slot, cmd);
I am a little concerned that this is a 'race' condition which I have just not seen at 160 Mhz - yet.
Any comments are welcome as I am a bit in the dark of what to try next?

NRollo
Posts: 21
Joined: Fri Jan 22, 2021 1:04 pm

Re: Issues with the SD SPI interface

Postby NRollo » Wed Dec 15, 2021 1:00 pm


Who is online

Users browsing this forum: awegel, Baidu [Spider], FrankJensen, StanInexeon, zelenecul and 129 guests