Просмотр исходного кода

Merge branch 'bugfix/panic_reset_hangs' into 'master'

Panic handler: Use same reset path as esp_restart(), disabling hardware

Closes #223 https://github.com/espressif/esp-idf/issues/223

See merge request !417

Ivan Grokhotkov 9 лет назад
Родитель
Сommit
6538252552
3 измененных файлов с 22 добавлено и 4 удалено
  1. 6 0
      components/esp32/include/rom/rtc.h
  2. 3 4
      components/esp32/panic.c
  3. 13 0
      components/esp32/system_api.c

+ 6 - 0
components/esp32/include/rom/rtc.h

@@ -181,6 +181,9 @@ void set_rtc_memory_crc(void);
 /**
 /**
   * @brief Software Reset digital core.
   * @brief Software Reset digital core.
   *
   *
+  * It is not recommended to use this function in esp-idf, use
+  * esp_restart() instead.
+  *
   * @param  None
   * @param  None
   *
   *
   * @return None
   * @return None
@@ -190,6 +193,9 @@ void software_reset(void);
 /**
 /**
   * @brief Software Reset digital core.
   * @brief Software Reset digital core.
   *
   *
+  * It is not recommended to use this function in esp-idf, use
+  * esp_restart() instead.
+  *
   * @param  int cpu_no : The CPU to reset, 0 for PRO CPU, 1 for APP CPU.
   * @param  int cpu_no : The CPU to reset, 0 for PRO CPU, 1 for APP CPU.
   *
   *
   * @return None
   * @return None

+ 3 - 4
components/esp32/panic.c

@@ -321,6 +321,8 @@ static void doBacktrace(XtExcFrame *frame)
     panicPutStr("\r\n\r\n");
     panicPutStr("\r\n\r\n");
 }
 }
 
 
+void esp_restart_noos() __attribute__ ((noreturn));
+
 /*
 /*
   We arrive here after a panic or unhandled exception, when no OCD is detected. Dump the registers to the
   We arrive here after a panic or unhandled exception, when no OCD is detected. Dump the registers to the
   serial port and either jump to the gdb stub, halt the CPU or reboot.
   serial port and either jump to the gdb stub, halt the CPU or reboot.
@@ -373,10 +375,7 @@ static void commonErrorHandler(XtExcFrame *frame)
 #endif
 #endif
 #if CONFIG_ESP32_PANIC_PRINT_REBOOT || CONFIG_ESP32_PANIC_SILENT_REBOOT
 #if CONFIG_ESP32_PANIC_PRINT_REBOOT || CONFIG_ESP32_PANIC_SILENT_REBOOT
     panicPutStr("Rebooting...\r\n");
     panicPutStr("Rebooting...\r\n");
-    for (x = 0; x < 100; x++) {
-        ets_delay_us(1000);
-    }
-    software_reset();
+    esp_restart_noos();
 #else
 #else
     disableAllWdts();
     disableAllWdts();
     panicPutStr("CPU halted.\r\n");
     panicPutStr("CPU halted.\r\n");

+ 13 - 0
components/esp32/system_api.c

@@ -73,6 +73,8 @@ esp_err_t esp_efuse_read_mac(uint8_t* mac)
 esp_err_t system_efuse_read_mac(uint8_t mac[6]) __attribute__((alias("esp_efuse_read_mac")));
 esp_err_t system_efuse_read_mac(uint8_t mac[6]) __attribute__((alias("esp_efuse_read_mac")));
 
 
 
 
+void esp_restart_noos() __attribute__ ((noreturn));
+
 void IRAM_ATTR esp_restart(void)
 void IRAM_ATTR esp_restart(void)
 {
 {
 #ifdef CONFIG_WIFI_ENABLED
 #ifdef CONFIG_WIFI_ENABLED
@@ -81,6 +83,17 @@ void IRAM_ATTR esp_restart(void)
 
 
     // Disable scheduler on this core.
     // Disable scheduler on this core.
     vTaskSuspendAll();
     vTaskSuspendAll();
+
+    esp_restart_noos();
+}
+
+/* "inner" restart function for after RTOS, interrupts & anything else on this
+ * core are already stopped. Stalls other core, resets hardware,
+ * triggers restart.
+*/
+void IRAM_ATTR esp_restart_noos()
+{
+
     const uint32_t core_id = xPortGetCoreID();
     const uint32_t core_id = xPortGetCoreID();
     const uint32_t other_core_id = core_id == 0 ? 1 : 0;
     const uint32_t other_core_id = core_id == 0 ? 1 : 0;
     esp_cpu_stall(other_core_id);
     esp_cpu_stall(other_core_id);