Horns
Horns

Reputation: 21

STM32F429, FatFs, f_write. Creating a lot of files in a loop with f_write, after several entries FR_DISK_ERR

I'm trying to save lot of files at SD card in the loop with f_write function form FatFs libery, unfortunately after max 50 loop entries f_write returns FR_DISK_ERR.

Making one test took over 30 minutes, so I made Enity Test, which saves 10,000 files on the SD card, the program still saves < 50 files.

for(uint16_t i = 0; i < 10000; ++i){

    if(f_mount(&mfs,"0:",0) != FR_OK){

        to_int.put_str("Mount error");
        break;

    }

    if(f_chdrive("0:" ) != FR_OK){

        to_int.put_str("Oper error");
        break;

    }

    sprintf(f_name, "test%d.txt", i);
    if(f_open(&fil, f_name, FA_WRITE | FA_CREATE_ALWAYS)!= FR_OK){

        to_int.put_str("Write error");
        break;

    }

    if(f_write(&fil, wtext, sizeof(wtext), (void *)&wbytes) != FR_OK){ //<------FR_DISK_ERR

        to_int.put_str("Write Error\n");
        break;

    }

    f_sync(&fil);
    f_close(&fil);
    f_mount(0, "0:", 0);

    to_int.put_str(f_name);\
    to_int.put_str(" writed!\n");

}

Upvotes: 0

Views: 926

Answers (1)

James Novorita
James Novorita

Reputation: 86

So it appears that this could potentially be a stack size issue, especially if you can repeat this right at 50. What do you have your stack size configured at? The third party FATFS used by ST has issues when reading and writing large numbers of files if you don't have enough stack space.

Increase your stack size and it should work just fine.

Upvotes: 0

Related Questions