Showing results for 
Search instead for 
Did you mean: 

disk_initialize() in FatFs library (ff.c/diskio.c) timing out

Associate III

I am trying to do disk i/o with a FAT32-formatted SD card (32GB ADATA) using SPI on a STM32H742VIT6.

The disk_initialize() function in diskio.c does not complete because it looks like the wait_ready() function is always timing out.

static int wait_ready(DWORD timeout_ms)
	BYTE d;
	Timer2 = timeout_ms;
	do {
		d = xchg_spi(0xFF);		
		/* This loop takes a time. Insert rot_rdq() here for multitask envilonment. */
	} while (d != 0xFF && Timer2);	/* Wait for card goes ready or timeout */
	return (d == 0xFF) ? 1 : 0;

I probed the SPI signals and see that MISO (output from SD card) is always 0x00 during this while loop.

Can anyone give me an idea what I should try?



0x00 isn't going to break out of the loop, going to have to look at what you're sending to the card prior and why you're not getting the response you expect.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

what I should try?

Find an SD card example for this or similar board? Build it, play with it?


Sorry, it's like the code indicates -- I'm sending 0xFF bytes repeatedly to the card and the while loop is executing until either it receives a 0xFF in return or the timer expires.  The timer is expiring every time because all the SD card seems to generate in response are 0x00's.


Sorry, before this loop I just send 80 dummy clocks to the SD card (sending 0xFF's while CS is held high).

The comment on the line of code that is not receiving the 0xFF response it expects is:

/* Put the card SPI/Idle state */

So that's what it's trying to do, FYI...