Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c081119

Browse files
authored
Merge pull request #445 from pennam/restore-freertos
FreeRTOS restore original behaviour and allow override startup hooks
2 parents 212f999 + 11fb728 commit c081119

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

‎boards.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ portenta_c33.build.fpu=-mfpu=fpv5-sp-d16
1212
portenta_c33.build.float-abi=-mfloat-abi=hard
1313

1414
portenta_c33.build.board=PORTENTA_C33
15-
portenta_c33.build.defines=-DF_CPU=200000000 -DPROVIDE_FREERTOS_HOOK
15+
portenta_c33.build.defines=-DF_CPU=200000000
1616
portenta_c33.vid.0=0x2341
1717
portenta_c33.pid.0=0x0068
1818
portenta_c33.vid.1=0x2341

‎cores/arduino/main.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void unsecure_registers() {
6565

6666
extern "C" void Stacktrace_Handler(void);
6767
extern "C" __attribute__((weak)) void start_freertos_on_header_inclusion() {}
68+
extern "C" __attribute__((weak)) void early_start_freertos_on_header_inclusion() {}
6869

6970
void arduino_main(void)
7071
{
@@ -112,10 +113,9 @@ void arduino_main(void)
112113
Serial.begin(115200);
113114
#endif
114115
startAgt();
116+
early_start_freertos_on_header_inclusion();
115117
setup();
116-
#ifdef PROVIDE_FREERTOS_HOOK
117118
start_freertos_on_header_inclusion();
118-
#endif
119119
while (1)
120120
{
121121
loop();

‎libraries/Arduino_FreeRTOS/src/Arduino_FreeRTOS.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ extern "C" {
2727
#include "lib/FreeRTOS-Kernel-v10.5.1/semphr.h"
2828
#include "lib/FreeRTOS-Kernel-v10.5.1/task.h"
2929
#include "lib/FreeRTOS-Kernel-v10.5.1/timers.h"
30+
#include <stdbool.h>
31+
32+
33+
// If you need to automatically start FREERTOS, declare either EARLY_AUTOSTART_FREERTOS or
34+
// AUTOSTART_FREERTOS in your library or sketch code (.ino or .cpp file)
35+
//
36+
// EARLY_AUTOSTART_FREERTOS -> if you need the scheduler to be already running in setup()
37+
// AUTOSTART_FREERTOS -> if you only declare the threads in setup() and use them in loop()
38+
39+
void _start_freertos_on_header_inclusion_impl(bool early_start);
40+
void early_start_freertos_on_header_inclusion();
41+
void start_freertos_on_header_inclusion();
42+
#define EARLY_AUTOSTART_FREERTOS \
43+
void early_start_freertos_on_header_inclusion() { \
44+
_start_freertos_on_header_inclusion_impl(true); \
45+
}
46+
#define AUTOSTART_FREERTOS \
47+
void start_freertos_on_header_inclusion() { \
48+
_start_freertos_on_header_inclusion_impl(false); \
49+
}
50+
3051

3152
#ifdef __cplusplus
3253
}

‎libraries/Arduino_FreeRTOS/src/portable/FSP/port.c‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "FreeRTOSConfig.h"
3333
#include "../../lib/FreeRTOS-Kernel-v10.5.1/FreeRTOS.h"
3434
#include "../../lib/FreeRTOS-Kernel-v10.5.1/task.h"
35+
#include "portmacro.h"
3536

3637
#if BSP_TZ_NONSECURE_BUILD
3738
#include "tz_context.h"
@@ -225,28 +226,34 @@ static void prvTaskExitError(void);
225226

226227
#endif
227228

228-
#ifdef PROVIDE_FREERTOS_HOOK
229-
void loop_thread_func(void* arg) {
229+
extern void setup(void);
230+
extern void loop(void);
231+
232+
static void sketch_thread_func(void* arg) {
233+
bool early_start = (bool)arg;
234+
if (early_start) {
235+
setup();
236+
}
230237
while (1)
231238
{
232239
loop();
233240
}
234241
}
235242

236-
static TaskHandle_t loop_task;
237-
void start_freertos_on_header_inclusion() {
238-
xTaskCreate(
239-
(TaskFunction_t)loop_thread_func,
240-
"Loop Thread",
241-
4096 / 4, /* usStackDepth in words */
242-
NULL, /* pvParameters */
243-
4, /* uxPriority */
244-
&loop_task /* pxCreatedTask */
245-
);
246-
247-
vTaskStartScheduler();
243+
void _start_freertos_on_header_inclusion_impl(bool early_start) {
244+
static TaskHandle_t sketch_task;
245+
if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) {
246+
xTaskCreate(
247+
(TaskFunction_t)sketch_thread_func,
248+
"Sketch Thread",
249+
4096 / 4, /* usStackDepth in words */
250+
(void*)early_start, /* pvParameters */
251+
4, /* uxPriority */
252+
&sketch_task /* pxCreatedTask */
253+
);
254+
vTaskStartScheduler();
255+
}
248256
}
249-
#endif
250257

251258
/* Arduino specific overrides */
252259
void delay(uint32_t ms) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /