Fatfs delay at write at new sector

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Fatfs delay at write at new sector

Postby brp80000 » Fri Dec 14, 2018 8:00 pm

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?

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: Fatfs delay at write at new sector

Postby permal » Fri Dec 14, 2018 9:57 pm

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?

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: Fatfs delay at write at new sector

Postby loboris » Fri Dec 14, 2018 10:32 pm

brp80000 wrote:
Fri Dec 14, 2018 8:00 pm
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?
Before writing the sector it must be erased, and 4K sector erase time is 50-200 ms !
If possible, use the SD Card to write the log file, it is much faster

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: Fatfs delay at write at new sector

Postby brp80000 » Sat Dec 15, 2018 1:22 am

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?

ESP_Sprite
Posts: 9020
Joined: Thu Nov 26, 2015 4:08 am

Re: Fatfs delay at write at new sector

Postby ESP_Sprite » Sat Dec 15, 2018 3:40 am

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.

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: Fatfs delay at write at new sector

Postby brp80000 » Sat Dec 15, 2018 8:49 am

I am use it
  • void IRAM_ATTR timer_group0_isr(void *para)
    {
    ....
    }
This does not help to solve the problem, I lose interrupts.
My opinion is that this is a MCU for smart home, not a CPU for data processing)))

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: Fatfs delay at write at new sector

Postby ESP_igrr » Sat Dec 15, 2018 9:15 am

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.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: Fatfs delay at write at new sector

Postby loboris » Sat Dec 15, 2018 9:39 am

brp80000 wrote:
Sat Dec 15, 2018 1:22 am
May be use flash without fatfs and use the command espartition_write() will the problem persist?
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...

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: Fatfs delay at write at new sector

Postby brp80000 » Sat Dec 15, 2018 10:58 am

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

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: Fatfs delay at write at new sector

Postby brp80000 » Sat Dec 15, 2018 11:12 am

ESP_igrr wrote:
Sat Dec 15, 2018 9:15 am
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.
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();
    }
    }
what is the problem that it does not work during flash operations?

Who is online

Users browsing this forum: jonnny and 119 guests