Convert Figma logo to code with AI

RT-Thread logort-thread

RT-Thread is an open source IoT Real-Time Operating System (RTOS).

10,277
4,963
10,277
314

Top Related Projects

'Classic' FreeRTOS distribution. Started as Git clone of FreeRTOS SourceForge SVN repo. Submodules the kernel.

10,446

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.

4,656

Arm Mbed OS is a platform operating system designed for the internet of things

13,291

Espressif IoT Development Framework. Official development framework for Espressif SoCs.

4,872

RIOT - The friendly OS for IoT

Quick Overview

RT-Thread is an open-source, real-time operating system (RTOS) for embedded devices. It provides a rich set of components and a user-friendly development environment, making it suitable for various IoT and embedded applications. RT-Thread supports multiple architectures and has a strong community backing its development.

Pros

  • Highly scalable and modular architecture
  • Extensive component library for rapid development
  • Strong community support and regular updates
  • Compatible with various development tools and IDEs

Cons

  • Learning curve for developers new to RTOS concepts
  • Limited documentation in English compared to Chinese
  • Some advanced features may require commercial licensing

Code Examples

  1. Creating and starting a thread:
#include <rtthread.h>

void thread_entry(void *parameter)
{
    while (1)
    {
        rt_kprintf("Hello, RT-Thread!\n");
        rt_thread_mdelay(1000);
    }
}

int main(void)
{
    rt_thread_t tid = rt_thread_create("test_thread",
                                       thread_entry, RT_NULL,
                                       1024, 25, 10);
    if (tid != RT_NULL)
        rt_thread_startup(tid);
    return 0;
}
  1. Using a semaphore for synchronization:
#include <rtthread.h>

static rt_sem_t sem;

void thread_entry(void *parameter)
{
    rt_sem_take(sem, RT_WAITING_FOREVER);
    rt_kprintf("Semaphore acquired\n");
    rt_sem_release(sem);
}

int main(void)
{
    sem = rt_sem_create("test_sem", 1, RT_IPC_FLAG_FIFO);
    rt_thread_t tid = rt_thread_create("test_thread",
                                       thread_entry, RT_NULL,
                                       1024, 25, 10);
    if (tid != RT_NULL)
        rt_thread_startup(tid);
    return 0;
}
  1. Using a message queue for inter-thread communication:
#include <rtthread.h>

static rt_mq_t mq;

void sender_thread(void *parameter)
{
    int msg = 42;
    rt_mq_send(mq, &msg, sizeof(int));
}

void receiver_thread(void *parameter)
{
    int msg;
    rt_mq_recv(mq, &msg, sizeof(int), RT_WAITING_FOREVER);
    rt_kprintf("Received message: %d\n", msg);
}

int main(void)
{
    mq = rt_mq_create("test_mq", sizeof(int), 10, RT_IPC_FLAG_FIFO);
    rt_thread_t tid1 = rt_thread_create("sender", sender_thread, RT_NULL, 1024, 25, 10);
    rt_thread_t tid2 = rt_thread_create("receiver", receiver_thread, RT_NULL, 1024, 25, 10);
    if (tid1 != RT_NULL && tid2 != RT_NULL)
    {
        rt_thread_startup(tid1);
        rt_thread_startup(tid2);
    }
    return 0;
}

Getting Started

  1. Download and install RT-Thread Studio from the official website.
  2. Create a new project in RT-Thread Studio, selecting your target board.
  3. Configure the project settings and select the required components.
  4. Write your application code using RT-Thread APIs.
  5. Build and flash the project to your target board.
  6. Debug and test your application using RT-Thread Studio's tools.

For more detailed instructions, refer to the RT-Thread documentation and tutorials available on the official website.

Competitor Comparisons

'Classic' FreeRTOS distribution. Started as Git clone of FreeRTOS SourceForge SVN repo. Submodules the kernel.

Pros of FreeRTOS

  • Wider industry adoption and support
  • More extensive documentation and learning resources
  • Broader range of supported architectures and platforms

Cons of FreeRTOS

  • Steeper learning curve for beginners
  • Less modular architecture compared to RT-Thread
  • Fewer built-in components and middleware options

Code Comparison

RT-Thread example:

#include <rtthread.h>

static void thread_entry(void *parameter)
{
    while (1) {
        rt_kprintf("Hello, RT-Thread!\n");
        rt_thread_mdelay(1000);
    }
}

