
build-keil
PopularUse when you need to build embedded projects via the Keil MDK command line, calling bundled scripts to parse project files, execute builds, and locate firmware artifacts.
975stars
164forks
Updated 8/20/2026
Related Skills
SKILL.md
read-only
name
build-keil
description
Use when you need to build embedded projects via the Keil MDK command line, calling bundled scripts to parse project files, execute builds, and locate firmware artifacts.
Build Keil MDK Project
Applicable Scenarios
- The
Project Profilespecifiesbuild_system: keilor.uvprojx/.uvprojfiles exist in the workspace. - The user wants to build, rebuild, or verify firmware artifacts for a Keil MDK project.
- The flashing or debugging workflow requires a new
AXF(ELF),HEX, orBINfile. - Need to verify whether the Keil MDK environment is ready (UV4.exe, ARMCC/ARMCLANG) before building.
Required Inputs
- Workspace path,
.uvprojx/.uvprojproject file path, or an existingProject Profile. - Optional build target name, UV4.exe path, and log output path.
Automatic Detection
- Upon startup, the script automatically reuses the last successful profile from
.em_skill.jsonin the project root as default parameters (explicit parameters take precedence; manual--resumeis not required).--resumeis used only to assert that the cache must exist, exiting non-zero if missing. If there is no cache or the user explicitly requests a re-scan, the script automatically falls back to standard scanning. - The script automatically searches common Keil MDK installation paths and environment variables (
KEIL_ROOT,MDK_ROOT) to locate UV4.exe. - Parses the Target list in
.uvprojxproject files, extracting target MCU models, output directories, and toolchains (ARMCC/ARMCLANG). - If no target is specified, the first Target in the project is used by default.
- Searches the output directory for AXF, HEX, and BIN artifacts, ordered by
ELF > HEX > BIN. - If multiple equally plausible project files or targets exist, candidates are listed rather than silently guessed.
Execution Steps
- Read references/usage.md first to determine whether this run is for environment detection, project scanning, listing targets, or executing a build.
- For common single-project, single-target scenarios, prefer a single invocation to complete detection + build:
This starts only one Python process, avoiding the overhead of three serial calls (python scripts/keil_builder.py --detect --project <project_file> --target <target_name>--detect→--list-targets→--build). - Execute
--scanand--list-targetsstep-by-step only when interactive selection is required (multiple project files or targets needing user confirmation). - Read the build results and artifact scan report output by the script, focusing on preferred artifacts (AXF/ELF > HEX > BIN), error/warning statistics, and failure classifications.
- Write the build target, artifact path, target MCU model, and toolchain information back to the
Project Profile, handing them off to downstream skills as needed.
Failure Triage
- Returns
environment-missingwhen Keil MDK is not installed or UV4.exe is unavailable. - Returns
project-config-errorwhen project files are corrupted, target names are invalid, or compilation fails due to configuration issues. - Returns
artifact-missingwhen compilation appears successful but no flashable or debuggable artifact is found. - Returns
ambiguous-contextwhen multiple equally plausible project files or targets exist and making an arbitrary choice is unsafe.
Platform Notes
- Keil MDK runs natively only on Windows; command-line compilation via UV4.exe requires a Windows environment.
- Bundled scripts can still execute project parsing (
--list-targets), project scanning (--scan), and artifact scanning (--scan-artifacts) on non-Windows platforms, but actual compilation will be blocked. - Build logs may contain Chinese characters encoded in GBK; the script automatically attempts multiple encodings.
- Artifact paths in the output should remain absolute paths to allow downstream flashing and debugging skills to reuse them directly.
Output Conventions
After script execution completes, the following key information must be extracted and presented to the user:
- Build status (Success / Failure)
- Project file and target name
- Target MCU model and toolchain (e.g., STM32F103RC [ARMCC])
- Firmware size details (Code, RO-data, RW-data, ZI-data) and Flash/RAM summary
- Build elapsed time
- Artifact list (AXF/HEX/BIN and file sizes)
- Error/Warning counts
- If failed: Failure classification and log evidence
Example output format:
Build Succeeded ✅
Project: Demo02.uvprojx → Target: Demo02
MCU: STM32F103RC | Toolchain: ARMCC
Firmware Size: Flash ≈ 3.2 KB RAM ≈ 1.6 KB
Artifacts: Demo02.axf (518.9 KB), Demo02.hex (9.0 KB)
Time Elapsed: 00:00:05
- Update
Project Profilewithartifact_path,artifact_kind,target_mcu, andtoolchain. - Upon success, recommend
flash-keil,flash-openocd, ordebug-gdb-openocd.
Hand-off Relationships
- When the next intent is flashing hardware, pass successful build results to
flash-keil(using Keil's built-in debugger) orflash-openocd(using OpenOCD). - When the next intent requires symbol information or a debug session, pass successful build results to
debug-gdb-openocd.





