From b71fde68e9a4257d6f026091de130932acbb580b Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sat, 27 Jun 2020 16:17:42 +0200 Subject: [PATCH] core/panic: launch USB bootloader for easy recovery If a board was flashed via USB bootloader, a crash means the user has to perform a procedure to manually enter the bootloader again for recovery. To allow for easier recovery, automatically lauch the bootloader on crash if `DEVELHELP` is enabled. --- core/panic.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/panic.c b/core/panic.c index 4de948711c..b2d7d2b4f8 100644 --- a/core/panic.c +++ b/core/panic.c @@ -36,6 +36,13 @@ #include "ps.h" #endif +/* If a device is flashed over USB bootloader, try to launch + * the bootloader again on crash so the user can re-flash it. + */ +#if defined(DEVELHELP) && defined(MODULE_USB_BOARD_RESET) +#include "usb_board_reset.h" +#endif + const char assert_crash_message[] = "FAILED ASSERTION."; /* flag preventing "recursive crash printing loop" */ @@ -81,8 +88,13 @@ NORETURN void core_panic(core_panic_t crash_code, const char *message) pm_reboot(); #else /* DEVELHELP set => power off system */ + /* or start bootloader */ +#ifdef MODULE_USB_BOARD_RESET + usb_board_reset_in_bootloader(); +#else pm_off(); #endif +#endif /* DEVELHELP */ /* tell the compiler that we won't return from this function (even if we actually won't even get here...) */