From a071d57e82937fc4083bb0a85b2582ba430f20ff Mon Sep 17 00:00:00 2001 From: Felix Storm Date: Mon, 27 Jan 2020 11:20:02 +0100 Subject: [PATCH 1/2] ESP32: reset task wdt in SdVolume::freeClusterCount() --- Marlin/src/sd/SdVolume.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Marlin/src/sd/SdVolume.cpp b/Marlin/src/sd/SdVolume.cpp index 926dd1c7d456..5b161e2b114c 100644 --- a/Marlin/src/sd/SdVolume.cpp +++ b/Marlin/src/sd/SdVolume.cpp @@ -291,6 +291,15 @@ int32_t SdVolume::freeClusterCount() { for (uint16_t i = 0; i < n; i++) if (cacheBuffer_.fat32[i] == 0) free++; } + #if defined(ESP32) + // Needed in order to reset the idle task watchdog timer on the ESP32 as reading the complete FAT may easily + // block for 10+ seconds. yield() is not sufficient here as it will not let lower prio tasks (i.e. idle) run. + static uint32_t lastTaskDelay = 0; + if (millis() - lastTaskDelay > 1000) { + vTaskDelay(1); // delay 1 tick (minimum amount, usually 10 or 1 ms depending on skdconfig.h) + lastTaskDelay = millis(); + } + #endif // ESP32 } return free; } From 49aa721075ca0b52aa7dc5cab8fa8a0d1c4e2667 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 27 Jan 2020 18:14:57 -0600 Subject: [PATCH 2/2] Update SdVolume.cpp --- Marlin/src/sd/SdVolume.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Marlin/src/sd/SdVolume.cpp b/Marlin/src/sd/SdVolume.cpp index 5b161e2b114c..c51e42108ce3 100644 --- a/Marlin/src/sd/SdVolume.cpp +++ b/Marlin/src/sd/SdVolume.cpp @@ -291,13 +291,14 @@ int32_t SdVolume::freeClusterCount() { for (uint16_t i = 0; i < n; i++) if (cacheBuffer_.fat32[i] == 0) free++; } - #if defined(ESP32) - // Needed in order to reset the idle task watchdog timer on the ESP32 as reading the complete FAT may easily - // block for 10+ seconds. yield() is not sufficient here as it will not let lower prio tasks (i.e. idle) run. - static uint32_t lastTaskDelay = 0; - if (millis() - lastTaskDelay > 1000) { - vTaskDelay(1); // delay 1 tick (minimum amount, usually 10 or 1 ms depending on skdconfig.h) - lastTaskDelay = millis(); + #ifdef ESP32 + // Needed to reset the idle task watchdog timer on ESP32 as reading the complete FAT may easily + // block for 10+ seconds. yield() is insufficient since it blocks lower prio tasks (e.g., idle). + static millis_t nextTaskTime = 0; + const millis_t ms = millis(); + if (ELAPSED(ms, nextTaskTime) { + vTaskDelay(1); // delay 1 tick (Minimum. Usually 10 or 1 ms depending on skdconfig.h) + nextTaskTime = ms + 1000; // tickle the task manager again in 1 second } #endif // ESP32 }