echoplayer: detect boot reason during system_init

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 025d641d1f9eddadd8f9f382119e3c95ea91c477
Author: Aidan MacDonald <[email protected]>
Date:   Fri Jan 16 23:54:45 2026 +0000

    echoplayer: detect boot reason during system_init
    
    Change-Id: I6fdc16e7476044b43e11d3f63d971bd8de860c58

diff --git a/firmware/reggen/stm32h743.regs b/firmware/reggen/stm32h743.regs
index df8d7235ae..16584f0851 100644
--- a/firmware/reggen/stm32h743.regs
+++ b/firmware/reggen/stm32h743.regs
@@ -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
diff --git a/firmware/target/arm/stm32/echoplayer/system-echoplayer.c b/firmware/target/arm/stm32/echoplayer/system-echoplayer.c
index 15ca8a81c9..f9a2763205 100644
--- a/firmware/target/arm/stm32/echoplayer/system-echoplayer.c
+++ b/firmware/target/arm/stm32/echoplayer/system-echoplayer.c
@@ -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);
 }
diff --git a/firmware/target/arm/stm32/echoplayer/system-echoplayer.h b/firmware/target/arm/stm32/echoplayer/system-echoplayer.h
index 3f93d84e30..abfd96c145 100644
--- a/firmware/target/arm/stm32/echoplayer/system-echoplayer.h
+++ b/firmware/target/arm/stm32/echoplayer/system-echoplayer.h
@@ -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__ */
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.