RTOS for Raspberry Pi 5 built during the CATERPILLAR TECH CHALLENGE 2025
- Operating System: Raspberry Pi OS (64-bit), based on Debian Bookworm.
- Kernel Version String: 6.15.0-rc7-v8-16k-NTP+
- Kernel Type: Custom compiled with PREEMPT_RT (Full Real-Time Preemption).
- Architecture: aarch64 (64-bit).
- Build Method: Natively compiled on the Raspberry Pi 5.
- Key Kernel Configurations :
- Full Real-Time Preemption (CONFIG_PREEMPT_RT=y)
- Timer Frequency set to 1000 Hz (CONFIG_HZ_1000=y)
- Full Dynamic Ticks (CONFIG_NO_HZ_FULL=y)
- Default CPU Frequency Governor set to "performance"
- Kernel PPS (Pulse Per Second) timing support (CONFIG_NTP_PPS=y)
- PPS client support for GPIO (CONFIG_PPS_CLIENT_GPIO=y)
This repository documents the complete process of building, deploying, and validating a PREEMPT_RT real-time kernel for the Raspberry Pi 5.
The RTOS kernel enables deterministic scheduling and microsecond-level latency, making it ideal for real-time applications such as robotics, control systems, and embedded AI.
In this project, the RT kernel is used as the foundation for a real-time monocular depth estimation system, but this Repository focuses entirely on the kernel build and deployment process.
- Raspberry Pi 5 (8GB LPDDR4X-4267 SDRAM)
- 64GB SanDisk microSD card (OS + kernel)
- Optional: 128GB USB 3.2 storage (datasets/logging)
- Official Raspberry Pi Active Cooler (recommended)
- HDMI display (to verify boot and logs)
- GPIO peripherals (optional for testing): LED, buzzer
- Raspberry Pi OS (64-bit, Debian Bookworm)
- Kernel source: Raspberry Pi Linux
rpi-6.15.ybranch - PREEMPT_RT support (integrated into ARM64 kernel ≥6.12)
- Toolchain and dependencies for native compilation
The stock Raspberry Pi OS kernel is optimized for general-purpose workloads (desktop, server) and cannot guarantee strict timing deadlines.
By compiling and deploying the PREEMPT_RT kernel, we achieve:
- Full kernel preemption (CONFIG_PREEMPT_RT=y)
- Deterministic response times (<200µs under stress)
- High-resolution scheduler (1000 Hz tick rate)
- Reduced jitter via tickless kernel (CONFIG_NO_HZ_FULL)
- Stable CPU frequency (performance governor)
These changes transform the Pi 5 into a real-time capable system suitable for robotics, industrial automation, and safety-critical edge AI.
On a fresh Raspberry Pi OS install, run:
sudo apt update && sudo apt upgrade -y
sudo apt install git bc bison flex libssl-dev make -y
sudo apt install libncurses5-dev -y
sudo apt install raspberrypi-kernel-headers -y
mkdir ~/kernel && cd ~Clone the official Raspberry Pi Linux repository:
git clone --depth 1 --branch rpi-6.15.y https://github.com/raspberrypi/linux
cd linux✅ Starting with kernel 6.12, PREEMPT_RT is integrated for ARM64 — no external patches needed.
-
Load Raspberry Pi 5 defaults:
make bcm2712_defconfig
-
Open menuconfig:
make menuconfig
-
Enable the following key options:
- General Setup → Preemption Model → Fully Preemptible Kernel (Real-Time)
- Processor type and features → Timer frequency → 1000 Hz
- CPU Frequency Default Governor → performance
- Full dynticks system (CONFIG_NO_HZ_FULL=y)
- NTP/PPS client GPIO support
-
Disable debugging and power-saving governors to reduce jitter.
Compile natively on Raspberry Pi 5:
make prepare
make CFLAGS='-O3 -march=native' -j6 Image.gz modules dtbs
sudo make -j6 modules_installRecommendation: Use 1.5 × number of CPU cores for -j (Pi 5 has 4 cores → -j6).
sudo mkdir /boot/firmware/NTP
sudo mkdir /boot/firmware/NTP/overlays-NTPsudo cp arch/arm64/boot/dts/broadcom/*.dtb /boot/firmware/NTP/
sudo cp arch/arm64/boot/dts/overlays/*.dtb* /boot/firmware/NTP/overlays-NTP/
sudo cp arch/arm64/boot/dts/overlays/README /boot/firmware/NTP/overlays-NTP/
sudo cp arch/arm64/boot/Image.gz /boot/firmware/kernel_2712-NTP.imgEdit /boot/firmware/config.txt and add:
os_prefix=NTP/
overlay_prefix=overlays-NTP/
kernel=/kernel_2712-NTP.img
⚠️ This ensures the stock kernel remains intact for recovery.
sudo reboot nowAfter reboot, check:
uname -aExpected output:
Linux raspberrypi 6.15.0-rc7-v8-16k-NTP+ #1 SMP PREEMPT_RT ...
Install and run cyclictest:
sudo apt install rt-tests -y
sudo cyclictest -Sp90 -i200 -n -l100000- Idle latency: ~15–20 µs
- CPU+Memory stress latency: <200 µs
✅ Confirms deterministic scheduling suitable for real-time tasks.
- Re-flash SD with Raspberry Pi Imager if unbootable.
- Keep the default kernel untouched for recovery.
- Use
gpiozeroinstead of deprecatedRPi.GPIO.
-
Run inside Pi desktop session:
sudo -E chrt -f 75 python3 app.py
For convenience, use this one-step automation script:
Save as build_rt_kernel.sh:
#!/bin/bash
set -e
echo "[*] Installing dependencies..."
sudo apt update && sudo apt install -y \
git bc bison flex libssl-dev make libncurses5-dev raspberrypi-kernel-headers
echo "[*] Cloning Raspberry Pi 6.15.y kernel..."
cd ~
[ -d linux ] && sudo rm -rf linux
git clone --depth 1 --branch rpi-6.15.y https://github.com/raspberrypi/linux
cd linux
echo "[*] Configuring kernel..."
make bcm2712_defconfig
yes "" | make menuconfig
echo "[*] Building kernel..."
make prepare
make CFLAGS='-O3 -march=native' -j6 Image.gz modules dtbs
sudo make -j6 modules_install
echo "[*] Setting up boot directories..."
sudo mkdir -p /boot/firmware/NTP/overlays-NTP
echo "[*] Copying kernel and device trees..."
sudo cp arch/arm64/boot/dts/broadcom/*.dtb /boot/firmware/NTP/
sudo cp arch/arm64/boot/dts/overlays/*.dtb* /boot/firmware/NTP/overlays-NTP/
sudo cp arch/arm64/boot/dts/overlays/README /boot/firmware/NTP/overlays-NTP/
sudo cp arch/arm64/boot/Image.gz /boot/firmware/kernel_2712-NTP.img
echo "[*] Updating /boot/firmware/config.txt..."
sudo tee -a /boot/firmware/config.txt > /dev/null <<EOL
os_prefix=NTP/
overlay_prefix=overlays-NTP/
kernel=/kernel_2712-NTP.img
EOL
echo "[*] Build complete. Rebooting into PREEMPT_RT kernel..."
sudo reboot nowRun:
chmod +x build_rt_kernel.sh
./build_rt_kernel.sh- The PREEMPT_RT kernel on Raspberry Pi 5 provides deterministic, microsecond-level scheduling.
- It is validated under load with <200µs latency.
- Applications such as depth estimation, robotics, and control systems can now reliably run on the Pi 5 as a real-time platform.