diff --git a/libraries/AP_HAL_ChibiOS/CrashDump.cpp b/libraries/AP_HAL_ChibiOS/CrashDump.cpp index 6273fc730af..8a03da9f3cf 100644 --- a/libraries/AP_HAL_ChibiOS/CrashDump.cpp +++ b/libraries/AP_HAL_ChibiOS/CrashDump.cpp @@ -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 diff --git a/libraries/AP_HAL_ChibiOS/CrashDump.h b/libraries/AP_HAL_ChibiOS/CrashDump.h index e2dc881996e..935eb93684f 100644 --- a/libraries/AP_HAL_ChibiOS/CrashDump.h +++ b/libraries/AP_HAL_ChibiOS/CrashDump.h @@ -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 diff --git a/libraries/AP_HAL_ChibiOS/CrashDump_flash.cpp b/libraries/AP_HAL_ChibiOS/CrashDump_flash.cpp index c7c98135354..3709b9a4f13 100644 --- a/libraries/AP_HAL_ChibiOS/CrashDump_flash.cpp +++ b/libraries/AP_HAL_ChibiOS/CrashDump_flash.cpp @@ -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 diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/watchdog.c b/libraries/AP_HAL_ChibiOS/hwdef/common/watchdog.c index 689f9e4acc1..f685dd96569 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/watchdog.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/watchdog.c @@ -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 diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/watchdog.h b/libraries/AP_HAL_ChibiOS/hwdef/common/watchdog.h index de8e3941494..824fdf221c4 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/watchdog.h +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/watchdog.h @@ -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