Hardware

FreeRTOS — Real-Time OS for IoT Firmware

FreeRTOS is the world’s most widely deployed real-time operating system for microcontrollers, and it is the RTOS foundation of every FSS Technology embedded firmware project that requires concurrent task execution, deterministic timing, and structured inter-task communication. Running on STM32, ESP32, and a wide range of ARM Cortex-M microcontrollers, FreeRTOS provides the preemptive multitasking infrastructure that […]

Used by FSS: Since 2015
Projects: 10+
Category: Hardware
FREERTOS FSS // 2011

FreeRTOS is the world’s most widely deployed real-time operating system for microcontrollers, and it is the RTOS foundation of every FSS Technology embedded firmware project that requires concurrent task execution, deterministic timing, and structured inter-task communication. Running on STM32, ESP32, and a wide range of ARM Cortex-M microcontrollers, FreeRTOS provides the preemptive multitasking infrastructure that transforms complex, multi-concern firmware — simultaneous sensor reading, protocol communication, data logging, and user interface — from an unmanageable monolithic interrupt-driven state machine into a clear, maintainable architecture of cooperating tasks. Amazon’s stewardship of FreeRTOS since 2017, now part of the AWS IoT ecosystem, has further extended it with IoT-oriented libraries including coreMQTT, coreHTTP, and AWS IoT Device Defender integration.

Core FreeRTOS Concepts in IoT Firmware

Tasks: The Foundation of Concurrent Firmware

FreeRTOS tasks are independent threads of execution, each with its own stack and priority level. The FreeRTOS scheduler preemptively switches between tasks based on priority and blocking state, ensuring that the highest-priority runnable task always has CPU time. FSS firmware architects assign carefully considered priorities to firmware tasks: safety and control tasks (watchdog monitoring, alarm detection, motor control loops) receive the highest priorities and are never blocked by lower-priority communication or logging work; MQTT publishing and data processing tasks run at medium priority; diagnostic logging runs at the lowest priority and executes only when no higher-priority task needs the CPU.

A typical FSS IoT device firmware runs 5-8 FreeRTOS tasks. A temperature and humidity monitoring device might have: a sensor task that wakes every 30 seconds to read I²C sensors and push readings to a queue; a processing task that reads the queue, applies calibration corrections, checks thresholds, and writes to a ring buffer; an MQTT task that publishes buffered readings to Azure IoT Hub when Wi-Fi is connected; an OTA task that periodically checks for firmware updates; and a watchdog task that monitors task heartbeats and triggers a system reset if any task stops responding. This clean separation of concerns makes each task individually understandable and testable.

Queues: Safe Inter-Task Data Transfer

FreeRTOS queues provide thread-safe, blocking data transfer between tasks. A producing task posts data to a queue; a consuming task blocks waiting for data, waking immediately when data arrives. The queue’s internal mutex and atomic operations prevent data corruption from concurrent access — a safety guarantee that ad-hoc global variable sharing between interrupt service routines and tasks cannot provide. FSS uses queues as the primary inter-task communication mechanism in all firmware projects: sensor reading tasks post measurement structs to processing queues; processing tasks post formatted telemetry to MQTT publishing queues; alert detection tasks post alarm events to notification queues. Queue depth is sized to absorb bursts — a measurement burst during connectivity loss fills the queue until the MQTT task can drain it when connectivity is restored.

Semaphores and Mutexes for Resource Protection

When multiple tasks must share a peripheral — an SPI bus, an I²C bus, a UART interface — concurrent access without coordination corrupts transmissions and produces undefined hardware behaviour. FreeRTOS mutexes provide priority-inheriting mutual exclusion: a task acquiring the mutex for an I²C bus holds exclusive access for the duration of its transaction; other tasks block at the mutex until it is released. FreeRTOS’s priority inheritance mechanism prevents priority inversion — the pathological condition where a low-priority task holding a mutex blocks a high-priority task indefinitely while medium-priority tasks run. FSS applies mutexes to every shared peripheral in firmware, making concurrent peripheral access safe and the firmware behaviour predictable.

Software Timers for Periodic Operations

FreeRTOS software timers execute callbacks in the context of the timer service task, enabling periodic and one-shot timed operations without consuming a dedicated task per timer. FSS firmware uses software timers for: connection watchdog timeouts that trigger reconnection attempts if an MQTT connection has been silent for 60 seconds; LED blink patterns with timed on/off cycles; debounce timeouts for button input processing; and keepalive ping timers for long-lived TCP connections. Software timers are more efficient than dedicated timer tasks for short-lived or infrequent operations, reducing total task count and stack memory consumption.

FreeRTOS Memory Management

