flash-keil

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Keil MDK 烧录

Keil MDK Flashing

适用场景

Applicable Scenarios

  • Project Profile
    中标明
    build_system: keil
    或工作区中存在
    .uvprojx
    /
    .uvproj
    文件。
  • 用户希望将编译产物烧录到目标板,且工程已在 Keil 中配置好调试器(ST-Link、J-Link、CMSIS-DAP 等)。
  • 不需要额外安装 OpenOCD,直接使用 Keil MDK 内置的 Flash Download 功能。
  • Project Profile
    indicates
    build_system: keil
    or there are
    .uvprojx
    /
    .uvproj
    files in the workspace.
  • Users want to flash compiled products to the target board, and the debugger (ST-Link, J-Link, CMSIS-DAP, etc.) has been configured in Keil for the project.
  • No need to install additional OpenOCD; directly use the built-in Flash Download function of Keil MDK.

必要输入

Required Inputs

  • .uvprojx
    /
    .uvproj
    工程文件路径(或从
    Project Profile
    获取)。
  • 可选的构建目标名称和 UV4.exe 路径。
  • Path to the
    .uvprojx
    /
    .uvproj
    project file (or obtained from
    Project Profile
    ).
  • Optional build target name and UV4.exe path.

自动探测

Automatic Detection

  • 复用
    build-keil
    的 UV4.exe 探测逻辑(配置文件 → 环境变量 → 常见路径 → PATH)。
  • 解析工程 XML 中的
    <DriverSelection>
    识别调试器类型(ST-Link、J-Link、CMSIS-DAP、ULINK)。
  • 若未指定目标,默认使用工程中的第一个 Target。
  • Reuse the UV4.exe detection logic of
    build-keil
    (configuration 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, the first Target in the project is used by default.

执行步骤

Execution Steps

  1. 先阅读 references/usage.md,确认本次操作。
  2. 对于常见场景,直接一次调用完成探测+烧录:
    bash
    python scripts/keil_flasher.py --detect --flash --project <工程文件> --target <目标名>
  3. 读取脚本输出的烧录结果报告,关注成功/失败状态、调试器类型和日志证据。
  4. 将烧录结果写回
    Project Profile
    ,推荐下一步 skill。
  1. First read references/usage.md to confirm this operation.
  2. For common scenarios, directly complete detection + flashing with one call:
    bash
    python scripts/keil_flasher.py --detect --flash --project <project file> --target <target name>
  3. Read the flashing result report output by the script, focusing on success/failure status, debugger type, and log evidence.
  4. Write the flashing result back to
    Project Profile
    and recommend the next skill.

失败分流

Failure Diversion

  • environment-missing
    :Keil MDK 未安装或 UV4.exe 不可用。
  • connection-failure
    :调试器连接失败(USB 未连接、驱动问题、目标板未上电)。
  • project-config-error
    :工程文件中的 Flash 配置无效或目标名不存在。
  • 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
    : Invalid Flash configuration in the project file or target name does not exist.

平台说明

Platform Notes

  • Keil MDK 烧录仅在 Windows 上支持。
  • 烧录使用工程中已配置的调试器和 Flash 算法,无需额外配置。
  • 烧录日志可能包含 GBK 编码字符,脚本自动处理多种编码。
  • Keil MDK flashing is only supported on Windows.
  • Flashing uses the debugger and Flash algorithm configured in the project, no additional configuration is required.
  • Flashing logs may contain GBK encoded characters, and the script automatically handles multiple encodings.

输出约定

Output Conventions

脚本执行完成后,必须将以下关键信息提取并呈现给用户:
  • 烧录状态(成功/失败)
  • 工程文件和目标名
  • 芯片型号(如 STM32F103RC)
  • 调试器类型(如 ST-Link、J-Link)
  • 烧录固件路径和大小(如 Demo02.axf, 519.6 KB)
  • 烧录完成时间
  • 若失败:失败分类和日志证据
示例输出格式:
烧录成功 ✅
  工程: Demo02.uvprojx → 目标: Demo02
  芯片: STM32F103RC | 调试器: ST-Link
  固件: Demo02.axf (519.6 KB)
  状态: Erase Done → Programming Done → Verify OK → Application running
  • 成功后推荐
    serial-monitor
    (查看串口输出)或
    debug-gdb-openocd
    (在线调试)。
  • 失败时输出失败分类和日志证据,帮助用户定位问题。
After the script is executed, 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:
Flashing succeeded ✅
  Project: Demo02.uvprojx → Target: Demo02
  Chip: STM32F103RC | Debugger: ST-Link
  Firmware: Demo02.axf (519.6 KB)
  Status: Erase Done → Programming Done → Verify OK → Application running
  • After success, recommend
    serial-monitor
    (view serial output) or
    debug-gdb-openocd
    (online debugging).
  • When failed, output the failure category and log evidence to help users locate the problem.

交接关系

Handover Relationships

  • build-keil
    接收编译成功的工程信息。
  • 烧录成功后交给
    serial-monitor
    (查看串口输出)或
    debug-gdb-openocd
    (在线调试)。
  • Receive project information of successful compilation from
    build-keil
    .
  • After successful flashing, hand over to
    serial-monitor
    (view serial output) or
    debug-gdb-openocd
    (online debugging).