SkillAgentSearch skills...

Stk

SuperTinyKernel™ RTOS is a lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. For ARM Cortex-M, RISC-V MCUs with x86 emulator. Suits embedded systems with limited RAM and FLASH.

Install / Use

/learn @SuperTinyKernel-RTOS/Stk

README

Logo

SuperTinyKernel™ RTOS

Lightweight High-Performance Deterministic C++ RTOS for Embedded Systems


MIT License Build Status Test Coverage Platform: Arm Cortex-M Platform: RISC-V membrowse


Overview

SuperTinyKernel™ RTOS (STK) is a high-performance, deterministic, bare-metal C++ real-time operating system designed for resource-constrained embedded systems. By focusing on a preemptive and deterministic thread scheduler rather than peripheral abstraction (HAL), STK provides a lightweight yet robust foundation for multitasking embedded applications where timing and minimal overhead are critical.

STK is implemented in C++ with a clean Object-Oriented Design while remaining friendly to embedded developers:

  • No aggressive namespace usage
  • No dependency on modern C++ features or STL
  • No dynamic memory allocation
  • Transparent and readable implementation
  • Fully-featured C interface for C-only development

It is an open-source project, navigate its internals for more details.


Key Features

| Feature | Description | |---------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Soft real-time | No strict time slots, mixed cooperative (by tasks) and preemptive (by kernel) scheduling | | Hard real-time (KERNEL_HRT) | Guaranteed execution window, deadline monitoring by the kernel | | Static task model (KERNEL_STATIC) | Tasks created once at startup | | Dynamic task model (KERNEL_DYNAMIC) | Tasks can be created and exit at runtime | | Rich scheduling capabilities | All major scheduling strategies are supported: priority-less (Round-Robin), fixed-priority, weighted (SWRR), earliest-deadline-first (EDF), and mixed-criticality adaptive (MCAS/MCAS4) | | Mixed-criticality | Supports MCAS (2-level) and MCAS4 (4-level) adaptive strategies featuring SWRR-based group scheduling, automatic cascade escalation/recovery, and elastic CPU share adaptation driven by per-group EWMA execution-pressure estimation | | Tick or Tickless modes | Supports fixed-interval periodic interrupts (Tick) for simplicity, or dynamic timer-based wakeups (Tickless, KERNEL_TICKLESS) to maximize CPU sleep duration and power efficiency | | Extensible via C++ interfaces | Kernel functionality can be extended by implementing available C++ interfaces | | Multi-core support (AMP) | One STK instance per physical core for optimal, lock-free performance | | Memory Protection Unit (MPU) support | Supports privileged ACCESS_PRIVILEGED and non-privileged tasks ACCESS_USER | | Low-power aware | MCU enters sleep when no task is runnable (sleeping) | | Synchronization API | Rich set of primitives in stk::sync: Mutex, RWMutex, Semaphore, Event, EventFlags, ConditionVariable, Pipe, SpinLock, ScopedCriticalSection — plus low-level hw::CriticalSection and hw::SpinLock | | Thread-Local Storage (TLS) | Per-task TLS via a dedicated CPU register (r9 on ARM Cortex-M, tp/x4 on RISC-V). GetTls() / SetTls() are inline zero-overhead helpers | | Tiny footprint | Minimal code unrelated to scheduling | | Safety-critical systems ready | No dynamic heap memory allocation (satisfies MISRA C++:2008 Rule 18-4-1) | | C++ and C API | Can be used easily in C++ and C projects | | Easy porting | Requires very small to none BSP surface | | Traceable | Scheduling is fully traceable with a SEGGER SystemView | | Development mode (x86) | Run the same threaded application on Windows | | 100% test coverage | Every source-code line of scheduler logic is covered by unit tests | | QEMU test coverage | All repository commits are automatically covered by unit tests executed on QEMU for Cortex-M and RISC-V |


Modes of Operation

Soft Real-Time (Default)

  • Tasks cooperate using Sleep() or Yield()
  • Timing is a best-effort
  • Preemptive scheduling: tasks can not block execution of other tasks even if they do not cooperate (see Built-in Scheduling Strategies)
  • Dedicated task switching strategies (SwitchStrategyRoundRobin, SwitchStrategyFixedPriority, SwitchStrategySmoothWeightedRoundRobin)
// task is added without any time constraints
void AddTask(ITask *user_task)

Hard Real-Time (HRT)

  • Separate kernel mode of operation set by the KERNEL_HRT flag
  • Periodic tasks with strict execution windows
  • Tasks must notify kernel when the work is done by using Yield()
  • Kernel enforces deadlines
  • Any violation fails the application deterministically (ITask::OnDeadlineMissed(uint32_t duration) callback is called, where duration is the overrun amount in ticks)
  • Dedicated HRT task switching strategies (SwitchStrategyRoundRobin, SwitchStrategyRM, SwitchStrategyDM, SwitchStrategyEDF)
// task is added time constraints: periodicity, deadline and start delay
AddTask(ITask *user_task, Timeout periodicity_tc, Timeout deadline_tc, Timeout start_delay_tc)

Static vs Dynamic

  • KERNEL_STATIC: tasks are created once at startup, kernel never returns to main().
  • KERNEL_DYNAMIC: tasks may exit, kernel returns to main() when all tasks exit.

Tick / Tickless Context Switching

Tick-Based Mode (Default)

  • Kernel time advances in fixed periodic interrupts (ticks)
  • Hardware timer generates interrupts at a constant frequency
  • Scheduler decisions are evaluated on each tick
  • Simple and predictable behavior
  • Suitable for systems where:
    • Timing granularity is fixed and acceptable
    • Power consumption is not critical
  • Lower implementation complexity, but may introduce unnecessary CPU wa
View on GitHub
GitHub Stars14
CategoryDevelopment
Updated15h ago
Forks1

Languages

C

Security Score

95/100

Audited on Apr 2, 2026

No findings