Skip to content
You Start with one site
Amounts in Start with one site
Engineering · Embedded Systems & Electronics

RTOS Programming

Split firmware into tasks with FreeRTOS, so the urgent job always runs on time. Eight lessons on the STM32 or ESP32 you already own, from a jitter test to the same project on Zephyr.

Found this useful?
The same work in two example timelines, in equal steps, for a high, a medium and a low priority task that share one I2C lock. Without priority inheritance the low task holds the lock for 24 steps, the medium task runs in between, and the high task waits 20 steps. With priority inheritance the low task runs at priority 3 from step 4, holds the lock for 10 steps, and the high task waits 6.

A controller reads its sensor on time in one cycle and a few milliseconds late in the next, and the motor runs rough. An emergency button is read only when a long loop reaches it. Two tasks use one I2C bus at the same moment and both read wrong data, now and then. A device passes every test on the bench and resets by itself after three weeks in the field.

In this course you build firmware that keeps its timing under load. You give each job a task and a priority, pass data through queues, share a bus through a mutex, keep interrupts short, and reserve all memory when the program is built. Then you find planted bugs with a trace tool, and move a project to Zephyr with no change to its behaviour.

How each lesson goes
  1. 1Start from a faultThe LCD takes 4 ms more, and every job in the loop comes 4 ms later.
  2. 2See how the RTOS does itEach task is Ready, Running, Blocked or Suspended, and the scheduler picks.
  3. 3Build it from tasksThree tasks joined by queues of 16 places, each at its own pace.
  4. 4Prove it with a traceA record of which task ran when, taken while the system runs.
You will be able to
  1. Measure jitter, and split firmware into tasks with priorities that meet their deadlines
  2. Pass data with queues, share buses with mutexes, and keep interrupts short
  3. Find deadlocks, priority inversion and stack overflows with trace tools, and move a design to Zephyr

New to this? Know C on a microcontroller and new to an RTOS? Start with lesson 1: measure the jitter of a loop and of a task.

You need An STM32 Blue Pill with an ST-Link, or an ESP32 DevKitC, with the LEDs, buttons, potentiometer, OLED and BME280 of the earlier courses.

The engineering behind it

Several jobs on one chip, each on time, without missing a sample.

Lessons
More about this course

Every number has a reason

A task does not get its priority, its queue or its stack because it sounds right. Each number comes from a deadline or a measurement.

  • 13.1 msone pass of a plain loop; when the LCD takes 4 ms more, the sensor read comes every 17.1 msTiming
  • Shortest periodgets the highest priority: the LED every 1 ms above the sensor every 5 ms, above the report every 20 msPriority
  • 16 placesin each queue of the pipeline at 100 Hz, so a slow display does not lose a sampleQueues
  • 50 msof quiet on a pin before a software timer counts the press; each bounce starts the 50 ms againInterrupts
  • 30 bytes freein a 60 byte heap, and a request for 20 fails, because no two free blocks lie side by sideMemory

A lock protects the data. Its order and its owner decide the timing.

With no lock
Damaged data
  • Two tasks on one bus mix their bytes
  • Both get garbage, now and then
  • No error message

The test: is the fault rare and impossible to repeat?

With a mutex
Safe, if used right
  • One task holds the bus at a time
  • Priority inheritance stops a high task waiting behind a low one
  • The same order of locks everywhere, or a deadlock

The test: does the high task still meet its deadline?

Why FreeRTOS, then Zephyr

Runs on your boardSTM32, ESP32, RP2040 and hundreds more.
Priority schedulingThe most urgent ready task runs, at once.
Queues and mutexesData between tasks with no half-written values.
Static memoryEvery object reserved when you build, nothing requested while it runs.
Trace toolsSystemView or Tracealyzer record each task, microsecond by microsecond.
Zephyr for a new chipDrivers, networking and over 600 boards; pins in a devicetree.

Honest limits. The timing stays in the firmware: one task reads the sensor on a strict schedule and another sends the readings on, so a slow write or a network stop does not cost a reading. The device keeps every event before it sends them onward.

Before you start

  • C on an STM32 or an ESP32
  • GPIO, interrupts, I2C and a UART on that chip
  • An STM32 Blue Pill with an ST-Link, or an ESP32 DevKitC
  • A logic analyzer or oscilloscope helps in lesson 1, but is optional
The full course notes

Production firmware runs dozens of concurrent tasks: reading sensors, driving actuators, handling communication, managing power, and responding to user input, all with deterministic timing. A bare-metal super loop can handle a few of these, but it breaks down when tasks have conflicting timing requirements. This course teaches you to build concurrent firmware correctly using a Real-Time Operating System (RTOS). Each lesson builds a working RTOS application on hardware you already own from earlier courses. #RTOS #FreeRTOS #EmbeddedSystems

Why RTOS?

Beyond Super-Loops

Bare-metal main loops work until they do not. When you need sensor reads every 10ms, display updates every 50ms, and serial logging every 100ms, all without blocking each other, you need an RTOS. This course teaches you when and why.

Synchronization Done Right

Priority inversion, deadlocks, race conditions, and starvation. These are not textbook concepts; they are bugs that ship in real products. Lesson 4 gives you the mental models and practical patterns to avoid them.

Debug the Invisible

RTOS bugs are timing bugs. You cannot find them with printf. Lesson 7 teaches you to use Tracealyzer and SystemView to visualize task execution, find priority inversions, and measure jitter. This lesson alone is worth bookmarking.

Portable Skills

FreeRTOS runs on STM32, ESP32, RP2040, and hundreds of other platforms. Zephyr adds Linux-like abstractions with devicetree. These skills transfer across every embedded job.

Course Structure

