| 其中 
 [csharp] view plain copy
 print?
 
 
 SD_Initialize()  SD_ReadDisk(buff,sector,count)  SD_WriteDisk(buff,sector,count)  
 
 
 这个3个函数是在SD驱动文件里面的。 这样处理之后,如果直接编译的话,会出现get_fattime这个符号报错,是因为我们在ff.c里面使用到了这个函数,但是没有定义,所以最后的这个函数添加上去,但是没有实现具体功能的。 [csharp] view plain copy
 print?
 
 
 int get_fattime()  {      return 0;  }  
 至此就完成了底层函数的移植。那么接下来如何测试,我们的文件系统呢?
 
 三、首先贴上主函数,看是如何实现对我们文件的访问的 [csharp] view plain copy
 print?
 
 
 int main(void)  {            //初始化系统定时器      SysTick_Init();      USART1_Config();      SPIx_Init();                    //初始化SPI      printf("\r\n ("__DATE__ " - " __TIME__ ") \r\n");        res = f_mount(0,&fs);       //挂接根文件系统            if(res != FR_OK){          printf("mount filesystem 0 failed : %d\n\r",res);      }      //写文件测试      printf("write file test......\n\r");      res = f_open(&fdst, "0:/test.txt", FA_CREATE_ALWAYS | FA_WRITE);      if(res != FR_OK){          printf("open file error : %d\n\r",res);      }else{          res = f_write(&fdst, Test_Buffer, sizeof(Test_Buffer), &bw);               /* Write it to the dst file */          if(res == FR_OK){              printf("write data ok! %d\n\r",bw);          }else{              printf("write data error : %d\n\r",res);          }          /*close file */          f_close(&fdst);      }      //读文件测试      printf("read file test......\n\r");      res = f_open(&fsrc, "0:/test.txt", FA_OPEN_EXISTING | FA_READ);      if(res != FR_OK){          printf("open file error : %d\n\r",res);      }else{          res = f_read(&fsrc, buffer, sizeof(Test_Buffer), &br);     /* Read a chunk of src file */          if(res==FR_OK){              printf("read data num : %d\n\r",br);              printf("%s\n\r",buffer);          }else{              printf("read file error : %d\n\r",res);          }          /*close file */          f_close(&fsrc);      }  
 
 具体函数暂时不进行分析,等待分析执行流程的时候一并解决,现在关键是看现象,才有动力!如果这时候进行编译下载的话,会发现打印的信息是乱码,为什么呢?因为在
 
 ffconf.h文件里面默认的是支持日文的,所以对于文件名的支持类型,我们得修改呀! 修改的地方不多,如下两处: [csharp] view plain copy
 print?
 
 
 // #define _CODE_PAGE   932  #define _CODE_PAGE  936         //支持中文长文件名  // #define _CODE_PAGE   437         //只支持英文长文件名  // #define _USE_LFN 0         #define _USE_LFN    1           //支持中文长文件名  
 
 这样编译之后就没有问题了。
 
 
 暂时就到这里吧,算是初步成功了,一些类似于uboot或者shell更强大的功能,暂时不搞,分析完文件系统再说!
 
 |