From e8d67ac530bc6e229c2fb53a63eea32bea726325 Mon Sep 17 00:00:00 2001 From: Laurent MEUNIER Date: Mon, 11 Jul 2016 16:14:03 +0200 Subject: [PATCH] INIT: uARM no rtos: Align pre-main initialization steps between TCs In uARM, the library's hook _platform_post_stackheap_init does not seem to exist and I couldnot find a documentation describing the initialisation flow. All we know is that _open is called after RAM init and before the C++ init, so this is a working placeholder. This is maybe not acceptable so a uARM lib expert may propose a better hook to fullfil the requirement. At least this is a workign setup. This series should solve issue reported here: STM32 (At least F401) breaks if Tickers are activated in a global object #2115 --- platform/retarget.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/platform/retarget.cpp b/platform/retarget.cpp index fbeff4c6a7..d9787c8298 100644 --- a/platform/retarget.cpp +++ b/platform/retarget.cpp @@ -149,13 +149,21 @@ static inline int openmode_to_posix(int openmode) { return posix; } +extern "C" WEAK void mbed_sdk_init(void); +extern "C" WEAK void mbed_sdk_init(void) { +} + extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) { #if defined(__MICROLIB) && (__ARMCC_VERSION>5030000) // Before version 5.03, we were using a patched version of microlib with proper names // This is the workaround that the microlib author suggested us static int n = 0; + static int mbed_sdk_inited = 0; + if (!mbed_sdk_inited) { + mbed_sdk_inited = 1; + mbed_sdk_init(); + } if (!std::strcmp(name, ":tt")) return n++; - #else /* Use the posix convention that stdin,out,err are filehandles 0,1,2. */ @@ -516,10 +524,6 @@ extern "C" WEAK void mbed_main(void); extern "C" WEAK void mbed_main(void) { } -extern "C" WEAK void mbed_sdk_init(void); -extern "C" WEAK void mbed_sdk_init(void) { -} - #if defined(TOOLCHAIN_ARM) extern "C" int $Super$$main(void);