From 9a63abc5c606bdb9582c4fe70262c101037e9cf0 Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Tue, 13 Dec 2022 09:22:27 -0600 Subject: [PATCH] sd: utilize sdmmc_wait_ready with SPI mode. Update sdmmc framework to use sdmmc_wait_ready when accessing card in SPI mode. this will allow cards that do not return to ready to be polled for busy status until the SD data timeout expires Fixes #52931 Signed-off-by: Daniel DeGrasse --- subsys/sd/sdmmc.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/subsys/sd/sdmmc.c b/subsys/sd/sdmmc.c index f2614419ce6..a383288f0d8 100644 --- a/subsys/sd/sdmmc.c +++ b/subsys/sd/sdmmc.c @@ -1248,13 +1248,11 @@ static int sdmmc_read(struct sd_card *card, uint8_t *rbuf, } /* Verify card is back in transfer state after read */ - if (!card->host_props.is_spi) { - ret = sdmmc_wait_ready(card); - if (ret) { - LOG_ERR("Card did not return to ready state"); - k_mutex_unlock(&card->lock); - return -ETIMEDOUT; - } + ret = sdmmc_wait_ready(card); + if (ret) { + LOG_ERR("Card did not return to ready state"); + k_mutex_unlock(&card->lock); + return -ETIMEDOUT; } return 0; } @@ -1403,13 +1401,7 @@ static int sdmmc_write(struct sd_card *card, const uint8_t *wbuf, ret = sdhc_request(card->sdhc, &cmd, &data); if (ret) { LOG_DBG("Write failed: %d", ret); - if (card->host_props.is_spi) { - /* Just check card status */ - ret = sdmmc_read_status(card); - } else { - /* Wait for card to be idle */ - ret = sdmmc_wait_ready(card); - } + ret = sdmmc_wait_ready(card); if (ret) { return ret; } @@ -1422,13 +1414,7 @@ static int sdmmc_write(struct sd_card *card, const uint8_t *wbuf, return -EIO; } /* Verify card is back in transfer state after write */ - if (card->host_props.is_spi) { - /* Just check card status */ - ret = sdmmc_read_status(card); - } else { - /* Wait for card to be idle */ - ret = sdmmc_wait_ready(card); - } + ret = sdmmc_wait_ready(card); if (ret) { LOG_ERR("Card did not return to ready state"); return -ETIMEDOUT;