Skip to content

Commit 16bc6b6

Browse files
KlievanPeter Tönz
authored andcommitted
[sg fromtree] SD: Implement sdhc_card_busy in SDHC SPI-driver
Currently, the sdhc_card_busy function is unimplemented in the SDHC SPI-driver. This causes some functions which rely on f_sync(), such as fs_close(), to fail as it will timeout the busy-check. This PR implements sdhc_card_busy by checking if the MISO-line is kept high to check if the SD-card is idle (not busy). Solves zephyrproject-rtos#49982 Signed-off-by: Ivan Herrera Olivares <[email protected]> (cherry picked from commit 2c2b8c3)
1 parent 0b9a858 commit 16bc6b6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

drivers/sdhc/sdhc_spi.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,27 @@ static int sdhc_spi_init_card(const struct device *dev)
151151
return ret;
152152
}
153153

154+
/* Checks if SPI SD card is sending busy signal */
155+
static int sdhc_spi_card_busy(const struct device *dev)
156+
{
157+
const struct sdhc_spi_config *config = dev->config;
158+
struct sdhc_spi_data *data = dev->data;
159+
int ret;
160+
uint8_t response;
161+
162+
163+
ret = sdhc_spi_rx(config->spi_dev, data->spi_cfg, &response, 1);
164+
if (ret) {
165+
return -EIO;
166+
}
167+
168+
if (response == 0xFF) {
169+
return 0;
170+
} else
171+
return 1;
172+
173+
}
174+
154175
/* Waits for SPI SD card to stop sending busy signal */
155176
static int sdhc_spi_wait_unbusy(const struct device *dev,
156177
int timeout_ms,
@@ -732,6 +753,7 @@ static struct sdhc_driver_api sdhc_spi_api = {
732753
.get_host_props = sdhc_spi_get_host_props,
733754
.get_card_present = sdhc_spi_get_card_present,
734755
.reset = sdhc_spi_reset,
756+
.card_busy = sdhc_spi_card_busy,
735757
};
736758

737759

0 commit comments

Comments
 (0)