@@ -52,6 +52,13 @@ static void uart0_write_char_d(char c);
52
52
static void uart1_write_char_d (char c);
53
53
static void print_stack (uint32_t start, uint32_t end);
54
54
55
+ // using numbers different from "REASON_" in user_interface.h (=0..6)
56
+ enum rst_reason_sw
57
+ {
58
+ REASON_USER_SWEXCEPTION_RST = 254
59
+ };
60
+ static int s_user_reset_reason = REASON_DEFAULT_RST;
61
+
55
62
// From UMM, the last caller of a malloc/realloc/calloc which failed:
56
63
extern void *umm_last_fail_alloc_addr;
57
64
extern int umm_last_fail_alloc_size;
@@ -86,24 +93,20 @@ void __wrap_system_restart_local() {
86
93
register uint32_t sp asm (" a1" );
87
94
uint32_t sp_dump = sp;
88
95
89
- if (gdb_present ()) {
90
- /* When GDBStub is present, exceptions are handled by GDBStub,
91
- but Soft WDT will still call this function.
92
- Trigger an exception to break into GDB.
93
- TODO: check why gdb_do_break() or asm("break.n 0") do not
94
- break into GDB here. */
95
- raise_exception ();
96
- }
97
-
98
96
struct rst_info rst_info;
99
97
memset (&rst_info, 0 , sizeof (rst_info));
100
- system_rtc_mem_read (0 , &rst_info, sizeof (rst_info));
101
- if (rst_info.reason != REASON_SOFT_WDT_RST &&
102
- rst_info.reason != REASON_EXCEPTION_RST &&
103
- rst_info.reason != REASON_WDT_RST)
98
+ if (s_user_reset_reason == REASON_DEFAULT_RST)
104
99
{
105
- return ;
100
+ system_rtc_mem_read (0 , &rst_info, sizeof (rst_info));
101
+ if (rst_info.reason != REASON_SOFT_WDT_RST &&
102
+ rst_info.reason != REASON_EXCEPTION_RST &&
103
+ rst_info.reason != REASON_WDT_RST)
104
+ {
105
+ rst_info.reason = REASON_DEFAULT_RST;
106
+ }
106
107
}
108
+ else
109
+ rst_info.reason = s_user_reset_reason;
107
110
108
111
// TODO: ets_install_putc1 definition is wrong in ets_sys.h, need cast
109
112
ets_install_putc1 ((void *)&uart_write_char_d);
@@ -128,6 +131,9 @@ void __wrap_system_restart_local() {
128
131
else if (rst_info.reason == REASON_SOFT_WDT_RST) {
129
132
ets_printf_P (PSTR (" \n Soft WDT reset\n " ));
130
133
}
134
+ else {
135
+ ets_printf_P (PSTR (" \n Generic Reset\n " ));
136
+ }
131
137
132
138
uint32_t cont_stack_start = (uint32_t ) &(g_pcont->stack );
133
139
uint32_t cont_stack_end = (uint32_t ) g_pcont->stack_end ;
@@ -222,7 +228,13 @@ static void uart1_write_char_d(char c) {
222
228
}
223
229
224
230
static void raise_exception () {
225
- __asm__ __volatile__ (" syscall" );
231
+ if (gdb_present ())
232
+ __asm__ __volatile__ (" syscall" ); // triggers GDB when enabled
233
+
234
+ s_user_reset_reason = REASON_USER_SWEXCEPTION_RST;
235
+ ets_printf_P (PSTR (" \n User exception (panic/abort/assert)" ));
236
+ __wrap_system_restart_local ();
237
+
226
238
while (1 ); // never reached, needed to satisfy "noreturn" attribute
227
239
}
228
240
0 commit comments