RTOS#

Real-time operating system. A scheduler, a set of synchronisation primitives, and a memory model designed for microcontrollers where bounded latency matters more than throughput. A bare-metal super-loop is fine for a blinky; once the firmware juggles three or more independent tasks (radio, sensors, comms), an RTOS pays for itself in code clarity and timing guarantees.

RTOSes#

RTOS

Footprint

Note

FreeRTOS

Tiny (~6 KB minimum)

The dominant embedded RTOS. Now Amazon-maintained as part of AWS IoT. Used inside ESP-IDF and many vendor SDKs.

Zephyr

Small to medium

Linux Foundation project. Device tree, kconfig, full networking and Bluetooth stacks; the modern successor to mbed for new projects.

ChibiOS / RT

Small (~5 KB)

Italian-origin RTOS with a strong reputation for deterministic timing and small footprint.

NuttX

Medium

POSIX-like RTOS; powers the PX4 autopilot. Larger than FreeRTOS but a much more familiar API for Linux programmers.

RT-Thread

Small to medium

Chinese-origin RTOS with growing global adoption; extensive driver ecosystem.

ThreadX (Azure RTOS)

Small

Microsoft’s offering after the Express Logic acquisition. Now Eclipse Foundation; renamed Eclipse ThreadX.

mbed OS

Medium

Arm’s RTOS, now maintenance-only.

Primitives#

Every RTOS offers roughly the same primitives; what differs is the API surface and the configuration mechanism.

Primitive

Purpose

Task / thread

A unit of execution. The scheduler picks one to run at a time; preempts based on priority.

Queue / mailbox

Pass data between tasks without sharing memory.

Semaphore

Count-based signaling; the canonical way to release a waiting task from an ISR.

Mutex

Mutual exclusion with priority inheritance to prevent priority inversion.

Event group / flags

Wait on one of several events from one task.

Software timer

One-shot or periodic callback dispatched from a timer task; cheaper than burning a hardware timer per timeout.

Direct-to-task notification

FreeRTOS lightweight alternative to a semaphore; faster and smaller.

Pitfalls#

  • ISR-safe APIs only inside ISRs. Every RTOS has a separate set of API entry points for interrupt context (...FromISR in FreeRTOS, isr_ in Zephyr); calling the regular API from an ISR corrupts the scheduler state.

  • Priority inversion when a high-priority task waits on a mutex held by a low-priority task that a medium-priority task preempts. Mutexes with priority inheritance fix this; raw semaphores do not.

  • Stack overflow per task. Each task gets its own stack; sized too small and the firmware crashes in mysterious ways. Enable the RTOS stack-overflow check during development.

  • Heap fragmentation. Long-running firmware that allocates and frees from a small RTOS heap will fragment it. Prefer static allocation; reach for heap_4 or heap_5 if dynamic allocation is required.

References#