在读取文件目录时,调用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;
}
此帖出自
小平头技术问答
错误如下:
**** 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
一周热门 更多>