flash-jlink

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

J-Link 烧录

J-Link Firmware Flashing

适用场景

Applicable Scenarios

  • 工作区已有可用固件产物,且目标板连接了 SEGGER J-Link 探针。
  • 需要使用 J-Link Commander 进行烧录和校验,而非 OpenOCD。
  • 需要利用 J-Link RTT(Real-Time Transfer)进行高速日志捕获。
  • 需要扫描工作区中的
    .jlink
    配置文件或
    .vscode/launch.json
    中的 J-Link 设置。
  • A usable firmware artifact exists in the workspace, and the target board is connected to a SEGGER J-Link probe.
  • Need to use J-Link Commander for flashing and verification instead of OpenOCD.
  • Need to use J-Link RTT (Real-Time Transfer) for high-speed log capture.
  • Need to scan
    .jlink
    configuration files in the workspace or J-Link settings in
    .vscode/launch.json
    .

必要输入

Required Inputs

  • 固件产物路径,或包含
    artifact_path
    Project Profile
  • --device
    参数指定目标芯片型号(如
    STM32F407VG
    ),J-Link Commander 要求必须指定。
  • 可选的接口类型(SWD 或 JTAG,默认 SWD)和烧录速度。
  • 若产物为 BIN,还需要
    --base-address
    烧录基地址。
  • Firmware artifact path, or a
    Project Profile
    containing
    artifact_path
    .
  • The
    --device
    parameter to specify the target chip model (e.g.,
    STM32F407VG
    ), which is required by J-Link Commander.
  • Optional interface type (SWD or JTAG, default is SWD) and flashing speed.
  • If the artifact is a BIN file, the
    --base-address
    flashing base address is also required.

自动探测

Auto Detection

  • ELF > HEX > BIN
    选择固件产物。
  • 脚本自动查找 JLinkExe,按配置文件、PATH、常见安装路径的顺序搜索。
  • --scan-configs
    扫描工作区
    .jlink
    文件和
    .vscode/launch.json
    中的 J-Link 配置。
  • 不会猜测设备名;当
    --device
    缺失时阻塞并返回
    ambiguous-context
  • Select firmware artifacts in the order of
    ELF > HEX > BIN
    .
  • The script automatically searches for JLinkExe in the order of configuration files, PATH, and common installation paths.
  • --scan-configs
    scans J-Link configurations in workspace
    .jlink
    files and
    .vscode/launch.json
    .
  • Does not guess device names; blocks and returns
    ambiguous-context
    when
    --device
    is missing.

执行步骤

Execution Steps

  1. 先阅读 references/usage.md,确认本次是环境探测、配置扫描,还是执行烧录。
  2. 若不确定 J-Link 环境状态,先运行自带脚本 scripts/jlink_flasher.py
    --detect
    模式确认。
  3. 若不确定设备型号或接口配置,使用
    --scan-configs
    扫描工作区线索。
  4. 使用
    --artifact
    +
    --device
    执行烧录,可选
    --interface
    --speed
  5. 对 BIN 文件,必须同时提供
    --base-address
  6. 需要 RTT 日志时,使用
    --rtt
    启动 RTT 捕获。
  7. 读取脚本输出的烧录结果报告,重点关注校验状态和失败分类。
  1. First read references/usage.md to confirm whether this is environment detection, configuration scanning, or flashing execution.
  2. If unsure about the J-Link environment status, first run the built-in script scripts/jlink_flasher.py in
    --detect
    mode to confirm.
  3. If unsure about the device model or interface configuration, use
    --scan-configs
    to scan for clues in the workspace.
  4. Use
    --artifact
    +
    --device
    to execute flashing, with optional
    --interface
    and
    --speed
    .
  5. For BIN files,
    --base-address
    must be provided at the same time.
  6. When RTT logs are needed, use
    --rtt
    to start RTT capture.
  7. Read the flashing result report output by the script, focusing on verification status and failure categories.

失败分流

Failure Handling

  • JLinkExe
    不可用时,返回
    environment-missing
  • 当无法安全解析到产物,或
    BIN
    缺少烧录基地址时,返回
    artifact-missing
  • 当 J-Link 无法发现探针或目标时,返回
    connection-failure
  • 当配置文件无效或设备名不被 J-Link 识别时,返回
    project-config-error
  • 当烧录开始但校验或复位失败时,返回
    target-response-abnormal
  • --device
    缺失且无法从工作区推断时,返回
    ambiguous-context
  • Returns
    environment-missing
    when JLinkExe is unavailable.
  • Returns
    artifact-missing
    when the artifact cannot be safely resolved or the BIN file lacks a flashing base address.
  • Returns
    connection-failure
    when J-Link cannot detect the probe or target.
  • Returns
    project-config-error
    when the configuration file is invalid or the device name is not recognized by J-Link.
  • Returns
    target-response-abnormal
    when flashing starts but verification or reset fails.
  • Returns
    ambiguous-context
    when
    --device
    is missing and cannot be inferred from the workspace.

平台说明

Platform Notes

  • JLinkExe 在 Linux/macOS 下为
    JLinkExe
    ,Windows 下为
    JLink.exe
  • SEGGER 默认安装路径:Linux
    /opt/SEGGER/JLink/
    ,Windows
    C:\Program Files\SEGGER\JLink\
  • 自带脚本使用 Python 标准库和 subprocess 调用 JLinkExe,跨平台兼容。
  • RTT 功能为 J-Link 独有,不占用 UART,适合无串口场景。
  • JLinkExe is
    JLinkExe
    on Linux/macOS, and
    JLink.exe
    on Windows.
  • Default SEGGER installation paths:
    /opt/SEGGER/JLink/
    for Linux,
    C:\Program Files\SEGGER\JLink\
    for Windows.
  • The built-in script uses Python standard libraries and subprocess to call JLinkExe, which is cross-platform compatible.
  • The RTT function is exclusive to J-Link, does not occupy UART, and is suitable for scenarios without a serial port.

输出约定

Output Conventions

  • 输出 JLinkExe 命令、设备名、接口类型、产物路径和校验结果。
  • Project Profile
    中保留或更新
    artifact_path
    artifact_kind
    jlink_device
    jlink_interface
  • 烧录成功后推荐
    serial-monitor
    debug-jlink
  • Outputs JLinkExe command, device name, interface type, artifact path, and verification result.
  • Retains or updates
    artifact_path
    ,
    artifact_kind
    ,
    jlink_device
    ,
    jlink_interface
    in the
    Project Profile
    .
  • serial-monitor
    or
    debug-jlink
    is recommended after successful flashing.

交接关系

Handover Relationships

  • 当下一步要看运行日志时,将成功烧录结果交给
    serial-monitor
  • 当用户需要 GDB 调试时,将结果交给
    debug-jlink
  • 当需要 RTT 日志替代串口时,可直接使用本 skill 的
    --rtt
    模式。
  • When needing to view runtime logs next, pass the successful flashing result to
    serial-monitor
    .
  • When the user needs GDB debugging, pass the result to
    debug-jlink
    .
  • When RTT logs are needed instead of serial ports, the
    --rtt
    mode of this skill can be used directly.