From 18d02abf9d0a1d92162fa78d9e6a2b9d51de4438 Mon Sep 17 00:00:00 2001 From: Oskar Date: Mon, 31 Jul 2023 01:27:56 +0200 Subject: [PATCH] Fix bug where WDG wouldn't initialize if ASMS is turned on after SDCL bootup --- sdcl-firmware/Core/Src/main.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sdcl-firmware/Core/Src/main.c b/sdcl-firmware/Core/Src/main.c index cf04a6b..b08876a 100644 --- a/sdcl-firmware/Core/Src/main.c +++ b/sdcl-firmware/Core/Src/main.c @@ -254,10 +254,11 @@ int main(void) /* USER CODE BEGIN WHILE */ bool pAMC = false; + bool pASMS = false; mission_t new_mission = mission; // By default, don't change mission - // Wait 1s to prevent bus error state while ABX is starting up - // Wait 5s for the discharge of the DC link (so AMS can't restart) + // Wait at least 1s to prevent bus error state while ABX is starting up + // Wait at least 5s for the discharge of the DC link (so AMS can't restart) // During that time, show loading animation to show LEDs work while (HAL_GetTick() < 5000) { setMissionLED(M_MANUAL, GPIO_PIN_SET); @@ -272,12 +273,6 @@ int main(void) setup_done = true; - // TEMP: Only enable WD if in autonomous mode because EMI currently messes it up during R2D - if (HAL_GPIO_ReadPin(ASMS_GPIO_Port, ASMS_Pin) == GPIO_PIN_RESET) { - MX_IWDG_Init(); - WD_initialized = true; - } - while (true) { // Compare with RESET for signals obtained via inverting buffer @@ -307,6 +302,12 @@ int main(void) } + // TEMP: Only enable WD if in autonomous mode because EMI currently messes it up during R2D + if (ASMS > pASMS) { + MX_IWDG_Init(); + WD_initialized = true; + } + txData = (tx_data_t) { .signals = { .asms_state = ASMS, @@ -328,6 +329,7 @@ int main(void) // Store previous button value to detect signal edges pAMC = AMC; + pASMS = ASMS; HAL_Delay(TX_UPDATE_PERIOD);