Real-Time C++: A High-Performance Tool for Embedded Systems!

Real-Time C++ sounds cool, right? In fact, it is the accompanying open-source code library for Professor C. M. Kormanyos’s comprehensive book, Real-Time C++. Simply put, it helps you write bare-metal, zero operating system embedded applications using modern C++ (14/17/20/23). Whether you are working with AVR, STM32, RISC-V, or Raspberry Pi, you can “write once, run anywhere.” Below, we will discuss its amazing features in a somewhat informal yet relatable manner.

What is Real-Time C++? Real-Time C++ is not an IDE, nor is it a plugin from a closed-source company. It is a complete open-source bare-metal library written entirely in C++. It includes:

  • MCAL (Microcontroller Abstraction Layer), which encapsulates the startup and register operations for various chips;
  • Simple Scheduler, for running tasks in a loop, feeding the watchdog, and running benchmarks;
  • Examples, Benchmarks, and Code Snippets from the Book, to help you learn more thoroughly;
  • Cross-Platform Scripts, allowing you to use Make, CMake, Visual Studio, Atmel Studio, or whatever you prefer.

Why Use It? What Problems Does It Solve? Embedded development often encounters:

  • • Writing in C leads to confusion, with a plethora of functions and globals, making maintenance difficult;
  • • Wanting to use C++, but fearing performance issues and bloated libraries;
  • • Needing to modify a lot of startup code and linker scripts for different boards;
  • • Wanting to run a small benchmark but having to write timing, interrupts, I/O, etc. from scratch… Real-Time C++ is here to alleviate these “pains”:
  • • Completely written in modern C++: templates, object-oriented, type-safe, with zero overhead;
  • • Comes with hundreds of examples, benchmarks, and safety checks, giving you confidence in performance and memory usage;
  • • MCAL is highly portable, requiring only minor modifications for low-level startup, while the logic layer remains unchanged;
  • • Continuous integration, CodeQL, Coverity ensure high quality.

Core Features and Highlights

  • Multiple Compilers and Standards: GCC, Clang, MSVC, supporting C++14/17/20/23.
  • Diverse Target Boards: From AVR ATmega328P to STM32F4, RISC-V, ESP32… dozens of options.
  • Benchmarks: Comes with speed test examples to measure your MCU’s capabilities.
  • Bare-Metal Multitasking: Lightweight loop scheduling, supporting timed tasks, watchdog feeding, and task switching.
  • Cross-Platform Build: Make, CMake, shell, bat, Visual Studio, Atmel Studio… compatible with any workflow.

Code Example: Get LED Blinky Running in One Minute Below is a demonstration of a minimal blinky, running a 1Hz LED toggle on STM32F4-NUCLEO using CMake:

// ref_app/src/main.cpp
#include <mcal_reg.h>
#include <mcal_port.h>
#include <mcal_led.h>
#include <mcal_scheduler.h>

int main() {
  mcal::port::init();
  mcal::led::init(); // Initialize GPIO
  mcal::scheduler::init();
  mcal::scheduler::add_task(
[](){ mcal::led::toggle();}, // Toggle LED
    std::chrono::seconds(1) // 1 second period
);
  mcal::scheduler::start(); // Never returns
return 0;
}

As long as your CMakeLists.txt specifies <span>-DTARGET=stm32f446</span> and <span>-DCMAKE_TOOLCHAIN_FILE=…</span>, just run <span>cmake && make</span>, and you can flash the firmware. The LED will blink on and off every second, continuously.

Pros and Cons AnalysisPros:

  • • Modern C++: High readability, high reusability, zero virtual overhead;
  • • Ready to use: Hundreds of examples, dozens of boards, high integration;
  • • Performance is known: Comes with benchmarks for easy measurement;
  • • Maintainable: CI, static analysis, code coverage, and comprehensive documentation.Cons:
  • • Learning curve: Requires familiarity with templates and a deep understanding of C++ features;
  • • Library size: Slightly larger compared to “bare C”, but sufficient for regular MCUs;
  • • Configuration complexity: Initial use requires exploring build scripts and toolchains;
  • • Heavy use of templates: Slower compilation and harder-to-understand errors, requiring patience from beginners.

Conclusion If you are a C++ enthusiast looking to use familiar syntax and concepts in bare-metal and embedded scenarios, Real-Time C++ will make you exclaim, “This is awesome!”: Highly abstract yet zero cost, template metaprogramming with predictable performance, and a unified logic across multiple platforms. Although it may be a bit challenging to get started, once you master it, your code quality, maintainability, and performance insights will significantly improve. This library is nearly irreplaceable for elegantly writing C++ in the MCU world.

Project Address: https://github.com/ckormanyos/real-time-cpp

Leave a Comment