野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2047|回复: 2

FATFS系统移植出现的问题

[复制链接]
发表于 2023-5-9 15:56:46 | 显示全部楼层 |阅读模式
大佬们   在按照火哥出的视频中移植系统 到后面写入打开文件名以及中文文件名的部分时 出现在串口调试助手上的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错误

res错误
回复

使用道具 举报

发表于 2023-5-11 11:37:37 | 显示全部楼层
升级新的FATFS,把中文换成英文试试
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-5-18 16:01:07 | 显示全部楼层
lrz 发表于 2023-5-11 11:37
升级新的FATFS,把中文换成英文试试

谢谢大佬 这个问题我前一段找到答案了 是在移植的过程中我diskio.c文件中的读部分中地址做移位了 写那部分忘记了导致地址对不上 现在已经改好了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-4-27 09:14 , Processed in 0.067272 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表