Skip to content

Commit da6ec83

Browse files
authored
Hardware WDT Stack Dump Tool (#7010)
* Hardware WDT Stack Dump This Sketch demonstrates the use of a tool to print a stack dump at reboot after a Hardware WDT event. The module hwdt_app_entry.cpp writes a stack dump to the serial interface after a Hardware Watchdog Timer has struck and a new boot cycle has begun. The sketch must properly initialized the Serial port before the crash. hwdt_app_entry.cpp is the core file that does the work. * Corrected Style. Improved HWDT reset detectionat boot. * Style and typos * Update comments. * Improvements to reset reason determination. Improved comments. Added option to match the UART speed used by the sketch. Added option to print greeting at the start to indicate the HWDT stack dump code is active. Isolated logic for handling strings: one assuming they are not inited at the time the code is running and one that does. The later appears to be the case. * Style plus Fix issue with HWDT reason detection when sketch crashes too fast. Added sample sketch menu option for crashing with a function defined with a weak attribute via prototype, but never actually defined in full function form. eg. `void trouble(void){return;}` * Moved all configuration options to the top. Adjusted configuration option order for most likely to be used to the top. Tried to improve comments. Replace numbers with enum values. * Removed clutter of having an alternate printing method. Regular global strings have worked reliably. Tweaked reset reason detection. Reordered elements in global structure. Improve #if test for debug option Always improving comments. * Added delays around uart_div_modify. This appeara to resolve the lost data problem that occurs when printing after a flash upload using esptool. Curiously, esptool stub also uses similar delays. Word choices and description improvements. * Finished TODO looked at assembly of app_entry_redefinable to confirm no mixed up stack frame was created. Also removed no longer needed extra level of function calling. Use existing macros from uart_register,h to handle getting current UART speed. Added some missing `const`. * Comment changes. Added a few newlines to printing. Decreased the settling delay after the uart_div_modify call. * Improved comments. Print caution message when stack integrity checks failed. * Several corrections to set_uart_speed Comment improvements Added missing ";" * Removed unused include. Code cleanup. Comments. * Now runs from flash before SDK is started. Cache_Read_Enable working. Free 1K of IRAM and 200 bytes of DRAM. * Changed ICACHE size from 32K to 16K to avoid conflict with SDK or core selecting smaller 16K ICACHE. The Issue: Cache_Read_Enable does not clear the bit field when mapping IRAM to ICACHE on register 0x3FF00024. Thus, no problem upgrading from 16K to 32K; however, you cannot downgrade from 32K to 16K. These bits are cleared at boot. Improved uart data rate change handling. Update comments. * Added support to print ThunkStack. Adjustments to inline asm. Added "memory" when callx0 is used. * comment cleanup. added missing additional #if defined() Made structure name unique. Changed HWDT_INFO to HWDR_INFO_S. * Update style used for structure and typedef to match that used in core when snake case is used. Moved a constexpr block up a scope so that some #ifdef debug code compiles again. * Updated comments * Corrected new errors from upgrade to GCC 10.1 toolchain related to constexpr and casting integers to pointers. Cleared warning for asm. * Work around divide by 0 HWDT event under toolchain 10.1. * Changes to move feature into core. Making ready for selection via tools menu, updated defines to DEBUG_ESP_,,, format. Added HWDT and HWDT_NO4KEXTRA options to boards.txt.py. These options are selectable from Arduino IDE 'Tools->Debug Level' Converted macro names that use to be constexprs to uppercase. Update comments. Added comments to maintainers anotated by '//C' Revised example. * Fix stack character buffer length. * Updated comment to reflect support via Arduino IDE Tools menu. * Improve meshing of HWDT and NOEXTRA4K * Made compatible with `disable_extra4k_at_link_time()` usage. Changed to strings containing "no4kextra" to "noextra4k" to be consistant with original usage. Updated example to provide indications of which build options were used or resulted. Some comment cleanup. * CI style * Adjusted down the ROM Stack space for the extra 4K Heap option. If too large, a really bad crashes occurs. Updated the example to start WiFi. This helps double check ROM Stack space size is not too small at start. Removed stale comment. Changed cont stack check functions to make globally available. * Add replacement aes_unwrap for the debug HWDT option. Improves the SYS stack space available when using the extra 4K Heap option in conjunction with HWDT. Replaces the ROM AES buffer at 0x3FFFEA80 with one provided by malloc(). * Update umm_info_safe_printf_P to support default of unaligned PROGMEM strings. * Improve cont stack trace for yielding case. Check if cont stack is yielding to SYS, use g_pcont->sp_yield to limit the amount of the cont stack dumped. Generalized dev logic path to create a generalized debug function hwdt_pre_sdk_init_icache. * Added missed update to heap.cpp for change to use PSTR instead of PSTR4 * Updated comments and #if in aes_unwrap. * Update boards.txt
1 parent 0049090 commit da6ec83

File tree

11 files changed

+1913
-16
lines changed

11 files changed

+1913
-16
lines changed

boards.txt

+420
Large diffs are not rendered by default.

cores/esp8266/core_esp8266_app_entry_noextra4k.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ extern "C" void call_user_start();
2727
/* this is the default NONOS-SDK user's heap location */
2828
static cont_t g_cont __attribute__ ((aligned (16)));
2929

30+
#if defined(DEBUG_ESP_HWDT_NOEXTRA4K) || defined(DEBUG_ESP_HWDT)
31+
extern "C" cont_t * ICACHE_RAM_ATTR get_noextra4k_g_pcont(void)
32+
{
33+
return &g_cont;
34+
}
35+
36+
#else
3037
extern "C" void app_entry_redefinable(void)
3138
{
3239
g_pcont = &g_cont;
3340

3441
/* Call the entry point of the SDK code. */
3542
call_user_start();
3643
}
44+
#endif

cores/esp8266/core_esp8266_main.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ extern "C" {
3535
#include <core_version.h>
3636
#include "gdb_hooks.h"
3737
#include "flash_quirks.h"
38+
#include "hwdt_app_entry.h"
3839
#include <umm_malloc/umm_malloc.h>
3940
#include <core_esp8266_non32xfer.h>
4041
#include "core_esp8266_vm.h"
4142

42-
4343
#define LOOP_TASK_PRIORITY 1
4444
#define LOOP_QUEUE_SIZE 1
4545

@@ -349,10 +349,14 @@ extern "C" void user_init(void) {
349349

350350
cont_init(g_pcont);
351351

352+
#if defined(DEBUG_ESP_HWDT) || defined(DEBUG_ESP_HWDT_NOEXTRA4K)
353+
debug_hwdt_init();
354+
#endif
355+
352356
#if defined(UMM_HEAP_EXTERNAL)
353357
install_vm_exception_handler();
354358
#endif
355-
359+
356360
#if defined(NON32XFER_HANDLER) || defined(MMU_IRAM_HEAP)
357361
install_non32xfer_exception_handler();
358362
#endif

cores/esp8266/heap.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ void IRAM_ATTR print_loc(size_t size, const char* file, int line)
175175
if (inISR && (uint32_t)file >= 0x40200000) {
176176
DEBUG_HEAP_PRINTF("File: %p", file);
177177
} else if (!inISR && (uint32_t)file >= 0x40200000) {
178-
char buf[ets_strlen(file) + 1] __attribute__((aligned(4)));
179-
ets_strcpy(buf, file);
178+
char buf[strlen_P(file) + 1];
179+
strcpy_P(buf, file);
180180
DEBUG_HEAP_PRINTF(buf);
181181
} else {
182182
DEBUG_HEAP_PRINTF(file);

0 commit comments

Comments
 (0)