HAL_ChibiOS: added stm32_was_software_reset()

This commit is contained in:
Andrew Tridgell 2022-02-05 12:41:54 +11:00
parent a641eb3a30
commit f2308e96a9
2 changed files with 23 additions and 4 deletions

View File

@ -29,18 +29,22 @@
#define WDG_RESET_STATUS (*(__IO uint32_t *)(RCC_BASE + 0xD0))
#define WDG_RESET_CLEAR (1U<<16)
#define WDG_RESET_IS_IWDG (1U<<26)
#define WDG_RESET_IS_SFT (1U<<24)
#elif defined(STM32F7) || defined(STM32F4)
#define WDG_RESET_STATUS (*(__IO uint32_t *)(RCC_BASE + 0x74))
#define WDG_RESET_CLEAR (1U<<24)
#define WDG_RESET_IS_IWDG (1U<<29)
#define WDG_RESET_IS_SFT (1U<<28)
#elif defined(STM32F1) || defined(STM32F3)
#define WDG_RESET_STATUS (*(__IO uint32_t *)(RCC_BASE + 0x24))
#define WDG_RESET_CLEAR (1U<<24)
#define WDG_RESET_IS_IWDG (1U<<29)
#define WDG_RESET_IS_SFT (1U<<28)
#elif defined(STM32G4) || defined(STM32L4)
#define WDG_RESET_STATUS (*(__IO uint32_t *)(RCC_BASE + 0x94))
#define WDG_RESET_CLEAR (1U<<23)
#define WDG_RESET_IS_IWDG (1U<<29)
#define WDG_RESET_IS_SFT (1U<<28)
#else
#error "Unsupported IWDG MCU config"
#endif
@ -56,7 +60,7 @@ typedef struct
#define IWDGD (*(IWDG_Regs *)(IWDG_BASE))
static bool was_watchdog_reset;
static uint32_t reset_reason;
static bool watchdog_enabled;
/*
@ -88,8 +92,8 @@ void stm32_watchdog_pat(void)
*/
void stm32_watchdog_save_reason(void)
{
if (WDG_RESET_STATUS & WDG_RESET_IS_IWDG) {
was_watchdog_reset = true;
if (reset_reason == 0) {
reset_reason = WDG_RESET_STATUS;
}
}
@ -106,7 +110,17 @@ void stm32_watchdog_clear_reason(void)
*/
bool stm32_was_watchdog_reset(void)
{
return was_watchdog_reset;
stm32_watchdog_save_reason();
return (reset_reason & WDG_RESET_IS_IWDG) != 0;
}
/*
return true if reboot was from a software reset
*/
bool stm32_was_software_reset(void)
{
stm32_watchdog_save_reason();
return (reset_reason & WDG_RESET_IS_SFT) != 0;
}
/*

View File

@ -20,6 +20,11 @@ void stm32_watchdog_pat(void);
*/
bool stm32_was_watchdog_reset(void);
/*
return true if reboot was from a software reset
*/
bool stm32_was_software_reset(void);
/*
save the reset reason code
*/