esp_vfs_spiffs_register causing TWDT panic?

0xffff
Posts: 41
Joined: Tue Jun 19, 2018 1:53 am

esp_vfs_spiffs_register causing TWDT panic?

Postby 0xffff » Thu Jul 12, 2018 6:34 am

Hi,

I have some code to mount the spiffs:

Code: Select all

bool mount_spiffs()
{
    // fill out spiffs config object
    esp_vfs_spiffs_conf_t conf;
    conf.base_path = "/spiffs";
    conf.partition_label = NULL;
    conf.max_files = 5;
    conf.format_if_mount_failed = true;

    esp_err_t ret = esp_vfs_spiffs_register( &conf );
    if( ret != ESP_OK )
    {
        if ( ret == ESP_FAIL ) {
            ESP_LOGE( __func__, "Failed to mount or format filesystem" );
        } else if ( ret == ESP_ERR_NOT_FOUND ) {
            ESP_LOGE( __func__, "Failed to find SPIFFS partition" );
        } else {
            ESP_LOGE( __func__, "Failed to initialize SPIFFS (%d)", ret );
        }
        return false;
    }
    else
    {
        ESP_LOGI( __func__, "spiffs mounted successfully" );
        return true;
    }
}

void spiffs_task( void *pvParameters ) {
    if ( !mount_spiffs() ) {
        // This is a serious problem that the spiffs did not mount
        // TODO - publish an error!
        ESP_LOGE(__func__,"SPIFFS did not mount!!");
        esp_restart();
    } else {
        ESP_LOGI(__func__,"Mounted SPIFFS");
        xEventGroupSetBits(relevant_events,bit_spiffs_ready);
    }
    vTaskDelete(NULL);
}
The task is run from app_main with priority 1 (lowest priority). But it generates the following error:

Code: Select all

W (289) SPIFFS: mount failed, -10025. formatting...
Task watchdog got triggered. The following tasks did not reset the watchdog in time:
 - IDLE (CPU 0)
Tasks currently running:
CPU 0: spiffs_task
Aborting.
abort() was called at PC 0x400d34eb on core 0
0x400d34eb: task_wdt_isr at /dev/esp32/Firmware/esp-idf/components/esp32/task_wdt.c:236
As I understand it, this is happening because the watchdog timer is not being fed. However, I think it's actually the spiff formatting that is causing the issue, and I'm not sure why it's not feeding the TWDT, or what I can do about it.

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: esp_vfs_spiffs_register causing TWDT panic?

Postby ESP_Dazz » Thu Jul 12, 2018 11:53 am

TWDT triggering means that the IDLE task did not feed the watchdog in time, and in this case it is the IDLE task on CPU 0 that failed to feed the TWDT. The cause of this is usually because a higher priority task is starving the IDLE task from any CPU time which probably means the spiffs_task is stuck in an infinite/very long loop somewhere in its program flow.

Possible cause
Following your program flow, the only loop I see in the program flow is as follows:
mount_spiffs() -> esp_vfs_spiffs_register() -> esp_spiffs_init() -> Mount fails and tries to format if mount by calling SPIFFS_format() then gets stuck in the while loop inside.

Try setting conf.format_if_mount_failed = false; and see if the TWDT still triggers.

Conversely you can also use menuconfig to configure the TWDT to panic upon timeout, allowing you to see the stack trace of the program.

0xffff
Posts: 41
Joined: Tue Jun 19, 2018 1:53 am

Re: esp_vfs_spiffs_register causing TWDT panic?

Postby 0xffff » Thu Jul 12, 2018 3:23 pm

Yes, if I turn off CPU0 IDLE task checking it works ok because after about 10 seconds the spiffs are formatted. However, it would be nice to have Idle task checking enabled and still be able to format spiffs if mount fails.

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: esp_vfs_spiffs_register causing TWDT panic?

Postby ESP_Dazz » Fri Jul 13, 2018 6:09 am

Try setting the priority of spiffs_task to 0 so that it has the same priority as the IDLE task. That way the scheduler will time slice between spiffs_task and the IDLE task, giving a chance for the IDLE task to run every tick.

0xffff
Posts: 41
Joined: Tue Jun 19, 2018 1:53 am

Re: esp_vfs_spiffs_register causing TWDT panic?

Postby 0xffff » Mon Jul 16, 2018 12:57 am

Great idea. Thanks!

Who is online

Users browsing this forum: No registered users and 114 guests