fflush() and fsync() don't really write data to SD card

Weizzh
Posts: 9
Joined: Mon Nov 22, 2021 9:32 am

fflush() and fsync() don't really write data to SD card

Postby Weizzh » Tue Jan 25, 2022 2:33 am

ESP32 WROVER, IDF 4.2
Hi there,
I want to write heavy data to SD card, about 10k*20 per second. Since I have to get data continually from other tasks, I use fflush() and fsync() following fwrite() in a loop. But when I turn off the esp32, I found the data file size was 0. So I am obliged to use fclose() and fopen() every several fwrite(). Then I get a system crash after several munites, and when I check the data on SD card, I observe some data loss. Maybe using fclose() and fopen() frequently are not efficient and robust.
So what is the right way of writing data to SD card continually without knowing the end time?

Who is online

Users browsing this forum: Bing [Bot], ClosedLoop, dengbq and 36 guests