liblitesdcard/sdcard: add timeout when waiting card to be ready.

This commit is contained in:
Florent Kermarrec 2020-07-06 20:07:06 +02:00
parent 31d4d7c22c
commit e473c6f29e
1 changed files with 6 additions and 2 deletions

View File

@ -448,6 +448,7 @@ void sdcard_decode_csd(void) {
int sdcard_init(void) { int sdcard_init(void) {
unsigned short rca; unsigned short rca;
uint16_t timeout;
/* initialize freq */ /* initialize freq */
sdcard_set_clk_freq(16000000); sdcard_set_clk_freq(16000000);
@ -461,15 +462,18 @@ int sdcard_init(void) {
busy_wait(1); busy_wait(1);
sdcard_send_ext_csd(); sdcard_send_ext_csd();
/* wait for card to be ready */ /* wait for card to be ready */
/* FIXME: 1.8v support */ timeout = 10;
for(;;) { while (timeout) {
sdcard_app_cmd(0); sdcard_app_cmd(0);
sdcard_app_send_op_cond(1, 0); sdcard_app_send_op_cond(1, 0);
if (sdcard_response[3] & 0x80000000) { if (sdcard_response[3] & 0x80000000) {
break; break;
} }
busy_wait(1); busy_wait(1);
timeout--;
} }
if (timeout == 0)
return 0;
/* send identification */ /* send identification */
sdcard_all_send_cid(); sdcard_all_send_cid();