# FreeRTOS

**FreeRTOS** 是一组 C 语言库的集合，包含一个实时内核以及一套面向微控制器和小型微处理器的模块化库。它由理查德·巴里（Richard Barry）于 2003 年前后首次开发，自 2017 年起由[亚马逊云科技](https://www.edgepedia.org/zh/amazon-web-services)（AWS）托管维护。<sup>[1](https://github.com/FreeRTOS/FreeRTOS-Kernel-Book/blob/main/ch01.md/)</sup> 该内核将应用程序组织为独立的执行线程（任务），并按优先级进行调度，使应用程序能够满足硬实时截止时间的要求。它以 MIT 许可证发布为开源软件，可用于任何目的，包括商业产品，且不要求用户是 AWS 客户。<sup>[1](https://github.com/FreeRTOS/FreeRTOS-Kernel-Book/blob/main/ch01.md/)</sup><sup> • </sup><sup>[2](https://github.com/FreeRTOS/FreeRTOS/blob/main/FreeRTOS/License/license.txt)</sup> 它支持 40 多种处理器架构，并包含对称多处理（SMP）、支持 IPv6 的线程安全 TCP 协议栈以及云连接库等特性。<sup>[3](https://en.freertos.org/)</sup>

| 关键事实 | 详情 |
|---|---|
| 起源 | 约 2003 年由理查德·巴里创建；由其公司 Real-Time Engineers Ltd 开发，直至 2016/2017 年 AWS 接管维护<sup>[1](https://github.com/FreeRTOS/FreeRTOS-Kernel-Book/blob/main/ch01.md/)</sup><sup> • </sup><sup>[4](https://aws.amazon.com/blogs/opensource/announcing-freertos-kernel-v10/)</sup> |
| 许可证 | 自内核版本 10（2017 年 11 月）起采用 MIT 开源许可证，取代此前的修改版 GPLv2 许可证；版权所有 (C) 2020 Amazon.com, Inc. 或其关联公司<sup>[4](https://aws.amazon.com/blogs/opensource/announcing-freertos-kernel-v10/)</sup><sup> • </sup><sup>[2](https://github.com/FreeRTOS/FreeRTOS/blob/main/FreeRTOS/License/license.txt)</sup> |
| 默认调度 | 固定优先级抢占式策略，同优先级任务采用轮转时间片；抢占和时间片均可在 FreeRTOSConfig.h 中禁用<sup>[5](https://2fwww.freertos.org/Documentation/02-Kernel/02-Kernel-features/01-Tasks-and-co-routines/04-Task-scheduling)</sup> |
| 内核核心 | 每个移植版本共有的三个文件：list.c、queue.c 和 tasks.c；croutine.c 实现可选的、已弃用的协程功能<sup>[6](https://github.com/FreeRTOS/FreeRTOS-Kernel)</sup> |
| 内存选项 | 五种示例堆实现（heap_1 至 heap_5）；自 V9.0.0 起，任务、队列、信号量、互斥量、事件组和定时器也可静态创建<sup>[7](https://2fwww.freertos.org/Documentation/02-Kernel/02-Kernel-features/09-Memory-management/01-Memory-management)</sup><sup> • </sup><sup>[8](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/09-Memory-management/03-Static-vs-Dynamic-memory-allocation)</sup> |
| 多处理 | SMP 支持允许一个内核实例在共享内存的多个相同核心上调度任务；在 AMP 配置中，每个核心运行各自的内核实例<sup>[9](https://sbop.freertos.org/Documentation/02-Kernel/02-Kernel-features/13-Symmetric-multiprocessing-introduction)</sup><sup> • </sup><sup>[5](https://2fwww.freertos.org/Documentation/02-Kernel/02-Kernel-features/01-Tasks-and-co-routines/04-Task-scheduling)</sup> |
| 当前版本 | FreeRTOS-Kernel V11.1.0 属于 FreeRTOS 202406.00 长期支持（LTS）版本的一部分<sup>[6](https://github.com/FreeRTOS/FreeRTOS-Kernel)</sup> |

## 历史与维护

理查德·巴里于 2003 年创建了 FreeRTOS，并通过其公司 Real-Time Engineers Ltd 与芯片厂商合作进行维护。在资源有限的情况下维护该项目 15 年后，巴里加入了亚马逊，2017 年 11 月 AWS 以 MIT 许可证发布了 FreeRTOS 内核版本 10 的核心代码，取代了此前修改版的 GPLv2 许可证。巴里指出，每 260 秒一次的下载频率正是这个小组织无法满足支持和功能需求的原因之一。<sup>[4](https://aws.amazon.com/blogs/opensource/announcing-freertos-kernel-v10/)</sup> 内核手册记载 AWS 于 2016 年接管维护，而巴里作为 AWS IoT 团队的高级首席工程师继续从事 FreeRTOS 的工作。<sup>[1](https://github.com/FreeRTOS/FreeRTOS-Kernel-Book/blob/main/ch01.md/)</sup>

选择 MIT 许可证是有意为之：该许可证在开源硬件项目中很常见，通常被列入企业使用的白名单，它允许 FreeRTOS 用于商业应用而无需公开专有源代码。<sup>[4](https://aws.amazon.com/blogs/opensource/announcing-freertos-kernel-v10/)</sup><sup> • </sup><sup>[1](https://github.com/FreeRTOS/FreeRTOS-Kernel-Book/blob/main/ch01.md/)</sup> 许可证文本涵盖 /FreeRTOS/Source 中的内核源文件以及大多数演示应用程序文件；演示项目还可能包含第三方软件，如厂商头文件、链接脚本和外设驱动，这些软件另行授权。<sup>[2](https://github.com/FreeRTOS/FreeRTOS/blob/main/FreeRTOS/License/license.txt)</sup>

**Amazon FreeRTOS。** Amazon FreeRTOS 于 2017 年 11 月 29 日发布，在内核基础上扩展了安全、本地和云连接以及空中下载（OTA）更新等库，面向连接 AWS IoT Core 或 AWS Greengrass 网关的基于微控制器的边缘设备。<sup>[10](https://aws.amazon.com/blogs/aws/announcing-amazon-freertos/)</sup> AWS IoT OTA 更新库管理通过 MQTT 或 HTTP 进行的固件更新通知、下载和加密验证（自 201912.00 版本起支持 HTTP 数据传输），OTA 代理可与应用程序共享网络连接以节省 RAM。<sup>[11](https://docs.aws.amazon.com/freertos/latest/userguide/ota-update-library.html)</sup><sup> • </sup><sup>[12](https://docs.aws.amazon.com/freertos/latest/userguide/ota-prereqs.html)</sup> 2020 年 12 月，AWS 推出了 FreeRTOS 长期支持版本，将内核与 FreeRTOS+TCP、coreMQTT、coreHTTP、corePKCS11、coreJSON 和 AWS IoT Device Shadow 等 IoT 库捆绑在一起；诸如 FreeRTOS 202012.02 LTS 这样的命名表示 2020 年 12 月 LTS 版本的第二个补丁。<sup>[13](https://aws.amazon.com.cdn.amazon.com/blogs/aws/new-freertos-long-term-support-to-provide-years-of-feature-stability/)</sup><sup> • </sup><sup>[14](https://aws.amazon.com/freertos/faqs/)</sup>

## 调度与任务

默认情况下，FreeRTOS 采用固定优先级抢占式调度策略，同优先级任务采用轮转时间片。“固定优先级”意味着调度器不会永久改变任务的优先级，但可以通过优先级继承临时提升它；“抢占式”意味着能够运行的最高优先级任务始终运行，即使在时间片中途也是如此；“时间片”意味着同优先级任务在每个节拍中断时轮流进入运行态。<sup>[5](https://2fwww.freertos.org/Documentation/02-Kernel/02-Kernel-features/01-Tasks-and-co-routines/04-Task-scheduling)</sup> 将 configUSE_PREEMPTION 设为 0 可选择协作式调度器，将 configUSE_TIME_SLICING 设为 0 可禁用每个节拍时同优先级任务之间的切换，从而减少调度器开销。<sup>[5](https://2fwww.freertos.org/Documentation/02-Kernel/02-Kernel-features/01-Tasks-and-co-routines/04-Task-scheduling)</sup><sup> • </sup><sup>[15](https://www.freertos.org/media/2018/161204_Mastering_the_FreeRTOS_Real_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf)</sup>

始终运行最高优先级就绪任务的一个后果是饥饿：一个从不阻塞或挂起的高优先级任务会永久性地饿死所有低优先级任务。推荐的设计是采用事件驱动型任务，在等待时进入阻塞态，将处理器让给低优先级工作。<sup>[5](https://2fwww.freertos.org/Documentation/02-Kernel/02-Kernel-features/01-Tasks-and-co-routines/04-Task-scheduling)</sup> 某些移植版本还提供移植特定的任务选择方法（通过 configUSE_PORT_OPTIMISED_TASK_SELECTION 启用），使用前导零计数等架构指令，比通用 C 方法更快，但通常将最大优先级数量限制为 32 个。<sup>[16](https://www.freertos.org/media/2018/FreeRTOS_Reference_Manual_V10.0.0.pdf)</sup>

**多处理。** 在非对称多处理（AMP）配置中，多核设备的每个核心运行各自独立的 FreeRTOS 实例，核心之间无需共享架构，仅在实例通信时需要共享部分内存。在 SMP 配置中，一个内核实例在共享内存的多个相同核心上调度任务。SMP API 与单核 API 基本相同，但单核假设不再成立：低优先级任务可能在一个核心上运行，而高优先级任务在另一个核心上运行，因此依赖优先级实现互斥的应用程序必须使用同步原语、核心亲和性（vTaskCoreAffinitySet）或将 configRUN_MULTIPLE_PRIORITIES 设为 0。<sup>[5](https://2fwww.freertos.org/Documentation/02-Kernel/02-Kernel-features/01-Tasks-and-co-routines/04-Task-scheduling)</sup><sup> • </sup><sup>[9](https://sbop.freertos.org/Documentation/02-Kernel/02-Kernel-features/13-Symmetric-multiprocessing-introduction)</sup>

## 任务间通信与内存

队列是任务间通信的主要形式，用作线程安全的 FIFO 缓冲区，在任务之间以及中断与任务之间传递消息；读取空队列的任务进入阻塞态，在数据到达或其阻塞时间到期之前不消耗 CPU 时间。队列按值复制传递数据，但指针队列可以按引用传递数据，单个队列可以通过带类型成员的结构体承载不同的消息类型。<sup>[17](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/02-Queues-mutexes-and-semaphores/01-Queues)</sup> 内核版本 10 增加了流缓冲区和消息缓冲区，这是针对单读者/单写者场景优化的通信原语，例如从中断向任务传递数据或在微控制器核心之间传递数据。<sup>[4](https://aws.amazon.com/blogs/opensource/announcing-freertos-kernel-v10/)</sup>

互斥量是包含优先级继承机制的二进制信号量：如果高优先级任务因低优先级任务持有的互斥量而阻塞，持有者的优先级会被临时提升，以尽量减少优先级反转。FreeRTOS 实现了一种旨在优化空间和执行周期的基本继承形式，文档指出它是最小化而非治愈优先级反转。二进制信号量不具备继承机制，是用于同步的更好选择，而互斥量适用于互斥，且不得在中断中使用。<sup>[18](https://freertos.org/Real-time-embedded-RTOS-mutexes.html)</sup> 每个任务还携带一个直接任务通知数组，每个通知包含一个状态和一个 32 位值，可作为事件组、信号量和邮箱的轻量级替代方案。<sup>[19](https://www.freertos.org/Documentation/02-Kernel/04-API-references/05-Direct-to-task-notifications/04-xTaskNotify)</sup>

**内存管理。** 每次创建任务、队列、互斥量、信号量、软件定时器或事件组时，内核都需要 RAM。下载包在 Source/Portable/MemMang 中包含五种示例堆实现：heap_1 不允许释放，heap_2 可释放但不合并相邻空闲块（现被视为遗留方案），heap_3 封装标准 malloc() 和 free() 以实现线程安全，heap_4 合并空闲块以避免碎片化，heap_5 将 heap_4 扩展至多个非相邻内存区域。项目中一次只能包含其中一个文件。<sup>[7](https://2fwww.freertos.org/Documentation/02-Kernel/02-Kernel-features/09-Memory-management/01-Memory-management)</sup> 标准 C 库函数在嵌入式系统上往往不适用，因为它们可能不可用、占用代码空间、非线程安全且执行时间不确定。<sup>[7](https://2fwww.freertos.org/Documentation/02-Kernel/02-Kernel-features/09-Memory-management/01-Memory-management)</sup> 自 V9.0.0 起，所列 RTOS 对象也可以使用应用程序编写者提供的内存静态创建，两种方法可在同一应用中共存。<sup>[8](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/09-Memory-management/03-Static-vs-Dynamic-memory-allocation)</sup>

## 软件定时器

软件定时器在其周期到期时执行回调函数，使用前必须显式创建。回调在定时器服务（守护）任务的上下文中运行，因此绝不能阻塞：不得调用 vTaskDelay() 或 vTaskDelayUntil()，也不得在访问队列或信号量时指定非零阻塞时间。该实现避免在中断上下文中执行回调，除非有定时器到期否则不消耗处理时间，不给节拍中断增加开销，也不在禁用中断的情况下遍历链表结构。<sup>[20](https://wina.freertos.org/Documentation/02-Kernel/02-Kernel-features/05-Software-timers/01-Software-timers)</sup>

## 生态系统与变体

内核仓库包含每个移植版本共有的三个文件（list.c、queue.c、tasks.c）、一个包含微控制器和编译器特定文件的可移植目录以及头文件；FreeRTOS-Kernel V11.1.0 随 202406.00 LTS 版本发布。<sup>[6](https://github.com/FreeRTOS/FreeRTOS-Kernel)</sup> 除内核外，FreeRTOS 库还提供网络和安全功能，包括 FreeRTOS+TCP 线程安全 TCP/IP 协议栈、用于与 AWS IoT 发布/订阅消息传递的 coreMQTT、用于 TLS 客户端认证的 corePKCS11，以及用于移植符合 POSIX 标准的应用程序的 FreeRTOS+POSIX。<sup>[21](https://docs.aws.amazon.com/freertos/latest/userguide/dev-guide-freertos-libraries.html)</sup>

厂商为其硬件提供修改过的内核。乐鑫的 [ESP-IDF](https://www.edgepedia.org/zh/espressif-iot-development-framework) 使用基于原版 FreeRTOS v10.4.3 的修改版 以利用 ESP32 和 ESP32-S3 的双核 SMP 能力，具有每核心空闲任务、基于自旋锁的临界区以及以字节而非字指定的任务栈大小；ESP-IDF 还提供亚马逊 SMP 内核的实验性移植。<sup>[22](https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32/api-guides/freertos-smp.html)</sup><sup> • </sup><sup>[23](https://docs.espressif.com/projects/esp-idf/en/v5.1-rc2/esp32/api-reference/kconfig.html)</sup> 协程面向 RAM 严重受限的极小型处理器，在内核功能列表中已被弃用。<sup>[24](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/01-Tasks-and-co-routines/00-Tasks-and-co-routines)</sup><sup> • </sup><sup>[1](https://github.com/FreeRTOS/FreeRTOS-Kernel-Book/blob/main/ch01.md/)</sup>

## References

1. [FreeRTOS Kernel Book, Chapter 1: Preface (FreeRTOS-Kernel-Book, GitHub)](https://github.com/FreeRTOS/FreeRTOS-Kernel-Book/blob/main/ch01.md/)
2. [FreeRTOS License (license.txt), FreeRTOS GitHub](https://github.com/FreeRTOS/FreeRTOS/blob/main/FreeRTOS/License/license.txt)
3. [FreeRTOS homepage](https://en.freertos.org/)
4. [Announcing FreeRTOS Kernel Version 10, AWS Open Source Blog (29 November 2017)](https://aws.amazon.com/blogs/opensource/announcing-freertos-kernel-v10/)
5. [FreeRTOS scheduling (single-core, AMP and SMP), FreeRTOS documentation](https://2fwww.freertos.org/Documentation/02-Kernel/02-Kernel-features/01-Tasks-and-co-routines/04-Task-scheduling)
6. [FreeRTOS/FreeRTOS-Kernel repository, GitHub](https://github.com/FreeRTOS/FreeRTOS-Kernel)
7. [FreeRTOS heap memory management, FreeRTOS documentation](https://2fwww.freertos.org/Documentation/02-Kernel/02-Kernel-features/09-Memory-management/01-Memory-management)
8. [Static Vs Dynamic Memory Allocation, FreeRTOS documentation](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/09-Memory-management/03-Static-vs-Dynamic-memory-allocation)
9. [Symmetric Multiprocessing (SMP) with FreeRTOS, FreeRTOS documentation](https://sbop.freertos.org/Documentation/02-Kernel/02-Kernel-features/13-Symmetric-multiprocessing-introduction)
10. [Announcing Amazon FreeRTOS, AWS News Blog (29 November 2017)](https://aws.amazon.com/blogs/aws/announcing-amazon-freertos/)
11. [AWS IoT Over the air (OTA) library, FreeRTOS documentation](https://docs.aws.amazon.com/freertos/latest/userguide/ota-update-library.html)
12. [OTA update prerequisites, FreeRTOS documentation](https://docs.aws.amazon.com/freertos/latest/userguide/ota-prereqs.html)
13. [New – FreeRTOS Long Term Support to Provide Years of Feature Stability, AWS News Blog (15 December 2020)](https://aws.amazon.com.cdn.amazon.com/blogs/aws/new-freertos-long-term-support-to-provide-years-of-feature-stability/)
14. [FreeRTOS FAQs, Amazon Web Services](https://aws.amazon.com/freertos/faqs/)
15. [Mastering the FreeRTOS Real Time Kernel: A Hands-On Tutorial Guide (2018)](https://www.freertos.org/media/2018/161204_Mastering_the_FreeRTOS_Real_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf)
16. [FreeRTOS Reference Manual V10.0.0 (2018)](https://www.freertos.org/media/2018/FreeRTOS_Reference_Manual_V10.0.0.pdf)
17. [FreeRTOS queues, FreeRTOS documentation](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/02-Queues-mutexes-and-semaphores/01-Queues)
18. [FreeRTOS mutexes, FreeRTOS documentation](https://freertos.org/Real-time-embedded-RTOS-mutexes.html)
19. [xTaskNotify / xTaskNotifyIndexed API reference, FreeRTOS documentation](https://www.freertos.org/Documentation/02-Kernel/04-API-references/05-Direct-to-task-notifications/04-xTaskNotify)
20. [FreeRTOS software timers, FreeRTOS documentation](https://wina.freertos.org/Documentation/02-Kernel/02-Kernel-features/05-Software-timers/01-Software-timers)
21. [FreeRTOS Libraries, AWS FreeRTOS documentation](https://docs.aws.amazon.com/freertos/latest/userguide/dev-guide-freertos-libraries.html)
22. [ESP-IDF FreeRTOS (SMP), Espressif ESP-IDF Programming Guide](https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32/api-guides/freertos-smp.html)
23. [Project Configuration (CONFIG_FREERTOS_SMP), ESP-IDF Programming Guide](https://docs.espressif.com/projects/esp-idf/en/v5.1-rc2/esp32/api-reference/kconfig.html)
24. [Tasks and Co-routines, FreeRTOS documentation](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/01-Tasks-and-co-routines/00-Tasks-and-co-routines)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Embedded & soft processors › Embedded systems › Embedded operating systems and software platforms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/freertos

English original: https://www.edgepedia.org/freertos
