Skip to content

Commit

Permalink
Add WDT API for Core 0 and disable it while SPIFFS is formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
me-no-dev committed Dec 28, 2018
1 parent f49c854 commit 28ea39c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
16 changes: 15 additions & 1 deletion cores/esp32/esp32-hal-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
7 changes: 5 additions & 2 deletions cores/esp32/esp32-hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions libraries/SPIFFS/src/SPIFFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit 28ea39c

Please sign in to comment.