Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
  1. Home
  2. /
  3. Learn
  4. /
  5. Freertos

Learn Freertos - 10 Code Examples & CST Typing Practice Test

FreeRTOS is a lightweight, open-source real-time operating system (RTOS) kernel for embedded devices. It provides multitasking, scheduling, and inter-task communication for microcontrollers and small processors.

View all 10 Freertos code examples →
Hello World Task (FreeRTOS)Blink LED Task (FreeRTOS)Queue Example (FreeRTOS)Mutex Example (FreeRTOS)Timer Callback (FreeRTOS)Semaphore Synchronization (FreeRTOS)Task Delay Example (FreeRTOS)Queue Set Example (FreeRTOS)Priority Task Example (FreeRTOS)Event Group Example (FreeRTOS)

Learn FREERTOS with Real Code Examples

Updated Nov 27, 2025

Explain

FreeRTOS allows multiple tasks (threads) to run seemingly simultaneously on microcontrollers.

Provides task scheduling with priorities, preemption, and time slicing.

Supports inter-task communication using queues, semaphores, and mutexes.

Highly portable across 8/16/32-bit MCUs and architectures like ARM, AVR, PIC, and RISC-V.

Used widely in industrial, IoT, automotive, and consumer embedded systems.

Core Features

Tasks (threads)

Queues for message passing

Semaphores and mutexes

Event groups for synchronization

Tick-based software timers

Basic Concepts Overview

Task - independent unit of execution

Queue - thread-safe message passing

Semaphore - signaling between tasks

Mutex - mutual exclusion for shared resources

Tick - periodic timer driving scheduling

Project Structure

FreeRTOS source folder (tasks, queue, timers)

Application C source files

Board support package (BSP) and driver files

FreeRTOSConfig.h

Makefile or IDE project configuration

Building Workflow

Configure FreeRTOS kernel

Create tasks using xTaskCreate

Set up queues, semaphores, or mutexes

Start scheduler with vTaskStartScheduler

Test tasks and inter-task communication

Difficulty Use Cases

Beginner: blink LED task with delay

Intermediate: multiple tasks with queues

Advanced: ISR + tasks + priority management

Expert: tickless low-power mode and dynamic memory

Architect: complex multitasking IoT device

Comparisons

FreeRTOS vs Zephyr: FreeRTOS simpler, Zephyr more full-featured

FreeRTOS vs ChibiOS: FreeRTOS more widely used, ChibiOS faster kernel

FreeRTOS vs bare-metal: RTOS adds multitasking & scheduling

FreeRTOS vs Linux RT: FreeRTOS lighter, Linux richer OS

FreeRTOS vs ThreadX: FreeRTOS open-source, ThreadX commercial with safety certifications

Versioning Timeline

2003 - FreeRTOS created by Richard Barry

2006 - Kernel modularization

2012 - Tickless idle mode introduced

2015 - Amazon FreeRTOS announced

2018 - FreeRTOS+TCP and +FAT improvements

2020 - ARM Cortex-M MPU support enhancements

2022 - Latest FreeRTOS kernel updates

2024 - Expanded support for RISC-V and low-power MCUs

2025 - Continued integration with AWS IoT services

Glossary

Task - independent thread

Queue - message passing structure

Semaphore - signaling mechanism

Mutex - mutual exclusion

Tick - system timer interrupt for scheduling

Installation Setup

Download FreeRTOS Kernel from official GitHub

Choose target MCU and toolchain

Include FreeRTOS source files in project

Configure FreeRTOSConfig.h for tick rate, priorities, and memory

Build and flash project to microcontroller

Environment Setup

Install MCU toolchain (GCC/Keil/IAR)

Download FreeRTOS kernel

Configure FreeRTOSConfig.h

Include BSP and driver files

Set up debugger or serial output

Config Files

FreeRTOSConfig.h - kernel settings

*.c - task implementation

*.h - task headers

BSP files - hardware initialization

Makefile or IDE project files

Cli Commands

Build and flash via IDE/Makefile

Enable kernel-aware debugging

Monitor tasks using Tracealyzer

Simulate RTOS on POSIX port

Run memory/stress tests on MCU

Internationalization

Unicode support in string handling

Regional configuration for timers and measurement units

Multi-language documentation

Compliance with global MCU standards

Support for international IoT protocols

Accessibility

Kernel accessible via APIs

Documentation for tasks, queues, semaphores

Debugger integration for all tasks

Open-source community support

Examples and templates for beginners

Ui Styling

Not applicable (embedded system kernel)

Code organization and comments

Naming conventions for tasks and queues

Consistent API usage

Documentation for maintainability

State Management

Each task has its own stack and state

