From 6e2382203a46f59d59d9ab6372b4849711743c2d Mon Sep 17 00:00:00 2001 From: Karl Andersson Date: Sat, 31 Mar 2018 14:36:19 +0200 Subject: [PATCH] Force init() to be called first i.e. before static object allocation. Otherwise, statically allocated objects that need HAL may fail. --- STM32/cores/arduino/main.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/STM32/cores/arduino/main.cpp b/STM32/cores/arduino/main.cpp index 6c7570c..ed6db09 100644 --- a/STM32/cores/arduino/main.cpp +++ b/STM32/cores/arduino/main.cpp @@ -31,20 +31,25 @@ void initVariant() { } void setupUSB() __attribute__((weak)); void setupUSB() { } +// Force init to be called *first*, i.e. before static object allocation. +// Otherwise, statically allocated objects that need HAL may fail. + __attribute__(( constructor (101))) void premain() { + +// Required by FreeRTOS, see http://www.freertos.org/RTOS-Cortex-M3-M4.html +#ifdef NVIC_PRIORITYGROUP_4 + HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); +#endif + + init(); +} + int main(void) { - //Used by FreeRTOS, see http://www.freertos.org/RTOS-Cortex-M3-M4.html - #ifdef NVIC_PRIORITYGROUP_4 - HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); - #endif - #ifdef STM32F7 SCB_EnableICache(); SCB_EnableDCache(); #endif - init(); - initVariant(); #if defined(MENU_DEBUG_DISABLED)