From e911d9867cf94ec8135e76fef70dc1c8948dcd6c Mon Sep 17 00:00:00 2001 From: Martin Kojtal <0xc0170@gmail.com> Date: Thu, 29 Jun 2017 14:35:00 +0100 Subject: [PATCH] retarget: fix microlib for mbed 2 This is as it used to be, reverting the removal. uARM does not have any hook that we could use for mbed sdk init and copy nvic, therefore _open is used that should be sufficient, but not ideal. For more information, visit https://github.com/ARMmbed/mbed-os/pull/2160/files#r76563844. --- platform/mbed_retarget.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/platform/mbed_retarget.cpp b/platform/mbed_retarget.cpp index f7bed54261..a7092e4fc0 100644 --- a/platform/mbed_retarget.cpp +++ b/platform/mbed_retarget.cpp @@ -177,6 +177,20 @@ static inline int openmode_to_posix(int openmode) { * */ extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) { #if defined(__MICROLIB) && (__ARMCC_VERSION>5030000) +#if !defined(MBED_CONF_RTOS_PRESENT) + // valid only for mbed 2 + // for ulib, this is invoked after RAM init, prior c++ + // used as hook, as post stack/heap is not active there + extern void mbed_copy_nvic(void); + extern void mbed_sdk_init(void); + + static int mbed_sdk_inited = 0; + if (!mbed_sdk_inited) { + mbed_copy_nvic(); + mbed_sdk_init(); + mbed_sdk_inited = 1; + } +#endif // 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;