keil
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseKeil MDK 工程构建
Keil MDK Project Build
本 skill 提供 Keil MDK 工程的发现、Target 枚举、构建、重建、清理能力,并返回可供 继续使用的固件产物路径。 仅作为兼容入口保留。
jlink/openocdflashThis skill provides discovery, Target enumeration, build, rebuild, and clean capabilities for Keil MDK projects, and returns firmware artifact paths that can be used by . is only retained as a compatibility entry.
jlink/openocdflash配置
Configuration
环境级配置(skill/config.json)
Environment-level Configuration (skill/config.json)
skill 目录下的 包含环境级配置,首次使用前确认 路径正确:
config.jsonuv4_exejson
{
"uv4_exe": "C:\\Keil_v5\\UV4\\UV4.exe",
"operation_mode": 1
}- :UV4.exe 完整路径(必填)
uv4_exe - :
operation_mode直接执行 /1输出风险摘要但不阻塞 /2执行前确认3
The in the skill directory contains environment-level configurations. Before first use, confirm that the path is correct:
config.jsonuv4_exejson
{
"uv4_exe": "C:\\Keil_v5\\UV4\\UV4.exe",
"operation_mode": 1
}- : Full path of UV4.exe (required)
uv4_exe - :
operation_modeExecute directly /1Output risk summary without blocking /2Confirm before execution3
工程级配置(workspace/.embeddedskills/config.json)
Project-level Configuration (workspace/.embeddedskills/config.json)
工程级共享配置统一保存在工作区的 中:
.embeddedskills/config.jsonjson
{
"keil": {
"project": "",
"target": "",
"log_dir": ".embeddedskills/build"
}
}- :默认工程路径(相对 workspace),构建成功后会自动更新
project - :默认 Target 名称,构建成功后会自动更新
target - :构建日志输出目录,默认
log_dir.embeddedskills/build
Project-level shared configurations are uniformly stored in in the workspace:
.embeddedskills/config.jsonjson
{
"keil": {
"project": "",
"target": "",
"log_dir": ".embeddedskills/build"
}
}- : Default project path (relative to workspace), which will be automatically updated after successful build
project - : Default Target name, which will be automatically updated after successful build
target - : Build log output directory, default is
log_dir.embeddedskills/build
参数解析优先级
Parameter Parsing Priority
参数解析顺序(从高到低):
- CLI 显式参数
- 环境级配置(skill/config.json)
- 工程级配置(.embeddedskills/config.json)
- (上次构建记录)
.embeddedskills/state.json - 搜索/询问
Parameter parsing order (from highest to lowest):
- Explicit CLI parameters
- Environment-level configuration (skill/config.json)
- Project-level configuration (.embeddedskills/config.json)
- (last build record)
.embeddedskills/state.json - Search/query
子命令
Subcommands
| 子命令 | 用途 | 风险 |
|---|---|---|
| 搜索当前目录下的 .uvprojx/.uvmpw 工程 | 低 |
| 枚举工程中的 Target | 低 |
| 增量编译 | 中 |
| 全量重建 | 中 |
| 清理工程 | 高 |
| 通过 Keil 烧录固件(兼容入口,优先建议使用 jlink/openocd) | 高 |
| Subcommand | Purpose | Risk |
|---|---|---|
| Search for .uvprojx/.uvmpw projects in the current directory | Low |
| Enumerate Targets in the project | Low |
| Incremental compilation | Medium |
| Full rebuild | Medium |
| Clean the project | High |
| Flash firmware via Keil (compatibility entry, priority recommendation to use jlink/openocd) | High |
执行流程
Execution Flow
- 读取 ,确认
config.json路径有效uv4_exe - 未指定子命令时默认执行
scan - 未提供工程路径时先执行 搜索工程
scan - 同时发现多个工程或多个 Target 时,列出选项让用户选择,绝不自动猜测
- 按
build/rebuild/clean决定是否需要确认operation_mode - 成功后,尽量从工程配置中解析
build/rebuild/flash_file等产物路径debug_file - 仅在最近一次构建成功时允许执行
flash - 所有构建命令输出到日志文件后解析,返回结构化结果
- Read and confirm that the
config.jsonpath is validuv4_exe - Default to executing when no subcommand is specified
scan - Execute to search for projects first if no project path is provided
scan - List options for users to choose when multiple projects or multiple Targets are found simultaneously, never guess automatically
- decide whether confirmation is needed according to
build/rebuild/cleanoperation_mode - After successful , try to parse artifact paths such as
build/rebuild/flash_filefrom project configurations as much as possibledebug_file - is only allowed to execute when the last build was successful
flash - All build commands are output to log files and then parsed, returning structured results
脚本调用
Script Invocation
skill 目录下有两个 Python 脚本,使用标准库实现,无额外依赖。
There are two Python scripts in the skill directory, implemented using standard libraries with no additional dependencies.
keil_project.py — 工程扫描与 Target 枚举
keil_project.py — Project Scanning and Target Enumeration
bash
undefinedbash
undefined扫描工程
Scan projects
python <skill-dir>/scripts/keil_project.py scan --root <搜索目录> --json
python <skill-dir>/scripts/keil_project.py scan --root <search directory> --json
枚举 Target
Enumerate Targets
python <skill-dir>/scripts/keil_project.py targets --project <工程路径> --json
undefinedpython <skill-dir>/scripts/keil_project.py targets --project <project path> --json
undefinedkeil_build.py — 构建 / 重建 / 清理 / 烧录
keil_build.py — Build / Rebuild / Clean / Flash
bash
python <skill-dir>/scripts/keil_build.py <build|rebuild|clean|flash> \
--uv4 <UV4路径> \
--project <工程路径> \
--target <TargetName> \
--log-dir <日志目录> \
--jsonrebuild--clean-first-cr-rbash
python <skill-dir>/scripts/keil_build.py <build|rebuild|clean|flash> \
--uv4 <UV4 path> \
--project <project path> \
--target <TargetName> \
--log-dir <log directory> \
--jsonrebuild--clean-first-cr-r输出格式
Output Format
所有脚本以 JSON 格式返回,基础字段为 (ok/error)、、、,并可能附带 、、、、、。
statusactionsummarydetailscontextartifactsmetricsstatenext_actionstiming成功示例:
json
{
"status": "ok",
"action": "build",
"summary": "build 成功,errors=0 warnings=2",
"details": {
"project": "project.uvprojx",
"target": "Debug",
"log_file": ".build/project-Debug-build.log",
"flash_file": "Objects/project.hex",
"debug_file": "Objects/project.axf"
},
"metrics": { "errors": 0, "warnings": 2, "flash_bytes": 32768, "ram_bytes": 8192 }
}错误示例:
json
{
"status": "error",
"action": "flash",
"error": { "code": "build_not_clean", "message": "最近一次构建存在错误,禁止继续烧录" }
}All scripts return results in JSON format. The basic fields are (ok/error), , , , and may also include , , , , , .
statusactionsummarydetailscontextartifactsmetricsstatenext_actionstimingSuccess Example:
json
{
"status": "ok",
"action": "build",
"summary": "build succeeded, errors=0 warnings=2",
"details": {
"project": "project.uvprojx",
"target": "Debug",
"log_file": ".build/project-Debug-build.log",
"flash_file": "Objects/project.hex",
"debug_file": "Objects/project.axf"
},
"metrics": { "errors": 0, "warnings": 2, "flash_bytes": 32768, "ram_bytes": 8192 }
}Error Example:
json
{
"status": "error",
"action": "flash",
"error": { "code": "build_not_clean", "message": "The last build had errors, flashing is prohibited" }
}核心规则
Core Rules
- 不修改工程配置文件(.uvprojx / .uvmpw / .uvoptx)
- 不自动猜测工程路径或 Target,有歧义时必须询问用户
- 参数解析优先级详见上方"参数解析优先级"章节
- 构建成功后优先使用返回的 /
flash_file与debug_file串联jlink/openocd - 前必须确认最近一次构建成功(errors == 0)
flash - 不在自动流程中隐式执行
clean - 构建失败时优先展示首个错误和日志文件路径
- 结果回显中始终包含工程名、Target 名、日志路径;若识别到产物路径也要回显
- Do not modify project configuration files (.uvprojx / .uvmpw / .uvoptx)
- Do not automatically guess project paths or Targets; must ask users when there is ambiguity
- Refer to the "Parameter Parsing Priority" section above for parameter parsing priority
- After successful build, prioritize using the returned /
flash_fileto integrate withdebug_filejlink/openocd - Must confirm that the last build was successful (errors == 0) before executing
flash - is not implicitly executed in automatic processes
clean - When build fails, prioritize displaying the first error and log file path
- The result echo always includes the project name, Target name, and log path; if artifact paths are identified, they should also be echoed
参考
References
遇到编译器相关问题时可查阅 。
references/compiler-notes.mdFor compiler-related issues, refer to .
references/compiler-notes.md