A custom-built Real-Time Operating System (RTOS) written in Modern C++ (C++17) for the STM32F407 Discovery Board.
The ultimate goal of this project is to implement a lightweight eBPF (Extended Berkeley Packet Filter) Virtual Machine inside the kernel, allowing for safe, dynamic code execution on the microcontroller without flashing firmware updates.
• [x] Bootloader: Custom Assembly startup ( startup.s ) and Linker Script ( .ld ).
• [x] Build System: CMake + ARM GCC Toolchain (No IDE required).
• [x] GPIO (Digital I/O)
• [x] UART (Serial Communication)
• [ ] eBPF VM: Instruction interpreter (In Progress).
• [x] Scheduler: Round-Robin task switching (Planned).
• STM32F407G-DISC1 (Discovery Board)
• Mini-USB Cable (for programming via ST-Link)
• Micro-USB Cable (optional, for USB OTG features)
• VS Code (Editor)
• ARM GNU Toolchain (arm-none-eabi-gcc)
• CMake (Build Automation)
• STM32CubeProgrammer (Optional, for flashing)
Below is the file tree generated after a successful build:
.
├── build
└── micro_eBPF
└── software
├── CMakelists.txt
├── Toolchain.cmake
├── build
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ │ ├── 3.31.0-rc1
│ │ │ ├── CMakeASMCompiler.cmake
│ │ │ ├── CMakeCCompiler.cmake
│ │ │ ├── CMakeCXXCompiler.cmake
│ │ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ │ ├── CMakeSystem.cmake
│ │ │ ├── CompilerIdC
│ │ │ │ ├── CMakeCCompilerId.c
│ │ │ │ └── CMakeCCompilerId.o
│ │ │ └── CompilerIdCXX
│ │ │ ├── CMakeCXXCompilerId.cpp
│ │ │ └── CMakeCXXCompilerId.o
│ │ ├── CMakeConfigureLog.yaml
│ │ ├── CMakeDirectoryInformation.cmake
│ │ ├── Makefile.cmake
│ │ ├── Makefile2
│ │ ├── STM32_RTOS_CPP.elf.dir
│ │ │ ├── ASM.includecache
│ │ │ ├── DependInfo.cmake
│ │ │ ├── build.make
│ │ │ ├── cmake_clean.cmake
│ │ │ ├── compiler_depend.make
│ │ │ ├── compiler_depend.ts
│ │ │ ├── depend.internal
│ │ │ ├── depend.make
│ │ │ ├── flags.make
│ │ │ ├── progress.make
│ │ │ └── src
│ │ │ ├── App
│ │ │ │ ├── Ledblinker.cpp.obj
│ │ │ │ ├── Ledblinker.cpp.obj.d
│ │ │ │ ├── MotorControl.cpp.obj
│ │ │ │ └── MotorControl.cpp.obj.d
│ │ │ ├── drivers
│ │ │ │ ├── Gpio.cpp.obj
│ │ │ │ ├── Gpio.cpp.obj.d
│ │ │ │ ├── Timer.cpp.obj
│ │ │ │ ├── Timer.cpp.obj.d
│ │ │ │ ├── Uart.cpp.obj
│ │ │ │ └── Uart.cpp.obj.d
│ │ │ ├── kernel
│ │ │ │ ├── Scheduler.cpp.obj
│ │ │ │ ├── Scheduler.cpp.obj.d
│ │ │ │ ├── Thread.cpp.obj
│ │ │ │ ├── Thread.cpp.obj.d
│ │ │ │ ├── mutex.cpp.obj
│ │ │ │ └── mutex.cpp.obj.d
│ │ │ ├── main.cpp.obj
│ │ │ ├── main.cpp.obj.d
│ │ │ └── startup.s.obj
│ │ ├── TargetDirectories.txt
│ │ ├── cmake.check_cache
│ │ └── progress.marks
│ ├── Makefile
│ ├── STM32_RTOS_CPP.bin
│ ├── STM32_RTOS_CPP.elf
│ ├── STM32_RTOS_CPP.map
│ └── cmake_install.cmake
├── include
│ ├── Drivers
│ │ ├── Gpio.hpp
│ │ ├── Registers.hpp
│ │ ├── Timer.hpp
│ │ └── Uart.hpp
│ └── Kernel
│ ├── Scheduler.hpp
│ └── Thread.hpp
├── src
│ ├── App
│ │ ├── Ledblinker.cpp
│ │ └── MotorControl.cpp
│ ├── drivers
│ │ ├── Gpio.cpp
│ │ ├── Timer.cpp
│ │ └── Uart.cpp
│ ├── kernel
│ │ ├── Scheduler.cpp
│ │ ├── Thread.cpp
│ │ └── mutex.cpp
│ ├── main.cpp
│ └── startup.s
└── stm32_flash.ld
This project uses an Out-of-Source build system to keep the code clean.
1. Open Terminal in the software directory.
2. Create a Build Directory:
mkdir build
cd build3. Configure (Generate Makefiles):
cmake -G "MinGW Makefiles" ..
4. Compile:
cmake --build .
Success: You will see [100%] Built target STM32_RTOS_CPP.elf and a generated STM32_RTOS_CPP.bin file.
1. Connect the board via the Mini-USB (ST-LINK) port.
2. The board appears as a USB Drive named DIS_F407VG .
3. Drag the STM32_RTOS_CPP.bin file from the build folder into the drive.
4. The LEDs will flash while copying, then the board will reset and run your code.
1. Open STM32CubeProgrammer.
2. Connect to the board.
3. Select STM32_RTOS_CPP.elf .
4. Click Download.
The next phase introduces the eBPF Virtual Machine to the kernel:
1. Instruction Set: Define 64-bit eBPF opcodes (ALU, JMP, MEM).
2. Registers: Implement the 11 virtual registers ( r0 - r10 ).
3. Interpreter: A switch-case engine to decode and execute bytecode.
4. Maps: Shared memory data structures for kernel-user interaction.
This project is open-source. Feel free to use it for learning RTOS development.