diff --git a/cores/arduino/cortex_handlers.c b/cores/arduino/cortex_handlers.c index e125b6ee8..ee2065a17 100644 --- a/cores/arduino/cortex_handlers.c +++ b/cores/arduino/cortex_handlers.c @@ -20,6 +20,9 @@ #include #include +/* libc */ +void __libc_init_array(void); + /* RTOS Hooks */ extern void svcHook(void); extern void pendSVHook(void); @@ -146,16 +149,19 @@ void Reset_Handler(void) pDest = &__data_start__; if ((&__data_start__ != &__data_end__) && (pSrc != pDest)) { - for (; pDest < &__data_end__; pDest++, pSrc++) + for (; pDest < &__data_end__; pDest += sizeof(uint32_t), pSrc += sizeof(uint32_t)) *pDest = *pSrc; } /* Clear the zero section */ - if ((&__data_start__ != &__data_end__) && (pSrc != pDest)) { - for (pDest = &__bss_start__; pDest < &__bss_end__; pDest++) + if ((&__bss_start__ != &__bss_end__)) { + for (pDest = &__bss_start__; pDest < &__bss_end__; pDest += sizeof(uint32_t)) *pDest = 0; } + /* Initialize C library */ + __libc_init_array(); + SystemInit(); main(); diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index a6d2cb5f5..6a771b3ad 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -26,9 +26,6 @@ void initVariant() { } extern USBDeviceClass USBDevice; -// Initialize C library -extern "C" void __libc_init_array(void); - /* * \brief Main entry point of Arduino application */ @@ -36,8 +33,6 @@ int main( void ) { init(); - __libc_init_array(); - initVariant(); delay(1);