Fatfs delay at write at new sector
Fatfs delay at write at new sector
I created fatfs then I create a file and write data to it every 50 ms. I ran into a problem when the page defined by CONFIG_WL_SECTOR_SIZE_4096=y ends I get a system delay (around 100 ms) at which I miss even a few interrupts from the timer. Therefore, I lose data retrieval from the ADC and lose writing multiple lines to the log file. If I use CONFIG_WL_SECTOR_SIZE_512=y I get the same failure, but in 8 times more often. My log file should be up to 2 MB. How can I work around this problem?
Re: Fatfs delay at write at new sector
I'm no expert at fatfs, but I'd guess it has to do with the driver preparing/working with the media you're writing to. Disk I/O is generally slow, compared to anything else going on in an MCU.
Can you perhaps use a more compact disk format, or use an in-memory cache that writes to disk using another core than the one receiving the interrupts?
Can you perhaps use a more compact disk format, or use an in-memory cache that writes to disk using another core than the one receiving the interrupts?
Re: Fatfs delay at write at new sector
Before writing the sector it must be erased, and 4K sector erase time is 50-200 ms !brp80000 wrote: ↑Fri Dec 14, 2018 8:00 pmI created fatfs then I create a file and write data to it every 50 ms. I ran into a problem when the page defined by CONFIG_WL_SECTOR_SIZE_4096=y ends I get a system delay (around 100 ms) at which I miss even a few interrupts from the timer. Therefore, I lose data retrieval from the ADC and lose writing multiple lines to the log file. If I use CONFIG_WL_SECTOR_SIZE_512=y I get the same failure, but in 8 times more often. My log file should be up to 2 MB. How can I work around this problem?
If possible, use the SD Card to write the log file, it is much faster
Re: Fatfs delay at write at new sector
Now it is a big problem for me. I purchased 200 pieces of ESP32 with 32 MB of memory. And already ordered printed circuit boards. Can be there is still what the decision?
May be use flash without fatfs and use the command espartition_write() will the problem persist?
May be use flash without fatfs and use the command espartition_write() will the problem persist?
-
- Posts: 9764
- Joined: Thu Nov 26, 2015 4:08 am
Re: Fatfs delay at write at new sector
You can actually have interrupts running while flash is used, but you do need to take good care that the ISR never ever accesses anything flash-related (or psram-related, if you have that). See here for more info.
Re: Fatfs delay at write at new sector
I am use it
My opinion is that this is a MCU for smart home, not a CPU for data processing)))
- void IRAM_ATTR timer_group0_isr(void *para)
{
....
}
My opinion is that this is a MCU for smart home, not a CPU for data processing)))
Re: Fatfs delay at write at new sector
Aside from declaring the interrupt with IRAM_ATTR, you need to pass corresponding flag, ESP_INTR_FLAG_IRAM, to esp_intr_alloc or timer_driver_install.
Re: Fatfs delay at write at new sector
Writing directly to flash can be the solution.
You should erase the flash sectors range used for logging before using it.
Than you can write to the sector without erasing it first, and the 4K sector write operation is relatively fast, less than 1 ms.
So, writte data to 4K RAM buffer, when full, write to the Flash sector mantaining the buffer position and Flash sector number...
Re: Fatfs delay at write at new sector
1. It is not possible to do the same with FATFS, because I use formatting before starting to write a new log?
2. Could it be possible to use one core to prepare pages in fatfs while the second core will respond to interrupts and create a queue to write to flash?
3. If dont use Fatfs i need erase about 500 sector in flash is it no problem? And there is no guarantee that I use them when recording (log may end) at any time
2. Could it be possible to use one core to prepare pages in fatfs while the second core will respond to interrupts and create a queue to write to flash?
3. If dont use Fatfs i need erase about 500 sector in flash is it no problem? And there is no guarantee that I use them when recording (log may end) at any time
Re: Fatfs delay at write at new sector
See my interrupt
- void IRAM_ATTR timer_group0_isr(void *para) //
{
int timer_idx = (int) para;
TIMERG0.hw_timer[timer_idx].update = 1;
// Clear the interrupt
// and update the alarm time for the timer with reload
TIMERG0.int_clr_timers.t1 = 1;
// After the alarm has been triggered
// we need enable it again, so it is triggered the next time
TIMERG0.hw_timer[timer_idx].config.alarm_en = TIMER_ALARM_EN;
static portBASE_TYPE xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(xBinarySemaphore , &xHigherPriorityTaskWoken);
if( xHigherPriorityTaskWoken == pdTRUE)
{
portYIELD_FROM_ISR();
}
}
Who is online
Users browsing this forum: Google [Bot] and 114 guests