cancel
Showing results for 
Search instead for 
Did you mean: 

Bare-Metal OS for STM32F746 with Dynamic ELF Loader

EmbSoft3
Visitor

 

1000031323.bmp

Hi everyone,

I wanted to share a project I’ve been building over the last few years. It’s called Mk, an operating system built entirely from scratch for the STM32F746G-DISCO and STM32F746G-Eval2 boards.

These boards are powered by an ARM Cortex-M7 running at 216MHz. Initially, my goal was just to implement a small scheduler, but I stacked layers one after another to make it as complete as possible. Currently, I think I've added enough layers to claim it as a functional, lightweight OS.

Mk features:

A Kernel

  • Preemptive, priority-based multitasking scheduler (fixed-priority, O(1) selection via hardware CLZ instruction)
  • Trusted Execution Environment (TEE) using the Cortex-M7 MPU (privileged and unprivileged mode isolation)
  • Synchronization primitives: mutex, semaphore, event flags, mailbox
  • Fixed-size memory pools
  • Synchronous and asynchronous callback execution system

A Dynamic ELF Loader Mk can load and execute external .elf binaries at runtime, relocated dynamically into 64 KB pages of the external SDRAM. Programs reference Mk's own API symbols directly via extern . The full kernel symbol table is embedded in the firmware at a fixed address meaning external applications require no copy of the kernel API in their own binary. See the sym2srec tool for details on the symbol embedding mechanism.

A File System

  • FAT32 with multi-partition support
  • Concurrent access management from multiple tasks (per-volume mutex)
  • Full POSIX-like API for file and directory manipulation
  • Supports SD/MMC cards and USB Mass Storage Class (MSC) devices

A USB Stack

  • Multitasking USB host stack built directly on the STM32F7 OTG peripheral
  • Supported device classes: HUB, HID (keyboard, mouse, joystick, gamepad), MSC

A Graphics Engine

  • Hardware-accelerated 2D rendering pipeline using the LTDC and ChromART (DMA2D) accelerators
  • Drawing primitives (rectangles, circles, lines, arcs), BMP 24/32-bit image rendering
  • Full Unicode text rendering (UTF-8/16/32)
  • UI widget library: buttons, text fields, edit fields, graphs, cursors, layers

A Shell Built-in interactive shell with support for both native and dynamically loaded commands.


Codebase & Links

For those who'd like to dig into how it works, here are the key files and entry points:

Boot sequence: The system enters the assembly ResetHandler() routine. The system is then initialized in mk_system_init(), which calls mk_main(), responsible for launching the kernel and all other subsystems.

Kernel core: The kernel lives under these sources and includes directories. Every system call is dispatched through the SVC exception, handled in mk_scheduler_handle().

Application prototype: A minimal application example can be found here (a simple BlinkLed). It must be paired with a linker script, an application descriptor (mk_application_data) and compiled with the following flags: -fPIC -shared. Symbol resolution at runtime is handled in mk_application_loadDynamic() and in this sources directory. Other example applications can be found here: a Pong game and the built-in Shell.

Graphics Engine: The graphics engine is composed of several tasks that execute painting callbacks, input-listening callbacks, and process drawing requests submitted by applications. Each module is isolated and interactions between components go through asynchronous requests. The rendering pipeline entry point is mk_display_painter(), the listening entry point is mk_display_listener() and the request manager entry point is mk_display_handler().

File System: The file system layer is handled by multiple tasks running in parallel. One dedicated task is responsible for managing concurrent accesses to a given file. Each access is performed through synchronous or asynchronous requests, handled in mk_file_handle().

An early version of the documentation can be found here.

I hope you find this project interesting! I'd be happy to answer any questions or discuss any part of the low-level implementation.

Thanks for reading!

0 REPLIES 0