cancel
Showing results for 
Search instead for 
Did you mean: 

Facing an hanging issue with SD card directory Reading using FATFS

Abin
Associate III

Hai All,

The code is given here,

void fatfs_FileDirectory(void)
{
FRESULT res;
DIR dir;
FILINFO fno;
int nfile, ndir;
 
res = f_opendir(&dir,USERPath);                                       /*Open Directory*/
 
    if (res == FR_OK) {
    nfile = ndir = 0;
for (;;) {
printf("Started to read Directory\n");
    res = f_readdir(&dir, &fno);                    /* Read a directory item */
    printf("End to read Directory\n");
    if (res != FR_OK || fno.fname[0] == 0) break;  /* Error or end of directory */
    if (fno.fattrib & AM_DIR) {
           printf("   <DIRECTORY>   %s\n", fno.fname);
           ndir++;
    } else {                                /* File Size & File Name */
           printf("%10lu -> %s\n", fno.fsize, fno.fname);
           nfile++;
    }
}
}
}

-- This is the function which I ma using.

While reading the directory it will direct to the following function

FRESULT f_readdir (
DIR* dp, /* Pointer to the open directory object */
FILINFO* fno /* Pointer to file information to return */
)
{
FRESULT res;
DEFINE_NAMEBUF;
 
 
res = validate(dp); /* Check validity of the object */
 
if (res == FR_OK) {
 
if (!fno)
{
res = dir_sdi(dp, 0); /* Rewind the directory object */
}
else
{
INIT_BUF(*dp);
res = dir_read(dp, 0); /* Read an item */
 
printf("dir_read\n");
 
if (res == FR_NO_FILE) { /* Reached end of directory */
 
printf("NO FILE\n");
 
dp->sect = 0;
res = FR_OK;
}
if (res == FR_OK) { /* A valid entry is found */
 
printf("FILE available\n");
 
get_fileinfo(dp, fno); /* Get the object information */
 
printf("FILE INFO GOT\n");
 
res = dir_next(dp, 0); /* Increment index for next */
if (res == FR_NO_FILE) {
dp->sect = 0;
res = FR_OK;
}
}
FREE_BUF();
}
}
 
LEAVE_FF(dp->fs, res);
}

Here 

get_fileinfo(dp, fno); /* Get the object information */
function getting hanged.How to solve this issue.Please help me.
0 REPLIES 0