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:
1 parent
c7f9c2ef79
commit
f6fc21d40d
4 files changed
+50
-3
No files matched your search
@@ -12,6 +12,41 @@ extern "C" {
|
||||
void retainedClockInvalidate() { g_retained_clock[0] = 0; }
|
||||
}
|
||||
#endif
|
||||
|
||||
// CUSTOM (TeTeHacko): hardfault recorder. On a fault, save the stacked PC/LR/PSR
|
||||
// to g_hardfault_record and reset; simple_repeater/main.cpp prints it on the next
|
||||
// boot. Both halves had to move here (18. 10. 2026):
|
||||
// - The record lived at a fixed 0x2003FFF0, the top of RAM, which is where the
|
||||
// Adafruit bootloader's stack lands on the reset after the fault. .noinit
|
||||
// (after .bss) survives, same as the retained clock.
|
||||
// - The handler was a patch in the framework's utility/debug.cpp and it NEVER
|
||||
// linked: the core is built as an archive, the startup's weak
|
||||
// HardFault_Handler already satisfies the vector table, so the linker never
|
||||
// pulled debug.o in (nm on any build showed only the weak symbol). An object
|
||||
// of the application is always linked, so a strong definition here wins.
|
||||
// debug.o would only come in with CFG_DEBUG (dbgPrintVersion() in the core's
|
||||
// main.cpp), which would then be a duplicate symbol -- no env sets it.
|
||||
#define HARDFAULT_MAGIC 0xFA010DEB
|
||||
extern "C" {
|
||||
uint32_t g_hardfault_record[4] __attribute__((section(".noinit"))); // magic, pc, lr, psr
|
||||
|
||||
void HardFault_c_handler(uint32_t* sp) {
|
||||
g_hardfault_record[1] = sp[6]; // stacked PC
|
||||
g_hardfault_record[2] = sp[5]; // stacked LR
|
||||
g_hardfault_record[3] = sp[7]; // stacked xPSR
|
||||
g_hardfault_record[0] = HARDFAULT_MAGIC;
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
__attribute__((naked)) void HardFault_Handler(void) {
|
||||
__asm volatile(
|
||||
"tst lr, #4 \n"
|
||||
"ite eq \n"
|
||||
"mrseq r0, msp \n"
|
||||
"mrsne r0, psp \n"
|
||||
"b HardFault_c_handler \n");
|
||||
}
|
||||
}
|
||||
#include <target.h>
|
||||
|
||||
#include <bluefruit.h>
|
||||
|
||||
Reference in new issue
Block a user