小学生
最后登录1970-1-1
在线时间 小时
注册时间2019-12-7
|

楼主 |
发表于 2019-12-8 10:32:39
|
显示全部楼层
main.c文件如下
- #include "stm32f10x.h"
- #include "./usart/bsp_usart.h"
- #include "./led/bsp_led.h"
- #include "./flash/bsp_spi_flash.h"
- #include "ff.h" /* Declarations of FatFs API */
- FATFS fs;
- FIL fp;
- UINT bw;
- UINT br;
- const char wData[]="欢迎使用野火开发板!";
- char rData[4096]="";
- /*
- * 函数名:main
- * 描述 :主函数
- * 输入 :无
- * 输出 :无
- */
- int main(void)
- {
- FRESULT res;
- LED_GPIO_Config();
- LED_BLUE;
-
- /* 配置串口为:115200 8-N-1 */
- USART_Config();
- printf("\r\n这是一个 FATFS文件系统移植实验 \r\n");
-
- res = f_mount(&fs,"1:",1);
-
- printf("f_mount res=%d\n",res);
-
- if(res==FR_NO_FILESYSTEM)
- {
- res=f_mkfs("1:",0,0);
- printf("\r\nf_mkfs res=%d\n",res);
-
- //格式化后要取消挂载再重新挂载
- res = f_mount(NULL,"1:",1);
- res = f_mount(&fs,"1:",1);
-
- printf("\r\nsecond f_mount res=%d\n",res);
- }
-
- res=f_open(&fp,"1:abcd.txt",FA_OPEN_ALWAYS|FA_READ|FA_WRITE );
- printf("f_open res=%d\n",res);
- if(res==FR_OK )
- {
- res=f_write(&fp,wData,sizeof(wData),&bw);
- printf("\r\nbw=%d",bw);
- if(res==FR_OK )
- {
- f_lseek(&fp,0);
- res=f_read(&fp,rData,f_size(&fp),&br);
-
- if(res==FR_OK )
- {
- printf("\r\n文件内容:%s br=%d",rData,br);
- }
- }
- }
- f_close(&fp);
-
- while(1);
- }
复制代码 |
|