From e5a06beefcc3f8fae7aa2de2ce2a44709ddd45e9 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Thu, 27 May 2021 12:51:08 +0200 Subject: [PATCH] Fix the RESET_FORCED case not being used and not being able to correctly determine the reason for the reset when the reset is forced. Before 31b06cd7d20bf93d3820a6e99ea70725c25b20b2 it was possible for early init code to overwrite the reset reason, however this commit also broke the code that allows the system, and developer, to determine the reason for the reset when the reset was forced. --- src/main/drivers/system_stm32h7xx.c | 7 +++---- src/main/startup/system_stm32h7xx.c | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/drivers/system_stm32h7xx.c b/src/main/drivers/system_stm32h7xx.c index d8e1391f0c..61a2fd6ae0 100644 --- a/src/main/drivers/system_stm32h7xx.c +++ b/src/main/drivers/system_stm32h7xx.c @@ -110,10 +110,8 @@ void systemReset(void) NVIC_SystemReset(); } -void forcedSystemResetWithoutDisablingCaches(void) +void systemResetWithoutDisablingCaches(void) { - // Don't overwrite the PERSISTENT_OBJECT_RESET_REASON; just make another attempt - __disable_irq(); NVIC_SystemReset(); } @@ -184,7 +182,8 @@ void systemCheckResetReason(void) case RESET_BOOTLOADER_POST: // Boot loader activity magically prevents SysTick from interrupting. // Issue a soft reset to prevent the condition. - forcedSystemResetWithoutDisablingCaches(); // observed that disabling dcache after cold boot with BOOT pin high causes segfault. + persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_FORCED); + systemResetWithoutDisablingCaches(); // observed that disabling dcache after cold boot with BOOT pin high causes segfault. case RESET_MSC_REQUEST: case RESET_NONE: diff --git a/src/main/startup/system_stm32h7xx.c b/src/main/startup/system_stm32h7xx.c index b84874fa51..23d9af7c54 100644 --- a/src/main/startup/system_stm32h7xx.c +++ b/src/main/startup/system_stm32h7xx.c @@ -69,7 +69,7 @@ #include "build/debug.h" -void forcedSystemResetWithoutDisablingCaches(void); +void systemResetWithoutDisablingCaches(void); #if !defined (HSE_VALUE) #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */ @@ -179,7 +179,7 @@ void HandleStuckSysTick(void) } if (tickStart == tickEnd) { - forcedSystemResetWithoutDisablingCaches(); + systemResetWithoutDisablingCaches(); } } @@ -389,7 +389,7 @@ static void SystemClockHSE_Config(void) #ifdef USE_H7_HSE_TIMEOUT_WORKAROUND if (status == HAL_TIMEOUT) { - forcedSystemResetWithoutDisablingCaches(); // DC - sometimes HSERDY gets stuck, waiting longer doesn't help. + systemResetWithoutDisablingCaches(); // DC - sometimes HSERDY gets stuck, waiting longer doesn't help. } #endif