20 Replies Latest reply on Apr 27, 2017 3:22 PM by lewis.william

    Problem with FatFs and STM32Cube_FW_F7_V1.6.0 (Possible STM32Cube Bug)

    Lori B.

      Hi all! I'm trying to interface a STM32F7 with an 32 GB SDHC card, using the latest firmware libraries.

      I'm using a STM32f746G DISCO and I started from the project under STM32746G-Discovery/Appllications/FatFs/FatFs_uSD..

       I wrote a simple function and I executed it in the main after linking the driver and mounting the disk, to test reliability. The function is the following, where I write 1000 files in a loop..


      ErrorStatus Test(void)
      FIL MyFile;
      FRESULT res;
      uint32_t byteswritten;
      TCHAR StringPath[100] = {0};

      while(cont < 1000)
      sprintf((char*)StringPath,"File%d.fil", cont);

      res = f_open(&MyFile, StringPath, FA_CREATE_ALWAYS | FA_WRITE);
      if(res !=FR_OK)
      return ERROR;

      res = f_write(&MyFile, (void*)TempBuffer, sizeof(TempBuffer), (void *)&byteswritten);
      if((byteswritten == 0) || (res != FR_OK))
      return ERROR;


      return SUCCESS;



      TempBuffer is a global uint8_t buffer of size 51200.

      The problem is that after correctly writing some files, f_write returns "FR_DISK_ERR" and I can't understand why..

      Decreasing the buffer's size seems to allow a bigger number of files to be written before the error, but it doesn't solve it...


      Actually the problem is part of a much bigger project, but since I'm trying to understand what's wrong, I'm trying to keep things as simple as possible. That's why I took a STM32Cube project and left it untouched apart from the function I wrote.. But I really can't get the point of this problem anymway..Any idea?

      I'm not using DMA, nor SD peripheral interrupt (as in the example).. The file ffconf.h is left untouched with _USE_LFN = 0, _USE_STRFUNC=2, _MIN_SS=__MAX_SS=512.. Systick priority is as low as possible (0x0F)..