Kernel maintains ready/blocked/suspended queues

Semaphores and mutexes manage shared resources

Software timers track periodic events

Global state should be protected by mutexes

Data Management

Task-local variables

Queue-based message passing

Event group flags

Shared resources with mutexes

EEPROM/NVRAM for persistent data

Architecture

Kernel: manages tasks, scheduling, and system tick

Tasks: independent threads with priorities

Queues and semaphores: synchronization and communication

Tick timer: drives task scheduling

Optional modules: timers, software hooks, memory management

Rendering Model

Not GUI-based

Tasks run on scheduler tick

Kernel manages context switching

Communication via queues/semaphores

Optional timers for periodic actions

Architectural Patterns

Preemptive priority-based multitasking

Cooperative multitasking support

Producer-consumer pattern with queues

Event-driven tasks with semaphores

Tick-driven scheduling

Real World Architectures

IoT sensor node with network connectivity

Motor control in industrial automation

Battery-powered wearable device

Consumer electronics with multitasking

Low-power edge AI device

Design Principles

Lightweight kernel

Deterministic scheduling

Portability across MCUs

Flexible inter-task communication

Scalability from small to medium embedded devices

Scalability Guide

Partition tasks for modularity

Use queues/semaphores efficiently

Optimize stack and heap usage

Prioritize critical real-time tasks

Leverage software timers for event scheduling

Migration Guide

Update FreeRTOS kernel to latest version

Adjust FreeRTOSConfig.h for new MCU

Refactor task priorities and stack sizes

Integrate new peripheral drivers

Test low-power modes and tickless idle

Performance Notes

Keep tasks short and deterministic

Minimize critical section durations

Avoid blocking calls in high-priority tasks

Optimize queue usage

Use tickless idle for low-power applications

Security Notes

Protect shared resources with mutexes

Validate input from external peripherals

Isolate critical tasks when possible

Use memory-safe APIs

Enable MPU support if available for task protection

Monitoring Analytics

Trace task execution

Monitor queue/semaphore usage

Check stack usage per task

Debug timing and jitter

Evaluate low-power operation

Code Quality

Use consistent task naming

Minimize shared global variables

Document API usage

Ensure deterministic task timing

Unit test tasks and synchronization primitives

Practical Examples

Blink LED with periodic task

UART communication using queues

Sensor data acquisition with mutex protection

Motor control with priority tasks

Low-power IoT node using tickless idle

Troubleshooting

Check stack size for each task

Verify task priorities to avoid starvation

Monitor queue overflow or underflow

Debug using FreeRTOS+Trace or RTT

Ensure ISR compatibility with kernel APIs

Testing Guide

Unit test individual tasks

Simulate queues and semaphores

Verify ISR-task interaction

Check task scheduling with priority inversion

Perform long-duration stress testing

Deployment Options

Direct to microcontroller flash

Simulated environment on PC (POSIX port)

IoT edge devices with FreeRTOS+TCP

Industrial MCU boards

Battery-powered embedded sensors

Tools Ecosystem

Official FreeRTOS Kernel

FreeRTOS+TCP and +FAT modules

Tracealyzer for task monitoring

Segger SystemView for real-time debugging

Vendor-specific BSP and HAL libraries

Integrations

IoT connectivity stacks (MQTT, LwIP)

Peripheral driver libraries

Hardware abstraction layers

Debugging/profiling tools

Power management and low-power APIs

Productivity Tips

Use templates for tasks and queues

Keep tasks short and modular

Enable kernel-aware debugging

Profile using tracing tools

Regularly check stack and heap usage

Challenges

Avoiding priority inversion

Debugging concurrency issues

Optimizing memory footprint

Ensuring deterministic timing

Porting to new microcontrollers

Learning Path

Understand task creation and scheduling

Learn inter-task communication mechanisms

Practice ISR and task interactions

Explore timers and software hooks

Integrate with peripherals and connectivity stacks

Skill Improvement Plan

Week 1: Task basics and delays

Week 2: Queues, semaphores, mutexes

Week 3: ISR-safe coding and priorities

Week 4: Tickless idle and power management

Week 5: Integrate networking/IoT functionality

Interview Questions

Explain preemptive vs cooperative scheduling in FreeRTOS.

What are queues, semaphores, and mutexes?

How do you handle priority inversion?

How to integrate FreeRTOS with ISRs?

Explain tickless idle mode and low-power operation.

Cheat Sheet

xTaskCreate() -> create task

vTaskDelay() -> delay task

xQueueSend()/xQueueReceive() -> send/receive data

xSemaphoreTake()/Give() -> mutex/semaphore

vTaskStartScheduler() -> start RTOS

Books

Mastering FreeRTOS

