diff --git a/src/main.c b/src/main.c index 4f31b2d..b2dcf9d 100644 --- a/src/main.c +++ b/src/main.c @@ -27,6 +27,7 @@ #include "power_mgmt.h" #include "battery.h" #include "coulomb_counter.h" +#include "watchdog.h" #include #include #include @@ -42,6 +43,9 @@ extern volatile uint8_t cdc_estop_clear_request; /* BNO055 active flag (set if BNO055 initialized successfully) */ static bool bno055_active = false; +/* Watchdog reset flag (set if MCU was reset by IWDG timeout) */ +static bool g_watchdog_reset_detected = false; + /* * Apply a PID tuning command string from the USB terminal. * Format: P I D T M ? @@ -119,6 +123,9 @@ int main(void) { HAL_Init(); SystemClock_Config(); + /* Detect watchdog reset (Issue #300) — must be before safety_init() */ + g_watchdog_reset_detected = watchdog_was_reset_by_watchdog(); + /* USB CDC */ USBD_Init(&hUsbDevice, &SaltyLab_Desc, 0); USBD_RegisterClass(&hUsbDevice, &USBD_CDC); @@ -128,6 +135,11 @@ int main(void) { status_init(); HAL_Delay(3000); /* Wait for USB host to enumerate */ + /* Log watchdog reset event if it occurred (Issue #300) */ + if (g_watchdog_reset_detected) { + printf("[WATCHDOG] MCU reset by IWDG timeout detected. Main loop may have hung.\n"); + } + /* Init IMU (MPU6000 via SPI1 — mpu6000.c wraps icm42688 + complementary filter) */ int imu_ret = mpu6000_init() ? 0 : -1;