modm
2025q3Features
-
Object-oriented C++23 API designed for high performance and low memory overhead.
-
Modular HAL generation using the lbuild data-driven code generator for over 3,800 microcontrollers.
-
Support for multiple vendors including STMicroelectronics (STM32), Microchip (SAM, AVR), and Raspberry Pi (RP2040).
-
Build system agnostic design supporting CMake, SCons, and Makefiles.
-
Zero-allocation HAL implementation to minimize RAM consumption in deeply embedded systems.
-
Cross-platform peripheral interfaces for GPIO, ADC, DAC, UART, I2C, SPI, CAN, and Ethernet.
-
Integrated cooperative, stackful fibers and a lightweight task scheduler.
-
Target-independent drivers for a wide range of external I2C and SPI sensors and devices.
-
Debug and logging system providing IOStream and printf-compatible interfaces.
-
Functional partial libstdc++ implementation specifically optimized for AVR architectures.
-
Integration with FreeRTOS and FreeRTOS+TCP for real-time multitasking and networking.
-
Native support for TinyUSB stack for both host and device roles.
-
Support for FatFS to enable FAT/exFAT filesystem operations on block devices.
-
Integration with LVGL for building embedded graphical user interfaces.
-
Support for Nanopb to handle Protocol Buffers in memory-constrained environments.
-
Built-in lightweight unit testing system suitable for execution on 8-bit AVRs.
-
Crash reporting via CrashCatcher for debugging HardFaults on ARM Cortex-M.
-
Support for Segger Real-Time Transport (RTT) for high-speed logging.
Architecture
modm follows a modular, data-driven architectural pattern centered around the lbuild code generator. Unlike traditional static libraries, modm generates a custom library instance tailored specifically to the target microcontroller and project requirements. The architecture is layered to provide maximum portability while maintaining hardware-specific optimizations. At the lowest level, the library generates startup code and a Hardware Abstraction Layer (HAL) that provides a unified C++23 interface for peripherals like GPIO, UART, and SPI across different vendors.
Above the HAL, modm provides target-independent drivers for external components (sensors, displays, etc.) and high-level communication protocols. A key architectural principle is the avoidance of dynamic memory allocation within the HAL, ensuring predictable RAM consumption. The system also includes a cooperative multitasking layer based on stackful fibers, allowing for complex asynchronous logic without the overhead of a full preemptive RTOS, though integration with FreeRTOS is provided for more demanding applications.
Use Cases
This library is ideal for:
- Autonomous Robotics: Specifically optimized for high-reliability requirements in competitions like Eurobot where predictable program flow is critical.
- Resource-Constrained Devices: Ideal for 8-bit AVR and small ARM Cortex-M0+ devices where low RAM and flash consumption are paramount.
- Cross-Platform Development: Projects that need to maintain a single codebase across different microcontroller families (e.g., STM32 and SAM).
- Rapid Prototyping: Developers using supported development boards (Nucleo, Discovery, Arduino) who need a high-level C++ API without sacrificing performance.
- Industrial Communication: Applications requiring robust CAN, CAN-FD, or Ethernet stacks with integrated third-party networking libraries.
- Embedded GUI Development: Systems requiring graphical interfaces via LVGL integration on various display controllers.
Getting Started
To begin using modm, developers must clone the repository recursively to include all necessary submodules: git clone --recurse-submodules https://github.com/modm-io/modm.git. The library relies on the lbuild tool to generate the specific library files for your target; this process involves creating a project configuration file that specifies the microcontroller and required modules.
Comprehensive documentation, including installation guides for the required toolchains and a detailed “Discover” guide, is available at modm.io. The repository also contains hundreds of up-to-date examples for various architectures and development boards, which serve as the primary reference for implementing peripheral drivers and third-party integrations.
Related Projects (5)
modm-devices: Curated Microcontroller Device Data
A comprehensive repository of curated data for AVR, STM32, SAM, and NRF52 microcontrollers. It provides tools to extract, patch, and reformat vendor-specific data into a unified format for generating Hardware Abstraction Layers (HAL) and startup code.
ARUW Main Control Board (MCB)
The ARUW Main Control Board (MCB) is the central firmware repository for the University of Washington's RoboMaster competition robots. It leverages the modm C++ HAL and the Taproot controls framework to manage complex systems including chassis drive, turret stabilization, and launcher mechanisms on the RoboMaster Development Board Type A.
CMSIS Device Headers for Microchip SAM
A collection of CMSIS-compliant device header files for Microchip SAM microcontrollers, including SAMD21, SAMD51, and SAME51 families. These headers are sourced from official Microchip device packs and processed for better compatibility with Unix-based development environments.
CMSIS Device Headers for STM32
A comprehensive collection of CMSIS device headers for the entire STM32 microcontroller family, maintained by the modm-io project. These headers are sourced from official STM32Cube libraries and normalized for cross-platform development by converting line endings to Unix style and removing trailing whitespace.