Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware WDT Stack Dump Tool #7010

Merged
merged 76 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
82c7d33
Hardware WDT Stack Dump
mhightower83 Jan 11, 2020
8fbaa7e
Corrected Style. Improved HWDT reset detectionat boot.
mhightower83 Jan 11, 2020
e272111
Style and typos
mhightower83 Jan 11, 2020
254c50f
Update comments.
mhightower83 Jan 11, 2020
093ac02
Improvements to reset reason determination.
mhightower83 Jan 14, 2020
7978860
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Jan 14, 2020
25f0140
Style plus
mhightower83 Jan 14, 2020
b8abe5b
Moved all configuration options to the top.
mhightower83 Jan 14, 2020
c2cbb87
Removed clutter of having an alternate printing method.
mhightower83 Jan 14, 2020
309ac45
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Jan 14, 2020
1df82c0
Added delays around uart_div_modify. This appeara to resolve the lost
mhightower83 Jan 14, 2020
99c6e4c
Merge branch 'pr-hwdt-stack-dump' of github.com:mhightower83/Arduino …
mhightower83 Jan 15, 2020
ad3bbad
Finished TODO looked at assembly of app_entry_redefinable to confirm
mhightower83 Jan 15, 2020
b08714b
Comment changes.
mhightower83 Jan 16, 2020
ca0eab3
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Jan 19, 2020
be7417a
Improved comments.
mhightower83 Jan 20, 2020
e458e7e
Merge branch 'pr-hwdt-stack-dump' of github.com:mhightower83/Arduino …
mhightower83 Jan 20, 2020
4528446
Several corrections to set_uart_speed
mhightower83 Jan 21, 2020
ed826ea
Removed unused include.
mhightower83 Jan 21, 2020
b60b6a2
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Jan 23, 2020
81418df
Now runs from flash before SDK is started.
mhightower83 Jan 31, 2020
17fab8a
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Jan 31, 2020
c0121fe
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Feb 6, 2020
1c4b356
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Feb 14, 2020
1f0e6f4
Changed ICACHE size from 32K to 16K to avoid conflict with
mhightower83 Feb 14, 2020
7288abf
Added support to print ThunkStack.
mhightower83 Feb 15, 2020
714ab07
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Mar 17, 2020
e8bf3f0
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Mar 27, 2020
32737bb
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Apr 7, 2020
dbfaf0d
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Apr 16, 2020
06a001d
Merge branch 'master' into pr-hwdt-stack-dump
earlephilhower Apr 24, 2020
eec0192
comment cleanup. added missing additional #if defined()
mhightower83 Apr 25, 2020
1264394
Update style used for structure and typedef to match that used in core
mhightower83 Apr 26, 2020
15d11ff
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Apr 26, 2020
8dd28e2
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 May 5, 2020
1da67e3
Updated comments
mhightower83 May 5, 2020
4db3c0d
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 May 31, 2020
fa83586
Merge branch 'pr-hwdt-stack-dump' of github.com:mhightower83/Arduino …
mhightower83 May 31, 2020
0592c4a
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Jun 19, 2020
f74ebbd
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Jul 7, 2020
7d75454
Corrected new errors from upgrade to GCC 10.1 toolchain related to
mhightower83 Jul 11, 2020
dcce57d
Work around divide by 0 HWDT event under toolchain 10.1.
mhightower83 Jul 13, 2020
f14db29
Merge branch 'master' into pr-hwdt-stack-dump
devyte Jul 17, 2020
ec2ef11
Merge branch 'pr-hwdt-stack-dump' of github.com:mhightower83/Arduino …
mhightower83 Jul 17, 2020
8c2d214
Changes to move feature into core.
mhightower83 Jul 17, 2020
9024184
Fix stack character buffer length.
mhightower83 Jul 26, 2020
1f7342d
Merge branch 'master' into pr-hwdt-stack-dump
devyte Aug 4, 2020
2ce297c
Updated comment to reflect support via Arduino IDE Tools menu.
mhightower83 Aug 4, 2020
3a351ae
Merge branch 'pr-hwdt-stack-dump' of github.com:mhightower83/Arduino …
mhightower83 Aug 4, 2020
1bd4e33
Improve meshing of HWDT and NOEXTRA4K
mhightower83 Aug 5, 2020
65f8e1d
Made compatible with `disable_extra4k_at_link_time()` usage.
mhightower83 Aug 7, 2020
c31a354
CI style
mhightower83 Aug 7, 2020
18a5f41
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Sep 2, 2020
67085cd
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Sep 17, 2020
b7e4b68
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Sep 30, 2020
b080d33
Adjusted down the ROM Stack space for the extra 4K Heap option.
mhightower83 Oct 1, 2020
dbc2c34
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Oct 2, 2020
ba524a3
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Oct 2, 2020
dea96b2
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Oct 17, 2020
fd1131d
Add replacement aes_unwrap for the debug HWDT option.
mhightower83 Oct 17, 2020
8bfcda7
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Oct 24, 2020
ea1f384
Update umm_info_safe_printf_P to support default of unaligned PROGMEM…
mhightower83 Oct 27, 2020
a1ab73d
Improve cont stack trace for yielding case.
mhightower83 Oct 27, 2020
720fe3b
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Oct 28, 2020
2b46960
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Nov 11, 2020
761d736
Added missed update to heap.cpp for change to use PSTR instead of PSTR4
mhightower83 Nov 25, 2020
fd1e2e1
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Nov 25, 2020
b94777e
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Dec 6, 2020
504b769
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Dec 15, 2020
5b161db
Updated comments and #if in aes_unwrap.
mhightower83 Dec 17, 2020
9801d28
Merge branch 'master' into pr-hwdt-stack-dump
earlephilhower Dec 23, 2020
755ab97
Merge branch 'pr-hwdt-stack-dump' of github.com:mhightower83/Arduino …
mhightower83 Jan 14, 2021
96b6ddb
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Jan 14, 2021
e7c5061
Merge branch 'master' into pr-hwdt-stack-dump
mhightower83 Mar 28, 2021
37efba8
Update boards.txt
mhightower83 Mar 29, 2021
dcec7de
Merge branch 'master' into pr-hwdt-stack-dump
d-a-v Apr 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libraries/esp8266/examples/HwdtStackDump/AddOn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void printHelpAddOn(Print& out)__attribute__((weak));
int hotKeyHandlerAddOn(Print& out, int hotKey)__attribute__((weak));
void crashMeIfYouCan(void)__attribute__((weak));
83 changes: 83 additions & 0 deletions libraries/esp8266/examples/HwdtStackDump/AddOn.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#ifdef HWDT_STACK_DUMP_H

