From 795efccf753c1993b4b30c1a041fcb06069c409e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=A1lvez?= Date: Fri, 2 Nov 2018 12:39:32 +0100 Subject: [PATCH] Fix SD-Card initialization process After command ACMD41 was being sent we were not waiting for the error idle state bit being cleared, so we were really never going out from the initialization phase. --- include/sd_card.h | 4 ++++ spi/mmc.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/sd_card.h b/include/sd_card.h index ec6d582..b58fd7c 100644 --- a/include/sd_card.h +++ b/include/sd_card.h @@ -42,4 +42,8 @@ extern void sd_card_init(void); //#define CT_SDC (CT_SD1|CT_SD2) /* SD */ #define CT_BLOCK 0x08 /* Block addressing */ +/* SD error code bits */ +#define SD_ERR_IDLE_STATE 0x01 +#define SD_ERR_ILLEGAL_CMD 0x04 + #endif /* _SD_CARD_H_ */ diff --git a/spi/mmc.c b/spi/mmc.c index 8819b59..1f20ddd 100644 --- a/spi/mmc.c +++ b/spi/mmc.c @@ -424,7 +424,7 @@ DSTATUS disk_initialize(uint8_t drv) while (MCF_SLT_SCNT(0) - target > 0) { res = send_cmd(ACMD41, 1UL << 30); /* Wait for end of initialization with ACMD41(HCS) */ - if (res != 0xff) + if ((res & SD_ERR_IDLE_STATE) == 0) break; } debug_printf("res = %d\r\n", res);