From f50e23aea6d5c4dab6db6ada61de4e0efde9a0e2 Mon Sep 17 00:00:00 2001 From: Laurent MEUNIER Date: Mon, 11 Jul 2016 16:14:03 +0200 Subject: [PATCH] INIT:ARM no rtos: Align pre-main initialization steps between TCs Various toolchains supported in MBED don't followthe same initialization steps. This can have impacts on platform behavior. For STM32, it is needed to call the HAL_Init() _after_ the RAM has been initialized (sdata from flash / zero initialized data) and _before_ the C++ objects are being created, especially if those objects require support of tickers for instance. In GCC and IAR, this was done in previous commit to avoid HAL_Init() to be called twice. In ARM this there is no hook defined in MBED yet to place the call. The proposal is to take benefit of the library's _platform_post_stackheap_init function that is going to be called before __rt_lib_init where the C++ object init is done (__cpp_initialize__aeabi_) This series should solve issue reported here: STM32 (At least F401) breaks if Tickers are activated in a global object #2115 --- platform/retarget.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/retarget.cpp b/platform/retarget.cpp index 17af0798b3..fbeff4c6a7 100644 --- a/platform/retarget.cpp +++ b/platform/retarget.cpp @@ -524,10 +524,14 @@ extern "C" WEAK void mbed_sdk_init(void) { extern "C" int $Super$$main(void); extern "C" int $Sub$$main(void) { - mbed_sdk_init(); mbed_main(); return $Super$$main(); } + +extern "C" void _platform_post_stackheap_init (void) { + mbed_sdk_init(); +} + #elif defined(TOOLCHAIN_GCC) extern "C" int __real_main(void);