Real-Time-C++
This repository provides companion code for the book C.M. Kormanyos, Real-Time C++:
Efficient Object-Oriented and Template Microcontroller Programming, 4$^{th}$ Edition
and is made available for educational and exploratory use.
The repository has several main parts.
GNU/GCC cross compilers and various additional tools
running on Win*, optionally needed for certain builds
as described below, can be found in the related
ckormanyos/real-time-cpp-toolchains
repository.
Details on the Reference Application
The reference application boots with a small startup code and subsequently
initializes a skinny microcontroller abstraction layer (MCAL). Control is
then passed to a simple multitasking scheduler that manages the
LED application, calls a cyclic benchmark task and services the watchdog.
The LED application toggles a user-LED with a frequency of $\frac{1}{2}~\text{Hz}$.
The result is LED on for one second, LED off for one second.
The LED application runs cyclically and perpetually
without break or pause.
The reference application is compatible with C++20, 23 and beyond.
Portability
The application software is implemented once and used uniformly
on each supported target in the ref_app.
Differences among the individual targets arise only
in the lower software layers pertaining
to chip-specific and board-specific startup/MCAL details.
In this way the project exhibits a high level of portability.
Supported Targets in the Reference Application
The reference application supports the following targets (in alpha-numeric order):
| Target name (as used in build command) |
Target Description |
*(breadboard) |
am335x |
BeagleBone with Texas Instruments(R) AM335x ARM(R) A8 |
|
am6254_soc |
PocketBeagle2 with multicore Texas Instruments(R) AM6254 |
|
atmega2560 |
MICROCHIP(R) [former ATMEL(R)] AVR(R) ATmega2560 |
|
atmega4809 |
MICROCHIP(R) [former ATMEL(R)] AVR(R) ATmegax4809 |
X |
avr (as used in the book) |
MICROCHIP(R) [former ATMEL(R)] AVR(R) ATmega328P |
X |
bcm2835_raspi_b |
RaspberryPi(R) Zero with ARM1176-JZFS(TM) |
X |
bl602_sifive_e24_riscv |
BL602 single-core RISC-V (SiFive E24) |
X |
Debug/Release |
PC on Win* via MSVC x64 compiler Debug/Release |
|
esp32p4_riscv_soc |
Espressif ESP32-P4 multicore RISC-V SoC |
X |
host |
PC/Workstation on Win*/mingw64/*nix via host compiler |
|
lpc11c24 |
NXP(R) OM13093 LPC11C24 board ARM(R) Cortex(R)-M0+ |
|
nxp_imxrt1062 |
Teensy 4.0 Board / NXP(R) iMXRT1062 ARM(R) Cortex(R)-M7 |
X |
r7a4m1ab |
Renesas(R) R7FA4M1AB ARM(R) Cortex(R)-M4F |
X |
riscvfe310 |
SiFive RISC-V FE310 SoC |
|
rl78 |
Renesas(R) RL78/G13 |
|
rpi_pico_rp2040 |
RaspberryPi(R) Pico RP2040 with dual ARM(R) Cortex(R)-M0+ |
X |
rpi_pico2_rp2350 |
RaspberryPi(R) Pico2 RP2350 with dual ARM(R) Cortex(R)-M33 |
X |
rx63n |
Renesas(R) RX630/RX631 |
|
stm32f100 |
STMicroelectronics(R) STM32F100 ARM(R) Cortex(R)-M3 |
X |
stm32f407 |
STMicroelectronics(R) STM32F407 ARM(R) Cortex(R)-M4F |
|
stm32f429 |
STMicroelectronics(R) STM32F429 ARM(R) Cortex(R)-M4F |
|
stm32f446 |
STMicroelectronics(R) STM32F446 ARM(R) Cortex(R)-M4F |
|
stm32h7a3 |
STMicroelectronics(R) STM32H7A3 ARM(R) Cortex(R)-M7 |
|
stm32l100c |
STMicroelectronics(R) STM32L100 ARM(R) Cortex(R)-M3 |
X |
stm32l152 |
STMicroelectronics(R) STM32L152 ARM(R) Cortex(R)-M3 |
|
stm32l432 |
STMicroelectronics(R) STM32L432 ARM(R) Cortex(R)-M4F |
X |
v850es_fx2 |
Renesas(R) Electronics V850es/Fx2 upd703231 |
|
wch_ch32v307 |
WCH CH32v307 RISC-V board |
|
wch_ch32v307_llvm |
WCH CH32v307 RISC-V board (but using an LLVM toolchain) |
|
x86_64-w64-mingw32 |
PC on Win*/mingw64 via GNU/GCC x86_x64 compiler |
|
xtensa_esp32_s3 |
Espressif (XTENSA) NodeMCU ESP32-S3 |
X |
xtensa32 |
Espressif (XTENSA) NodeMCU ESP32 |
X |
In this table, *(breadboard) means the board (or certain versions of it) can be readily
used with a common breadboard. This may possibly need some very straightforward
manual soldering/mounting of header-pins.
Getting Started with the Reference Application
It is easiest to get started with the reference application using one of the
supported boards, such as avr (ARDUINO) or bcm2835_raspi_b
(RaspberryPi ZERO) or am335x (BeagleBoneBlack), etc.
The reference application can be found
in the directory ref_app and its
subdirectories.
The reference application uses cross-development and
build systems are supported on:
*nix make tools in combination with Bash/GNUmake (bash script) on LINUX/MacOS,
- ported
*nix-like make tools on Win* in combination with batch script or Microsoft(R) Visual Studio(R) via External Makefile,
- MICROCHIP(R) [former ATMEL(R)] Studio on
Win*,
- or platform-independent CMake.
Upon successful completion of the build,
the resulting artifacts including HEX-files
(such as ref_app.hex), map files, size reports, etc.,
are available in the bin directory.
Build with Bash Shell Script and GNU make
To get started with the reference application on *nix
- Open a terminal in the directory ref_app.
- The terminal should be located directly in ref_app for the paths to work out (be found by the upcoming build).
- Identify the Bash shell script ref_app/target/build/build.sh.
- Consider which configuration (such as
target avr) you would like to build.
- Execute
build.sh with the command: ./target/build/build.sh avr rebuild.
- This shell script calls GNU make with parameters
avr rebuild which subsequently rebuilds the entire solution for target avr.
- If you're missing AVR GCC tools and need to get them on
*nix, run sudo apt install gcc-avr avr-libc.
Example Build on *nix for target avr
We will now exemplify how to build the reference application on a command shell
in *nix for target avr. This target system includes essentially
any ARDUINO(R)-compatible board. This is also the board compatibility
actually used with the homemade boards in the book.
Install gcc-avr if needed.
sudo apt install gcc-avr avr-libc
Clone or get the ckormanyos/real-time-cpp
repository. Then build with:
cd real-time-cpp
cd ref_app
./target/build/build.sh avr rebuild
Example Build on *nix for target stm32f446
We will now exemplify how to build the reference application on a command shell
in *nix for an ARM(R) target. Consider, for example, the build variant
target stm32f446. The NUCLEO-F446RE board from STMicroelectronics(R)
can conveniently be used for this.
Install gcc-arm-none-eabi if needed.
sudo apt install gcc-arm-none-eabi
Clone or get the ckormanyos/real-time-cpp
repository. Then build with:
cd real-time-cpp
cd ref_app
./target/build/build.sh stm32f446 rebuild
Example Build on MacOS for target stm32f446
We will now exemplify how to build the reference application in a command shell
in MacOS for an ARM(R) target. Consider, for example, the build variant
target stm32f446. The NUCLEO-F446RE board from STMicroelectronics(R)
can conveniently be used for this.
Clone or get the ckormanyos/real-time-cpp
repository.
The default version 3.81 of GNUmake on MacOS can (now) be used.
The make files used in this repository have been made
compatible with it. For background information, see also
issue 273.
Build the target with a direct manual call to make.
cd real-time-cpp
cd ref_app
make -f target/app/make/app_make.gmk rebuild TGT=stm32f446
If the toolchain is needed then it must be installed or retrieved
prior to building the target of the reference application.
You can obtain via wget (or optionally install)
the gcc-arm-none-eabi toolchain if needed.
In this case, I have found it convenient to use
a modern gcc-arm-none-eabi for MacOS which can be found at
Arm GNU Toolchain Downloads.
The arm-non-eabi toolchain can be fetched via wget
and successfully used locally in the shell. If this is desired,
follow the step-by-step procedure below.
Step 1: Make a local directory (such as macos-gnu-arm-toolchain) and cd into it.
cd real-time-cpp
mkdir -p macos-gnu-arm-toolchain
cd macos-gnu-arm-toolchain
Step 2: Fetch the toolchain's tarball with wget, unpack it
and add the compiler's bin-directory to the shell's executable path.
wget --no-check-certificate https://developer.arm.com/-/media/Files/downloads/gnu/12.2.rel1/binrel/arm-gnu-toolchain-12.2.rel1-darwin-x86_64-arm-none-eabi.tar.xz
tar -xvf arm-gnu-toolchain-12.2.rel1-darwin-x86_64-arm-none-eabi.tar.xz
PATH=$(pwd)/arm-gnu-toolchain-12.2.rel1-darwin-x86_64-arm-none-eabi/bin:$PATH
Step 3: Optionally echo the PATH for a quick path-check.
It can also be helpful to query arm-non-eabi-g++'s version.
This is expected to verify that the toolchain is correctly added
to this shell's local PATH.
echo $PATH
arm-none-eabi-g++ -v
Now simply use the commands to build the target
with a direct call to make (which is the same
as shown above for the *nix case).
cd real-time-cpp
cd ref_app
make -f target/app/make/app_make.gmk rebuild TGT=stm32f446
Build with VisualStudio(R) Project and CMD Batch
To get started with the reference application on Win*
- Clone or get the ckormanyos/real-time-cpp repository.
- Get and setup (from the ckormanyos/real-time-cpp-toolchains repository) any needed GNU/GCC cross compilers running on
Win*, as described in detail a few paragraphs below.
- Start Visual Studio(R) 2019 (or later, Community Edition is OK)
- Open the solution
ref_app.sln in the ref_app directory.
- Select the desired configuration.
- Then rebuild the entire solution.
The ref_app build in Microsoft(R) VisualStudio(R)
makes heavy use of cross development using a project
workspace of type External Makefile.
GNUmake is invoked via batch file in the build process.
It subsequently runs in combination with several Makefiles.
To build any ref_app target other than Debug or Release for Win32, a cross-compiler
(GNU/GCC cross compiler) is required. See the text below for additional details.
GNU/GCC cross compilers running on Win*