extern struct rst_info resetInfo;

void printHwdtDebugInfo(Print& out) {
extern struct rst_info resetInfo;
out.println(String(F("RTC_SYS[0] = ")) + (hwdt_info.rtc_sys_reason) + F(", resetInfo.reason = ") + (resetInfo.reason) + F(", ") + ESP.getResetReason());
out.println(String(F("ROM API reset reason = ")) + (hwdt_info.rom_api_reason));
out.println(String(F("HWDT reset reason = ")) + (hwdt_info.reset_reason));
if (REASON_EXT_SYS_RST < hwdt_info.reset_reason) {
out.println(String(F("Reset reason confirmation failed!\n")));
}

out.println();
if (hwdt_info.sys) {
out.println(String(F("Stack Usages:")));
out.printf_P(PSTR(" ctx: sys %6u\r\n"), hwdt_info.sys);
uint32 cont_flags = hwdt_info.cont_integrity;
out.printf_P(PSTR(" ctx: cont %6u, Integrity Flags: %04X - %s\r\n"), hwdt_info.cont, cont_flags, (cont_flags) ? "fail" : "pass");
if (hwdt_info.rom) {
out.printf_P(PSTR(" ctx: ROM %6u\r\n"), hwdt_info.rom);
}
} else {
out.println(F("No stack usage information available at this time. Try restart."));
}
out.println();
}


void printHelpAddOn(Print& out) {
out.println(F(" 0 - Divide by zero, exception(0);"));
out.println(F(" p - panic();"));
out.println(F(" c - Hardware WDT reset by calling a missing function."));
out.println();
out.println(F("Additional options:"));
out.println(F(" d - Print some HWDT Debug info."));
}



int hotKeyHandlerAddOn(Print& out, int hotKey) {
switch (hotKey) {
case 'd':
printHwdtDebugInfo(out);
break;
case 'p':
out.println(F("Time to panic()!"));
panic();
break;
case '0':
out.println(F("Crashing by dividing by zero."));
out.printf_P(PSTR("This should not print %d\n"), divideA_B(1, 0));
break;
case 'c':
out.println(F("Now calling: void crashMeIfYouCan(void)__attribute__((weak));"));
out.println(F("This function was missing when the sketch was linked. ..."));
crashMeIfYouCan();
break;
default:
return 0;
}
return 1;
}

