Skip to main content
Visitor II
December 9, 2023
Question

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

  • December 9, 2023
  • 2 replies
  • 1833 views

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?

Thanks,
-Brian

    This topic has been closed for replies.

    2 replies

    Graduate II
    December 9, 2023

    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.

    briankazAuthor
    Visitor II
    December 10, 2023

    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.

    -Brian

    Super User
    December 9, 2023

    what I should try?

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