FreeRTOS provides five memory allocation implementations (heap_1 through heap_5) with different characteristics. FSS uses heap_4 — a coalescing first-fit allocator — for projects that require dynamic task and queue creation, and static allocation (heap_1 equivalent via task and queue creation with pre-allocated buffers) for safety-critical firmware where dynamic memory allocation is prohibited by coding standards. Static allocation eliminates runtime memory exhaustion failures at the cost of requiring all memory to be allocated at compile time; FSS applies static allocation on STM32 firmware projects targeting certification or safety standards, and heap_4 on ESP32 projects where the generous SRAM budget reduces heap exhaustion risk.

FreeRTOS + AWS IoT Integration

Amazon’s FreeRTOS ecosystem adds IoT connectivity libraries on top of the RTOS kernel: coreMQTT provides an MQTT 3.1.1 client designed for microcontroller memory constraints; corePKCS11 abstracts cryptographic operations for TLS certificate management; AWS IoT Device Shadow enables device state synchronisation between device firmware and cloud; AWS IoT Jobs delivers firmware update commands to devices at scale. FSS integrates these libraries into ESP32 and STM32 firmware that communicates with Azure IoT Hub (using the MQTT interface, compatible with coreMQTT) and AWS IoT Core, providing a proven, well-tested IoT connectivity stack that handles reconnection, QoS 1 delivery guarantees, and TLS certificate management correctly.

Limitations and Considerations

Stack Sizing Complexity

Each FreeRTOS task requires a dedicated stack, and stack overflow — a task using more stack than allocated — produces memory corruption and unpredictable firmware behaviour. Correctly sizing task stacks requires analysing maximum call depth and local variable usage, a process that is tedious for complex tasks. FSS uses FreeRTOS stack high watermark monitoring in development builds to measure actual peak stack usage per task and size stacks with an appropriate safety margin, then validates stack sizes through extended stress testing before production release.

Debugging Multi-Task Firmware

Debugging concurrent firmware defects — race conditions, deadlocks, priority inversions, queue overflow — requires different techniques than sequential software debugging. FSS engineers use FreeRTOS’s runtime statistics APIs, SEGGER SystemView for visual task execution timeline analysis, and structured logging with task-stamped log entries to diagnose concurrency defects efficiently. These diagnostic capabilities are integrated into FSS firmware from project start, not added reactively when problems occur.

FreeRTOS Use Cases at FSS

GEST Controller Firmware

FreeRTOS on STM32 managing 8 concurrent tasks: BLE stack integration, RFID reader interface, display driver, event logging, Ethernet communication, configuration management, OTA update, and watchdog. Priority-based scheduling ensures BLE events are serviced within 10ms regardless of communication load.

Multi-Sensor Industrial Logger

ESP32 FreeRTOS firmware reading 16 I²C sensors via 2 buses (mutex-protected), buffering 72 hours of readings in SPI flash (mutex-protected), and publishing over MQTT when LTE connectivity is available. Queue-based architecture decouples sensor timing from network availability.

Motor Controller with FreeRTOS

STM32G4 FreeRTOS firmware with 10kHz motor control ISR posting encoder data to a high-priority processing task via queue, CANopen communication task at medium priority, and diagnostic logging at low priority. Deterministic task scheduling ensures control loop timing is unaffected by communication load.

OTA-Enabled Device Fleet

FreeRTOS OTA update task integrated with AWS IoT Jobs on 500-device ESP32 fleet. Background OTA download in low-priority task; signature verification and partition swap triggered after successful download without interrupting normal sensor operation.

Real-Time Alert System

FreeRTOS binary semaphore-based alarm architecture: GPIO interrupt ISR posts to semaphore; high-priority alarm task unblocks immediately, evaluates alert condition, and triggers notification within 5ms of hardware event — deterministic response time regardless of other firmware activity.

BLE + Wi-Fi Concurrent Firmware

ESP32 FreeRTOS firmware running simultaneous BLE GATT server (for mobile app proximity configuration) and Wi-Fi MQTT client (for cloud telemetry). Dual-core assignment: BLE stack on core 0, application and MQTT on core 1 — zero interference between wireless stacks.

FSS FreeRTOS Expertise

FSS Technology’s embedded engineers have been writing FreeRTOS firmware since 2012, across STM32, ESP32, NXP Kinetis, and Nordic nRF52 platforms. Our team maintains internal FreeRTOS firmware architecture templates, stack sizing guidelines, and debugging runbooks that encode a decade of production embedded development experience. We apply FreeRTOS correctly from the start — right task architectures, safe inter-task communication patterns, and validated stack sizing — avoiding the subtle concurrency defects that are easy to introduce and expensive to diagnose in the field. Contact FSS to discuss your real-time firmware development requirements.

// next step

Let's build something great together.

From proof of concept to production fleet — FSS delivers.

Start a Project Explore All Technologies See Our Products