Skip to content

Commit

Permalink
Hardware WDT Stack Dump Tool (#7010)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mhightower83 authored Apr 7, 2021
1 parent 0049090 commit da6ec83
Show file tree
Hide file tree
Showing 11 changed files with 1,913 additions and 16 deletions.
420 changes: 420 additions & 0 deletions boards.txt

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions cores/esp8266/core_esp8266_app_entry_noextra4k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ extern "C" void call_user_start();
/* this is the default NONOS-SDK user's heap location */
static cont_t g_cont __attribute__ ((aligned (16)));

#if defined(DEBUG_ESP_HWDT_NOEXTRA4K) || defined(DEBUG_ESP_HWDT)
extern "C" cont_t * ICACHE_RAM_ATTR get_noextra4k_g_pcont(void)
{
return &g_cont;
}

#else
extern "C" void app_entry_redefinable(void)
{
g_pcont = &g_cont;

/* Call the entry point of the SDK code. */
call_user_start();
}
#endif
8 changes: 6 additions & 2 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ extern "C" {
#include <core_version.h>
#include "gdb_hooks.h"
#include "flash_quirks.h"
#include "hwdt_app_entry.h"
#include <umm_malloc/umm_malloc.h>
#include <core_esp8266_non32xfer.h>
#include "core_esp8266_vm.h"


#define LOOP_TASK_PRIORITY 1
#define LOOP_QUEUE_SIZE 1

Expand Down Expand Up @@ -349,10 +349,14 @@ extern "C" void user_init(void) {

cont_init(g_pcont);

#if defined(DEBUG_ESP_HWDT) || defined(DEBUG_ESP_HWDT_NOEXTRA4K)
debug_hwdt_init();
#endif

#if defined(UMM_HEAP_EXTERNAL)
install_vm_exception_handler();
#endif

#if defined(NON32XFER_HANDLER) || defined(MMU_IRAM_HEAP)
install_non32xfer_exception_handler();
#endif
Expand Down
4 changes: 2 additions & 2 deletions cores/esp8266/heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ void IRAM_ATTR print_loc(size_t size, const char* file, int line)
if (inISR && (uint32_t)file >= 0x40200000) {
DEBUG_HEAP_PRINTF("File: %p", file);
} else if (!inISR && (uint32_t)file >= 0x40200000) {
char buf[ets_strlen(file) + 1] __attribute__((aligned(4)));
ets_strcpy(buf, file);
char buf[strlen_P(file) + 1];
strcpy_P(buf, file);
DEBUG_HEAP_PRINTF(buf);
} else {
DEBUG_HEAP_PRINTF(file);
Expand Down
Loading

0 comments on commit da6ec83

Please sign in to comment.