diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index 85e22808..8a1e1b2f 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -64,6 +64,7 @@ void unsecure_registers() { #define str(s) #s extern "C" void Stacktrace_Handler(void); +extern "C" __attribute__((weak)) void start_freertos_on_header_inclusion() {} void arduino_main(void) { @@ -111,6 +112,7 @@ void arduino_main(void) Serial.begin(115200); #endif startAgt(); + start_freertos_on_header_inclusion(); setup(); while (1) { diff --git a/libraries/Arduino_FreeRTOS/src/portable/FSP/port.c b/libraries/Arduino_FreeRTOS/src/portable/FSP/port.c index c0b5938d..036bd626 100644 --- a/libraries/Arduino_FreeRTOS/src/portable/FSP/port.c +++ b/libraries/Arduino_FreeRTOS/src/portable/FSP/port.c @@ -225,6 +225,28 @@ static void prvTaskExitError(void); #endif +void loop_thread_func(void* arg) { + setup(); + while (1) + { + loop(); + } +} + +static TaskHandle_t loop_task; +void start_freertos_on_header_inclusion() { + xTaskCreate( + (TaskFunction_t)loop_thread_func, + "Loop Thread", + 4096 / 4, /* usStackDepth in words */ + NULL, /* pvParameters */ + 4, /* uxPriority */ + &loop_task /* pxCreatedTask */ + ); + + vTaskStartScheduler(); +} + /* Arduino specific overrides */ void delay(uint32_t ms) { if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {