STC32G144K246 SPI接口读取TF卡测试,FATFS读取TF卡上一个2MB多文件,每次读取8KB,直至文件结束。
直接读到RAM缓冲区不做任何处理。
原始demo程序,SPI时钟频率10MHz,增加如下代码测量速度。
- void speedTest(const char *rootPath)
- {
- uint16_t br;
- uint32_t total, time;
-
- f_open(&file, str_concat(rootPath, "/test.dat"), FA_READ);
- printf("打开文件并读取文件内容\n");
-
- sec = 0;
- Timer1_Init();
-
- total = 0;
- LED = 1;
- do
- {
- f_read(&file, testbuf, 8192, &br);
- total += br;
- }while(br == 8192);
- LED = 0;
-
- TR1 = 0;
- ET1 = 0;
- time = (((TH1*256+TL1) - 151) * 1000UL)/(65536UL - 151);
- time += sec*1000;
-
- f_close(&file);
- printf("file read %ld byte : %ld ms.\n", total, time);
- }
复制代码
测量结果如下
文件大小2124765字节,耗时5.078秒,平均速度约408KB/S。
|