SD Card module error when mounting. Need Help
Posted: Sat Dec 27, 2025 12:09 pm
Hi everyone,
I’m trying to use an SD card module with my ESP32 over SPI, but I keep getting errors when mounting the filesystem. My setup:
ESP32 pins:
MISO → 19
MOSI → 23
SCK → 18
CS → 15
3.3 V → VCC
GND → GND
The SD card module is a cheap one I got from China. There are 10 KΩ resistors in series on MISO, MOSI, CS, and SCK on the module.
SD card: 16 GB, FAT32
Here’s the code I’m using:
#include <stdio.h>
#include "esp_system.h"
#include "esp_log.h"
#include "esp_err.h"
#include "driver/spi_common.h"
#include "driver/spi_master.h"
#include "sdmmc_cmd.h"
#include "esp_vfs_fat.h"
#define PIN_NUM_MISO 19
#define PIN_NUM_MOSI 23
#define PIN_NUM_CLK 18
#define PIN_NUM_CS 15
static const char *TAG = "SD_CARD";
void app_main(void)
{
esp_err_t ret;
// Use SPI host
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
host.slot = SPI2_HOST; // HSPI
host.max_freq_khz = 100; // start super slow
// SPI bus configuration
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 = 8192,
};
ret = spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CH_AUTO);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize SPI bus");
return;
}
// SD SPI device configuration
sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
slot_config.gpio_cs = PIN_NUM_CS;
slot_config.host_id = host.slot;
// FAT filesystem mount configuration
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = false,
.max_files = 5,
.allocation_unit_size = 4096
};
sdmmc_card_t *card;
ESP_LOGI(TAG, "Mounting SD card at 100 kHz...");
ret = esp_vfs_fat_sdspi_mount("/sdcard", &host, &slot_config, &mount_config, &card);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to mount filesystem (%s)", esp_err_to_name(ret));
return;
}
ESP_LOGI(TAG, "SD card mounted successfully!");
sdmmc_card_print_info(stdout, card);
ESP_LOGI(TAG, "You can now increase host.max_freq_khz gradually (e.g., 8MHz, 16MHz, 20MHz) and test again.");
}
And here’s the log I get:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
...
I (330) SD_CARD: Mounting SD card at 100 kHz...
I (330) sdspi_transaction: cmd=52, R1 response: command not supported
I (370) sdspi_transaction: cmd=5, R1 response: command not supported
E (3370) sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
E (3370) vfs_fat_sdmmc: sdmmc_card_init failed (0x107)
E (3370) SD_CARD: Failed to mount filesystem (ESP_ERR_TIMEOUT)
I’ve tried powering the module with 3.3 V and verified the wiring. The SD card is inserted and Formated to FAT32.
I’m trying to use an SD card module with my ESP32 over SPI, but I keep getting errors when mounting the filesystem. My setup:
ESP32 pins:
MISO → 19
MOSI → 23
SCK → 18
CS → 15
3.3 V → VCC
GND → GND
The SD card module is a cheap one I got from China. There are 10 KΩ resistors in series on MISO, MOSI, CS, and SCK on the module.
SD card: 16 GB, FAT32
Here’s the code I’m using:
#include <stdio.h>
#include "esp_system.h"
#include "esp_log.h"
#include "esp_err.h"
#include "driver/spi_common.h"
#include "driver/spi_master.h"
#include "sdmmc_cmd.h"
#include "esp_vfs_fat.h"
#define PIN_NUM_MISO 19
#define PIN_NUM_MOSI 23
#define PIN_NUM_CLK 18
#define PIN_NUM_CS 15
static const char *TAG = "SD_CARD";
void app_main(void)
{
esp_err_t ret;
// Use SPI host
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
host.slot = SPI2_HOST; // HSPI
host.max_freq_khz = 100; // start super slow
// SPI bus configuration
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 = 8192,
};
ret = spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CH_AUTO);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize SPI bus");
return;
}
// SD SPI device configuration
sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
slot_config.gpio_cs = PIN_NUM_CS;
slot_config.host_id = host.slot;
// FAT filesystem mount configuration
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = false,
.max_files = 5,
.allocation_unit_size = 4096
};
sdmmc_card_t *card;
ESP_LOGI(TAG, "Mounting SD card at 100 kHz...");
ret = esp_vfs_fat_sdspi_mount("/sdcard", &host, &slot_config, &mount_config, &card);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to mount filesystem (%s)", esp_err_to_name(ret));
return;
}
ESP_LOGI(TAG, "SD card mounted successfully!");
sdmmc_card_print_info(stdout, card);
ESP_LOGI(TAG, "You can now increase host.max_freq_khz gradually (e.g., 8MHz, 16MHz, 20MHz) and test again.");
}
And here’s the log I get:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
...
I (330) SD_CARD: Mounting SD card at 100 kHz...
I (330) sdspi_transaction: cmd=52, R1 response: command not supported
I (370) sdspi_transaction: cmd=5, R1 response: command not supported
E (3370) sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
E (3370) vfs_fat_sdmmc: sdmmc_card_init failed (0x107)
E (3370) SD_CARD: Failed to mount filesystem (ESP_ERR_TIMEOUT)
I’ve tried powering the module with 3.3 V and verified the wiring. The SD card is inserted and Formated to FAT32.