FatFs下目录扫描出现问题了,高手帮忙啊

2019-03-25 20:33发布

在读取文件目录时,调用sprintf函数时,总是出错,不知问题在哪里,高手帮忙啊。 /**************************************************************************************
* FunctionName   : AppScanFiles()
* Description    : 扫描文件
* EntryParameter : path - 路径
* ReturnValue    : 成功返回-0;失败返回-1
**************************************************************************************/
FRESULT AppScanFiles(CHAR* path)
{
 FATFS fs;               /*Work area (file system object) for logical drive*/
    FRESULT res;
    FILINFO fno;
    DIR dir;
    int length;
    CHAR *fn;
    CHAR *pathName; #if _USE_LFN
    static char lfn[_MAX_LFN * (_DF1S ? 2 : 1) + 1];
    fno.lfname = lfn;
    fno.lfsize = sizeof(lfn);
#endif     f_mount(0, &fs);                               // 一定不能少     res = f_opendir(&dir, path);                   // 打开目录
    if (res == FR_OK)
    {
     length = strlen(path);                     // 获取目录长度
        for (;;)
        {
            res = f_readdir(&dir, &fno);           // 读目录
            if (res != FR_OK || fno.fname[0] == 0)
            {
             break;
            }             if (fno.fname[0] == '.')               // 一个点代表当前目录,两个点代表上级目
            {
             continue;
            } #if _USE_LFN   // 长文件名
            fn = *fno.lfname ? fno.lfname : fno.fname;
#else          // 短文件名
            fn = fno.fname;
#endif             if (fno.fattrib & AM_DIR)             // Directory
            {
                sprintf(&path[length], "/%s", fn);  //调用时出错!
                res = AppScanFiles(path);
                if (res != FR_OK) break;
                path[length] = 0;
            }
            else
            {
             UARTSendString(fn);                // 串口输出文件名
            }
        }
    }     f_mount(0, 0);
    return res;
}
  此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
7条回答
zhaojun_xf
1楼-- · 2019-03-25 23:47
_NXP LPC1000_

错误如下:

 

**** Build of configuration Debug for project FAT ****

make all
Building file: ../Source/app.c
Invoking: MCU C Compiler
arm-none-eabi-gcc -D__USE_CMSIS=CMSISv1p30_LPC11xx -DDEBUG -D__CODE_RED -I"E:LPC1114CMSISv1p30_LPC11xxinc" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m0 -mthumb -D__REDLIB__ -MMD -MP -MF"Source/app.d" -MT"Source/app.d" -o"Source/app.o" "../Source/app.c"
Finished building: ../Source/app.c
 
Building target: FAT.axf
Invoking: MCU Linker
arm-none-eabi-gcc -nostdlib -L"E:LPC1114CMSISv1p30_LPC11xxDebug" -Xlinker -Map=FAT.map -mcpu=cortex-m0 -mthumb -T "fat32_Debug.ld" -o"FAT.axf"  ./Source/app.o ./Source/cr_startup_lpc11.o ./Source/diskio.o ./Source/ff.o ./Source/gpio.o ./Source/main.o ./Source/sd.o ./Source/ssp.o ./Source/uart.o   -lCMSISv1p30_LPC11xx
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/bin/ld.exe: FAT.axf section .text will not fit in region MFlash32
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/bin/ld.exe: region MFlash32 overflowed by 14112 bytes
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(__fillbuf.o): In function `__filbuf':
__fillbuf.c:(" />.text.(float, int, long, bool, float __restrict)+0x88): undefined reference to `_Csyscall3'
__fillbuf.c:(" />.text.(float, int, long, bool, float __restrict)+0xf6): undefined reference to `_Csys_read_'
__fillbuf.c:(" />.text.(float, int, long, bool, float __restrict)+0x19e): undefined reference to `_Csyscall3'
__fillbuf.c:(" />.text.(float, int, long, bool, float __restrict)+0x1c2): undefined reference to `_Csyscall3'
__fillbuf.c:(" />.text.(float, int, long, bool, float __restrict)+0x1d8): undefined reference to `_Csyscall3'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(_deferredlazyseek.o): In function `__flsbuf':
_deferredlazyseek.c:(" />.text.(float, long, short, bool, float __restrict)+0xf8): undefined reference to `_Csyscall1'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(_ldexpl.o): In function `_ldexpl':
_ldexpl.c:(" />.text._ldexpl+0x64): undefined reference to `errno'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(_writebuf.o): In function `_Cwritebuf':
_writebuf.c:(" />.text._Cwritebuf+0x22): undefined reference to `_Csyscall3'
_writebuf.c:(" />.text._Cwritebuf+0x38): undefined reference to `_Csyscall3'
_writebuf.c:(" />.text._Cwritebuf+0x6e): undefined reference to `_Csyscall1'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(alloc.o): In function `malloc':
alloc.c:(" />.text.malloc+0x98): undefined reference to `_sbrk'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(error.o): In function `perror':
error.c:(" />.text.perror+0x80): undefined reference to `errno'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(error.o): In function `__assert':
error.c:(" />.text.__assert+0x32): undefined reference to `_Csyscall1'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(error.o): In function `_Csysdie':
error.c:(" />.text._Csysdie+0x26): undefined reference to `_Csyscall3'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(fseek.o): In function `fseek':
fseek.c:(" />.text.fseek+0x2a): undefined reference to `_Csyscall1'
fseek.c:(" />.text.fseek+0x9e): undefined reference to `_Csyscall1'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(ftell.o): In function `ftell':
ftell.c:(" />.text.ftell+0x4c): undefined reference to `errno'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(stdlib.o): In function `exit':
stdlib.c:(" />.text.exit+0x28): undefined reference to `_Csyscall1'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(raise.o): In function `raise':
raise.c:(" />.text.raise+0x6): undefined reference to `_Csyscall0'
raise.c:(" />.text.raise+0x10): undefined reference to `_Csyscall2'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(fclose.o): In function `fclose':
fclose.c:(" />.text.fclose+0x4e): undefined reference to `_Csyscall1'
fclose.c:(" />.text.fclose+0x74): undefined reference to `_Csys_tmpnam_'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(remove.o): In function `remove':
remove.c:(" />.text.remove+0x6): undefined reference to `_Csyscall1'
c:/nxp/lpcxpresso_3.3/tools/bin/../lib/gcc/arm-none-eabi/4.3.3/../../../../arm-none-eabi/lib/armv6-mlibcr_c.a(remove.o): In function `rename':
remove.c:(" />.text.rename+0xa): undefined reference to `_Csyscall2'
remove.c:(" />.text.rename+0x20): undefined reference to `_Csyscall1'
collect2: ld returned 1 exit status
make: *** [FAT.axf] Error 1

chenzhufly
2楼-- · 2019-03-26 04:39
内存不够用
chenzhufly
3楼-- · 2019-03-26 07:22
 精彩回答 2  元偷偷看……
zhaojun_xf
4楼-- · 2019-03-26 08:47
谢谢你的回复,哎,我就不喜欢用库函数,出了问题一点都不好把握!
zhaojun_xf
5楼-- · 2019-03-26 09:07
用你的方式也没有解决,还是出错。虽然我的程序可以正常运行了,我还是想知道为什么LPCXpresso中不能使用sprintf函数,难道是LPCXpresso库的问题?还是有别原因呢?
linxiaorui
6楼-- · 2019-03-26 14:31
楼主你的问题搞定了没?我也是这样找不了有目录下的文件,只能找到磁盘根目录下的文件

一周热门 更多>