RTIC
v2.2.0Features
-
Hardware-accelerated task scheduling using the system’s interrupt controller.
-
Support for both event-triggered tasks and software-spawned tasks.
-
Message passing mechanism for transferring data to software tasks at spawn time.
-
Integrated timer queue for scheduling tasks with specific delays or periodic execution.
-
Preemptive multitasking based on user-defined task priorities.
-
Data race free memory sharing via fine-grained, priority-based critical sections.
-
Compile-time guarantees for deadlock-free execution using Stack Resource Policy (SRP).
-
Highly efficient memory management where all tasks share a single call stack.
-
Zero-cost abstractions with a minimal software footprint for the scheduler.
-
No hard dependency on a dynamic memory allocator (heapless operation).
-
Full support for the entire ARM Cortex-M microcontroller family.
-
Support for most RISC-V devices with specific backend implementations.
-
Amenability to formal Worst Case Execution Time (WCET) and scheduling analysis.
-
Integration with Rust’s ownership and type system for safety guarantees.
-
Support for QEMU and ESP32 environments for testing and simulation.
Architecture
RTIC is built on the Real-Time For the Masses (RTFM) framework, utilizing a declarative syntax to define tasks and resources. Its architecture is unique in that it lacks a traditional software-based scheduler; instead, it leverages the hardware’s Nested Vectored Interrupt Controller (NVIC) or equivalent to manage task preemption and execution. This hardware-centric approach ensures that context switching occurs with the lowest possible latency, as the hardware itself handles the saving and restoring of registers.
The system operates on the Stack Resource Policy (SRP), which allows all tasks to share a single call stack safely. By assigning static priorities to tasks and using priority ceilings for shared resources, RTIC guarantees at compile-time that deadlocks cannot occur and that data races are impossible. This design makes the system highly predictable and amenable to Worst Case Execution Time (WCET) analysis.
Core Components
- Task Dispatcher: Maps software and hardware tasks to specific interrupt vectors for hardware-accelerated scheduling.
- Resource Manager: Implements priority-based critical sections for safe data sharing between tasks of different priorities.
- Timer Queue: Manages scheduled and periodic tasks using hardware timers to trigger software tasks in the future.
- Message Queue: Facilitates asynchronous data transfer between tasks at the moment they are spawned.
Use Cases
This RTOS is ideal for:
- Industrial Automation: Managing high-speed sensor data and actuator control with strict timing requirements.
- Safety-Critical Systems: Applications requiring formal guarantees against deadlocks and memory corruption at compile time.
- Battery-Powered Devices: Systems needing minimal CPU overhead to maximize sleep cycles and energy efficiency through hardware-driven wakeups.
- Automotive Sensors: Processing CAN bus or LIN bus signals where predictable latency and high reliability are mandatory.
- Medical Instrumentation: Real-time monitoring where deterministic behavior and memory safety are paramount.
- Digital Signal Processing: Handling high-frequency interrupts for audio or radio frequency applications with minimal jitter.
Getting Started
To begin developing with RTIC, developers should first install the Rust toolchain and the appropriate target support for their hardware (e.g., thumbv7m-none-eabi). The primary entry point for documentation is the RTIC Book (https://rtic.rs), which provides a comprehensive guide from basic task spawning to advanced resource management. Projects are typically structured using the #[rtic::app] attribute, which allows developers to define local and shared resources along with task functions that respond to hardware interrupts. For rapid prototyping and testing, the framework supports QEMU and provides an xtask based workflow for running continuous integration checks and formatting locally.
Related Projects (23)
Modular Music CV/Gate Sequencer for STM32
A modular music CV/Gate sequencer built for the STM32F103C8 (Blue Pill) using the Rust programming language and the RTIC framework. It features a custom Cherry MX keypad interface, dual MCP4921 DACs for control voltage output, and WS2812 LED support for visual feedback.
Rauk - RTIC Analysis Using KLEE
Rauk is a measurement-based Worst-Case Execution Time (WCET) analysis tool for RTIC applications targeting ARM Cortex-M microcontrollers. It utilizes the KLEE symbolic execution engine to automatically generate test vectors that ensure full path coverage of user tasks for hardware-in-the-loop timing measurements.
Rust Embedded Examples
A collection of embedded Rust projects utilizing the stm32f1xx-hal crate and the Real-Time Interrupt-driven Concurrency (RTIC) framework. Targeted at the NUCLEO-F103RB development board, these examples demonstrate various peripheral interactions including GPIO, USART, and PWM.
Rust for Arduino Portenta-H7
A collection of Rust-based examples and a development environment for the Arduino Portenta-H7 board. It utilizes the RTIC (Real-Time Interrupt-driven Concurrency) framework and the stm32h7xx-hal to provide high-performance, memory-safe firmware for the STM32H747 microcontroller.
Rust IR Thermometer Firmware
A Rust-based firmware for an infrared thermometer utilizing the STM32L151CBT6 microcontroller and the MLX90614 sensor. It leverages the RTIC framework for real-time task management and supports features like data logging to EEPROM, LCD display, and UART streaming.
STM32F4 RTIC Playground
A development playground for the Black Pill STM32F411CE microcontroller using the RTIC (Real-Time Interrupt-driven Concurrency) framework in Rust. It demonstrates hardware integration with OLED displays, USB serial/HID communication, and various embedded peripherals using the stm32f4xx-hal.
STM32F429 RTIC and smoltcp Example Application
A Rust-based example application for the STM32F429 microcontroller utilizing the RTIC (Real-Time Interrupt-driven Concurrency) framework and the smoltcp TCP/IP stack. It demonstrates Ethernet connectivity, PHY initialization, and UDP communication on embedded hardware.
UART Communication between nRF52840 and STM32F401 Nucleo
A collection of Rust-based example programs demonstrating UART communication between an nRF52840 DK and an STM32F401 Nucleo board. It utilizes the RTIC framework for concurrency and features examples ranging from basic byte transfers to structured data using COBS and the Postcard serialization library.
Microgroove
An open-source 8-track MIDI sequence generator built on the Raspberry Pi Pico using the Rust RTIC framework. It features multiple sequence generation engines including random melodies, Euclidean rhythms, and Mutable Instruments' Grids algorithms, with support for scales, swing, and complex track interplay.