Close
0%
0%

Bare-Metal Operating System for STM32F7

Operating system from scratch for STM32F7 (ARM Cortex-M7)

Similar projects worth following
0 followers
Mk is a bare-metal operating system built from scratch for the STM32F746G-Eval2 and STM32F746G-DISCO REV.C boards. It targets the STM32F74xxx and STM32F75xxx MCU families and provides a complete software ecosystem: a preemptive kernel, a dynamic ELF loader, a FAT file system, a multitasking USB stack, a graphical engine with Unicode support, and an interactive shell — all written in C and ARM assembly, with no external dependencies.

welcome

Kernel

  • Preemptive, priority-based multitasking scheduler (fixed-priority, O(1) selection via CLZ)
  • Trusted Execution Environment (TEE) using the Cortex-M7 MPU:
    • Handler mode (privileged): full access to protected memory and system resources
    • Thread mode (privileged): used by kernel and system tasks — full memory access, unrestricted use of protected instructions (MSR/MRS on BASEPRI, etc.)
    • Thread mode (unprivileged): used by user applications — restricted memory access enforced by the MPU; 
  • Synchronization primitives: mutex (with priority inheritance), semaphore, event flags, mailbox
  • Fixed-size memory pools, no variable-size dynamic allocation, eliminating heap fragmentation entirely
  • Synchronous and asynchronous callback execution system
  • Structured fault handling: HardFault, MemFault, BusFault, UsageFault, stack overflow detection

Dynamic ELF Loader

Mk can load and execute external ".elf" files at runtime, relocated into 64 KB pages of external
SDRAM. Programs reference Mk's own API symbols directly. The full kernel symbol table
is embedded in the firmware at a fixed address, so external applications require no copy of the
kernel API in their own binary. Shared libraries can be added to overcome the 64 KB page limit.

See the sym2srec tool for details on the symbol embedding mechanism.

File System

  • FAT32 with multi-partition support
  • Concurrent access from multiple tasks (per-volume mutex)
  • Full API: open, close, read, write, seek, tell, eof, stat, rename, unlink, chmod, expand, truncate, directory browsing
  • Supports SD/MMC cards and USB Mass Storage Class (MSC) devices

USB Stack

  • Multitasking USB host stack built on the STM32F7 OTG peripheral
  • Supported device classes: HUB, HID (keyboard, mouse, joystick, gamepad), MSC
  • Designed for extensibility, new device classes can be added without modifying the core stack

Graphical Engine

  • Hardware-accelerated 2D rendering via the Cortex-M7 ChromART (DMA2D) unit
  • Drawing primitives: rectangles, circles, lines, ...
  • Image rendering: BMP 24-bit and 32-bit
  • Full Unicode text rendering: ASCII, UTF-8, UTF-16, UTF-32
  • Font manager: native fonts stored in FLASH or QSPI; additional fonts can be loaded at runtime into RAM
  • UI object library: buttons, text fields, edit fields, progress bars, 2D graphs, cursors, layers
  • Event-driven application model: painting callbacks and input-listening callbacks
  • Screenshot capability

Shell

The system includes a built-in interactive shell supporting both native and dynamically loaded commands, allowing users to navigate directories (ls, cd, pwd), list mounted disks (lsdsk), and fully manage external applications (launch, install, uninstall, terminate, getapps).

Architecture

Mk follows a three-layer architecture:

  • Foundation: It manages hardware peripherals (STM32F7), handles kernel execution (scheduler, mutexes, etc.), and provides low-level BSP drivers.
  • Subsystems: It delivers system-wide services including a custom hardware-accelerated graphics engine, a dynamic ELF loader, a FAT file system, and a USB stack.
  • System Platform: It runs high-level applications like the Supervisor (fault management), the Home screen, and the Shell.

Video Demonstration

For a complete overview of the system booting, the shell interaction, and dynamic application loading, watch the full video

Mk

  • 1 × 32F746GDISCOVERY or STM32746G-EVAL Discovery/Eval kit with STM32F746NG MCU
  • 1 × J-Link Pro Debug probe with USB and Ethernet interfaces

  • 1
    Build, Flash, and Debug Instructions

    Detailed step-by-step instructions for setting up the toolchain, configuring the build options, flashing the generated firmware, and initiating a debug session can be found in my github

View all instructions

Enjoy this project?

Share

Discussions

Does this project spark your interest?

Become a member to follow this project and never miss any updates