mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
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:
@@ -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) */
|
||||
|
||||
@@ -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) ||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user