FreeRTOS
'Classic' FreeRTOS distribution. Started as Git clone of FreeRTOS SourceForge SVN repo. Submodules the kernel.
Top Related Projects
Linux kernel source tree
Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
Arm Mbed OS is a platform operating system designed for the internet of things
RIOT - The friendly OS for IoT
RT-Thread is an open source IoT Real-Time Operating System (RTOS). https://rt-thread.github.io/rt-thread/
Quick Overview
FreeRTOS is a popular, open-source real-time operating system for microcontrollers and small microprocessors. It is designed to be small, simple, and easy to use, making it ideal for embedded systems and IoT devices. FreeRTOS provides essential features such as task management, inter-task communication, timing, and memory management.
Pros
- Lightweight and efficient, suitable for resource-constrained devices
- Extensive documentation and community support
- Highly portable, supporting a wide range of microcontroller architectures
- Free to use with both open-source and proprietary licenses available
Cons
- Limited features compared to full-fledged operating systems
- Steep learning curve for developers new to real-time systems
- Requires careful design and implementation to avoid common pitfalls like priority inversion
Code Examples
- Creating and starting a task:
void vTaskFunction(void *pvParameters) {
for (;;) {
// Task code here
}
}
int main(void) {
xTaskCreate(vTaskFunction, "ExampleTask", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
vTaskStartScheduler();
return 0;
}
- Using a semaphore for synchronization:
SemaphoreHandle_t xSemaphore;
void vTask1(void *pvParameters) {
for (;;) {
if (xSemaphoreTake(xSemaphore, portMAX_DELAY) == pdTRUE) {
// Critical section code
xSemaphoreGive(xSemaphore);
}
}
}
int main(void) {
xSemaphore = xSemaphoreCreateMutex();
// Create tasks and start scheduler
}
- Using a queue for inter-task communication:
QueueHandle_t xQueue;
void vSenderTask(void *pvParameters) {
int32_t lValueToSend = 0;
for (;;) {
xQueueSend(xQueue, &lValueToSend, 0);
lValueToSend++;
vTaskDelay(pdMS_TO_TICKS(100));
}
}
void vReceiverTask(void *pvParameters) {
int32_t lReceivedValue;
for (;;) {
if (xQueueReceive(xQueue, &lReceivedValue, portMAX_DELAY) == pdPASS) {
// Process received value
}
}
}
Getting Started
- Download FreeRTOS from the official website or clone the GitHub repository.
- Include FreeRTOS source files in your project.
- Configure FreeRTOSConfig.h for your specific microcontroller and application needs.
- Implement your tasks and initialize the scheduler:
#include "FreeRTOS.h"
#include "task.h"
void vTask1(void *pvParameters) {
for (;;) {
// Task 1 code
}
}
void vTask2(void *pvParameters) {
for (;;) {
// Task 2 code
}
}
int main(void) {
xTaskCreate(vTask1, "Task1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
xTaskCreate(vTask2, "Task2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL);
vTaskStartScheduler();
return 0;
}
- Compile and flash the program to your microcontroller.
Competitor Comparisons
Linux kernel source tree
Pros of Linux
- Supports a wide range of hardware architectures and devices
- Highly scalable, suitable for systems from embedded to supercomputers
- Extensive driver support and hardware compatibility
Cons of Linux
- Larger memory footprint and resource requirements
- More complex and harder to learn for beginners
- Longer boot times compared to real-time operating systems
Code Comparison
Linux kernel (simplified system call):
SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf, size_t, count)
{
struct fd f = fdget_pos(fd);
if (!f.file)
return -EBADF;
return vfs_write(f.file, buf, count, &f.file->f_pos);
}
FreeRTOS task creation:
void vTaskCode(void * pvParameters)
{
for (;;)
{
// Task code here
}
}
xTaskCreate(vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
The Linux kernel code shows a system call implementation, while the FreeRTOS code demonstrates task creation, highlighting the different focus of these operating systems. Linux provides a full-featured kernel with system calls, while FreeRTOS emphasizes real-time task management.
Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
Pros of Zephyr
- More comprehensive and feature-rich, offering a complete OS with extensive device drivers and networking stacks
- Better support for modern development practices, including a robust build system and configuration tools
- Stronger focus on security, with built-in security features and regular security audits
Cons of Zephyr
- Steeper learning curve due to its more complex architecture and extensive feature set
- Larger memory footprint, which may not be suitable for extremely resource-constrained devices
- Less widespread adoption compared to FreeRTOS, potentially leading to a smaller community and fewer resources
Code Comparison
FreeRTOS task creation:
void vTaskFunction(void *pvParameters) {
for (;;) {
// Task code here
}
}
xTaskCreate(vTaskFunction, "TaskName", STACK_SIZE, NULL, TASK_PRIORITY, NULL);
Zephyr thread creation:
void thread_entry(void *p1, void *p2, void *p3) {
while (1) {
// Thread code here
}
}
K_THREAD_DEFINE(thread_id, STACK_SIZE, thread_entry, NULL, NULL, NULL, THREAD_PRIORITY, 0, 0);
Both examples show similar concepts, but Zephyr uses a macro-based approach for thread definition, which can be more convenient in some cases.
Arm Mbed OS is a platform operating system designed for the internet of things
Pros of mbed-os
- Comprehensive hardware abstraction layer (HAL) for ARM Cortex-M devices
- Extensive libraries and middleware support
- Integrated development environment (Mbed Studio) for streamlined development
Cons of mbed-os
- Steeper learning curve due to its complexity
- Larger memory footprint compared to FreeRTOS
- Less suitable for resource-constrained devices
Code Comparison
mbed-os example:
#include "mbed.h"
DigitalOut led(LED1);
int main() {
while (true) {
led = !led;
ThisThread::sleep_for(500ms);
}
}
FreeRTOS example:
#include "FreeRTOS.h"
#include "task.h"
void vLEDTask(void *pvParameters) {
for (;;) {
GPIO_ToggleBits(GPIOD, GPIO_Pin_12);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
The mbed-os code demonstrates its hardware abstraction layer with the DigitalOut
class and ThisThread
namespace, while FreeRTOS uses more low-level GPIO manipulation and task management functions. mbed-os provides a higher level of abstraction, potentially simplifying development for some use cases.
RIOT - The friendly OS for IoT
Pros of RIOT-OS
- More extensive networking support, including IPv6 and 6LoWPAN
- Broader hardware support, including microcontrollers and IoT devices
- Active community-driven development with frequent updates
Cons of RIOT-OS
- Steeper learning curve due to more complex architecture
- Larger memory footprint, which may be an issue for resource-constrained devices
- Less widespread adoption in commercial applications compared to FreeRTOS
Code Comparison
RIOT-OS example (main.c):
#include "thread.h"
int main(void)
{
thread_create(stack, sizeof(stack), THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST, thread_handler, NULL, "thread");
return 0;
}
FreeRTOS example (main.c):
#include "FreeRTOS.h"
#include "task.h"
int main(void)
{
xTaskCreate(vTaskFunction, "Task1", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
vTaskStartScheduler();
return 0;
}
Both examples demonstrate the creation of a thread/task, but RIOT-OS uses a different API and naming convention compared to FreeRTOS. RIOT-OS's approach may be more intuitive for developers familiar with POSIX threads, while FreeRTOS follows its own conventions.
RT-Thread is an open source IoT Real-Time Operating System (RTOS). https://rt-thread.github.io/rt-thread/
Pros of RT-Thread
- More comprehensive IoT ecosystem with built-in components and packages
- Better support for Chinese developers and documentation
- Smaller memory footprint for resource-constrained devices
Cons of RT-Thread
- Less widespread adoption and community support outside of China
- Fewer third-party tools and integrations compared to FreeRTOS
- Limited English documentation and resources
Code Comparison
RT-Thread initialization:
#include <rtthread.h>
int main(void)
{
/* Initialize RT-Thread kernel */
rt_kprintf("Hello, RT-Thread!\n");
return 0;
}
FreeRTOS initialization:
#include "FreeRTOS.h"
#include "task.h"
int main(void)
{
/* Create tasks and start the scheduler */
vTaskStartScheduler();
return 0;
}
Both RT-Thread and FreeRTOS are real-time operating systems for embedded devices, but they have different strengths and target audiences. RT-Thread offers a more comprehensive IoT ecosystem and better support for Chinese developers, while FreeRTOS has wider global adoption and more third-party integrations. The code comparison shows that RT-Thread has a simpler initialization process, while FreeRTOS requires explicit task creation and scheduler start.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
The FreeRTOS 202411.00 release updates FreeRTOS Kernel, FreeRTOS+TCP, coreMQTT, corePKCS11, coreHTTP, coreJSON, AWS IoT Over-the-air-Updates (OTA), AWS IoT Device Shadow, AWS IoT Jobs, AWS IoT Device Defender, Backoff Algorithm, AWS IoT Fleet Provisioning, coreSNTP, SigV4, and FreeRTOS Cellular Interface libraries to their 202406-LTS versions. It also updates coreMQTT Agent to v1.3.0 and MbedTLS to v3.5.1. This release also adds ARMv7-R No_GIC Port Demo, ARMv7-R MPU Port Demos and FreeRTOS_Plus_TCP_IPv6_Demo Windows Simulator Demo. Additionally, all WinSim Demos are updated to use TLSv1.3. This release also updates WolfSSL to version v5.6.4.
The FreeRTOS 202212.00 release updates FreeRTOS Kernel, FreeRTOS+TCP, coreMQTT, corePKCS11, coreHTTP, coreJSON, AWS IoT Over-the-air-Updates (OTA), AWS IoT Device Shadow, AWS IoT Jobs, AWS IoT Device Defender, Backoff Algorithm, AWS IoT Fleet Provisioning, coreSNTP, SigV4, and FreeRTOS Cellular Interface libraries to their LTS 2.0 versions. It also updates coreMQTT Agent to v1.2.0 to be compatible with coreMQTT v2.X.X, and updates MbedTLS to v3.2.1. This release also adds Visual Studio static library projects for the FreeRTOS Kernel, FreeRTOS+TCP, Logging, MbedTLS, coreHTTP, and corePKCS11. With the addition of the static library projects, all Visual Studio projects have been updated to use them. Additionally, all demos dependent on coreMQTT have been updated to work with coreMQTT v2.X.X.
Getting started
The FreeRTOS.org website contains a FreeRTOS Kernel Quick Start Guide, a list of supported devices and compilers, the API reference, and many other resources.
Getting help
You can use your Github login to get support from both the FreeRTOS community and directly from the primary FreeRTOS developers on our active support forum. The FAQ provides another support resource.
Cloning this repository
This repo uses Git Submodules to bring in dependent components.
Note: If you download the ZIP file provided by the GitHub UI, you will not get the contents of the submodules. (The ZIP file is also not a valid git repository)
If using Windows, because this repository and its submodules contain symbolic links, set core.symlinks
to true with the following command:
git config --global core.symlinks true
In addition to this, either enable Developer Mode or, whenever using a git command that writes to the system (e.g. git pull
, git clone
, and git submodule update --init --recursive
), use a console elevated as administrator so that git can properly create symbolic links for this repository. Otherwise, symbolic links will be written as normal files with the symbolic links' paths in them as text. This gives more explanation.
To clone using HTTPS:
git clone https://github.com/FreeRTOS/FreeRTOS.git --recurse-submodules
Using SSH:
git clone git@github.com:FreeRTOS/FreeRTOS.git --recurse-submodules
If you have downloaded the repo without using the --recurse-submodules
argument, you need to run:
git submodule update --init --recursive
Repository structure
This repository contains the FreeRTOS Kernel, a number of supplementary libraries including the LTS ones, and a comprehensive set of example projects. Many libraries (including the FreeRTOS kernel) are included as Git submodules from their own Git repositories.
Kernel source code and example projects
FreeRTOS/Source
contains the FreeRTOS kernel source code (submoduled from https://github.com/FreeRTOS/FreeRTOS-Kernel).
FreeRTOS/Demo
contains pre-configured example projects that demonstrate the FreeRTOS kernel executing on different hardware platforms and using different compilers.
Supplementary library source code and example projects
FreeRTOS-Plus/Source
contains source code for additional FreeRTOS component libraries, as well as select partner provided libraries. These subdirectories contain further readme files and links to documentation.
FreeRTOS-Plus/Demo
contains pre-configured example projects that demonstrate the FreeRTOS kernel used with the additional FreeRTOS component libraries.
Previous releases
Releases contains older FreeRTOS releases.
FreeRTOS Lab Projects
FreeRTOS Lab projects are libraries and demos that are fully functional, but may be experimental or undergoing optimizations and refactorization to improve memory usage, modularity, documentation, demo usability, or test coverage.
Most FreeRTOS Lab libraries can be found in the FreeRTOS-Labs repository.
A number of FreeRTOS Lab Demos can be found in the FreeRTOS Github Organization by searching for "Lab" or following this link to the search results.
coreMQTT Agent Demos
The FreeRTOS/coreMQTT-Agent-Demos repository contains demos to showcase use of the coreMQTT-Agent library to share an MQTT connection between multiple application tasks.
The demos show a single MQTT connection usage between multiple application tasks for interacting with AWS services (including Over-the-air-Updates, Device Shadow, Device Defender) alongside performing simple Publish-Subscribe operations.
CBMC
The FreeRTOS/Test/CBMC/proofs
directory contains CBMC proofs.
To learn more about CBMC and proofs specifically, review the training material here.
In order to run these proofs you will need to install CBMC and other tools by following the instructions here.
Top Related Projects
Linux kernel source tree
Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
Arm Mbed OS is a platform operating system designed for the internet of things
RIOT - The friendly OS for IoT
RT-Thread is an open source IoT Real-Time Operating System (RTOS). https://rt-thread.github.io/rt-thread/
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot