From ce89e7e2446ec96c8ad6052c3038bf2b823104fa Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 11 Oct 2016 18:36:08 +0200 Subject: [PATCH] Launch libc initialization after hardware setup This pachs allows C++ global constructors to run after hardware initialization. This helps some libraries that setups hardware in class constructor to work properly. See also #169 --- cores/arduino/cortex_handlers.c | 4 ---- cores/arduino/main.cpp | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cores/arduino/cortex_handlers.c b/cores/arduino/cortex_handlers.c index 4192690d3..6c45c6395 100644 --- a/cores/arduino/cortex_handlers.c +++ b/cores/arduino/cortex_handlers.c @@ -134,7 +134,6 @@ __attribute__ ((section(".isr_vector"))) const DeviceVectors exception_table = }; extern int main(void); -extern void __libc_init_array(void); /* This is called on processor reset to initialize the device and call main() */ void Reset_Handler(void) @@ -156,9 +155,6 @@ void Reset_Handler(void) *pDest = 0; } - /* Initialize the C library */ - __libc_init_array(); - SystemInit(); main(); diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index 8af01b573..49ebc27f5 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -24,6 +24,9 @@ void initVariant() __attribute__((weak)); void initVariant() { } +// Initialize C library +extern "C" void __libc_init_array(void); + /* * \brief Main entry point of Arduino application */ @@ -31,6 +34,8 @@ int main( void ) { init(); + __libc_init_array(); + initVariant(); delay(1);