This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit c6afd72bb2aa0c36b40b1fa5572cdb568ee08830 Author: Jacob Dahl <[email protected]> AuthorDate: Fri Nov 20 11:41:56 2026 -0700 arch/arm/stm32: Add the pre-clock hook to every STM32 family. The H7 was the only family whose __start called stm32_preclock_hook(). Every STM32 __start now calls it right before stm32_clockconfig(), so a board can use it on any family. Most families set up clocks before they initialize .data and .bss, so the hook must not rely on them. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jacob Dahl <[email protected]> --- arch/arm/src/common/stm32/stm32_start_m0_v1.c | 14 ++++++++++++++ arch/arm/src/common/stm32/stm32_start_m33_v1.c | 14 ++++++++++++++ arch/arm/src/common/stm32/stm32_start_m3m4_v1.c | 14 ++++++++++++++ arch/arm/src/stm32f7/stm32_start.c | 14 ++++++++++++++ arch/arm/src/stm32h7/stm32_start.c | 9 ++++----- arch/arm/src/stm32l4/stm32l4_start.c | 14 ++++++++++++++ arch/arm/src/stm32n6/stm32_start.c | 14 ++++++++++++++ arch/arm/src/stm32wb/stm32wb_start.c | 14 ++++++++++++++ arch/arm/src/stm32wl5/stm32wl5_start.c | 14 ++++++++++++++ 9 files changed, 116 insertions(+), 5 deletions(-) diff --git a/arch/arm/src/common/stm32/stm32_start_m0_v1.c b/arch/arm/src/common/stm32/stm32_start_m0_v1.c index b2585f49bc6..ac35a242686 100644 --- a/arch/arm/src/common/stm32/stm32_start_m0_v1.c +++ b/arch/arm/src/common/stm32/stm32_start_m0_v1.c @@ -68,6 +68,13 @@ const uintptr_t g_idle_topstack = IDLE_STACK; # define showprogress(c) #endif +/* Called from __start before the system clock is set up. On some STM32 + * families it runs before .data and .bss are initialized, so it must not + * rely on them. A bootloader can hand over to the ROM bootloader here. + */ + +void stm32_preclock_hook(void) weak_function; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -85,6 +92,13 @@ void __start(void) const uint32_t *src; uint32_t *dest; + /* Let the board act before the system clock is set up. */ + + if (stm32_preclock_hook) + { + stm32_preclock_hook(); + } + /* Configure the uart so that we can get debug output as soon as possible */ stm32_clockconfig(); diff --git a/arch/arm/src/common/stm32/stm32_start_m33_v1.c b/arch/arm/src/common/stm32/stm32_start_m33_v1.c index 9583d3a03f8..8ca91f4fd3a 100644 --- a/arch/arm/src/common/stm32/stm32_start_m33_v1.c +++ b/arch/arm/src/common/stm32/stm32_start_m33_v1.c @@ -108,6 +108,13 @@ const uintptr_t g_idle_topstack = HEAP_BASE; void __start(void) noinstrument_function; #endif +/* Called from __start before the system clock is set up. On some STM32 + * families it runs before .data and .bss are initialized, so it must not + * rely on them. A bootloader can hand over to the ROM bootloader here. + */ + +void stm32_preclock_hook(void) weak_function; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -175,6 +182,13 @@ void __start(void) } #endif + /* Let the board act before the system clock is set up. */ + + if (stm32_preclock_hook) + { + stm32_preclock_hook(); + } + /* Configure clocks, the FPU, GPIO and the debug UART only after .data and * .bss are valid. GPIO configuration uses a spinlock stored in .bss. */ diff --git a/arch/arm/src/common/stm32/stm32_start_m3m4_v1.c b/arch/arm/src/common/stm32/stm32_start_m3m4_v1.c index ad74f104e3c..fc06ed25d94 100644 --- a/arch/arm/src/common/stm32/stm32_start_m3m4_v1.c +++ b/arch/arm/src/common/stm32/stm32_start_m3m4_v1.c @@ -99,6 +99,13 @@ const uintptr_t g_idle_topstack = HEAP_BASE; void __start(void) noinstrument_function; #endif +/* Called from __start before the system clock is set up. On some STM32 + * families it runs before .data and .bss are initialized, so it must not + * rely on them. A bootloader can hand over to the ROM bootloader here. + */ + +void stm32_preclock_hook(void) weak_function; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -127,6 +134,13 @@ void __start(void) mpu_early_reset(); + /* Let the board act before the system clock is set up. */ + + if (stm32_preclock_hook) + { + stm32_preclock_hook(); + } + /* Configure the UART so that we can get debug output as soon as possible */ stm32_clockconfig(); diff --git a/arch/arm/src/stm32f7/stm32_start.c b/arch/arm/src/stm32f7/stm32_start.c index 347c0dd79e6..2dcea1cb353 100644 --- a/arch/arm/src/stm32f7/stm32_start.c +++ b/arch/arm/src/stm32f7/stm32_start.c @@ -110,6 +110,13 @@ const uintptr_t g_idle_topstack = HEAP_BASE; void __start(void) noinstrument_function; #endif +/* Called from __start before the system clock is set up. On some STM32 + * families it runs before .data and .bss are initialized, so it must not + * rely on them. A bootloader can hand over to the ROM bootloader here. + */ + +void stm32_preclock_hook(void) weak_function; + /**************************************************************************** * Name: stm32_tcmenable * @@ -229,6 +236,13 @@ void __start(void) arm_stack_check_init(); #endif + /* Let the board act before the system clock is set up. */ + + if (stm32_preclock_hook) + { + stm32_preclock_hook(); + } + /* Configure the UART so that we can get debug output as soon as possible */ stm32_clockconfig(); diff --git a/arch/arm/src/stm32h7/stm32_start.c b/arch/arm/src/stm32h7/stm32_start.c index efd46f1fa90..db0ab47e967 100644 --- a/arch/arm/src/stm32h7/stm32_start.c +++ b/arch/arm/src/stm32h7/stm32_start.c @@ -117,8 +117,9 @@ const uintptr_t g_idle_topstack = HEAP_BASE; void __start(void) noinstrument_function; #endif -/* Called from __start before any clock setup, with .data and .bss in place. - * A bootloader can hand over to the ROM bootloader here. +/* Called from __start before the system clock is set up. On some STM32 + * families it runs before .data and .bss are initialized, so it must not + * rely on them. A bootloader can hand over to the ROM bootloader here. */ void stm32_preclock_hook(void) weak_function; @@ -250,9 +251,7 @@ void __start(void) arm_stack_check_init(); #endif - /* Let the board act while the chip is still as reset left it, before - * any clock setup. - */ + /* Let the board act before the system clock is set up. */ if (stm32_preclock_hook) { diff --git a/arch/arm/src/stm32l4/stm32l4_start.c b/arch/arm/src/stm32l4/stm32l4_start.c index 411490c5bbc..0b1b1703ae3 100644 --- a/arch/arm/src/stm32l4/stm32l4_start.c +++ b/arch/arm/src/stm32l4/stm32l4_start.c @@ -105,6 +105,13 @@ const uintptr_t g_idle_topstack = HEAP_BASE; void __start(void) noinstrument_function; #endif +/* Called from __start before the system clock is set up. On some STM32 + * families it runs before .data and .bss are initialized, so it must not + * rely on them. A bootloader can hand over to the ROM bootloader here. + */ + +void stm32_preclock_hook(void) weak_function; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -147,6 +154,13 @@ void __start(void) } #endif + /* Let the board act before the system clock is set up. */ + + if (stm32_preclock_hook) + { + stm32_preclock_hook(); + } + /* Configure the UART so that we can get debug output as soon as possible */ stm32_clockconfig(); diff --git a/arch/arm/src/stm32n6/stm32_start.c b/arch/arm/src/stm32n6/stm32_start.c index e0bcd928227..038253f2701 100644 --- a/arch/arm/src/stm32n6/stm32_start.c +++ b/arch/arm/src/stm32n6/stm32_start.c @@ -105,6 +105,13 @@ static inline void stm32_enable_lob(void) void __start_c(void) noinstrument_function; +/* Called from __start before the system clock is set up. On some STM32 + * families it runs before .data and .bss are initialized, so it must not + * rely on them. A bootloader can hand over to the ROM bootloader here. + */ + +void stm32_preclock_hook(void) weak_function; + /**************************************************************************** * Name: __start * @@ -249,6 +256,13 @@ void __start_c(void) stm32_enable_lob(); + /* Let the board act before the system clock is set up. */ + + if (stm32_preclock_hook) + { + stm32_preclock_hook(); + } + stm32_clockconfig(); /* Give the enabled bus masters access to Secure memory */ diff --git a/arch/arm/src/stm32wb/stm32wb_start.c b/arch/arm/src/stm32wb/stm32wb_start.c index 6e80fa7f6d8..83e3a85cb0a 100644 --- a/arch/arm/src/stm32wb/stm32wb_start.c +++ b/arch/arm/src/stm32wb/stm32wb_start.c @@ -113,6 +113,13 @@ const uintptr_t g_idle_topstack = HEAP_BASE; void __start(void) noinstrument_function; #endif +/* Called from __start before the system clock is set up. On some STM32 + * families it runs before .data and .bss are initialized, so it must not + * rely on them. A bootloader can hand over to the ROM bootloader here. + */ + +void stm32_preclock_hook(void) weak_function; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -162,6 +169,13 @@ void __start(void) } #endif + /* Let the board act before the system clock is set up. */ + + if (stm32_preclock_hook) + { + stm32_preclock_hook(); + } + /* Configure the UART so that we can get debug output as soon as possible */ stm32_clockconfig(); diff --git a/arch/arm/src/stm32wl5/stm32wl5_start.c b/arch/arm/src/stm32wl5/stm32wl5_start.c index 24a7a9c240a..54885fad46e 100644 --- a/arch/arm/src/stm32wl5/stm32wl5_start.c +++ b/arch/arm/src/stm32wl5/stm32wl5_start.c @@ -109,6 +109,13 @@ const uintptr_t g_idle_topstack = HEAP_BASE; void __start(void) noinstrument_function; #endif +/* Called from __start before the system clock is set up. On some STM32 + * families it runs before .data and .bss are initialized, so it must not + * rely on them. A bootloader can hand over to the ROM bootloader here. + */ + +void stm32_preclock_hook(void) weak_function; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -151,6 +158,13 @@ void __start(void) } #endif + /* Let the board act before the system clock is set up. */ + + if (stm32_preclock_hook) + { + stm32_preclock_hook(); + } + /* Configure the UART so that we can get debug output as soon as possible */ stm32_clockconfig();
