Skip to content

Commit

Permalink
Merge branch 'bugfix/sdspi_acmd41_arg_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
fix(sdmmc): fixes for card initialization (ACMD41) (v5.1)

See merge request espressif/esp-idf!29377
  • Loading branch information
jack0c committed Mar 15, 2024
2 parents 59d686e + 7c20d54 commit b2123cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions components/sdmmc/sdmmc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,27 @@ esp_err_t sdmmc_init_ocr(sdmmc_card_t* card)
*/

uint32_t host_ocr = get_host_ocr(card->host.io_voltage);

/* In SPI mode, the only non-zero bit of ACMD41 is HCS (bit 30)
* In SD mode, bits 23:8 contain the supported voltage mask
*/
uint32_t acmd41_arg = 0;
if (!host_is_spi(card)) {
acmd41_arg = host_ocr;
}

if ((card->ocr & SD_OCR_SDHC_CAP) != 0) {
host_ocr |= SD_OCR_SDHC_CAP;
acmd41_arg |= SD_OCR_SDHC_CAP;
}

/* Send SEND_OP_COND (ACMD41) command to the card until it becomes ready. */
err = sdmmc_send_cmd_send_op_cond(card, host_ocr, &card->ocr);
err = sdmmc_send_cmd_send_op_cond(card, acmd41_arg, &card->ocr);

/* If time-out, re-try send_op_cond as MMC */
if (err == ESP_ERR_TIMEOUT && !host_is_spi(card)) {
ESP_LOGD(TAG, "send_op_cond timeout, trying MMC");
card->is_mmc = 1;
err = sdmmc_send_cmd_send_op_cond(card, host_ocr, &card->ocr);
err = sdmmc_send_cmd_send_op_cond(card, acmd41_arg, &card->ocr);
}

if (err != ESP_OK) {
Expand Down
2 changes: 1 addition & 1 deletion components/sdmmc/sdmmc_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
/* Maximum retry/error count for SEND_OP_COND (CMD1).
* These are somewhat arbitrary, values originate from OpenBSD driver.
*/
#define SDMMC_SEND_OP_COND_MAX_RETRIES 100
#define SDMMC_SEND_OP_COND_MAX_RETRIES 300
#define SDMMC_SEND_OP_COND_MAX_ERRORS 3

/* supported arguments for erase command 38 */
Expand Down

0 comments on commit b2123cc

Please sign in to comment.