diff --git a/components/NVM/USB.c b/components/NVM/USB.c index 5c746fc..2cd615d 100644 --- a/components/NVM/USB.c +++ b/components/NVM/USB.c @@ -55,6 +55,8 @@ static const char *TAG = "USB"; static const char *OTA_FILE = "/usb/esp/OTA_URL.txt"; const char *CONFIG_FILE = "/usb/esp/config.txt"; +__NOINIT_ATTR uint_fast8_t Restarts; + typedef enum { USB_STATE_UNINITIALIZED, @@ -281,6 +283,8 @@ static void app_usb_task(void *args) static uint8_t device_address = 1; usb_message_t msg; + esp_reset_reason() == ESP_RST_POWERON ? Restarts = 0 : Restarts++; + while (true) { switch (Current_State) @@ -313,9 +317,16 @@ static void app_usb_task(void *args) } else { - KLOG_ERROR(TAG, "No flash drive detected--rebooting."); - vTaskDelay(pdMS_TO_TICKS(100)); - esp_restart(); + if (Restarts <= 3) + { + KLOG_ERROR(TAG, "No flash drive detected--rebooting."); + vTaskDelay(pdMS_TO_TICKS(100)); + esp_restart(); + } + else + { + KLOG_WARN(TAG, "No flash drive detected after multiple attempts."); + } } } break;