Go Down

Topic: How to execute code prior to init()? (Read 676 times) previous topic - next topic

mavik

I encountered an issue when writing a bootloader that uses interrupts with the Arduino core library (which may be beyond the intended scope of the library?).

Moving interrupts into the bootflash section should be done prior to enabling interrupts. But setup() is called after init(), and init() enables interrupts. It would be convenient to have an optional preInit() function that could be used for such purposes, eg. in core/main.cpp:

Code: [Select]
void preInit() __attribute__((weak));
void preInit() { }

...


int main(void)
{
preInit();

init();

initVariant();

#if defined(USBCON)
USBDevice.attach();
#endif

setup();
   
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
       
return 0;
}


Go Up