Skip to content

Commit cce2852

Browse files
committed
Add FreeRTOS wrapper.
1 parent 28a5a3b commit cce2852

58 files changed

Lines changed: 11831 additions & 300 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ It is an [open-source project](https://github.com/SuperTinyKernel-RTOS), navigat
5151
| Safety-critical systems ready | No dynamic heap memory allocation |
5252
| C++ and C API | Can be used easily in C++ and C projects |
5353
| CMSIS-RTOS2 compatible | Full CMSIS-RTOS2 wrapper (`cmsis_os2_stk.cpp`) maps the standard ARM CMSIS-RTOS2 C API onto STK, enabling drop-in compatibility with STM32CubeMX, MCUXpresso, and other CMSIS-aware middleware |
54+
| FreeRTOS compatible | Full FreeRTOS wrapper (`freertos_stk.cpp`) maps the standard FreeRTOS C API onto STK, enabling drop-in migration of existing FreeRTOS codebases with minimal or no application changes |
5455
| Easy porting | Requires very small to none BSP surface |
5556
| Traceable | Scheduling is fully traceable with a SEGGER SystemView |
5657
| Development mode (x86) | Run the same threaded application on Windows |
@@ -257,12 +258,91 @@ For a seamless integration with C projects STK provides a dedicated, fully-featu
257258

258259
---
259260

260-
## CMSIS-RTOS2 Wrapper (`interop/cmsis/rtos2`)
261+
## Migrating from CMSIS-RTOS2 or FreeRTOS
261262

262-
STK provides a complete **CMSIS-RTOS2** compatibility layer (`cmsis_os2_stk.cpp`) that maps standard ARM [CMSIS-RTOS2 C API](https://arm-software.github.io/CMSIS_6/latest/RTOS2/group__CMSIS__RTOS.html) (`cmsis_os2.h` **v2.3.0**) onto the STK C++ kernel. This allows you to use STK as a drop-in RTOS backend in any project that targets the CMSIS-RTOS2 interface, including code generated by STM32CubeMX, MCUXpresso, or any other CMSIS-aware IDE or middleware stack. See [interop/cmsis/rtos2](https://github.com/SuperTinyKernel-RTOS/stk/tree/main/interop/cmsis/rtos2) for more details and example.
263+
STK ships two ready-made compatibility wrappers that let you swap out your existing RTOS backend and replace it with STK without rewriting application code. Both wrappers live under `interop/` and share the same design principles: thin translation of the source API onto STK primitives, ISR-safe where the original API requires it, and zero heap usage when the caller supplies static memory.
263264

264-
CMSIS-RTOS2 API works as documented in the CMSIS-RTOS2 specification.
265+
### CMSIS-RTOS2 Wrapper (`interop/cmsis/rtos2`)
265266

267+
STK provides a complete **CMSIS-RTOS2** compatibility layer (`cmsis_os2_stk.cpp`) that maps the standard ARM [CMSIS-RTOS2 C API](https://arm-software.github.io/CMSIS_6/latest/RTOS2/group__CMSIS__RTOS.html) (`cmsis_os2.h` **v2.3.0**) onto the STK C++ kernel. This allows you to use STK as a drop-in RTOS backend in any project that targets the CMSIS-RTOS2 interface, including code generated by STM32CubeMX, MCUXpresso, or any other CMSIS-aware IDE or middleware stack.
268+
269+
**Covered API groups:** Kernel Management, Thread Management, Thread Flags, Event Flags, Mutex, Semaphore, Timer, Message Queue, Memory Pool.
270+
271+
**Quick integration:**
272+
273+
```make
274+
# 1. Add wrapper source
275+
SRCS += libs/stk/interop/cmsis/rtos2/src/cmsis_os2_stk.cpp
276+
277+
# 2. Add include paths
278+
INCLUDES += -Ilibs/stk/include
279+
INCLUDES += -Ilibs/stk/interop/cmsis/rtos2/include
280+
```
281+
282+
```c
283+
// 3. No application changes required — existing CMSIS-RTOS2 calls work as-is
284+
#include "cmsis_os2.h"
285+
286+
int main(void)
287+
{
288+
osKernelInitialize();
289+
osThreadNew(app_thread, NULL, NULL);
290+
osKernelStart(); // never returns
291+
}
292+
```
293+
294+
See [interop/cmsis/rtos2](https://github.com/SuperTinyKernel-RTOS/stk/tree/main/interop/cmsis/rtos2) for the full API coverage table, design notes, and configuration macros.
295+
296+
---
297+
298+
### FreeRTOS Wrapper (`interop/freertos`)
299+
300+
STK provides a complete **FreeRTOS** compatibility layer (`freertos_stk.cpp`) that maps the standard FreeRTOS C API onto the STK C++ kernel. Existing FreeRTOS projects can migrate to STK with minimal or no changes to application code, while immediately gaining STK's lower scheduling overhead, reduced jitter, and smaller RAM footprint (see [Benchmark](#benchmark) above).
301+
302+
**Covered API groups:** Kernel Control, Task Management, Queue, Semaphore / Mutex, Software Timers, Event Groups, Task Notifications.
303+
304+
**Quick integration:**
305+
306+
```make
307+
# 1. Add wrapper source
308+
SRCS += libs/stk/interop/freertos/src/freertos_stk.cpp
309+
310+
# 2. Add include paths
311+
INCLUDES += -Ilibs/stk/include
312+
INCLUDES += -Ilibs/stk/interop/freertos/include
313+
```
314+
315+
```c
316+
// 3. No application changes required — existing FreeRTOS calls work as-is
317+
#include "FreeRTOS.h"
318+
#include "task.h"
319+
320+
int main(void)
321+
{
322+
xTaskCreate(app_task, "app", 256, NULL, 2, NULL);
323+
vTaskStartScheduler(); // never returns
324+
}
325+
```
326+
327+
See [interop/freertos](https://github.com/SuperTinyKernel-RTOS/stk/tree/main/interop/freertos) for the full API coverage table, design notes, known limitations, and `FreeRTOSConfig.h` requirements.
328+
329+
---
330+
331+
### Wrapper Comparison
332+
333+
| | CMSIS-RTOS2 | FreeRTOS |
334+
|---------------------|-------------------------------------------------|---------------------------------------------------|
335+
| Source file | `cmsis_os2_stk.cpp` | `freertos_stk.cpp` |
336+
| Header to include | `cmsis_os2.h` | `FreeRTOS.h`, `task.h` |
337+
| Priority model | Linear map: `osPriority` 1–56 → STK levels 0–31 | Direct clamp: FreeRTOS 0–N → STK levels 0–31 |
338+
| Max tasks macro | `CMSIS_STK_MAX_THREADS` (default: 16) | `FREERTOS_STK_MAX_TASKS` (default: 16) |
339+
| Default stack macro | `CMSIS_STK_DEFAULT_STACK_WORDS` (default: 256) | `FREERTOS_STK_DEFAULT_STACK_WORDS` (default: 256) |
340+
| Static allocation | `cb_mem` / `cb_size` attributes | `xTaskCreateStatic` / `xQueueCreateStatic` |
341+
| Scheduler backend | `SwitchStrategyFP32` | `SwitchStrategyFP32` |
342+
| Tickless support | `STK_TICKLESS_IDLE=1` | `STK_TICKLESS_IDLE=1` |
343+
344+
345+
> **Note:** Wrapper is missing important API your project is using? Contact with inquiry: [contact@supertinykernel.org](mailto:contact@supertinykernel.org)
266346
---
267347
268348
## Synchronization API (`stk/stk_sync.h`)

0 commit comments

Comments
 (0)