Applicable Scenarios
Project Profileis indicated inbuild_system: keilor.uvprojx/.uvprojfile exists in the workspace.- The user wants to flash the build output to the target board, and the project has already been configured with a debugger (ST-Link, J-Link, CMSIS-DAP, etc.) in Keil.
- No additional installation of OpenOCD is required; use the Keil MDK built-in Flash Download feature directly.
Required Inputs
.uvprojx/.uvprojProject file path (or obtained fromProject Profile).- Optional build target name and UV4.exe path.
Automatic Detection
- Upon script startup, automatically reuse the last successful profile in the project root directory
.em_skill.jsonas default parameters (explicit parameters take precedence; no need to manually pass--resume);--resumeis only used to assert that the cache must exist; if there is no cache, exit with a non-zero code. When there is no cache or the user explicitly requests re-detection, the script automatically falls back to a normal scan. - Reuse
build-keil's UV4.exe detection logic (config file → environment variables → common paths → PATH). - Parse
<DriverSelection>in the project XML to identify the debugger type (ST-Link, J-Link, CMSIS-DAP, ULINK). - If no target is specified, use the first Target in the project by default.
Execution Steps
- First read references/usage.mdto confirm this operation.
- For common scenarios, complete detection + flashing in a single call:
python scripts/keil_flasher.py --detect --flash --project <工程文件> --target <目标名> - Read the flashing result report output by the script, focusing on the success/failure status, debugger type, and log evidence.
- Write the flashing result back to
Project Profile, and recommend the next skill.
Failure Triage
environment-missing: Keil MDK is not installed or UV4.exe is unavailable.connection-failure: Debugger connection failed (USB not connected, driver issue, target board not powered on).project-config-error: The Flash configuration in the project file is invalid or the target name does not exist.
Platform Notes
- Keil MDK flashing is supported only on Windows.
- Flashing uses the debugger and Flash algorithm already configured in the project, with no additional configuration required.
- Flashing logs may contain GBK-encoded characters; the script automatically handles multiple encodings.
Output Conventions
After the script finishes executing, the following key information must be extracted and presented to the user:
- Flashing status (success/failure)
- Project file and target name
- Chip model (e.g., STM32F103RC)
- Debugger type (e.g., ST-Link, J-Link)
- Flashed firmware path and size (e.g., Demo02.axf, 519.6 KB)
- Flashing completion time
- If failed: failure category and log evidence
Example output format:
烧录成功 ✅
工程: Demo02.uvprojx → 目标: Demo02
芯片: STM32F103RC | 调试器: ST-Link
固件: Demo02.axf (519.6 KB)
状态: Erase Done → Programming Done → Verify OK → Application running
- On success, recommend
serial-monitor(view serial output) ordebug-gdb-openocd(online debugging). - On failure, output the failure category and log evidence to help the user locate the problem.
Handoff Relationships
- Receive successfully compiled project information from
build-keil. - After successful flashing, hand off to
serial-monitor(view serial output) ordebug-gdb-openocd(online debugging).