小学生
最后登录1970-1-1
在线时间 小时
注册时间2023-5-9
|
大佬们 在按照火哥出的视频中移植系统 到后面写入打开文件名以及中文文件名的部分时 出现在串口调试助手上的res4、9错误的情况 是不是因为移植的FATFS的版本是0.15版本的原因 有可以解决的方法吗
下面是我这边的主程序
#include "stm32f4xx.h"
#include "./led/bsp_led.h"
#include "./usart/bsp_debug_usart.h"
#include "./flash/bsp_spi_flash.h"
#include "ff.h"
#include <string.h>
FATFS fs;
FRESULT res;
FIL fil;
UINT bw;
UINT br;
char buf[4096] = {0};
//char read_buf[100] ;
#define STR_WRITE "我爱健身"
#define STR_WRITE1 "我不爱健身"
/*
* 函数名:main
* 描述 :主函数
* 输入 :无
* 输出 :无
*/
int main(void)
{
LED_GPIO_Config();
LED_BLUE;
/* 配置串口1为:115200 8-N-1 */
Debug_USART_Config();
printf("\r\n这是一个SPI FLASH 文件系统实验 \r\n");
res = f_mount(&fs,"1:",1);
printf("fmount res=%d",res);
if(res == FR_NO_FILESYSTEM)
//格式化
{
res = f_mkfs("1:",0,buf,sizeof(buf));
printf("\r\n f_mkfs res=%d",res);
//格式化后需要重新挂载文件系统
res = f_mount(NULL,"1:",1);
res = f_mount(&fs,"1:",1);
}
res = f_open(&fil, "1:mes.txt", FA_CREATE_ALWAYS|FA_READ|FA_WRITE);
printf("\r\n f_open res=%d",res);
//写入文件(短文件名)
res = f_write(&fil,STR_WRITE,strlen(STR_WRITE)+1,&bw);
printf("\r\n f_write res=%d len=%d bw=%d",res,strlen(STR_WRITE)+1,bw);
res = f_close(&fil);
printf("\r\n f_close res=%d",res);
res = f_open(&fil, "1:Take me to the church.txt", FA_CREATE_ALWAYS|FA_READ|FA_WRITE);
printf("\r\n f_open res=%d",res);
//写入文件(长文件名)
res = f_write(&fil,STR_WRITE1,strlen(STR_WRITE1)+1,&bw);
printf("\r\n f_write res=%d len=%d bw=%d",res,strlen(STR_WRITE1)+1,bw);
res = f_close(&fil);
printf("\r\n f_close res=%d",res);
res = f_open(&fil, "1:中文文字", FA_CREATE_ALWAYS|FA_READ|FA_WRITE);
printf("\r\n f_open res=%d",res);
//写入文件(长文件名)
res = f_write(&fil,"你看你",50,&bw);
printf("\r\n f_write res=%d len=%d bw=%d",res,50,bw);
res = f_close(&fil);
printf("\r\n f_close res=%d",res);
//读取文件
res = f_open(&fil, "1:中文文字", FA_OPEN_EXISTING|FA_READ);
printf("\r\n f_open res=%d",res);
res = f_read(&fil,buf,50,&br);
printf("\r\n f_read res=%d br=%d",res,br);
printf("\r\n读取到的文件内容为:%s",buf);
res = f_close(&fil);
printf("\r\n f_close res=%d",res);
while(1);
|
-
res错误
|