cancel
Showing results for 
Search instead for 
Did you mean: 

Slow block read with SPI fatfs

frnt
Senior

Hello,

I measured the performance of uSD card connected through the SPI on Read/Write operation.

The weird thing is that the Block read speed is 3x to 4x slower than the write speed.  I'm writing/read 4kB of data and the SD card is formatted with 4kB allocation unit.

The SPI transaction of the 4k write is about 5-7ms, when considering the SPI transaction of the block read it takes about 20ms.

Does someone have an idea of what the issues can be?

12 REPLIES 12

Is the function correct in your opinion?

I use FAT FS library (from FW from ST). It seems OK, but it is not clear in your code where you send the CMD to the SD card for block reading.

I'm sorry, here is the code of the read with CMDs sent:

DRESULT SD_disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count) 
{
	/* pdrv should be 0 */
	if (pdrv || !count) return RES_PARERR;

	/* no disk */
	if (Stat & STA_NOINIT) return RES_NOTRDY;

	/* convert to byte address */
	if (!(CardType & CT_SD2)) sector *= 512;

	SELECT();

	if (count == 1)
	{
		/* READ_SINGLE_BLOCK */
		if ((SD_SendCmd(CMD17, sector) == 0) && SD_RxDataBlock(buff, 512)) count = 0;
	}
	else
	{
		/* READ_MULTIPLE_BLOCK */
		if (SD_SendCmd(CMD18, sector) == 0)
		{
			do {
				if (!SD_RxDataBlock(buff, 512)) break;
				buff += 512;
			} while (--count);

			/* STOP_TRANSMISSION */
			SD_SendCmd(CMD12, 0);
		}
	}

	/* Idle */
	DESELECT();
	SPI_RxByte();

	return count ? RES_ERROR : RES_OK;
}