I'm fairly new to ESP-IDF and I'm trying to use an SD via SPI but every time it returns
Code: Select all
E (641) vfs_fat_sdmmc: sdmmc_card_init failed (0x109).
Code: Select all
#define SD_CLK_PIN GPIO_NUM_5
#define SD_MISO_PIN GPIO_NUM_6
#define SD_MOSI_PIN GPIO_NUM_7
#define SD_CS_PIN GPIO_NUM_8
ESP_LOGI(__FUNCTION__, "Initializing SD card");
// Configura i pin SPI per la comunicazione con la SD
spi_bus_config_t buscfg = {
.mosi_io_num = SD_MOSI_PIN,
.miso_io_num = SD_MISO_PIN,
.sclk_io_num = SD_CLK_PIN,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 4000,
};
// Inizializza il bus SPI
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
spi_device_interface_config_t devcfg = {
.mode = 0, // Modalità SPI
.clock_speed_hz = SDMMC_FREQ_DEFAULT, // Velocità di clock SPI
.spics_io_num = SD_CS_PIN, // Pin del chip select
.queue_size = 7, // Lunghezza della coda delle transazioni SPI
};
spi_device_handle_t spi;
ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &devcfg, &spi));
sdspi_dev_handle_t sd_handle;
sdspi_device_config_t dev_config = SDSPI_DEVICE_CONFIG_DEFAULT();
dev_config.host_id = SPI2_HOST;
dev_config.gpio_cs = SD_CS_PIN;
ESP_ERROR_CHECK(sdspi_host_init_device(&dev_config, &sd_handle));
sdmmc_host_t sd_host = SDSPI_HOST_DEFAULT();
sd_host.slot = SPI2_HOST;
sd_host.max_freq_khz = SDMMC_FREQ_DEFAULT;
sdmmc_card_t *card;
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = false,
.max_files = 5,
.allocation_unit_size = 16 * 1024
};
ESP_ERROR_CHECK(esp_vfs_fat_sdspi_mount("/", &sd_host, &dev_config, &mount_config, &card));
Thanks to anyone who can help me out!