Automated Code Generation and Validation for Software Components of Microcontrollers
Sebastian Haug, Christoph Böhm, Daniel Mayer
TL;DR
This work presents an end-to-end pipeline for autonomous HAL code generation for embedded microcontrollers by combining AST-based code analysis with Retrieval-Augmented Generation. Targeting STM32F407 GPIO operations, it automatically detects and fills missing HAL elements and validates them through compile-time checks and hardware emulation in Renode. Results show accurate, context-aware code generation that integrates into existing projects, with robustness across regeneration scenarios and iterative testing. The approach offers a path toward reducing manual low-level firmware development and enabling scalable, hardware-aware software generation for embedded systems.
Abstract
This paper proposes a method for generating software components for embedded systems, integrating seamlessly into existing implementations without developer intervention. We demonstrate this by automatically generating hardware abstraction layer (HAL) code for GPIO operations on the STM32F407 microcontroller. Using Abstract Syntax Trees (AST) for code analysis and Retrieval-Augmented Generation (RAG) for component generation, our approach enables autonomous code completion for embedded applications.
