Abstract
Embedded platforms with heterogeneous architecture consist of one primary and one or more secondary processors. Development of software systems for these platforms poses substantial difficulties, requiring a distinct set of tools for each constituent of the heterogeneous system. This work presents a C-like metaprogramming DSL and a library that provides a unified interface for programming secondary processors. The DSL is embedded in C++ and utilizes generative programming to compose low-level DSL code using high-level C++ constructs. By employing dynamic compilation via LLVM, the system enables runtime code optimizations, such as function specialization. The library architecture allows for simple extensibility to various target platforms, as demonstrated through system approbation on multiple hardware setups.
Introduction
Modern embedded systems are increasingly heterogeneous, combining a powerful primary processor (e.g., an ARM-based host) with low-power secondary microcontrollers (e.g., STM32) for real-time tasks. Traditionally, this architecture forces developers into "toolchain hell," requiring separate IDEs, compilers, and complex communication protocols for each chip. Furthermore, static firmware often lacks the flexibility to adapt to runtime environment changes without significant manual reconfiguration.
To address these challenges, we propose a unified library and an embedded Domain Specific Language (DSL) that allows developers to program both primary and secondary processors within a single C++ environment. This approach leverages dynamic compilation to optimize code for specific hardware conditions at runtime.
System Architecture
The library is designed as a modular framework that abstracts the complexities of cross-platform development and communication.
As shown in the architecture diagram, the system is divided into several key subsystems:
- DSL Module: Provides the C++ embedded language constructs (
Function,Value,Expr) used to build the program logic. - LLVM & CodeGen: Translates the DSL into LLVM Intermediate Representation (IR) and subsequently into native object code (
ObjCode) for the target architecture. - Memory Management: The
MemoryManagerallows the host to manage the target's memory space, handlingMemResidentobjects and global variables. - Connection Module: Abstracted via the
Connectioninterface, this module handles the physical transport layer (e.g., TCP, Serial, or USB) without requiring changes to the application logic.
Generative Programming and Dynamic Optimization
The DSL uses C++17 templates and generic lambdas to build an Abstract Syntax Tree (AST) of the program logic. Because the host translates this DSL into LLVM IR at runtime, it can perform "specialization." For example, if a PID controller coefficient is determined at runtime to be a specific constant, the compiler can replace expensive floating-point multiplications with faster integer bit-shifts or immediate-value operations.
This host-driven approach also simplifies memory management. By letting the more powerful primary processor manage the target's memory, the secondary microcontrollers are freed from the overhead of dynamic allocation, leading to more predictable real-time performance.
Evaluation and Results
The system was evaluated across four distinct hardware configurations, including x86 Linux hosts and ARM-based targets (Odroid XU4 and STM32F429i).
Key findings include:
- Code Efficiency: Qualitative analysis of generated LLVM IR for a PID controller showed fewer memory accesses compared to traditional static approaches. Specializing coefficients as constants allowed the LLVM backend to optimize mathematical operations significantly.
- Portability: The same DSL source code was successfully deployed across different architectures (x86 and ARM), proving the effectiveness of the LLVM-based abstraction layer.
- Reduced Overhead: The unified interface eliminated the need for manual synchronization between disparate toolchains, streamlining the development workflow.
Conclusion and Future Work
This library provides a powerful framework for programming heterogeneous systems by combining the expressive power of C++ with the optimization capabilities of LLVM. While currently limited by the lack of external library support and some missing language constructs (like switch statements), it establishes a foundation for more automated orchestration across clusters of microcontrollers. Future work will focus on expanding the DSL's feature set and implementing integrated debugging tools for the generated code.
Summary updated