int main(void)
{
    rt_thread_t tid = rt_thread_create("test", thread_entry, RT_NULL, 512, 8, 10);
    if (tid != RT_NULL) rt_thread_startup(tid);
    return 0;
}

FreeRTOS example:

#include "FreeRTOS.h"
#include "task.h"

void vTaskFunction(void *pvParameters)
{
    for (;;) {
        printf("Hello, FreeRTOS!\n");
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}

int main(void)
{
    xTaskCreate(vTaskFunction, "TestTask", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}

Both examples demonstrate creating and starting a simple task that prints a message every second. The syntax and function names differ, but the overall structure is similar.

10,446

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.

Pros of Zephyr

  • More extensive hardware support and device drivers
  • Stronger focus on security features and certifications
  • Larger and more active community, with backing from major tech companies

Cons of Zephyr

  • Steeper learning curve due to its complexity and feature-rich nature
  • Higher memory footprint, which may be a concern for resource-constrained devices

Code Comparison

RT-Thread example (creating a thread):

static void thread_entry(void *parameter)
{
    while (1)
    {
        rt_thread_mdelay(1000);
        rt_kprintf("Hello, RT-Thread!\n");
    }
}

int main(void)
{
    rt_thread_t tid = rt_thread_create("test_thread", thread_entry, RT_NULL, 1024, 10, 10);
    rt_thread_startup(tid);
    return 0;
}

Zephyr example (creating a thread):

void thread_entry(void *p1, void *p2, void *p3)
{
    while (1) {
        k_msleep(1000);
        printk("Hello, Zephyr!\n");
    }
}

int main(void)
{
    k_thread_create(&my_thread, stack_area, K_THREAD_STACK_SIZEOF(stack_area),
                    thread_entry, NULL, NULL, NULL, 0, 0, K_NO_WAIT);
    return 0;
}

Both examples demonstrate creating and starting a thread, but Zephyr's API is slightly more complex with additional parameters for thread creation.

4,656

Arm Mbed OS is a platform operating system designed for the internet of things

Pros of mbed-os

  • Extensive hardware support for a wide range of ARM-based microcontrollers
  • Comprehensive documentation and strong community support
  • Integrated development environment (Mbed Studio) for easier development

Cons of mbed-os

  • Larger memory footprint compared to RT-Thread
  • Steeper learning curve for beginners
  • Less flexible for customization in resource-constrained systems

Code Comparison

RT-Thread example (creating a thread):

static void thread_entry(void *parameter)
{
    while (1)
    {
        rt_thread_mdelay(1000);
        rt_kprintf("Hello, RT-Thread!\n");
    }
}

int main(void)
{
    rt_thread_t tid = rt_thread_create("test_thread", thread_entry, RT_NULL, 1024, 25, 10);
    rt_thread_startup(tid);
    return 0;
}

mbed-os example (creating a thread):

#include "mbed.h"

void thread_function(void const *args) {
    while (true) {
        ThisThread::sleep_for(1000ms);
        printf("Hello, Mbed OS!\n");
    }
}

int main() {
    Thread thread;
    thread.start(callback(thread_function));
    return 0;
}

Both RT-Thread and mbed-os are real-time operating systems for embedded devices, but they have different strengths. RT-Thread is more lightweight and flexible, while mbed-os offers broader hardware support and a more comprehensive ecosystem. The choice between them depends on project requirements and hardware constraints.

13,291

Espressif IoT Development Framework. Official development framework for Espressif SoCs.

Pros of esp-idf

  • Extensive support for Espressif's ESP32 family of microcontrollers
  • Robust Wi-Fi and Bluetooth stack implementations
  • Comprehensive documentation and examples for various use cases

Cons of esp-idf

  • Limited to Espressif's hardware platforms
  • Steeper learning curve for beginners compared to RT-Thread
  • Less flexible for porting to other architectures

Code Comparison

RT-Thread example (RTOS task creation):

#include <rtthread.h>

static void example_thread(void *param)
{
    while (1) {
        rt_kprintf("Hello, RT-Thread!\n");
        rt_thread_mdelay(1000);
    }
}

int main(void)
{
    rt_thread_t thread = rt_thread_create("example", example_thread, RT_NULL, 512, 10, 10);
    rt_thread_startup(thread);
    return 0;
}

esp-idf example (FreeRTOS task creation):

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

void example_task(void *pvParameters)
{
    while (1) {
        printf("Hello, ESP-IDF!\n");
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

void app_main()
{
    xTaskCreate(example_task, "example_task", 2048, NULL, 5, NULL);
}

Both examples demonstrate task creation and basic RTOS functionality, but esp-idf uses FreeRTOS APIs while RT-Thread uses its own RTOS APIs.

4,872

RIOT - The friendly OS for IoT

Pros of RIOT

  • More extensive hardware support, covering a wider range of microcontrollers and platforms
  • Larger and more active community, resulting in frequent updates and contributions
  • Better documentation and more comprehensive examples for developers

Cons of RIOT

  • Steeper learning curve due to its more complex architecture
  • Higher memory footprint, which may be a concern for resource-constrained devices
  • Less focus on real-time performance compared to RT-Thread

Code Comparison

RIOT example (main.c):

#include "thread.h"

void *thread_handler(void *arg)
{
    (void) arg;
    while (1) {
        /* Thread code here */
    }
    return NULL;
}

int main(void)
{
    thread_create(stack, sizeof(stack), THREAD_PRIORITY_MAIN - 1,
                  THREAD_CREATE_STACKTEST, thread_handler, NULL, "thread");
    return 0;
}

RT-Thread example (main.c):

#include <rtthread.h>

static void thread_entry(void *parameter)
{
    while (1) {
        /* Thread code here */
    }
}

int main(void)
{
    rt_thread_t tid = rt_thread_create("thread", thread_entry, RT_NULL,
                                       1024, 25, 5);
    if (tid != RT_NULL) rt_thread_startup(tid);
    return 0;
}

Both examples demonstrate thread creation, but RIOT uses a more POSIX-like approach, while RT-Thread has a simpler API for thread management.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

English | 中文 | Español | Deutsch

GitHubStars GiteeStars GitHub GitHub release Gitter GitHub pull-requests PRs Welcome RT-Thread BSP Static Build Check

RT-Thread

RT-Thread was born in 2006, it is an open source, neutral, and community-based real-time operating system (RTOS).

RT-Thread is mainly written in C language, easy to understand and easy to port(can be quickly port to a wide range of mainstream MCUs and module chips). It applies object-oriented programming methods to real-time system design, making the code elegant, structured, modular, and very tailorable.

RT-Thread has Standard version and Nano version. For resource-constrained microcontroller (MCU) systems, the Nano version that requires only 3KB Flash and 1.2KB RAM memory resources can be tailored with easy-to-use tools. For resource-rich IoT devices, RT-Thread can use the on-line software package management tool, together with system configuration tools, to achieve intuitive and rapid modular cutting, seamlessly import rich software packages; thus, achieving complex functions like Android's graphical interface and touch sliding effects, smart voice interaction effects, and so on.

RT-Thread Architecture

RT-Thread has not only a real-time kernel, but also rich components. Its architecture is as follows:

architecture

It includes:

  • Kernel layer: RT-Thread kernel, the core part of RT-Thread, includes the implementation of objects in the kernel system, such as multi-threading and its scheduling, semaphore, mailbox, message queue, memory management, timer, etc.; libcpu/BSP (Chip Migration Related Files/Board Support Package) is closely related to hardware and consists of peripheral drivers and CPU porting.

  • Components and Service Layer: Components are based on upper-level software on top of the RT-Thread kernel, such as virtual file systems, FinSH command-line interfaces, network frameworks, device frameworks, and more. Its modular design allows for high internal cohesion inside the components and low coupling between components.

  • RT-Thread software package: A general-purpose software component running on the RT-Thread IoT operating system platform for different application areas, consisting of description information, source code or library files. RT-Thread provides an open package platform with officially available or developer-supplied packages that provide developers with a choice of reusable packages that are an important part of the RT-Thread ecosystem. The package ecosystem is critical to the choice of an operating system because these packages are highly reusable and modular, making it easy for application developers to build the system they want in the shortest amount of time. RT-Thread supports 450+ software packages.

RT-Thread Features

  • Designed for resource-constrained devices, the minimum kernel requires only 1.2KB of RAM and 3 KB of Flash.
  • A variety of standard interfaces, such as POSIX, CMSIS, C++ application environment.
  • Has rich components and a prosperous and fast growing package ecosystem.
  • Elegant code style, easy to use, read and master.
  • High Scalability. RT-Thread has high-quality scalable software architecture, loose coupling, modularity, is easy to tailor and expand.
  • Supports high-performance applications.
  • Supports all mainstream compiling tools such as GCC, Keil and IAR.
  • Supports a wide range of architectures and chips.

Code Catalogue

RT-Thread source code catalog is shown as follow:

NameDescription
bspBoard Support Package based on the porting of various development boards
componentsComponents, such as finsh shell, file system, protocol stack etc.
documentationRelated documents, like coding style, doxygen etc.
examplesRelated sample code
includeHead files of RT-Thread kernel
libcpuCPU porting code such as ARM/MIPS/RISC-V etc.
srcThe source files for the RT-Thread kernel.
toolsThe script files for the RT-Thread command build tool.

RT-Thread has now been ported for nearly 200 development boards, most BSPs support MDK, IAR development environment and GCC compiler, and have provided default MDK and IAR project, which allows users to add their own application code directly based on the project. Each BSP has a similar directory structure, and most BSPs provide a README.md file, which is a markdown-format file that contains the basic introduction of BSP, and introduces how to simply start using BSP.

Resources

Supported Architectures

RT-Thread supports many architectures, and has covered the major architectures in current applications. Architecture and chip manufacturer involved:

  • **ARM Cortex-M0/M0+**:manufacturers like ST
  • ARM Cortex-M3:manufacturers like ST、Winner Micro、MindMotion, ect.
  • ARM Cortex-M4:manufacturers like ST、Infineon、Nuvoton、NXP、Nordic、GigaDevice、Realtek、Ambiq Micro, ect.
  • ARM Cortex-M7:manufacturers like ST、NXP
  • ARM Cortex-M23:manufacturers like GigaDevice
  • ARM Cortex-M33:manufacturers like ST
  • ARM Cortex-R4
  • ARM Cortex-A8/A9:manufacturers like NXP
  • ARM7:manufacturers like Samsung
  • ARM9:manufacturers like Allwinner、Xilinx 、GOKE
  • ARM11:manufacturers like Fullhan
  • MIPS32:manufacturers like loongson、Ingenic
  • **RISC-V RV32E/RV32I[F]/RV64[D]**:manufacturers like sifive、Canaan Kendryte、bouffalo_lab、Nuclei、T-Head、HPMicro
  • ARC:manufacturers like SYNOPSYS
  • DSP:manufacturers like TI
  • C-Sky
  • x86

Supported IDE and Compiler

The main IDE/compilers supported by RT-Thread are:

  • RT-Thread Studio IDE
  • MDK KEIL
  • IAR
  • GCC

RT-Thread Studio IDE

User Manual | Tutorial Videos

RT-Thread Studio IDE (a.k.a. RT-Studio) is a one-stop intergrated development environment built by RT-Thread team. It has a easy-to-use graphical configuration system and a wealth of software packages and components resources. RT-Studio has the features of project creation, configuration and management,as well as code editing, SDK management, build configuration, debugging configuration, program download and debug. We're looking to make the use of RT-Studio as intuitive as possible, reducing the duplication of work and improving the development efficiency.

studio

Env Tool

User Manual | Tutorial Videos

In the early stage, RT-Thread team also created an auxiliary tool called Env. It is an auxiliary tool with a TUI (Text-based user interface). Developers can use Env tool to configure and generate the GCC, Keil MDK, and IAR projects.

env

Getting Started

RT-Thread Programming Guide | RT-Thread Studio IDE | Kernel Sample | RT-Thread Beginners Guide

Based on STM32F103 BluePill | Raspberry Pi Pico

Simulator

RT-Thread BSP can be compiled directly and downloaded to the corresponding development board for use. In addition, RT-Thread also provides qemu-vexpress-a9 BSP, which can be used without hardware platform. See the getting started guide below for details. Getting Started of QEMU with Env: Windows | Linux Ubuntu | Mac OS

License

RT-Thread follows the Apache License 2.0 free software license. It's completely open-source, can be used in commercial applications for free, does not require the disclosure of code, and has no potential commercial risk. License information and copyright information can generally be seen at the beginning of the code:

/* Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 * ...
 */

Community

RT-Thread is very grateful for the support from all community developers, and if you have any ideas, suggestions or questions in the process of using RT-Thread, RT-Thread can be reached by the following means, and we are also updating RT-Thread in real time on these channels. At the same time, any questions can be asked in the issue section of RT-Thread repository or RT-Thread forum, and community members will answer them.

Website | Github | Twitter | LinkedIn | Youtube | Facebook | Medium

Contribution

If you are interested in RT-Thread and want to join in the development of RT-Thread and become a code contributor,please refer to the Code Contribution Guide.

Thanks for the following contributors!