Skip to content

Commit 28ea39c

Browse files
committed
Add WDT API for Core 0 and disable it while SPIFFS is formatting
1 parent f49c854 commit 28ea39c

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

Diff for: cores/esp32/esp32-hal-misc.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,21 @@ void disableLoopWDT(){
7070
}
7171
#endif
7272

73-
#ifndef CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1
73+
void enableCore0WDT(){
74+
TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0);
75+
if(idle_0 == NULL || esp_task_wdt_add(idle_0) != ESP_OK){
76+
log_e("Failed to add Core 0 IDLE task to WDT");
77+
}
78+
}
79+
80+
void disableCore0WDT(){
81+
TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0);
82+
if(idle_0 == NULL || esp_task_wdt_delete(idle_0) != ESP_OK){
83+
log_e("Failed to remove Core 0 IDLE task from WDT");
84+
}
85+
}
86+
87+
#ifndef CONFIG_FREERTOS_UNICORE
7488
void enableCore1WDT(){
7589
TaskHandle_t idle_1 = xTaskGetIdleTaskHandleForCPU(1);
7690
if(idle_1 == NULL || esp_task_wdt_add(idle_1) != ESP_OK){

Diff for: cores/esp32/esp32-hal.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ void enableLoopWDT();
7878
void disableLoopWDT();
7979
#endif
8080

81-
#ifndef CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1
82-
//enable/disable WDT for the IDLE task on Core 1
81+
//enable/disable WDT for the IDLE task on Core 0 (SYSTEM)
82+
void enableCore0WDT();
83+
void disableCore0WDT();
84+
#ifndef CONFIG_FREERTOS_UNICORE
85+
//enable/disable WDT for the IDLE task on Core 1 (Arduino)
8386
void enableCore1WDT();
8487
void disableCore1WDT();
8588
#endif

Diff for: libraries/SPIFFS/src/SPIFFS.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ bool SPIFFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFi
3939
.base_path = basePath,
4040
.partition_label = NULL,
4141
.max_files = maxOpenFiles,
42-
.format_if_mount_failed = formatOnFail
42+
.format_if_mount_failed = false
4343
};
4444

4545
esp_err_t err = esp_vfs_spiffs_register(&conf);
46-
if(err){
46+
if(err == ESP_FAIL && formatOnFail){
47+
if(format()){
48+
err = esp_vfs_spiffs_register(&conf);
49+
}
50+
}
51+
if(err != ESP_OK){
4752
log_e("Mounting SPIFFS failed! Error: %d", err);
4853
return false;
4954
}
@@ -65,7 +70,9 @@ void SPIFFSFS::end()
6570

6671
bool SPIFFSFS::format()
6772
{
73+
disableCore0WDT();
6874
esp_err_t err = esp_spiffs_format(NULL);
75+
enableCore0WDT();
6976
if(err){
7077
log_e("Formatting SPIFFS failed! Error: %d", err);
7178
return false;

0 commit comments

Comments
 (0)