From 6c79bcfd6d8a2ae710a477ab81d1b33a75a99a8b Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 1 Jan 2024 22:18:08 +0100 Subject: [PATCH] fix(sdio): Check card state after each block written (#4500) --- radio/src/targets/common/arm/stm32/diskio_sdio.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/radio/src/targets/common/arm/stm32/diskio_sdio.cpp b/radio/src/targets/common/arm/stm32/diskio_sdio.cpp index 4b049feb4..4bc5d378e 100644 --- a/radio/src/targets/common/arm/stm32/diskio_sdio.cpp +++ b/radio/src/targets/common/arm/stm32/diskio_sdio.cpp @@ -282,7 +282,7 @@ static DRESULT _write_dma(const BYTE *buff, DWORD sector, UINT count) return RES_ERROR; } - // Wait that the reading process is completed or a timeout occurs + // Wait that the writing process is completed or a timeout occurs uint32_t timeout = HAL_GetTick(); while((WriteStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT)); @@ -312,6 +312,10 @@ static DRESULT sdio_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count) res = _write_dma((BYTE *)scratch, sector++, 1); if (res != RES_OK) break; buff += BLOCK_SIZE; + + if (sdio_check_card_state_with_timeout(SD_TIMEOUT) < 0) { + return RES_ERROR; + } } return res; }