2023-09-11 10:30 PM
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?
2023-09-22 01:53 AM
Is the function correct in your opinion?
2023-09-22 04:05 AM
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.
2023-09-22 11:04 AM
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;
}