nrf52: hardfault recorder v aplikaci a v .noinit (#5)

Recorder nikdy nefungoval: handler byl patch v utility/debug.cpp
frameworku, jenže jádro se linkuje jako archiv a weak HardFault_Handler
ze startupu už vektor pokrývá, takže debug.o se do žádného buildu
nedostal (nm ukazoval jen W symbol). Záznam navíc ležel na 0x2003FFF0,
kam po resetu sahá zásobník bootloaderu.

Handler je teď silný symbol v NRF52Board.cpp a zapisuje do
g_hardfault_record v .noinit; funguje i s commitnutým pinem frameworku
(lokální patch už není potřeba). Ověřeno na x2: testovací build
s -D BENCH_FAULT_CMD, příkaz hardfault → po resetu
'HARDFAULT before last reboot: PC=00033442' = udf v handleCommand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-10-18 22:59:02 +02:00
1 parent c7f9c2ef79
commit f6fc21d40d
4 files changed
+50 -3

No files matched your search

+4 -2
View File
@@ -739,7 +739,8 @@ void setup() {
#if defined(NRF52_PLATFORM)
// CUSTOM (TeTeHacko diagnostics): print the hardfault record saved by the
// patched HardFault_Handler (framework debug.cpp) before the last reset.
// 16 B at the end of RAM, reserved in nrf52840_s140_v7_extrafs.ld.
// g_hardfault_record in .noinit (NRF52Board.cpp) -- the old fixed 0x2003FFF0 at
// the end of RAM was where the bootloader's stack lands on the following reset.
// NOTE: needs MESH_DEBUG or BOOT_DIAG_DELAY_MS to be readable at all (above).
// CUSTOM (TeTeHacko): why did this board last restart? The core latches
// NRF_POWER->RESETREAS in init() before clearing it, and it is the only thing
@@ -764,7 +765,8 @@ void setup() {
}
{
volatile uint32_t* hf = (volatile uint32_t*)0x2003FFF0;
extern uint32_t g_hardfault_record[4]; // NRF52Board.cpp, .noinit
volatile uint32_t* hf = g_hardfault_record;
if (hf[0] == 0xFA010DEB) {
Serial.printf("!!! HARDFAULT before last reboot: PC=%08lX LR=%08lX PSR=%08lX\n",
(unsigned long)hf[1], (unsigned long)hf[2], (unsigned long)hf[3]);