Issue #9: Fix timeout bug in write block command

This commit is contained in:
Mario Hüttel 2020-08-21 00:00:08 +02:00
parent 45564a7789
commit 04994bff51

View File

@ -739,6 +739,7 @@ DRESULT sdio_disk_write(const BYTE *buff, DWORD sector, UINT count)
uint32_t buff_offset = 0; uint32_t buff_offset = 0;
int ret; int ret;
UINT count_backup = count; UINT count_backup = count;
uint32_t retry_counter = 512;
if (sdio_check_write_protection()) if (sdio_check_write_protection())
return RES_WRPRT; return RES_WRPRT;
@ -754,10 +755,18 @@ DRESULT sdio_disk_write(const BYTE *buff, DWORD sector, UINT count)
return RES_ERROR; return RES_ERROR;
} }
while (status.statusstruct.READY_FOR_DATA != 1) { while (1) {
ret = sdio_check_status_register_cmd13(card_info.rca, &status.value); ret = sdio_check_status_register_cmd13(card_info.rca, &status.value);
if (ret) if (ret)
return RES_ERROR; return RES_ERROR;
if (status.statusstruct.CURRENT_STATE == CURRENT_STATE_TRAN)
break;
if (--retry_counter == 0)
return RES_ERROR;
sdio_wait_ms(1);
} }
if (count > 1) if (count > 1)