Skip to content

Commit 11b75da

Browse files
committed
Call init() before static object allocation
Force init to be called *first*, i.e. before static object allocation. Otherwise, statically allocated objects that need HAL may fail. Ex: LiquidCrystal use delayMicroseconds() which use HAL_GetTick() if System Tick not init infinite loop... Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 9ce596f commit 11b75da

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cores/arduino/main.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@
2626
void initVariant() __attribute__((weak));
2727
void initVariant() { }
2828

29+
// Force init to be called *first*, i.e. before static object allocation.
30+
// Otherwise, statically allocated objects that need HAL may fail.
31+
__attribute__(( constructor (101))) void premain() {
32+
init();
33+
}
34+
2935
/*
3036
* \brief Main entry point of Arduino application
3137
*/
3238
int main( void )
3339
{
34-
init();
35-
3640
initVariant();
3741

3842
#if defined(USBCON)

0 commit comments

Comments
 (0)