Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
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.
  • Loading branch information
mhightower83 committed Aug 7, 2020
commit 65f8e1dc294137abd49631720662b4ce1656d723
408 changes: 204 additions & 204 deletions boards.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cores/esp8266/core_esp8266_app_entry_noextra4k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ 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_NO4KEXTRA)
extern "C" cont_t * ICACHE_RAM_ATTR get_g_cont(void)
#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;
}
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ extern "C" void user_init(void) {

cont_init(g_pcont);

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

Expand Down
123 changes: 78 additions & 45 deletions cores/esp8266/hwdt_app_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@
* `app_entry_redefinable()`, and also to the stack pointer passed to the SDK,
* we can preserve the stack during an HWDT event.
*
* To use this tool, select HWDT or HWDT_NO4KEXTRA from the Arduino IDE menu
* To use this tool, select HWDT or HWDT_NOEXTRA4K from the Arduino IDE menu
* "Tools->Debug Level" before building your sketch. Note, 'Tools->Debug port'
* selection is not needed or referenced for printing the HWDT stack dump.
* To enable in other build environments, add DEBUG_ESP_HWDT_NO4KEXTRA or
* If the sketch is calling `disable_extra4k_at_link_time()`, then building with
* HWDT selected on the Arduino IDE menu "Tools->Debug Level", will have the
* same result as if built with HWDT_NOEXTRA4K selected.
*
* To enable in other build environments, add DEBUG_ESP_HWDT_NOEXTRA4K or
* DEBUG_ESP_HWDT global defines to your build.
*
* This tool prints to the serial port at the default serial port speed set by
Expand Down Expand Up @@ -109,7 +113,7 @@


/*
* DEBUG_ESP_HWDT_NO4KEXTRA
* DEBUG_ESP_HWDT_NOEXTRA4K
*
* This option will leave more of the system stack available for the stack dump.
* A problem we have with the "4K extra" option, is it pushes the system stack
Expand All @@ -128,7 +132,7 @@
* extra 4K in the heap.
*
* This option is now managed from the Arduinoo IDE menu 'Tools->Debug Level'
#define DEBUG_ESP_HWDT_NO4KEXTRA
#define DEBUG_ESP_HWDT_NOEXTRA4K
*/


Expand Down Expand Up @@ -244,7 +248,7 @@
/* End of Configuration Options */
/*____________________________________________________________________________*/

#if defined(DEBUG_ESP_HWDT) || defined(DEBUG_ESP_HWDT_NO4KEXTRA)
#if defined(DEBUG_ESP_HWDT) || defined(DEBUG_ESP_HWDT_NOEXTRA4K)

#include <c_types.h>
#include "cont.h"
Expand Down Expand Up @@ -389,41 +393,66 @@ static_assert(sizeof(hwdt_info_t) == sizeof(LOCAL_HWDT_INFO_T), "Local and inclu
// Map out who will live where.
#define ROM_STACK_A16_SZ (MK_ALIGN16_SZ(DEBUG_ESP_HWDT_ROM_STACK_SIZE))
#define CONT_STACK_A16_SZ (MK_ALIGN16_SZ(sizeof(cont_t)))
/*
* For WPS support, cont stack comes out of the user's heap address space.
* The the NONOS-SDK stack address is initialized before tbe reserved ROM stack
* space. In this configuration there is no extra 4K in the heap.
* Memory map: 0x3FFE8000, ..., (CONT_STACK), ..., (SYS), (ROM_STACK), 0x4000000
*
* sys_stack_first <= ROM_STACK
*/
#define ROM_STACK ((uint32_t *) ((uintptr_t)ROM_STACK_FIRST - ROM_STACK_A16_SZ))


#ifdef DEBUG_ESP_HWDT_NO4KEXTRA
/* This is the default NONOS-SDK user's heap location for NO4KEXTRA */
#define SYS_STACK_FIRST ROM_STACK
extern cont_t * get_g_cont(void);

#else
#define CONT_STACK_FIRST ROM_STACK // only for computation
/*
* For extra 4K of heap space, the continuation stack (user's stack) is created
* in the SYS stack address space. The NONOS-SDK stack starts before the cont
* stack.
* Memory map: 0x3FFE8000, ..., (SYS), (CONT_STACK), (ROM_STACK), 0x4000000
*
* sys_stack_first <= CONT_STACK
*/
#define CONT_STACK ((cont_t *)((uintptr_t)CONT_STACK_FIRST - CONT_STACK_A16_SZ))
#define SYS_STACK_FIRST CONT_STACK
#endif


uint32_t *g_rom_stack __attribute__((section(".noinit")));
uint32_t *sys_stack_first __attribute__((section(".noinit")));
size_t g_rom_stack_A16_sz __attribute__((section(".noinit")));
hwdt_info_t hwdt_info __attribute__((section(".noinit")));

extern "C" {

extern cont_t * get_noextra4k_g_pcont(void);

cont_t * ICACHE_RAM_ATTR get_noextra4k_g_pcont(void) __attribute__((weak));
cont_t * ICACHE_RAM_ATTR get_noextra4k_g_pcont(void) {
return NULL;
}

static void IRAM_MAYBE set__sys_stack_first(void) {
if (get_noextra4k_g_pcont()) {
sys_stack_first = ROM_STACK;
} else {
sys_stack_first = (uint32_t *)CONT_STACK;
}
}

#if USE_IRAM
#define ETS_PRINTF ets_uart_printf

#else
/*
This function is already in umm_malloc for some debug options.
Define here in case they are not enabled.
*/
* This function is already in umm_malloc for some debug options.
* Define here in case they are not enabled.
*/
int ICACHE_FLASH_ATTR umm_info_safe_printf_P(const char *fmt, ...) __attribute__((weak));
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.
*/
* 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);
va_list argPtr;
Expand Down Expand Up @@ -510,13 +539,10 @@ STATIC void IRAM_MAYBE check_g_pcont_validity(void) {
* Testing of vital pointers for validity could also aid as a partial
* indicator of power-on. Not needed for that purpose at this time.
*/
cont_t *noextra4k_g_pcont = get_noextra4k_g_pcont();
if (g_rom_stack == ROM_STACK &&
g_rom_stack_A16_sz == ROM_STACK_A16_SZ &&
#ifdef DEBUG_ESP_HWDT_NO4KEXTRA
g_pcont == get_g_cont()
#else
g_pcont == CONT_STACK
#endif
g_pcont == ((noextra4k_g_pcont) ? noextra4k_g_pcont : CONT_STACK)
) {
hwdt_info.g_pcont_valid = true;
} else {
Expand Down Expand Up @@ -808,9 +834,10 @@ STATIC uint32_t IRAM_MAYBE set_uart_speed(const uint32_t uart_no, const uint32_t
*/
STATIC void IRAM_MAYBE handle_hwdt(void) __attribute__((used));
STATIC void IRAM_MAYBE handle_hwdt(void) {
#ifdef DEBUG_ESP_HWDT_NO4KEXTRA
#ifdef DEBUG_ESP_HWDT_NOEXTRA4K
disable_extra4k_at_link_time();
#endif
set__sys_stack_first();

ets_memset(&hwdt_info, 0, sizeof(hwdt_info));
check_g_pcont_validity();
Expand Down Expand Up @@ -868,10 +895,14 @@ STATIC void IRAM_MAYBE handle_hwdt(void) {
}
hwdt_info.cont_integrity = cont_integrity;

#if defined(DEBUG_ESP_HWDT_NO4KEXTRA) || defined(DEBUG_ESP_HWDT_INFO)
const uint32_t *ctx_cont_ptr = skip_stackguard(g_pcont->stack, g_pcont->stack_end, CONT_STACKGUARD);
hwdt_info.cont = (uintptr_t)g_pcont->stack_end - (uintptr_t)ctx_cont_ptr;
const uint32_t *ctx_cont_ptr = NULL;
#if !defined(DEBUG_ESP_HWDT_INFO)
if (get_noextra4k_g_pcont())
#endif
{
ctx_cont_ptr = skip_stackguard(g_pcont->stack, g_pcont->stack_end, CONT_STACKGUARD);
hwdt_info.cont = (uintptr_t)g_pcont->stack_end - (uintptr_t)ctx_cont_ptr;
}

const uint32_t *ctx_sys_ptr = skip_stackguard(SYS_STACK, ROM_STACK, CONT_STACKGUARD);
hwdt_info.sys = (uintptr_t)ROM_STACK - (uintptr_t)ctx_sys_ptr;
Expand All @@ -897,10 +928,11 @@ STATIC void IRAM_MAYBE handle_hwdt(void) {
/* Print context SYS */
print_stack((uintptr_t)ctx_sys_ptr, (uintptr_t)ROM_STACK, PRINT_STACK::SYS);

#ifdef DEBUG_ESP_HWDT_NO4KEXTRA
/* Print separate ctx: cont stack */
print_stack((uintptr_t)ctx_cont_ptr, (uintptr_t)g_pcont->stack_end, PRINT_STACK::CONT);
#endif
if (get_noextra4k_g_pcont()) {
/* Print separate ctx: cont stack */
print_stack((uintptr_t)ctx_cont_ptr, (uintptr_t)g_pcont->stack_end, PRINT_STACK::CONT);
}

if (hwdt_info.cont_integrity) {
ETS_PRINTF("\nCaution, the stack is possibly corrupt integrity checks did not pass.\n\n");
}
Expand Down Expand Up @@ -981,27 +1013,28 @@ void ICACHE_RAM_ATTR app_entry_start(void) {
handle_hwdt_icache();
#endif

#ifdef DEBUG_ESP_HWDT_NO4KEXTRA
/*
* Continuation context is in BSS.
*/
g_pcont = get_g_cont();
#else
/*
* The continuation context is on the stack just after the reserved space
* for the ROM/eboot stack and before the SYS stack begins.
* All computations were done at top, save pointer to it now.
*/
g_pcont = CONT_STACK;
#endif
g_pcont = get_noextra4k_g_pcont();

if (!g_pcont) {
/*
* The continuation context is on the stack just after the reserved
* space for the ROM/eboot stack and before the SYS stack begins. All
* computations were done at top, save pointer to it now.
*/
g_pcont = CONT_STACK;
}

/*
* Use new calculated SYS stack from top.
* Call the entry point of the SDK code.
*/
asm volatile ("mov.n a1, %0\n\t"
"movi a0, 0x4000044c\n\t" /* Should never return; however, set return to Boot ROM Breakpoint */
"jx %1\n\t" ::
"r" (SYS_STACK_FIRST), "r" (call_user_start):
"r" (sys_stack_first), "r" (call_user_start):
"a0", "memory");

__builtin_unreachable();
Expand Down Expand Up @@ -1053,4 +1086,4 @@ void debug_hwdt_init(void) {

};

#endif // end of #if defined(DEBUG_ESP_HWDT) || defined(DEBUG_ESP_HWDT_NO4KEXTRA)
#endif // end of #if defined(DEBUG_ESP_HWDT) || defined(DEBUG_ESP_HWDT_NOEXTRA4K)
26 changes: 25 additions & 1 deletion libraries/esp8266/examples/HwdtStackDump/HwdtStackDump.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

There is a tool to print a stack dump at boot after a Hardware WDT
reset. To use the Hardware WDT Reset stack dump tool, you can select HWDT or
HWDT_NO4KEXTRA from the Arduino IDE menu "Tools->Debug Level" before
HWDT_NOEXTRA4K from the Arduino IDE menu "Tools->Debug Level" before
building your sketch. Note, 'Tools->Debug port' selection is not needed or
referenced for printing the HWDT stack dump.

Expand All @@ -19,6 +19,7 @@
#include <ESP8266WiFi.h>
#include <Esp.h>
#include <user_interface.h>
#include <coredecls.h> // g_pcont - only needed for this debug demo

void setup(void) {
WiFi.persistent(false); // w/o this a flash write occurs at every boot
Expand All @@ -27,6 +28,29 @@ void setup(void) {
delay(20); // This delay helps when using the 'Modified Serial monitor' otherwise it is not needed.
Serial.println();
Serial.println();

// #define DEMO_NOEXTRA4K
#ifdef DEMO_NOEXTRA4K
/*
When a call to disable_extra4k_at_link_time() is made, building with HWDT
selected on the Arduino IDE menu "Tools->Debug Level", will have the same
result as if built with HWDT_NOEXTRA4K selected.
*/
disable_extra4k_at_link_time();
#endif

Serial.printf_P(PSTR("This example was built with%s an extra 4K of heap space (g_pcont == 0x%08lX)\r\n"),
((uintptr_t)0x3FFFC000 < (uintptr_t)g_pcont) ? "" : "out",
(uintptr_t)g_pcont);
#if defined(DEBUG_ESP_HWDT) || defined(DEBUG_ESP_HWDT_NOEXTRA4K)
Serial.print(F("and with the HWDT"));
#if defined(DEBUG_ESP_HWDT_NOEXTRA4K)
Serial.print(F("_NOEXTRA4K"));
#endif
Serial.println(F(" option specified."));
#endif

Serial.println();
Serial.println(F("The Hardware Watchdog Timer Demo is now available for crashing ..."));
Serial.println();
processKey(Serial, '?');
Expand Down
2 changes: 1 addition & 1 deletion tools/boards.txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ def comb1 (lst, lstplusone):
def all_debug ():
listcomb = [ 'SSL', 'TLS_MEM', 'HTTP_CLIENT', 'HTTP_SERVER' ]
listnocomb = [ 'CORE', 'WIFI', 'HTTP_UPDATE', 'UPDATER', 'OTA', 'OOM', 'MDNS' ]
listplusone = [ 'HWDT', 'HWDT_NO4KEXTRA' ]
listplusone = [ 'HWDT', 'HWDT_NOEXTRA4K' ]
listsingle = [ 'NoAssert-NDEBUG' ]
options = combn(listcomb)
options += comb1(listnocomb, listplusone)
Expand Down