From 28ea39cf053d1069b698a7ac57f0eb6def82cb48 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Fri, 28 Dec 2018 21:14:46 +0200 Subject: [PATCH] Add WDT API for Core 0 and disable it while SPIFFS is formatting --- cores/esp32/esp32-hal-misc.c | 16 +++++++++++++++- cores/esp32/esp32-hal.h | 7 +++++-- libraries/SPIFFS/src/SPIFFS.cpp | 11 +++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index 0ebb3726..3a22346b 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -70,7 +70,21 @@ void disableLoopWDT(){ } #endif -#ifndef CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 +void enableCore0WDT(){ + TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0); + if(idle_0 == NULL || esp_task_wdt_add(idle_0) != ESP_OK){ + log_e("Failed to add Core 0 IDLE task to WDT"); + } +} + +void disableCore0WDT(){ + TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0); + if(idle_0 == NULL || esp_task_wdt_delete(idle_0) != ESP_OK){ + log_e("Failed to remove Core 0 IDLE task from WDT"); + } +} + +#ifndef CONFIG_FREERTOS_UNICORE void enableCore1WDT(){ TaskHandle_t idle_1 = xTaskGetIdleTaskHandleForCPU(1); if(idle_1 == NULL || esp_task_wdt_add(idle_1) != ESP_OK){ diff --git a/cores/esp32/esp32-hal.h b/cores/esp32/esp32-hal.h index 7cb44519..33595efd 100644 --- a/cores/esp32/esp32-hal.h +++ b/cores/esp32/esp32-hal.h @@ -78,8 +78,11 @@ void enableLoopWDT(); void disableLoopWDT(); #endif -#ifndef CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 -//enable/disable WDT for the IDLE task on Core 1 +//enable/disable WDT for the IDLE task on Core 0 (SYSTEM) +void enableCore0WDT(); +void disableCore0WDT(); +#ifndef CONFIG_FREERTOS_UNICORE +//enable/disable WDT for the IDLE task on Core 1 (Arduino) void enableCore1WDT(); void disableCore1WDT(); #endif diff --git a/libraries/SPIFFS/src/SPIFFS.cpp b/libraries/SPIFFS/src/SPIFFS.cpp index adc9148a..8dcded32 100644 --- a/libraries/SPIFFS/src/SPIFFS.cpp +++ b/libraries/SPIFFS/src/SPIFFS.cpp @@ -39,11 +39,16 @@ bool SPIFFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFi .base_path = basePath, .partition_label = NULL, .max_files = maxOpenFiles, - .format_if_mount_failed = formatOnFail + .format_if_mount_failed = false }; esp_err_t err = esp_vfs_spiffs_register(&conf); - if(err){ + if(err == ESP_FAIL && formatOnFail){ + if(format()){ + err = esp_vfs_spiffs_register(&conf); + } + } + if(err != ESP_OK){ log_e("Mounting SPIFFS failed! Error: %d", err); return false; } @@ -65,7 +70,9 @@ void SPIFFSFS::end() bool SPIFFSFS::format() { + disableCore0WDT(); esp_err_t err = esp_spiffs_format(NULL); + enableCore0WDT(); if(err){ log_e("Formatting SPIFFS failed! Error: %d", err); return false;