mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-16 00:43:00 +03:00
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
This commit is contained in:
@ -27,6 +27,13 @@ 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;
|
||||
@ -34,3 +41,4 @@ extern "C" void app_entry_redefinable(void)
|
||||
/* Call the entry point of the SDK code. */
|
||||
call_user_start();
|
||||
}
|
||||
#endif
|
||||
|
@ -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
|
||||
|
||||
@ -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
|
||||
|
@ -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);
|
||||
|
1242
cores/esp8266/hwdt_app_entry.cpp
Normal file
1242
cores/esp8266/hwdt_app_entry.cpp
Normal file
File diff suppressed because it is too large
Load Diff
21
cores/esp8266/hwdt_app_entry.h
Normal file
21
cores/esp8266/hwdt_app_entry.h
Normal file
@ -0,0 +1,21 @@
|
||||
#if !defined(HWDT_STACK_DUMP_H) || defined(HWDT_VERIFY_HWDT_INFO)
|
||||
#define HWDT_STACK_DUMP_H
|
||||
|
||||
typedef struct hwdt_info_ {
|
||||
uint32_t rom;
|
||||
uint32_t sys;
|
||||
uint32_t cont;
|
||||
uint32_t bearssl;
|
||||
uint32_t rom_api_reason;
|
||||
uint32_t rtc_sys_reason;
|
||||
uint32_t reset_reason;
|
||||
uint32_t cont_integrity;
|
||||
bool g_pcont_valid;
|
||||
} hwdt_info_t;
|
||||
|
||||
extern "C" void debug_hwdt_init(void);
|
||||
|
||||
extern uint32_t *g_rom_stack;
|
||||
extern hwdt_info_t hwdt_info;
|
||||
|
||||
#endif
|
@ -204,13 +204,8 @@ void umm_print_stats(int force) {
|
||||
#endif
|
||||
|
||||
int ICACHE_FLASH_ATTR umm_info_safe_printf_P(const char *fmt, ...) {
|
||||
/*
|
||||
To use ets_strlen() and ets_strcpy() safely with PROGMEM, flash storage,
|
||||
the PROGMEM address must be word (4 bytes) aligned. The destination
|
||||
address for ets_memcpy must also be word-aligned.
|
||||
*/
|
||||
char ram_buf[ets_strlen(fmt) + 1] __attribute__((aligned(4)));
|
||||
ets_strcpy(ram_buf, fmt);
|
||||
char ram_buf[strlen_P(fmt) + 1];
|
||||
strcpy_P(ram_buf, fmt);
|
||||
va_list argPtr;
|
||||
va_start(argPtr, fmt);
|
||||
int result = ets_vprintf(ets_uart_putc1, ram_buf, argPtr);
|
||||
|
@ -48,8 +48,7 @@ void ICACHE_FLASH_ATTR umm_print_stats(int force);
|
||||
|
||||
|
||||
int ICACHE_FLASH_ATTR umm_info_safe_printf_P(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
#define UMM_INFO_PRINTF(fmt, ...) umm_info_safe_printf_P(PSTR4(fmt), ##__VA_ARGS__)
|
||||
// use PSTR4() instead of PSTR() to ensure 4-bytes alignment in Flash, whatever the default alignment of PSTR_ALIGN
|
||||
#define UMM_INFO_PRINTF(fmt, ...) umm_info_safe_printf_P(PSTR(fmt), ##__VA_ARGS__)
|
||||
|
||||
|
||||
typedef struct umm_block_t umm_block;
|
||||
|
Reference in New Issue
Block a user