Applications › Migration from legacy RTOS
Keep your application code and swap the kernel underneath. STK ships ready-made wrappers for FreeRTOS, CMSIS-RTOS2, ThreadX, Infineon Abstraction RTOS and POSIX, a native C API, and a path to type-safe C++ when you are ready.
Kernel control, tasks, queues, semaphores and mutexes, software timers, event groups and task notifications.
Kernel management, threads, thread and event flags, mutexes, semaphores, timers, message queues and memory pools. Targets cmsis_os2.h v2.3.0, so code generated by STM32CubeMX or MCUXpresso can use it.
Kernel and system, threads, mutexes, semaphores, event flags, message queues, block and byte memory pools, application timers. Keeps the ThreadX scheduling model: priorities, preemption-threshold and time-slicing.
The cy_rtos_* API, so Infineon middleware that targets the abstraction layer can run on STK.
A deliberate subset: pthreads (threads, mutexes, condition variables, read-write locks, spinlocks, barriers, priorities, cancellation), semaphores, message queues, clocks and timers, and C11 threads. Signals, fork/exec, named semaphores, asynchronous cancellation and poll/select are not supported.
Not an RTOS wrapper: it maps Newlib's retargetable locks onto STK mutexes, so malloc, printf and fopen are safe to use next to STK in arm-none-eabi-gcc projects.
| FreeRTOS | CMSIS-RTOS2 | ThreadX | Infineon Abstraction RTOS | |
|---|---|---|---|---|
| Source file | freertos_stk.cpp | cmsis_os2_stk.cpp | threadx_stk.cpp | cyabs_rtos_stk.cpp |
| Header to include | FreeRTOS.h, task.h | cmsis_os2.h | tx_api.h | cyabs_rtos.h, cyabs_rtos_stk.h |
| Priority model | Direct clamp to levels 0–31 | Linear map, osPriority 1–56 to levels 0–31 | Inverted map (0 = highest), up to 1024 levels | Direct map, 32 levels by default, up to 1024 |
| Static allocation | xTaskCreateStatic, xQueueCreateStatic | cb_mem / cb_size attributes | Caller-allocated control blocks, stacks, pools | Caller-allocated objects; thread blocks and queue buffers from the STK allocator |
| Scheduler backend | SwitchStrategyFP32 | SwitchStrategyFP32 | SwitchStrategyPreemptionThreshold<N, true> | SwitchStrategyFixedPriority<N> |
| Task limit macro | FREERTOS_STK_MAX_TASKS (16) | CMSIS_STK_MAX_THREADS (16) | TX_STK_MAX_THREADS (16) | CY_RTOS_STK_MAX_THREADS (16) |
| Tickless idle | STK_TICKLESS_IDLE=1 | STK_TICKLESS_IDLE=1 | STK_TICKLESS_IDLE=1 | STK_TICKLESS_IDLE=1 |
The wrappers are C++ source files (.cpp) even though they expose a C API, so your toolchain must compile C++: GCC, Clang/ARMCC 6+ or IAR EWARM 8.0+ (Arm only). C++11 is the minimum, C++17 or later is recommended. On Arm, STK uses a minimal set of CMSIS.
Remove the original RTOS kernel sources from your build, add the wrapper source and the include paths. Your application code stays as it is.
# 1. Add wrapper source SRCS += libs/stk/interop/freertos/src/freertos_stk.cpp # 2. Add include paths INCLUDES += -Ilibs/stk/include INCLUDES += -Ilibs/stk/interop/freertos/include
Set the task limit, default stack size and priority levels with the wrapper macros from the table above. Define STK_TICKLESS_IDLE=1 for tickless idle. The FreeRTOS wrapper also lists its FreeRTOSConfig.h requirements in the repository.
Each wrapper has an API coverage table and a list of known limitations in its interop folder. Check it against the calls your project uses. POSIX is a subset by design.
Our benchmark compares native STK with FreeRTOS on a Cortex-M4. Your application will behave differently through a wrapper, so measure your own timing, RAM and flash, and use SEGGER SystemView to see the schedule.
If the wrapper lacks a call your project depends on, send us an inquiry.
The wrappers get you running quickly, but they speak your old API. STK itself is a type-safe C++ kernel, and moving to it module by module is where code gets shorter and safer. A pragmatic path:
Run FreeRTOS, CMSIS-RTOS2, ThreadX, Infineon or POSIX code through a wrapper. The quickest way to see STK on your hardware.
Call STK directly from C through stk_c.h (stk_kernel_*, stk_task_create_*), without a translation layer.
Write new modules as classes derived from stk::Task. Because the wrappers and the kernel are C++ anyway, C and C++ modules can live in one firmware.
Move to typed pipes, scoped locks and a compile-time configured kernel as modules are rewritten. There is no deadline: stop at whichever stage pays off.
Native C API
#include <stk_c.h>
#define STACK_WORDS 256
static stk_word_t g_stack0[STACK_WORDS];
static stk_word_t g_stack1[STACK_WORDS];
void task_led(void *arg)
{
while (1) { /* toggle LED */ stk_sleep_ms(500); }
}
void task_sensor(void *arg)
{
while (1) { /* read sensor */ stk_sleep_ms(100); }
}
int main(void)
{
stk_kernel_t *k = stk_kernel_create(0);
stk_kernel_init(k, STK_PERIODICITY_DEFAULT);
stk_task_t *t0 = stk_task_create_privileged(
task_led, NULL, g_stack0, STACK_WORDS);
stk_task_t *t1 = stk_task_create_privileged(
task_sensor, NULL, g_stack1, STACK_WORDS);
stk_kernel_add_task(k, t0);
stk_kernel_add_task(k, t1);
stk_kernel_start(k);
}Native C++ API
#include <stk.h>
using namespace stk;
class LedTask : public Task<256, ACCESS_PRIVILEGED>
{
void Run() override
{
Ticks next = GetTicks();
const Timeout period = GetTicksFromMs(500);
while (true)
{
/* toggle LED */
SleepUntil(next += period);
}
}
};
class SensorTask : public Task<256, ACCESS_PRIVILEGED>
{
void Run() override { /* same pattern, 100 ms */ }
};
int main()
{
static Kernel<KERNEL_STATIC, 2,
sched::SwitchStrategyRR, PlatformDefault> kernel;
static LedTask led;
static SensorTask sensor;
kernel.Initialize();
kernel.AddTask(&led);
kernel.AddTask(&sensor);
kernel.Start();
}Simplified from the C and C++ examples in the repository. Check the repository for exact, buildable code and the board-specific setup.
void * argumentsA C task receives an untyped pointer and casts it back. A C++ task keeps its state in typed member variables set by its constructor.
Task<256, ACCESS_PRIVILEGED> carries the stack size and access mode as template parameters. There is no separate stack array and word count to keep in sync.
void Run() override fails to compile if the signature is wrong, where a C task function pointer silently accepts a mismatched function.
Kernel<mode, tasks, strategy, platform> fixes mode flags, task count and scheduler at build time. Invalid combinations, such as hard real-time with time-slicing, are rejected by the compiler.
sync::PipeT<T, Capacity> is a FIFO of a concrete type with internal storage, and sync::SemaphoreT<T> picks its counter type. The byte-oriented Pipe and MessageQueue remain for C-ABI payloads. No heap is used.
Scoped guards such as hw::CriticalSection::ScopedLock release on every exit path, so an early return cannot leave a lock held.
C++ here means a disciplined subset: no STL, exceptions or RTTI, and no dynamic memory allocation, so footprint and timing stay predictable.
Architectural consulting, code reviews, training and integration support are available. See services.