FatFs unrealiable under high load on STM32H743
Hello,
I am using a STM32H743 with a W25Q128 external flash memory running FreeRTOS and FatFs. USB is configured for mass storage, to copy files from a computer to the flash memory. The following function is used to list all the files and directories in a directory and put them in a list:
void IndexFilesInDir(const char *path, SFileMgrList* psReturnList)
{
FRESULT res;
DIR dir;
FILINFO fno;
uint8_t u8Count = 0;
res = f_opendir(&dir, path); /* Open the directory */
if(strlen(path) != 0)
{
strcpy(&psReturnList->cFilename[0][0], "...");
psReturnList->bIsDir[0] = true;
psReturnList->bHasParentDirectory = true;
u8Count++;
}
else
{
psReturnList->bHasParentDirectory = false;
}
if (res == FR_OK) {
for (;;) {
res = f_readdir(&dir, &fno); /* Read a directory item */
if (res != FR_OK || fno.fname[0] == 0 || u8Count >= 128) break; /* Error or end of dir */
if (fno.fattrib & AM_DIR && strstr(fno.fname, "System Volume Information") == NULL)
{
psReturnList->bIsDir[u8Count] = true;
strcpy(&psReturnList->cFilename[u8Count][0], fno.fname);
u8Count++;
}
else
{
char *dot = strrchr(fno.fname, '.');
// Is this a .wav file?
if (dot != NULL && strcmp(dot, ".wav") == 0)
{
psReturnList->bIsDir[u8Count] = false;
strcpy(&psReturnList->cFilename[u8Count][0], fno.fname);
u8Count++;
}
}
}
psReturnList->endIndex = u8Count;
f_closedir(&dir);
} else {
printf("Failed to open \"%s\". (%u)\n", path, res);
}
}
This is based on the example from the FatFs website. Everything works fine until I start processing some audio data (= lots of SAI DMA interrupts). Then f_readdir returns random garbage or does not all the files or it lists files from another directory from time to time. Here's what I've tried and observed:
- Disabling the caches doesn't solve or change the problem.
- Reading and writing files via USB always works perfectly fine, even under high load conditions. I conclude from this that my low level SPI driver for the W25Q128 works fine.
- FatFs is only used in one Task.
- The microcontroller is not overloaded, other RTOS Tasks still work fine. Temporarily removing all the other tasks does not help or change anything.
Does anyone have any idea what could be causing this behavior?
Thanks!
