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

zhaojun_xf   2010-5-28 20:19 楼主

在读取文件目录时,调用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)

错误如下:

 

**** 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:\LPC1114\CMSISv1p30_LPC11xx\inc" -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:\LPC1114\CMSISv1p30_LPC11xx\Debug" -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-m\libcr_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-m\libcr_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-m\libcr_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-m\libcr_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-m\libcr_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-m\libcr_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-m\libcr_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-m\libcr_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-m\libcr_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-m\libcr_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-m\libcr_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-m\libcr_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-m\libcr_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-m\libcr_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-m\libcr_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

点赞  2010-5-28 20:20
内存不够用
生活就是油盐酱醋再加一点糖,快活就是一天到晚乐呵呵的忙 =================================== 做一个简单的人,踏实而务实,不沉溺幻想,不庸人自扰
点赞  2010-5-29 00:55
生活就是油盐酱醋再加一点糖,快活就是一天到晚乐呵呵的忙 =================================== 做一个简单的人,踏实而务实,不沉溺幻想,不庸人自扰
点赞  2010-5-29 01:55

回复 4楼 chenzhufly 的帖子

谢谢你的回复,哎,我就不喜欢用库函数,出了问题一点都不好把握!
点赞  2010-5-29 05:44

回复 板凳 chenzhufly 的帖子

用你的方式也没有解决,还是出错。虽然我的程序可以正常运行了,我还是想知道为什么LPCXpresso中不能使用sprintf函数,难道是LPCXpresso库的问题?还是有别原因呢?
点赞  2010-6-2 14:20
楼主你的问题搞定了没?我也是这样找不了有目录下的文件,只能找到磁盘根目录下的文件
点赞  2012-3-19 19:59
sprintf函数还没用过哦,,楼主开始研究M3了呢,你的M0书我刚买了,才看一点点。
点赞  2012-3-21 14:30
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复