cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H750 FATFS Label , File and Directory errors

Emre2blue
Associate II

hi,

I was trying to open Jpeg files from SD card and show them on LCD. LCD works, SDMMC works, I open the File System, I can read if its FAT32, I can read free space etc. But When I want to open a file or create a file on system it fails.

* I always get  FR_NO_FILE when I want to read a file.

* There is no error when I want to create a file and write something in it. But When I put the SD on PC There is no such file in it.

* Also I cannot read the label of the SDCard.

* Dcache disable & enable does not change the result.

Here is my Code sample :

** I've tried "0:" lately but it does not changed anything.  What should I do ?

void process_SD_card( void )
{
  FATFS       FatFs;                //Fatfs handle
  FIL         fil;                  //File handle
  FRESULT     fres;                 //Result after operations
  char        buf[100];
  FRESULT res;
  char buff[20];

  int x=0;
  do
  {
    //Mount the SD Card
    fres = f_mount(&FatFs, "0:", 1);    //1=mount now
    if (fres != FR_OK)
    {
      printf("No SD Card found : (%i)\r\n", fres);
      break;
    }
    printf("SD Card Mounted Successfully!!!\r\n");

    //Read the SD Card Total size and Free Size
    FATFS *pfs;
    DWORD fre_clust;
    uint32_t totalSpace, freeSpace;

    f_getfree("0:", &fre_clust, &pfs);
    totalSpace = (uint32_t)((pfs->n_fatent - 2) * pfs->csize * 0.5);
    freeSpace = (uint32_t)(fre_clust * pfs->csize * 0.5);

    printf("TotalSpace : %lu bytes, FreeSpace = %lu bytes\n", totalSpace, freeSpace);

    char str[12];

    f_getlabel("0:", str, 0);

   strcpy(buff, "/");
   res = list_dir(buff);


    //Open the file
    fres = f_open(&fil, "0:/emre.txt",  FA_WRITE | FA_CREATE_NEW);
    if(fres != FR_OK)
    {
      printf("File creation/open Error : (%i)\r\n", fres);
      break;
    }

    printf("Writing data!!!\r\n");
    //write the data
    f_puts("Welcome to EmbeTronicX", &fil);

    //close your file
    f_close(&fil);

    //Open the file
    fres = f_open(&fil, "1.txt", FA_READ);
    if(fres != FR_OK)
    {
      printf("File opening Error : (%i)\r\n", fres);
      break;
    }

    //read the data
    f_gets(buf, sizeof(buf), &fil);

    printf("Read Data : %s\n", buf);

    //close your file
    f_close(&fil);
    printf("Closing File!!!\r\n");

  } while( x );

  //We're done, so de-mount the drive
  f_mount(NULL, "", 0);
  printf("SD Card Unmounted Successfully!!!\r\n");
}

 

1 ACCEPTED SOLUTION

Accepted Solutions
Emre2blue
Associate II

Emre2blue_0-1737838079191.png

I think I've found the problem. I've turn to ANSI/OEM now. Everything works :D

View solution in original post

1 REPLY 1
Emre2blue
Associate II

Emre2blue_0-1737838079191.png

I think I've found the problem. I've turn to ANSI/OEM now. Everything works :D