cancel
Showing results for 
Search instead for 
Did you mean: 

Having a difficult time using SPI SD-card with STM32F446

CBarb.1
Associate III

I am having a very difficult time trying to read the file directory using the code I got from the web. I am able to get most SD card functions to work and I actually get the read directory function to work the first time but it only reads 6 of the 10 files on the directory after I do one read it no longer will read the file directory because when I do. if (res == FR_OK) I get a error code: FR_TOO_MANY_OPEN_FILES so I can no longer read the file directory...Any ideas as to what may be causing this issue?? I got more of the code from: https://github.com/eziya/STM32_SPI_SDCARD.

Unfortunately where I downloaded the SDfat files there is no place to ask any questions or post for help.Any suggestions will be greatly appreciated.

The lines of code in question are below:

if(response == '5')

    {

    printf("\n\rFile directory contains: \n\r"); // %s \n\r",buff);

    f_mount(&fs, "",0);

    if(fresult == FR_OK) {     // gives me -------> 'FR_TOO_MANY_OPEN_FILES" after first read of directory so it will not read

     fresult = scan_files(buff); }

    printf("Total Space on this SD disk: %lu \n\r", totalSpace);

    printf("Total Free Space on this SD disk: %u \n\r", freeSpace);

    }

   

   

   

   

   

   

   

   

   FRESULT scan_files (char* path)   /* Start node to be scanned (***also used as work area***) */

{

  FRESULT res;

  DIR dir;

  UINT i;

  static FILINFO fno;

  res = f_opendir(&dir, path);           /* Open the directory */

  if (res == FR_OK) {

    for (;;) {

      res = f_readdir(&dir, &fno);         /* Read a directory item */

      if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */

      if (fno.fattrib & AM_DIR) {          /* It is a directory */

        i = strlen(path);

        sprintf(&path[i], "/%s", fno.fname);

        res = scan_files(path);          /* Enter the directory */

        if (res != FR_OK) break;

        path[i] = 0;

      } else {                   /* It is a file. */

        printf("%s/%s\n\r", path, fno.fname);

      }

    }

    f_closedir(&dir);

  }

   ////////////////// get disk space parameters ////////////////

   f_getfree("", &fre_clust, &pfs);

   totalSpace = (uint32_t)((pfs->n_fatent - 2) * pfs->csize * 0.5);

   freeSpace = (uint32_t)(fre_clust * pfs->csize * 0.5);

  return res;

}

0 REPLIES 0