Skip to content

Commit a0b3876

Browse files
Add FreeRTOS support for RP2350 (#2406)
Pull in Raspberry Pi's custom RP2350 ARM and RISC-V ports for FreeRTOS. Basic tests run, but stress mutex test is failing in unique and interesting ways. * Add simplified switching test catching task swap problem * Freertosrp2350: use FreeRTOS macros in noInterrupts/interrupts when applicable. (#2456) * Use FreeRTOS macros in noInterrupts/interrupts when applicable. * Fixed calling taskEXIT_CRITICAL and taskENTER_CRITICAL --------- Co-authored-by: fietser28 <[email protected]>
1 parent 5f6e4af commit a0b3876

File tree

14 files changed

+117
-17
lines changed

14 files changed

+117
-17
lines changed

cores/rp2040/_freertos.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,8 @@ extern "C" {
5454

5555
extern void __freertos_idle_other_core() __attribute__((weak));
5656
extern void __freertos_resume_other_core() __attribute__((weak));
57+
58+
extern void __freertos_task_exit_critical() __attribute__((weak));
59+
extern void __freertos_task_enter_critical() __attribute__((weak));
5760
}
5861
extern SemaphoreHandle_t __get_freertos_mutex_for_ptr(mutex_t *m, bool recursive = false);

cores/rp2040/wiring_private.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <hardware/gpio.h>
2424
#include <hardware/sync.h>
2525
#include <map>
26+
#include "_freertos.h"
27+
2628

2729
// Support nested IRQ disable/re-enable
2830
#ifndef maxIRQs
@@ -32,22 +34,29 @@ static uint32_t _irqStackTop[2] = { 0, 0 };
3234
static uint32_t _irqStack[2][maxIRQs];
3335

3436
extern "C" void interrupts() {
35-
auto core = get_core_num();
36-
if (!_irqStackTop[core]) {
37-
// ERROR
38-
return;
37+
if (__freeRTOSinitted) {
38+
__freertos_task_exit_critical();
39+
} else {
40+
auto core = get_core_num();
41+
if (!_irqStackTop[core]) {
42+
// ERROR
43+
return;
44+
}
45+
restore_interrupts(_irqStack[core][--_irqStackTop[core]]);
3946
}
40-
restore_interrupts(_irqStack[core][--_irqStackTop[core]]);
4147
}
4248

4349
extern "C" void noInterrupts() {
44-
auto core = get_core_num();
45-
if (_irqStackTop[core] == maxIRQs) {
46-
// ERROR
47-
panic("IRQ stack overflow");
50+
if (__freeRTOSinitted) {
51+
__freertos_task_enter_critical();
52+
} else {
53+
auto core = get_core_num();
54+
if (_irqStackTop[core] == maxIRQs) {
55+
// ERROR
56+
panic("IRQ stack overflow");
57+
}
58+
_irqStack[core][_irqStackTop[core]++] = save_and_disable_interrupts();
4859
}
49-
50-
_irqStack[core][_irqStackTop[core]++] = save_and_disable_interrupts();
5160
}
5261

5362
// Only 1 GPIO IRQ callback for all pins, so we need to look at the pin it's for and
Submodule FreeRTOS-Kernel updated 32 files

libraries/FreeRTOS/src/FreeRTOS.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
#ifdef PICO_RP2350
2-
#error Sorry, FreeRTOS is not yet supported on the RP2350 in this core.
3-
#else
41
#include "../lib/FreeRTOS-Kernel/include/FreeRTOS.h"
5-
#endif

libraries/FreeRTOS/src/FreeRTOSConfig.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ extern unsigned long ulMainGetRunTimeCounterValue(void);
200200
#endif
201201
#endif
202202

203+
#define configENABLE_MPU 0
204+
#define configENABLE_TRUSTZONE 0
205+
#define configRUN_FREERTOS_SECURE_ONLY 1
206+
#define configENABLE_FPU 1
203207
/* The lowest interrupt priority that can be used in a call to a "set priority"
204208
function. */
205209
#ifndef configLIBRARY_LOWEST_INTERRUPT_PRIORITY
@@ -219,11 +223,16 @@ extern unsigned long ulMainGetRunTimeCounterValue(void);
219223
#ifndef configKERNEL_INTERRUPT_PRIORITY
220224
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
221225
#endif
226+
222227
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
223228
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
224229
#ifndef configMAX_SYSCALL_INTERRUPT_PRIORITY
230+
#ifdef PICO_RP2350
231+
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 16
232+
#else
225233
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
226234
#endif
235+
#endif
227236

228237
#ifndef configASSERT
229238
#ifdef __cplusplus
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "../lib/FreeRTOS-Kernel/include/mpu_syscall_numbers.h"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#ifdef PICO_RP2350
2+
#include "../lib/FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2350_ARM_NTZ/non_secure/mpu_wrappers_v2_asm.c"
3+
#endif

libraries/FreeRTOS/src/port.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
#ifdef PICO_RP2040
12
#include "../lib/FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2040/port.c"
3+
#else
4+
#include "../lib/FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2350_ARM_NTZ/non_secure/port.c"
5+
#endif

libraries/FreeRTOS/src/portasm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#ifdef PICO_RP2350
2+
#include "../lib/FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2350_ARM_NTZ/non_secure/portasm.c"
3+
#endif

libraries/FreeRTOS/src/portmacro.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
#ifdef PICO_RP2350
2+
#include "../lib/FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2350_ARM_NTZ/non_secure/portmacro.h"
3+
#else
14
#include "../lib/FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2040/include/portmacro.h"
5+
#endif

0 commit comments

Comments
 (0)