garfield

【原创】k60读写sdhc测试程序

0
阅读(5723)

发一个SDHC测试程序,FATFS文件

有关SDHC的速度,手册里是这样写的

1332338330_de793ebe

根据我测试的数据,加入文件系统后连续写可以达到5M/s,

因为我的RTC模块没有电池,所以也就没有修改文件系统的文件创建时间属性

 

工程说明

note:K60N512工程模版,
               使用50MHz晶振,系统时钟100MHz,总线50M
      ISR.h 中先撤销中断向量,再重新定义中断名称,已定义大部分中断,以后要使用其他的重新定义即可
      GPIO测试:最小系统板上LED接在PTA 4
                                       四个测试按键,采用下降沿中断     分别接在PTB 20,21,22,23
                                        按下产生中断,通过串口四向PC发送信息
               串口四配置:波特率115200,8位数据                 
      SDHC时钟频率25M         
designer:

时间:

main函数:

//头文件
#include "includes.h"
#include "ff.h"
#include "SD_API.h"

//********************************************************************
//文件系统相关定义
struct WSNSTATE  //
{
unsigned diskok:1; //

unsigned fileok:1; //
unsigned record:1; //
unsigned position:1; //
};

volatile struct WSNSTATE state; //
FATFS fs;            // Work area (file system object) for logical drive
DIR dirs;
FRESULT res;         // FatFs function common result code
UINT br,bw;         // File Write count
FIL faddata;  //

unsigned char filebuff[512]={0}; //文件缓存
uint16 filebuffoffset = 512;

//主函数
void main(void)
{

    uint32 run_counter;         //运行计数器
    uint16 i;
    uint8 filelist = 1;
    DisableInterrupts;       //禁止总中断
    SYS_Init(); 
    EnableInterrupts;  
    res = f_mount(0,&fs);      // for logical drive 0
    hw_uart_send_string(UART_TEST,"系统初始化完成\n");

     for(i=0;i<512;i++)
                  {            
                   filebuff[i] = 'x';       
                  }
             filebuff[511] = '\n';
        res = f_open(&faddata,"data.txt",FA_CREATE_ALWAYS | FA_WRITE);   
           for(i=0;i<100;i++)
             {
                res = f_lseek(&faddata,f_size(&faddata));             //写指针移到文件末尾
                 res = f_write(&faddata,filebuff,filebuffoffset, &bw);            //将文件缓冲区里的数据写入data.txt
            } 
     res = f_close(&faddata);         //关闭data.txt
//    ListFiles(&filelist); //将文件系统的文件列出菜单,以及创建时间等详细内容    
   for(;;)
    {

        run_counter++;
        if(run_counter >= 5000000)
        {
            run_counter = 0;
            light_change(Light_Run_PORT, Light_Run4);
        }
   } //end_for
} //end_main