int divideA_B(int a, int b) {
return (a / b);
}

#else
void printHwdtDebugInfo(Print& out) {
(void)out;
}

int hotKeyHandlerAddOn(Print& out, int hotKey) {
(void)out;
(void)hotKey;
return 0;
}

void printHelpAddOn(Print& out) {
(void)out;
}
#endif
52 changes: 52 additions & 0 deletions libraries/esp8266/examples/HwdtStackDump/HwdtStackDump.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
A Hardware WDT Reset stack dump tool by Michael Hightower

This Sketch demonstrates the use of a tool that prints a stack dump after
a Hardware WDT reset. After a Hardware Watchdog Timer reset, the module
hwdt_app_entry.cpp writes a stack dump to the serial interface.

The goal was to have a file (hwdt_app_entry.cpp) that could be dropped into
a sketch directory, then open the sketch project, build, upload, and debug.

When the ESP8266 restarts because of a Hardware WDT reset, the serial port
speed defaults to 115200 bps. For support of other speeds, review the
comments on option HWDT_UART_SPEED in wdt_app_entry.cpp.

*/

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Esp.h>
#include <user_interface.h>

#include "AddOn.h"
/*
If you need to run your sketch w/o this tool or you want to see the
difference with and without this tool. Comment out the #include below. And
comment out the "#define DEBUG_HWDT" line in hwdt_app_entry.cpp.
*/
#include "hwdt_app_entry.h"


void setup(void) {
#ifdef DEBUG_HWDT
enable_debug_hwdt_at_link_time();
#endif
WiFi.persistent(false); // w/o this a flash write occurs at every boot
WiFi.mode(WIFI_OFF);
Serial.begin(115200);
delay(20);
Serial.println();
Serial.println();
Serial.println(F("The Hardware Watchdog Timer Demo is now available for crashing ..."));
Serial.println();
processKey(Serial, '?');
}


void loop(void) {
if (Serial.available() > 0) {
int hotKey = Serial.read();
processKey(Serial, hotKey);
}
}
80 changes: 80 additions & 0 deletions libraries/esp8266/examples/HwdtStackDump/ProcessKey.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <esp8266_undocumented.h>

int* nullPointer = NULL;

void processKey(Print& out, int hotKey) {
switch (hotKey) {
case 'r':
out.printf_P(PSTR("Reset, ESP.reset(); ...\r\n"));
ESP.reset();
break;
case 't':
out.printf_P(PSTR("Restart, ESP.restart(); ...\r\n"));
ESP.restart();
break;
case 's': {
uint32_t startTime = millis();
out.printf_P(PSTR("Now crashing with Software WDT. This will take about 3 seconds.\r\n"));
ets_install_putc1(ets_putc);
while (true) {
ets_printf("%9lu\r", (millis() - startTime));
ets_delay_us(250000);
// stay in an loop blocking other system activity.
}
}
break;
case 'h':
out.printf_P(PSTR("Now crashing with Hardware WDT. This will take about 6 seconds.\r\n"));
// ESP.wdtDisable();
asm volatile("" ::: "memory");
asm volatile("mov.n a2, %0\n"
"mov.n a3, %1\n"
"mov.n a4, %2\n"
"mov.n a5, %3\n"
"mov.n a6, %4\n"
: : "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa));
// Could not find these in the stack dump, unless interrupts were enabled.
{
uint32_t startTime = millis();
// Avoid all the Core functions that play nice, so we can hog
// the system and crash.
ets_install_putc1(ets_putc);
xt_rsil(15);
while (true) {
ets_printf("%9lu\r", (millis() - startTime));
ets_delay_us(250000);
// stay in an loop blocking other system activity.
//
// Note:
// Hardware WDT kicks in if Software WDT is unable to perform.
// With the Hardware WDT, nothing is saved on the stack, that I have seen.
}
}
break;
case '\r':
out.println();
case '\n':
break;
case '?':
out.println();
out.println(F("Press a key + <enter>"));
out.println(F(" r - Reset, ESP.reset();"));
out.println(F(" t - Restart, ESP.restart();"));
out.println(F(" ? - Print Help"));
out.println();
out.println(F("Crash with:"));
out.println(F(" s - Software WDT"));
out.println(F(" h - Hardware WDT"));
printHelpAddOn(out);
out.println();
break;
default:
if (hotKeyHandlerAddOn(out, hotKey)) {
return;
}
out.printf_P(PSTR("\"%c\" - Not an option? / ? - help"), hotKey);
out.println();
processKey(out, '?');
break;
}
}
Loading