Real-Time Operating Systems for Embedded Systems

Hands-On FreeRTOS Projects

Embedded Systems with FreeRTOS

FreeRTOS Kernel and Multitasking Guide

Tutorials

Getting started with FreeRTOS on STM32

Task creation and scheduling basics

Inter-task communication with queues

Synchronization using semaphores and mutexes

Low-power tickless idle applications

Official Docs

https://www.freertos.org/

FreeRTOS Kernel API Reference

Community Links

FreeRTOS GitHub

FreeRTOS Forum

Embedded systems Stack Overflow

Vendor-specific MCU communities

YouTube embedded tutorials

Community Support

FreeRTOS GitHub

FreeRTOS Forum

Embedded systems Stack Overflow

Vendor-specific communities (STM32, TI, NXP)

YouTube embedded tutorials

Monetization

Embedded IoT device development

Industrial automation solutions

Consumer electronics RTOS deployment

Edge AI embedded systems

FreeRTOS training and consulting

Future Roadmap

Enhanced MPU/MPU+ task isolation

Deeper integration with AWS IoT services

Better support for multi-core MCUs

Improved trace and debugging tools

Continued focus on low-power embedded devices

When Not To Use

High-level OS features required (GUI, filesystem)

Very large memory embedded applications

Desktop-class multi-threading needs

Heavy network stacks without FreeRTOS+TCP

Applications needing full memory protection by default

Final Summary

FreeRTOS is a lightweight, open-source RTOS for embedded devices.

Supports multitasking, inter-task communication, and real-time scheduling.

Highly portable across MCUs and architectures.

Widely used in IoT, industrial, automotive, and consumer applications.

Ideal for projects needing predictable real-time behavior on resource-constrained devices.

Faq

Is FreeRTOS free? -> Yes, open-source MIT license.

Is it suitable for low-power MCUs? -> Yes, supports tickless idle.

Does it support networking? -> Yes, via FreeRTOS+TCP and LWIP.

Can I use it on 8-bit MCUs? -> Yes, portable kernel supports 8/16/32-bit devices.

Does it support C++? -> Yes, via wrapper classes and C++ tasks.

Code Sample Descriptions

1

Hello World Task (FreeRTOS)

#include <FreeRTOS.h>
#include <task.h>
#include <stdio.h>

void vTask(void* pvParameters) {
    printf("Hello, FreeRTOS!\n");
    vTaskDelete(NULL);
}

