fix(sdspi): 0x106 error during SD card init via SPI related fixes

Try to turn on CRC16 again if first failed, allow disabling of CRC check altogether

Releated https://github.com/espressif/esp-idf/issues/15450
This commit is contained in:
Adam Múdry
2026-03-09 19:10:55 +01:00
parent 5ecafbffc1
commit a4cec4355a
6 changed files with 55 additions and 3 deletions
@@ -33,6 +33,7 @@ extern "C" {
#define SDMMC_GO_IDLE_DELAY_MS 20
#define SDMMC_IO_SEND_OP_COND_DELAY_MS 10
#define SDMMC_INIT_SPI_CRC_RETRY_DELAY_MS 10
#define SDMMC_INIT_WAIT_DATA_READY_TIMEOUT_US (5000 * 1000)
#define SDMMC_READY_FOR_DATA_TIMEOUT_US (5000 * 1000)
@@ -191,6 +191,9 @@ typedef struct {
Currently this is only used by the SDIO driver. Set this flag when
using SDIO CMD53 byte mode, with user buffer that is behind the cache
or not aligned to 4 byte boundary. */
#define SDMMC_HOST_FLAG_SPI_IGNORE_DATA_CRC \
BIT(7) /*!< SPI mode only: Do not enable CRC verification (skip CMD59).
Not recommended as it disables data integrity checking. */
int slot; /*!< slot number, to be passed to host functions */
int max_freq_khz; /*!< max frequency supported by the host */
#define SDMMC_FREQ_DEFAULT 20000 /*!< SD/MMC Default speed (limited by clock divider) */
+4
View File
@@ -384,6 +384,10 @@ esp_err_t sdmmc_fix_host_flags(sdmmc_card_t* card)
}
}
if (card->host.flags & SDMMC_HOST_FLAG_SPI_IGNORE_DATA_CRC) {
ESP_LOGW(TAG, "SDMMC_HOST_FLAG_SPI_IGNORE_DATA_CRC flag is set on non-SPI host");
}
#if !SOC_SDMMC_UHS_I_SUPPORTED
if ((card->host.max_freq_khz == SDMMC_FREQ_SDR50) ||
(card->host.max_freq_khz == SDMMC_FREQ_DDR50) ||
+5 -2
View File
@@ -93,9 +93,12 @@ esp_err_t sdmmc_card_init(const sdmmc_host_t* config, sdmmc_card_t* card)
const bool is_mem = card->is_mem;
const bool is_sdio = !is_mem;
const bool ignore_data_crc = (config->flags & SDMMC_HOST_FLAG_SPI_IGNORE_DATA_CRC);
/* Enable CRC16 checks for data transfers in SPI mode */
SDMMC_INIT_STEP(is_spi, sdmmc_init_spi_crc);
if (!ignore_data_crc) {
/* Enable CRC16 checks for data transfers in SPI mode */
SDMMC_INIT_STEP(is_spi, sdmmc_init_spi_crc);
}
/* Use SEND_OP_COND to set up card OCR */
SDMMC_INIT_STEP(is_mem, sdmmc_init_ocr);
+5
View File
@@ -643,6 +643,11 @@ esp_err_t sdmmc_init_spi_crc(sdmmc_card_t* card)
*/
assert(host_is_spi(card));
esp_err_t err = sdmmc_send_cmd_crc_on_off(card, true);
if (err == ESP_ERR_NOT_SUPPORTED) { // Some cards fail to enable CRC on the first try, trying again
ESP_LOGD(TAG, "%s: enabling CRC failed with 0x%x, trying again", __func__, err);
vTaskDelay(SDMMC_INIT_SPI_CRC_RETRY_DELAY_MS / portTICK_PERIOD_MS);
err = sdmmc_send_cmd_crc_on_off(card, true);
}
if (err != ESP_OK) {
ESP_LOGE(TAG, "%s: sdmmc_send_cmd_crc_on_off returned 0x%x", __func__, err);
return err;