本帖最后由 bu2zhouzhu 于 2014-2-19 09:57 编辑
楼主,为啥我写SD卡的速度特别慢呢?代码贴出来你看看。
这段是diskio.c里的disk_write()函数。
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
#if _READONLY == 0
DRESULT disk_write (
BYTE drv, /* Physical drive nmuber (0..) */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to write (1..255) */
)
{
if (count > 1)
{
SD_WriteMultiBlocks((uint8_t *)buff, sector*BLOCK_SIZE, BLOCK_SIZE, count);
/* Check if the Transfer is finished */
SD_WaitWriteOperation();
while(SD_GetStatus() != SD_TRANSFER_OK);
}
else
{
SD_WriteBlock((uint8_t *)buff,sector*BLOCK_SIZE, BLOCK_SIZE);
/* Check if the Transfer is finished */
SD_WaitWriteOperation();
while(SD_GetStatus() != SD_TRANSFER_OK);
}
return RES_OK;
}
#endif /* _READONLY */
这段是main()函数
int main(void)
{
int res;
FIL fdst;
FATFS fs;
UINT bw; // File R/W count
BYTE buffer[512]; // file copy buffer
CHAR Buf1 = 60;
CHAR Buf2 = 70;
int i;
f_mount(0,&fs);
res = f_open(&fdst, "0:/demo.txt", FA_READ | FA_WRITE | FA_OPEN_ALWAYS);
if ( res == FR_OK )
{
for(i=0;i<100;i++)
{
if((i%2)==0) GPIO_SetBits(GPIOC, GPIO_Pin_13); //PC13口为LED小灯,此灯闪烁
else GPIO_ResetBits(GPIOC, GPIO_Pin_13);
f_write(&fdst, &Buf1, sizeof(Buf1), &bw);
f_lseek(&fdst, fdst.fsize);
f_sync(&fdst);
f_write(&fdst, &Buf2, sizeof(Buf2), &bw);
f_lseek(&fdst, fdst.fsize);
f_sync(&fdst);
}
f_close(&fdst);
f_mount(0, NULL);
GPIO_SetBits(GPIOA, GPIO_Pin_0);
//PA0口为另一个LED小灯,写入SD卡完成点亮。从上电到此灯亮,i=100的情况下大概是1分钟。巨慢 - -||
}
while (1){}
}
我用的是V3.5固件库+V4.5 stm32_eval_sdio_sd.c,用示波器量SD卡CLK引脚是24Mhz,并且已确认是4bit、4个SD卡引脚在传输数据。可是上面写入200个8bit char 数据需要1分钟左右写完。(我用LED灯做的指示)
|