AnsweredAssumed Answered

FatFs fails randomly with V1.11

Question asked by Lars Beiderbecke on May 11, 2018
Latest reply on May 13, 2018 by Clive Two.Zero

I'm using FatFs with SDMMC1 on a Nucleo STM32F722ZE with CubeMX 4.25.


My project uses FatFs to manipulate a MicroSD card, but I noticed that many operations just fail randomly, usually with FR_DISK_ERR.  For example, in this code snippet published my ElmChan to copy files


// example: fcopy("file1", "folder/file1"):

f_open(&src->fh, from_path, FA_READ);  // src, dst are global
f_open(&dst->fh, to_path, FA_WRITE | FA_CREATE_ALWAYS);  // to_path is file
while (1) {
  f_read(&src->fh, buffer, sizeof(buffer), &br);
  if (br == 0)
    break; // eof
  f_write(&dst->fh, buffer, br, &bw);  // <-------------------------------


the f_write would often fail when running in Run or in Debug mode.  On the other hand, it usually works when single stepping through this code.


But there are other functions that may fail, for example f_readdir().


I do not use DMA, not RTOS, and disabled the SDMMC1 interrupt. I'm using the stock function generated by CubeMX.


How can I fix the failing functions? Are FatFs functions executed serialized, or can two functions execute interleaved concurrently?