echoplayer: detect boot reason during system_init

Change-Id: I6fdc16e7476044b43e11d3f63d971bd8de860c58
This commit is contained in:
Aidan MacDonald 2026-01-16 23:54:45 +00:00
parent 86c975ee88
commit 025d641d1f
3 changed files with 43 additions and 0 deletions

View file

@ -254,6 +254,20 @@ RCC @ 0x58024400 : block {
0 LSION
}
RSR @ 0xd0 : reg {
30 LPWRRSTF
28 WWDG1RSTF
26 IWDGRSTF
24 SFTRSTF
23 PORRSTF
22 PINRSTF
21 BORRSTF
20 D2RSTF
19 D1RSTF
17 CPURSTF
16 RMVF
}
AHB1ENR @ 0xd8 : reg {
28 USB2OTGHSULPIEN
27 USB2OTGHSEN

View file

@ -54,6 +54,8 @@
# define F_MCO1 GPIOF_ANALOG()
#endif
enum echoplayer_boot_reason echoplayer_boot_reason = ECHOPLAYER_BOOT_REASON_NORMAL;
static const struct gpio_setting gpios[] = {
STM_DEFGPIO(GPIO_BUTTON_A, F_INPUT_PU),
STM_DEFGPIO(GPIO_BUTTON_B, F_INPUT_PU),
@ -212,6 +214,24 @@ void system_init(void)
pingroups, ARRAYLEN(pingroups));
fmc_init();
/* Read & clear reset source */
uint32_t rsr = reg_var(RCC_RSR);
reg_assignf(RCC_RSR, RMVF(1));
/*
* Determine boot reason -- SFTRST means a software reset
* occurred, which may be a reboot or a power off
*/
if (reg_vreadf(rsr, RCC_RSR, SFTRSTF))
{
reg_writef(RCC_APB4ENR, RTCAPBEN(1));
if (reg_readf(RTC_CR, WUTE))
echoplayer_boot_reason = ECHOPLAYER_BOOT_REASON_SW_REBOOT;
else
echoplayer_boot_reason = ECHOPLAYER_BOOT_REASON_SW_POWEROFF;
}
/* Disable RTC_OUT pin */
echoplayer_set_rtcout_mode(ECHOPLAYER_RTCOUT_DISABLED);
}

View file

@ -27,6 +27,15 @@ enum echoplayer_rtcout_mode
ECHOPLAYER_RTCOUT_REBOOT,
};
enum echoplayer_boot_reason
{
ECHOPLAYER_BOOT_REASON_NORMAL,
ECHOPLAYER_BOOT_REASON_SW_POWEROFF,
ECHOPLAYER_BOOT_REASON_SW_REBOOT,
};
void echoplayer_set_rtcout_mode(enum echoplayer_rtcout_mode mode);
extern enum echoplayer_boot_reason echoplayer_boot_reason;
#endif /* __SYSTEM_ECHOPLAYER_H__ */