echoplayer: disable parts of system_init() for application

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 21ba79d43182889559b5d7ba52eac861f9aa925e
Author: Aidan MacDonald <[email protected]>
Date:   Thu Jan 22 14:59:12 2026 +0000

    echoplayer: disable parts of system_init() for application
    
    Most of system_init() should only be performed once after
    reset, and is not safe to re-run when the bootloader jumps
    to the application.
    
    Change-Id: I4d2e804ce4884da13b9167ddcda860ef3b5ba7d0

diff --git a/firmware/target/arm/stm32/echoplayer/system-echoplayer.c b/firmware/target/arm/stm32/echoplayer/system-echoplayer.c
index f9a2763205..88f7b27720 100644
--- a/firmware/target/arm/stm32/echoplayer/system-echoplayer.c
+++ b/firmware/target/arm/stm32/echoplayer/system-echoplayer.c
@@ -29,6 +29,12 @@
 #include "regs/stm32h743/rtc.h"
 #include "regs/cortex-m/cm_scb.h"
 
+#ifdef BOOTLOADER
+# define BOOTLOADER_INIT 1
+#else
+# define BOOTLOADER_INIT 0
+#endif
+
 #define F_INPUT      GPIOF_INPUT(GPIO_PULL_DISABLED)
 #define F_INPUT_PU   GPIOF_INPUT(GPIO_PULL_UP)
 #define F_INPUT_PD   GPIOF_INPUT(GPIO_PULL_DOWN)
@@ -173,17 +179,20 @@ INIT_ATTR static void fmc_init(void)
 
 void system_init(void)
 {
-    /* Enable clocks for all used GPIO banks */
-    reg_writef(RCC_AHB4ENR,
-               GPIOAEN(1), GPIOBEN(1), GPIOCEN(1), GPIODEN(1),
-               GPIOEEN(1), GPIOFEN(1), GPIOGEN(1), GPIOHEN(1), GPIOIEN(1));
+    if (BOOTLOADER_INIT)
+    {
+        /* Enable clocks for all used GPIO banks */
+        reg_writef(RCC_AHB4ENR,
+                   GPIOAEN(1), GPIOBEN(1), GPIOCEN(1), GPIODEN(1),
+                   GPIOEEN(1), GPIOFEN(1), GPIOGEN(1), GPIOHEN(1), GPIOIEN(1));
 
-    /*
-     * NOTE: I think it's possible to disable clocks for the banks which
-     * we don't need to access at runtime because these are only clocking
-     * register access. Probably a micro-optimization but it supposedly
-     * does save a few uA/MHz.
-     */
+        /*
+         * NOTE: I think it's possible to disable clocks for the banks which
+         * we don't need to access at runtime because these are only clocking
+         * register access. Probably a micro-optimization but it supposedly
+         * does save a few uA/MHz.
+         */
+    }
 
     /*
      * Set cpu_power_on high as early as possible to
@@ -200,36 +209,42 @@ void system_init(void)
     system_debug_enable(true);
 #endif
 
-    /* Enable CPU cache */
-    stm32_enable_caches();
+    if (BOOTLOADER_INIT)
+    {
+        /* Enable CPU cache */
+        stm32_enable_caches();
 
-    /* Initialize system clocks */
-    echoplayer_clock_init();
+        /* Initialize system clocks */
+        echoplayer_clock_init();
+    }
 
     /* Enable systick early due to udelay() needed for FMC init */
     stm32_systick_enable();
 
-    /* Configure GPIOs and start FMC */
-    gpio_configure_all(gpios, ARRAYLEN(gpios),
-                       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))
+    if (BOOTLOADER_INIT)
     {
-        reg_writef(RCC_APB4ENR, RTCAPBEN(1));
+        /* Configure GPIOs and start FMC */
+        gpio_configure_all(gpios, ARRAYLEN(gpios),
+                           pingroups, ARRAYLEN(pingroups));
+        fmc_init();
+
+        /* Read & clear reset source */
+        uint32_t rsr = reg_var(RCC_RSR);
+        reg_assignf(RCC_RSR, RMVF(1));
 
-        if (reg_readf(RTC_CR, WUTE))
-            echoplayer_boot_reason = ECHOPLAYER_BOOT_REASON_SW_REBOOT;
-        else
-            echoplayer_boot_reason = ECHOPLAYER_BOOT_REASON_SW_POWEROFF;
+        /*
+         * 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 */
-- 
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.