|
|
@@ -30,6 +30,7 @@
|
|
|
|
|
|
#include "esp_private/panic_internal.h"
|
|
|
#include "port/panic_funcs.h"
|
|
|
+#include "esp_rom_sys.h"
|
|
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
|
@@ -58,6 +59,10 @@
|
|
|
#include "esp_gdbstub.h"
|
|
|
#endif
|
|
|
|
|
|
+#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
|
|
|
+#include "hal/usb_serial_jtag_ll.h"
|
|
|
+#endif
|
|
|
+
|
|
|
bool g_panic_abort = false;
|
|
|
static char *s_panic_abort_details = NULL;
|
|
|
|
|
|
@@ -68,13 +73,13 @@ static wdt_hal_context_t wdt1_context = {.inst = WDT_MWDT1, .mwdt_dev = &TIMERG1
|
|
|
#if !CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
|
|
|
|
|
|
#if CONFIG_ESP_CONSOLE_UART
|
|
|
-static uart_hal_context_t s_panic_uart = { .dev = CONFIG_ESP_CONSOLE_UART_NUM == 0 ? &UART0 : &UART1 };
|
|
|
+static uart_hal_context_t s_panic_uart = { .dev = CONFIG_ESP_CONSOLE_UART_NUM == 0 ? &UART0 :&UART1 };
|
|
|
|
|
|
void panic_print_char(const char c)
|
|
|
{
|
|
|
uint32_t sz = 0;
|
|
|
- while(!uart_hal_get_txfifo_len(&s_panic_uart));
|
|
|
- uart_hal_write_txfifo(&s_panic_uart, (uint8_t*) &c, 1, &sz);
|
|
|
+ while (!uart_hal_get_txfifo_len(&s_panic_uart));
|
|
|
+ uart_hal_write_txfifo(&s_panic_uart, (uint8_t *) &c, 1, &sz);
|
|
|
}
|
|
|
#endif // CONFIG_ESP_CONSOLE_UART
|
|
|
|
|
|
@@ -87,6 +92,27 @@ void panic_print_char(const char c)
|
|
|
}
|
|
|
#endif // CONFIG_ESP_CONSOLE_USB_CDC
|
|
|
|
|
|
+#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
|
|
|
+//Timeout; if there's no host listening, the txfifo won't ever
|
|
|
+//be writable after the first packet.
|
|
|
+
|
|
|
+#define USBSERIAL_TIMEOUT_MAX_US 50000
|
|
|
+static int s_usbserial_timeout = 0;
|
|
|
+
|
|
|
+void panic_print_char(const char c)
|
|
|
+{
|
|
|
+ while (!usb_serial_jtag_ll_txfifo_writable() && s_usbserial_timeout < (USBSERIAL_TIMEOUT_MAX_US / 100)) {
|
|
|
+ esp_rom_delay_us(100);
|
|
|
+ s_usbserial_timeout++;
|
|
|
+ }
|
|
|
+ if (usb_serial_jtag_ll_txfifo_writable()) {
|
|
|
+ usb_serial_jtag_ll_write_txfifo((const uint8_t *)&c, 1);
|
|
|
+ s_usbserial_timeout = 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+#endif //CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
|
|
|
+
|
|
|
+
|
|
|
#if CONFIG_ESP_CONSOLE_NONE
|
|
|
void panic_print_char(const char c)
|
|
|
{
|
|
|
@@ -96,7 +122,7 @@ void panic_print_char(const char c)
|
|
|
|
|
|
void panic_print_str(const char *str)
|
|
|
{
|
|
|
- for(int i = 0; str[i] != 0; i++) {
|
|
|
+ for (int i = 0; str[i] != 0; i++) {
|
|
|
panic_print_char(str[i]);
|
|
|
}
|
|
|
}
|
|
|
@@ -145,7 +171,7 @@ static void reconfigure_all_wdts(void)
|
|
|
//Reconfigure TWDT (Timer Group 0)
|
|
|
wdt_hal_init(&wdt0_context, WDT_MWDT0, MWDT0_TICK_PRESCALER, false); //Prescaler: wdt counts in ticks of TG0_WDT_TICK_US
|
|
|
wdt_hal_write_protect_disable(&wdt0_context);
|
|
|
- wdt_hal_config_stage(&wdt0_context, 0, 1000*1000/MWDT0_TICKS_PER_US, WDT_STAGE_ACTION_RESET_SYSTEM); //1 second before reset
|
|
|
+ wdt_hal_config_stage(&wdt0_context, 0, 1000 * 1000 / MWDT0_TICKS_PER_US, WDT_STAGE_ACTION_RESET_SYSTEM); //1 second before reset
|
|
|
wdt_hal_enable(&wdt0_context);
|
|
|
wdt_hal_write_protect_enable(&wdt0_context);
|
|
|
|
|
|
@@ -190,29 +216,29 @@ void esp_panic_handler(panic_info_t *info)
|
|
|
info->exception = PANIC_EXCEPTION_ABORT;
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- * For any supported chip, the panic handler prints the contents of panic_info_t in the following format:
|
|
|
- *
|
|
|
- *
|
|
|
- * Guru Meditation Error: Core <core> (<exception>). <description>
|
|
|
- * <details>
|
|
|
- *
|
|
|
- * <state>
|
|
|
- *
|
|
|
- * <elf_info>
|
|
|
- *
|
|
|
- *
|
|
|
- * ----------------------------------------------------------------------------------------
|
|
|
- * core - core where exception was triggered
|
|
|
- * exception - what kind of exception occured
|
|
|
- * description - a short description regarding the exception that occured
|
|
|
- * details - more details about the exception
|
|
|
- * state - processor state like register contents, and backtrace
|
|
|
- * elf_info - details about the image currently running
|
|
|
- *
|
|
|
- * NULL fields in panic_info_t are not printed.
|
|
|
- *
|
|
|
- * */
|
|
|
+ /*
|
|
|
+ * For any supported chip, the panic handler prints the contents of panic_info_t in the following format:
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * Guru Meditation Error: Core <core> (<exception>). <description>
|
|
|
+ * <details>
|
|
|
+ *
|
|
|
+ * <state>
|
|
|
+ *
|
|
|
+ * <elf_info>
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * ----------------------------------------------------------------------------------------
|
|
|
+ * core - core where exception was triggered
|
|
|
+ * exception - what kind of exception occured
|
|
|
+ * description - a short description regarding the exception that occured
|
|
|
+ * details - more details about the exception
|
|
|
+ * state - processor state like register contents, and backtrace
|
|
|
+ * elf_info - details about the image currently running
|
|
|
+ *
|
|
|
+ * NULL fields in panic_info_t are not printed.
|
|
|
+ *
|
|
|
+ * */
|
|
|
if (info->reason) {
|
|
|
panic_print_str("Guru Meditation Error: Core ");
|
|
|
panic_print_dec(info->core);
|
|
|
@@ -296,7 +322,7 @@ void esp_panic_handler(panic_info_t *info)
|
|
|
wdt_hal_disable(&rtc_wdt_ctx);
|
|
|
wdt_hal_write_protect_enable(&rtc_wdt_ctx);
|
|
|
panic_print_str("Entering gdb stub now.\r\n");
|
|
|
- esp_gdbstub_panic_handler(info->frame);
|
|
|
+ esp_gdbstub_panic_handler((void *)info->frame);
|
|
|
#else
|
|
|
#if CONFIG_ESP_COREDUMP_ENABLE
|
|
|
static bool s_dumping_core;
|
|
|
@@ -321,8 +347,7 @@ void esp_panic_handler(panic_info_t *info)
|
|
|
#if CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT || CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
|
|
|
|
|
|
if (esp_reset_reason_get_hint() == ESP_RST_UNKNOWN) {
|
|
|
- switch (info->exception)
|
|
|
- {
|
|
|
+ switch (info->exception) {
|
|
|
case PANIC_EXCEPTION_IWDT:
|
|
|
esp_reset_reason_set_hint(ESP_RST_INT_WDT);
|
|
|
break;
|
|
|
@@ -348,10 +373,10 @@ void esp_panic_handler(panic_info_t *info)
|
|
|
}
|
|
|
|
|
|
|
|
|
-void __attribute__((noreturn)) panic_abort(const char *details)
|
|
|
+void __attribute__((noreturn, no_sanitize_undefined)) panic_abort(const char *details)
|
|
|
{
|
|
|
g_panic_abort = true;
|
|
|
- s_panic_abort_details = (char*) details;
|
|
|
+ s_panic_abort_details = (char *) details;
|
|
|
|
|
|
#if CONFIG_APPTRACE_ENABLE
|
|
|
#if CONFIG_SYSVIEW_ENABLE
|
|
|
@@ -363,7 +388,7 @@ void __attribute__((noreturn)) panic_abort(const char *details)
|
|
|
#endif
|
|
|
|
|
|
*((int *) 0) = 0; // NOLINT(clang-analyzer-core.NullDereference) should be an invalid operation on targets
|
|
|
- while(1);
|
|
|
+ while (1);
|
|
|
}
|
|
|
|
|
|
/* Weak versions of reset reason hint functions.
|