硬件环境:神州一号开发板
软件环境:mdk
1、sd卡初始化
2、f_mount
3、扫描函数如下:
#define _USE_LFN 0
FRESULT scan_files (char* path)
{
FRESULT res;
FILINFO fno;
DIR dir;
int i;
char *fn;
#if _USE_LFN
static char lfn[_MAX_LFN * (_DF1S ? 2 : 1) + 1];
fno.lfname = lfn;
fno.lfsize = sizeof(lfn);
#endif
res = f_opendir(&dir, path);
if (res == FR_OK)
{
i = 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)
{
sprintf(&path[i], "/%s", fn);
res = scan_files(path);
if (res != FR_OK) break;
path[i] = 0;
}
else {
//printf("%s/%s\n", path, fn);
//USART1_Puts(path);
USART1_Puts(fn);//输出指定文件夹下的文件名称
USART1_Puts("\r\n");
}
}
}
else
{
USART1_Puts("open dir failed\n");
}
return res;
}
4、如果扫描卡的music目录下的文件,则
scan_files("music");即可