int main() {
    xTaskCreate(vTask, "Task1", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}

Basic FreeRTOS task printing Hello World.

Let’s Try →
2

Blink LED Task (FreeRTOS)

#include <FreeRTOS.h>
#include <task.h>
#include <stdint.h>
#include "gpio.h"

void vBlinkTask(void* pvParameters) {
    while(1) {
        GPIO_TogglePin(LED_PIN);
        vTaskDelay(pdMS_TO_TICKS(500));
    }
}

int main() {
    xTaskCreate(vBlinkTask, "Blink", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}

Toggles an LED using a FreeRTOS task.

Let’s Try →
3

Queue Example (FreeRTOS)

#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#include <stdio.h>

QueueHandle_t xQueue;

void vSenderTask(void* pvParameters) {
    int value = 42;
    xQueueSend(xQueue, &value, portMAX_DELAY);
    vTaskDelete(NULL);
}

void vReceiverTask(void* pvParameters) {
    int received;
    xQueueReceive(xQueue, &received, portMAX_DELAY);
    printf("Received: %d\n", received);
    vTaskDelete(NULL);
}

int main() {
    xQueue = xQueueCreate(1, sizeof(int));
    xTaskCreate(vSenderTask, "Sender", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
    xTaskCreate(vReceiverTask, "Receiver", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}

Shows sending and receiving messages via FreeRTOS queue.

Let’s Try →
4

Mutex Example (FreeRTOS)

#include <FreeRTOS.h>
#include <task.h>
#include <semphr.h>
#include <stdio.h>

SemaphoreHandle_t xMutex;

void vTask1(void* pvParameters) {
    xSemaphoreTake(xMutex, portMAX_DELAY);
    printf("Task1 in critical section\n");
    xSemaphoreGive(xMutex);
    vTaskDelete(NULL);
}

void vTask2(void* pvParameters) {
    xSemaphoreTake(xMutex, portMAX_DELAY);
    printf("Task2 in critical section\n");
    xSemaphoreGive(xMutex);
    vTaskDelete(NULL);
}

int main() {
    xMutex = xSemaphoreCreateMutex();
    xTaskCreate(vTask1, "T1", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
    xTaskCreate(vTask2, "T2", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}

Demonstrates mutual exclusion using FreeRTOS mutex.

Let’s Try →
5

Timer Callback (FreeRTOS)

#include <FreeRTOS.h>
#include <timers.h>
#include <stdio.h>

void vTimerCallback(TimerHandle_t xTimer) {
    printf("Timer callback triggered\n");
}

int main() {
    TimerHandle_t xTimer = xTimerCreate("Timer", pdMS_TO_TICKS(1000), pdTRUE, NULL, vTimerCallback);
    xTimerStart(xTimer, 0);
    vTaskStartScheduler();
    return 0;
}

Sets up a FreeRTOS software timer with a callback function.

Let’s Try →
6

Semaphore Synchronization (FreeRTOS)

#include <FreeRTOS.h>
#include <task.h>
#include <semphr.h>
#include <stdio.h>

SemaphoreHandle_t xBinarySem;

void vTaskProducer(void* pvParameters) {
    printf("Producer giving semaphore\n");
    xSemaphoreGive(xBinarySem);
    vTaskDelete(NULL);
}

void vTaskConsumer(void* pvParameters) {
    xSemaphoreTake(xBinarySem, portMAX_DELAY);
    printf("Consumer received semaphore\n");
    vTaskDelete(NULL);
}

int main() {
    xBinarySem = xSemaphoreCreateBinary();
    xTaskCreate(vTaskProducer, "Producer", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
    xTaskCreate(vTaskConsumer, "Consumer", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}

Uses a binary semaphore to synchronize two tasks.

Let’s Try →
7

Task Delay Example (FreeRTOS)

#include <FreeRTOS.h>
#include <task.h>
#include <stdio.h>

void vTaskDelayExample(void* pvParameters) {
    while(1) {
        printf("Task running\n");
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}

int main() {
    xTaskCreate(vTaskDelayExample, "DelayTask", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}

Demonstrates delaying a task for a fixed period.

Let’s Try →
8

Queue Set Example (FreeRTOS)

#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#include <stdio.h>

QueueHandle_t xQueue1, xQueue2;
QueueSetHandle_t xQueueSet;

int main() {
    xQueue1 = xQueueCreate(1, sizeof(int));
    xQueue2 = xQueueCreate(1, sizeof(int));
    xQueueSet = xQueueCreateSet(2);
    xQueueAddToSet(xQueue1, xQueueSet);
    xQueueAddToSet(xQueue2, xQueueSet);
    vTaskStartScheduler();
    return 0;
}

Demonstrates using a FreeRTOS queue set to manage multiple queues.

Let’s Try →
9

Priority Task Example (FreeRTOS)

#include <FreeRTOS.h>
#include <task.h>
#include <stdio.h>

void vHighPriorityTask(void* pvParameters) {
    printf("High priority task running\n");
    vTaskDelete(NULL);
}

void vLowPriorityTask(void* pvParameters) {
    printf("Low priority task running\n");
    vTaskDelete(NULL);
}

int main() {
    xTaskCreate(vLowPriorityTask, "Low", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
    xTaskCreate(vHighPriorityTask, "High", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
    vTaskStartScheduler();
    return 0;
}

Creates two tasks with different priorities to demonstrate scheduling.

Let’s Try →
10

Event Group Example (FreeRTOS)

#include <FreeRTOS.h>
#include <task.h>
#include <event_groups.h>
#include <stdio.h>

EventGroupHandle_t xEventGroup;

int main() {
    xEventGroup = xEventGroupCreate();
    xEventGroupSetBits(xEventGroup, 0x01);
    printf("Event bit set\n");
    vTaskStartScheduler();
    return 0;
}

Shows using FreeRTOS event groups for task synchronization.

Let’s Try →

Frequently Asked Questions about Freertos

What is Freertos?

FreeRTOS is a lightweight, open-source real-time operating system (RTOS) kernel for embedded devices. It provides multitasking, scheduling, and inter-task communication for microcontrollers and small processors.

What are the primary use cases for Freertos?

Task scheduling for embedded systems. IoT and sensor node software. Industrial automation control. Real-time motor and sensor management. Edge devices and microcontroller applications

What are the strengths of Freertos?

Very lightweight (few KB footprint). Highly portable across MCUs. Open-source with active community. Predictable real-time behavior. Easy integration with peripheral drivers

What are the limitations of Freertos?

Not a full-featured OS (no file system, GUI). Limited memory protection features. Requires careful design for hard real-time tasks. Debugging complex task interactions can be tricky. No native networking stack (requires integration)

How can I practice Freertos typing speed?

CodeSpeedTest offers 10+ real Freertos code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.

Learn Other Programming Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypherGremlinPartiqlHaskellElixirFsharpView all languages →
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.