AP_HAL_ChibiOS: reset crash handler without watchdog

This commit is contained in:
Andrew Tridgell
2026-08-25 10:46:36 +10:00
parent 0992ff02f2
commit bcb572f53d
5 changed files with 31 additions and 21 deletions
+16 -13
View File
@@ -40,10 +40,6 @@
static CrashCatcherInfo g_info;
#endif
#if AP_CRASHDUMP_FLASH_ENABLED
CRASH_CATCHER_TEST_WRITEABLE CrashCatcherReturnCodes g_crashCatcherDumpEndReturn = CRASH_CATCHER_TRY_AGAIN;
#endif
#if AP_CRASHDUMP_FLASH_ENABLED
static bool do_flash_crash_dump = true;
#endif
@@ -52,6 +48,15 @@ static bool do_sd_crash_dump = false;
static uint32_t sd_dump_size = 0;
#endif
static void wait_for_watchdog_or_reset() NORETURN;
static void wait_for_watchdog_or_reset()
{
if (!stm32_watchdog_enabled()) {
NVIC_SystemReset();
}
while (true) {}
}
const CrashCatcherMemoryRegion* CrashCatcher_GetMemoryRegions(void)
{
#if CRASHDUMP_SD_ENABLED || !AP_CRASHDUMP_FLASH_ENABLED
@@ -150,21 +155,19 @@ CrashCatcherReturnCodes CrashCatcher_DumpEnd(void)
crashdump_sd_end(sd_dump_size);
}
do_sd_crash_dump = false;
// Let the watchdog reboot us so the saved watchdog state is restored.
while (true) {}
}
#endif
#if AP_CRASHDUMP_FLASH_ENABLED
if (do_flash_crash_dump) {
return crashdump_flash_end(g_crashCatcherDumpEndReturn, g_info.isBKPT);
crashdump_flash_end();
do_flash_crash_dump = false;
}
if (g_info.isBKPT) {
return CRASH_CATCHER_EXIT;
}
do_flash_crash_dump = false;
return CRASH_CATCHER_TRY_AGAIN;
#else
// No configured backend accepted the dump. Let the watchdog reboot us so
// the saved watchdog state is restored.
while (true) {}
#endif
// Preserve watchdog-reset semantics when active; otherwise reset now.
wait_for_watchdog_or_reset();
}
#endif // AP_CRASHDUMP_ENABLED
+1 -2
View File
@@ -108,8 +108,7 @@ const CrashCatcherMemoryRegion *crashdump_flash_memory_regions(bool active);
void crashdump_flash_write(const void *memory,
CrashCatcherElementSizes element_size,
size_t element_count);
CrashCatcherReturnCodes crashdump_flash_end(CrashCatcherReturnCodes return_code,
bool is_breakpoint);
void crashdump_flash_end(void);
#endif
#ifdef __cplusplus
+1 -6
View File
@@ -266,8 +266,7 @@ void crashdump_flash_write(const void *memory,
}
}
CrashCatcherReturnCodes crashdump_flash_end(CrashCatcherReturnCodes return_code,
bool is_breakpoint)
void crashdump_flash_end(void)
{
if (dump_size + buf_off + sizeof(dump_size) >= stm32_crash_dump_max_size()) {
memset(&dump_buffer[sizeof(dump_buffer) - sizeof(dump_size)],
@@ -299,10 +298,6 @@ CrashCatcherReturnCodes crashdump_flash_end(CrashCatcherReturnCodes return_code,
}
stm32_flash_keep_unlocked(false);
if (return_code == CRASH_CATCHER_TRY_AGAIN && is_breakpoint) {
return CRASH_CATCHER_EXIT;
}
return return_code;
}
#endif // AP_CRASHDUMP_ENABLED && AP_CRASHDUMP_FLASH_ENABLED
@@ -87,6 +87,14 @@ void stm32_watchdog_init(void)
watchdog_enabled = true;
}
/*
return true if the watchdog has been started
*/
bool stm32_watchdog_enabled(void)
{
return watchdog_enabled;
}
/*
pat the dog, to prevent a reset. If not called for STM32_WDG_TIMEOUT_MS
after stm32_watchdog_init() then MCU will reset
@@ -9,6 +9,11 @@ extern "C" {
*/
void stm32_watchdog_init(void);
/*
return true if the watchdog has been started
*/
bool stm32_watchdog_enabled(void);
/*
pat the dog, to prevent a reset. If not called for STM32_WDG_TIMEOUT_MS
after stm32_watchdog_init() then MCU will reset