Introduction to FreeRTOS on STM32

When working on STM32 or other microcontroller projects, you often hear others say: “This project uses FreeRTOS.” What exactly is FreeRTOS? What benefits does it bring us? This article will provide a brief introduction to FreeRTOS.

1. What is FreeRTOS?

Let’s break down the name👇

  • Free → Free of charge

  • RTOS → Real-Time Operating System

Put together, it is a free real-time operating system.

⚠️ Note: RTOS is not a specific system, but a general term for a class of systems.

Common RTOS include: ✅ uC/OS ✅ RTX ✅ RT-Thread (domestic) ✅ FreeRTOS

These are all members of the RTOS family.

🌟 So what is a “real-time operating system”?

In simple terms, it is a system that can manage multiple tasks simultaneously and has very strict timing requirements.

For example:

You have written three tasks:

  • 🔹 Task A: Collect sensor data

  • 🔹 Task B: Control the motor

  • 🔹 Task C: Upload data via serial port

FreeRTOS will help you “schedule” who goes first and who goes next. Although the microcontroller’s CPU can only do one thing at a time, FreeRTOS will quickly switch tasks, making it feel like you are “working simultaneously”.

This is known as multitasking scheduling.

2. Why choose FreeRTOS?

There are many RTOS available on the market, so why do almost all STM32 engineers use FreeRTOS?

1️⃣ Free, open-source, worry-free for commercial use No need to worry about licensing issues, making it very suitable for product development.

2️⃣ Lightweight, highly portable The kernel code is compact and easy to port, with many chips (such as STM32, ESP32) having native support.

3️⃣ Clear structure, low learning curve Few files and intuitive logic, making it very suitable for transitioning from bare-metal to system development.

4️⃣ Complete ecosystem, active community Rich official documentation: English official website | Chinese site Major manufacturers’ SDKs all adopt FreeRTOS.

👉 Therefore: FreeRTOS is the best choice for getting started with RTOS!

3. Core Features of FreeRTOS

Although the FreeRTOS kernel is small, its functionality is very practical.

Function Category Features
🧩 Task Scheduling Supports preemptive, time-slice, and cooperative scheduling
⏱ Tickless Low Power Automatically turns off system tick interrupts when idle, saving power and improving efficiency
💾 Memory Management Supports both dynamic and static allocation
🔐 Synchronization Mechanisms Semaphores, queues, event groups, etc., allowing flexible task communication
⏳ Software Timers High precision, repeatable, and one-shot
⚠️ Stack Checking Supports task stack overflow detection, enhancing system stability
📦 Configurability Enable only the modules you need

In summary:

FreeRTOS = a compact, flexible, and stable embedded real-time system.

4. FreeRTOS vs Linux: Which is stronger?

“Can STM32 run Linux?” This is a question we all might have. In fact, the two are positioned completely differently👇

Comparison Item FreeRTOS Linux
🎯 Positioning Real-Time Operating System (RTOS) General-Purpose Operating System
⚡ Real-Time Performance Strong, fast response Relatively weak
💾 Resource Usage Small, only a few KB Large, at least several MB
🧠 Complexity Simple and easy to learn Feature-rich but complex
💰 Cost Low High
🔧 Applicable Scenarios MCU, STM32, ESP32 Industrial computers, servers, embedded Linux boards

It can be understood as👇

FreeRTOS is a “microcontroller-level” system, while Linux is a “computer-level” system.

Therefore, FreeRTOS is most suitable for resource-constrained MCUs.

5. Conclusion

FreeRTOS is like giving your microcontroller a “brain” — it helps you schedule tasks, manage time, and coordinate resources, making your code clearer, more efficient, and more stable.

💡 In summary:

FreeRTOS = the ultimate multitasking management tool for microcontrollers.

If you want to transition from bare-metal development to systematic development, FreeRTOS is definitely your best first step.

Follow me to learn more embedded knowledge~

Leave a Comment