Each lesson follows a consistent cycle:

  1. The Concurrency Problem A real scenario where bare-metal falls short. Multiple tasks that must coexist with timing guarantees.

  2. RTOS Theory The kernel mechanism that solves this problem: how it works internally, its guarantees, and its costs.

  3. FreeRTOS Implementation Build the solution on real hardware. Write tasks, configure the kernel, and handle edge cases.

  4. Test and Break It Deliberately create failure conditions (deadlock, priority inversion, stack overflow) to understand the theory viscerally.

  5. Design Patterns Reusable patterns for production firmware. When to use each primitive, and when simpler solutions are better.

Lessons

Lesson 1: Real-Time Systems Concepts

Real-Time Systems Concepts. Define hard, soft, and firm real-time. Measure jitter in bare-metal loops vs RTOS tasks. Understand worst-case execution time, scheduling theory, and rate-monotonic analysis. Build a jitter measurement rig. Build: Jitter measurement rig. Hardware: STM32 Blue Pill or ESP32 (from prior courses), LED.

Lesson 2: Tasks, Scheduling, and Context Switching

Tasks, Scheduling, and Context Switching. Explore task states, priority-based preemptive scheduling, time slicing, and the task control block. Understand stack allocation and context switch overhead. Build a priority-based traffic light controller. Build: Traffic light controller. Parts: 3 LEDs (red, yellow, green), 2 push buttons.

Lesson 3: Queues and Inter-Task Communication

Queues and Inter-Task Communication. Implement message queues, stream buffers, and event groups for passing data between tasks. Producer-consumer patterns, queue sizing, and blocking vs non-blocking sends. Build a sensor data pipeline with filtering. Build: Sensor data pipeline. Parts: Potentiometer, SSD1306 OLED (reuse from prior courses).

Lesson 4: Semaphores, Mutexes, and Synchronization

Semaphores, Mutexes, and Synchronization. Master binary and counting semaphores, mutexes with priority inheritance, and deadlock avoidance strategies. Build a multi-sensor I2C coordinator with mutex-protected bus access. Build: Multi-sensor I2C coordinator. Parts: BME280 + one other I2C sensor (reuse from prior courses).

Lesson 5: Memory Management and Safety

Memory Management and Safety. Compare FreeRTOS heap allocation schemes (heap_1 through heap_5). Implement static allocation, memory pools, and stack watermarking. Explore MPU-based memory protection. Build a memory-safe command processor. Build: Memory-safe command processor. Parts: Reuse existing.

Lesson 6: Software Timers and Interrupt Management

Software Timers and Interrupt Management. Configure software timers, deferred interrupt processing, and ISR-safe API calls. Understand critical sections, interrupt nesting, and the timer service task. Build a debounced multi-button input system. Build: Debounced multi-button input system. Parts: 4 push buttons, LEDs.

Lesson 7: Debugging and Profiling RTOS Applications

Debugging and Profiling RTOS Applications. Use Tracealyzer or SystemView to visualize task execution in real-time. Measure CPU load, detect stack overflows, find priority inversions, and profile queue throughput. Receive intentionally buggy RTOS firmware and diagnose every issue. Build: RTOS bug hunt (deadlock, priority inversion, stack overflow). Parts: Reuse existing.

Lesson 8: Zephyr RTOS Introduction

Zephyr RTOS Introduction. Set up the Zephyr build system with west. Learn devicetree, Kconfig, and Zephyr’s threading model. Port the traffic light controller from Lesson 2 to Zephyr and compare the two RTOS approaches. Build: Traffic light controller on Zephyr. Parts: Same as Lesson 2.

Hardware

No new purchases needed. This course uses hardware from the ATmega328P, STM32, or ESP32 courses:

PartSourceUsed In
STM32 Blue Pill + ST-Link (or ESP32 DevKitC)STM32 or ESP32 courseAll lessons
LEDs (red, yellow, green) + resistorsATmega328P courseLessons 1, 2, 6, 8
Push buttons + 10K resistorsATmega328P courseLessons 2, 6, 8
PotentiometerSTM32 courseLesson 3
SSD1306 OLED displayATmega328P or STM32 courseLesson 3
BME280 sensorATmega328P or STM32 courseLesson 4

If you have completed any of the previous embedded courses, you already have everything.

Skill Progression

SkillLessons 1-2Lessons 3-4Lessons 5-6Lessons 7-8
KernelScheduler, task states, preemptionQueues, semaphores, mutexesHeap schemes, timers, ISR integrationTrace tools, Zephyr kernel
PatternsTask decomposition, priority assignmentProducer-consumer, resource sharingStatic allocation, deferred processingProfiling, cross-RTOS portability
DebuggingJitter measurementQueue overflow detectionStack watermarking, MPU faultsTracealyzer, SystemView
Failure ModesMissed deadlines, starvationDeadlock, priority inversionHeap fragmentation, stack overflowAll combined in bug hunt

Prerequisites

Complete at least one prior embedded course

You should be comfortable with:

Helpful but not required:

  • FreeRTOS basics from STM32 lesson 8 (this course goes much deeper)
  • Basic understanding of operating system concepts (processes, threads, scheduling)

Getting Started

  1. Use your STM32 Blue Pill or ESP32 DevKitC from a previous course. Both run FreeRTOS.

  2. Gather LEDs, buttons, and sensors from your existing parts kit. No new purchases needed.

  3. Install Tracealyzer (free trial) or SEGGER SystemView (free) for lesson 7. Optional for earlier lessons.

  4. Start with Lesson 1. The jitter measurement rig gives you an immediate, visceral understanding of why RTOS matters.

  5. Break things deliberately. Each lesson includes a section where you intentionally create failure conditions. This is where the deepest learning happens.

© 2021-2026 SiliconWit®. All rights reserved.

8 lessons, in order.

SiliconWit makes these courses. We also run siliconwit.io, a monitoring service.