32K写入,4字节对齐
图1 4字节对齐
32K写入,不对齐
图2 不对齐
测试了下,以32K为大小写,对齐时平均速度6.4M/S,不对齐时200多K/S。不对齐时底层是memcpy和单页写,对齐时是多页写。
[mw_shl_code=c,true]/** @brief */
#define FATFS_WR_SIZE (32*1024)
#define FATFS_WR_CYCLE 1024
/** @brief */
FATFS fs;
/** @brief */
FIL f_txt;
//__align(4)
INT8U wbuffer[FATFS_WR_SIZE];
INT8U p[50];
extern u32 Tick;
INT8U res=0;
void SdcardTest(void)
{
INT32U bw=0;
INT32U time,speed;
sprintf((char*)p,"文件大小:%dKB",FATFS_WR_CYCLE*FATFS_WR_SIZE/1024);
LCD_ShowString(0,0,32,p);
LCD_ShowString(0,50,32,"写入耗时: ");
LCD_ShowString(0,100,32,"平均速度: ");
res = f_mount(&fs,"0:",1);
if(FR_OK == res)
{
res = f_open(&f_txt,"test.txt",FA_CREATE_ALWAYS|FA_WRITE);
if(FR_OK == res)
{
INT16U i;
Tick = 0;
for(i=0;i<FATFS_WR_CYCLE;i++)
{
res=f_write(&f_txt,wbuffer,FATFS_WR_SIZE,&bw);//写入BMP首部
if(res)break;
}
time = Tick/2;
}
f_close(&f_txt);
}
if(FR_OK == res)
{
sprintf((char*)p,"写入耗时:%dms",time);
LCD_ShowString(0,50,32,p);
speed = FATFS_WR_CYCLE*FATFS_WR_SIZE/time;
sprintf((char*)p,"平均速度:%dKB/s",speed);
LCD_ShowString(0,100,32,p);
LCD_ShowString(0,150,32,"测试完毕");
}
else
{
LCD_ShowString(0,150,32,"写入失败");
}
while(1);
}
[/mw_shl_code]