
openocd
OpenOCD 下载与调试工具,用于探针探测、固件烧录、Flash 擦除、GDB Server 启动、目标复位控制、 Telnet 在线调试(halt/resume/step/寄存器/内存/断点)、GDB 源码级调试,以及 Semihosting/ITM 输出捕获和底层查询。 当用户提到 OpenOCD、ST-Link、CMSIS-DAP、DAPLink、FTDI、烧录固件、擦除 Flash、GDB Server、 reset、interface/target/board 配置、openocd.cfg、在线调试、单步、断点、寄存器查看、 内存读写、semihosting 时自动触发,也兼容 /openocd 显式调用。 即使用户只是说"烧录一下"、"启动 GDB Server"、"擦除芯片"、"看看寄存器"、"单步调试" 或"抓一下 semihosting",只要上下文涉及 OpenOCD 支持的开源调试器就应触发此 skill。
- Installs
- 673
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/zhinkgit/embeddedskills --skill openocd- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads openocd automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
OpenOCD 下载与调试
本 skill 提供 OpenOCD 的探针探测、固件烧录、Flash 擦除、GDB Server 启动、目标复位、 Telnet 在线调试、GDB 源码级调试和 Semihosting 输出捕获能力。
配置
环境级配置(skill/config.json)
skill 目录下的 config.json 包含环境级配置(工具路径、端口号等),首次使用前确认 exe 路径正确:
{
"exe": "openocd",
"scripts_dir": "",
"gdb_port": 3333,
"telnet_port": 4444,
"gdb_exe": "",
"operation_mode": 1
}
exe:openocd.exe 路径或命令名(必填)scripts_dir:OpenOCD 配置脚本目录,为空时使用 OpenOCD 内置路径gdb_port:GDB Server 端口,默认 3333telnet_port:Telnet 端口,默认 4444gdb_exe:arm-none-eabi-gdb 路径,GDB 调试子命令(run/backtrace/locals)需要operation_mode:1直接执行 /2输出风险摘要但不阻塞 /3执行前确认
工程级配置(.embeddedskills/config.json)
board/interface/target 等工程参数统一在工作区的 .embeddedskills/config.json 中管理:
{
"openocd": {
"board": "",
"interface": "interface/stlink.cfg",
"target": "target/stm32f4x.cfg",
"adapter_speed": "4000",
"transport": "swd",
"tpiu_name": "stm32f4x.tpiu",
"traceclk": "168000000",
"pin_freq": "2000000"
}
}
board:board 配置(如board/stm32f4discovery.cfg),优先级高于 interface+targetinterface:interface 配置(如interface/stlink.cfg)target:target 配置(如target/stm32f4x.cfg)adapter_speed:调试速率 kHztransport:传输协议(swd/jtag)tpiu_name/traceclk/pin_freq:ITM/SWO 观测所需的 TPIU 参数
参数解析优先级:CLI 显式参数 > .embeddedskills/config.json(工程级)> skill/config.json(环境级)> .embeddedskills/state.json > 默认值/报错
成功执行后,确认过的参数会自动写回工程配置。
子命令
基础操作
| 子命令 | 用途 | 风险 |
|---|---|---|
probe | 验证 board 或 interface+target 组合,探测目标连通性 | 低 |
flash | 烧录固件(.elf / .hex / .bin) | 高 |
erase | 擦除目标 Flash | 高 |
reset / reset-init | 复位目标芯片 | 高 |
targets / flash-banks / adapter-info | 查询底层 target / flash / adapter 信息 | 低 |
raw | 执行受控 OpenOCD 原生命令 | 高 |
GDB Server
| 子命令 | 用途 | 风险 |
|---|---|---|
gdb-server | 启动 GDB Server,保持运行等待 GDB 连接 | 低 |
gdb backtrace/locals | 快捷获取调用栈和局部变量 | 低 |
gdb break/continue/next/step/finish/until | one-shot 执行流控制 | 低 |
gdb frame/print/watch/disassemble/threads/crash-report | one-shot 源码级诊断 | 低 |
Telnet 在线调试
| 子命令 | 用途 | 风险 |
|---|---|---|
halt | 暂停 CPU,返回 PC/xPSR | 低 |
resume | 恢复 CPU 运行 | 低 |
step | 单步执行(支持 --count N) | 低 |
reg | 查看所有 CPU 寄存器 | 低 |
read-mem | 读内存(--width 8/16/32,--length N) | 低 |
write-mem | 写内存(--width 8/16/32) | 高 |
bp | 设置硬件断点 | 低 |
rbp | 移除断点 | 低 |
run-to | 运行到指定地址(设置断点 + resume + 等待命中) | 低 |
Semihosting
| 子命令 | 用途 | 风险 |
|---|---|---|
semihosting | 启用 ARM Semihosting 并捕获目标 printf 输出 | 低 |
itm | 基于 TPIU/ITM 读取 SWO/ITM 观测数据 | 低 |
执行流程
- 读取
skill/config.json,确认exe路径有效 - 读取
.embeddedskills/config.json获取工程级配置(board/interface/target 等) - 读取
.embeddedskills/state.json获取历史状态 - 参数解析优先级:CLI 显式参数 >
.embeddedskills/config.json(工程级)>skill/config.json(环境级)>.embeddedskills/state.json> 默认值/报错 - 已知
board时优先使用-f board/*.cfg,否则组合-f interface/*.cfg -f target/*.cfg board、interface、target同时缺失时,不自动拼接组合,直接要求用户补充- 按
operation_mode决定是否需要确认后执行 - 根据子命令调用对应脚本
- 统一解析输出中的
Info、Error和就绪日志,返回结构化结果 - 成功执行后,将确认过的参数写回
.embeddedskills/config.json
脚本调用
skill 目录下有五个 Python 脚本,使用标准库实现,无额外依赖。
openocd_run.py — 探测 / 烧录 / 擦除 / 复位
# 探测连通性(使用 board)
python <skill-dir>/scripts/openocd_run.py probe --board board/stm32f4discovery.cfg --json
# 探测连通性(使用 interface + target)
python <skill-dir>/scripts/openocd_run.py probe --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 烧录 ELF 固件
python <skill-dir>/scripts/openocd_run.py flash --file build/app.elf --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 烧录 BIN 固件(必须提供地址)
python <skill-dir>/scripts/openocd_run.py flash --file build/app.bin --address 0x08000000 --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 擦除 Flash(自动选择 mass/sector)
python <skill-dir>/scripts/openocd_run.py erase --mode auto --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 复位目标
python <skill-dir>/scripts/openocd_run.py reset --mode halt --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 查询 target 列表
python <skill-dir>/scripts/openocd_run.py targets --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 查询 flash bank
python <skill-dir>/scripts/openocd_run.py flash-banks --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 执行受控 raw 命令
python <skill-dir>/scripts/openocd_run.py raw --interface interface/stlink.cfg --target target/stm32f4x.cfg --command "init" "targets" --json
通用可选参数:--board <cfg>、--search <目录>、--adapter-speed <kHz>、--transport <swd|jtag>、--exe <openocd路径>
openocd_gdb.py — GDB Server 启动与调试
# 启动 GDB Server(保持运行)
python <skill-dir>/scripts/openocd_gdb.py server --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 无子命令时默认 server(向后兼容)
python <skill-dir>/scripts/openocd_gdb.py --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 执行自定义 GDB 命令序列
python <skill-dir>/scripts/openocd_gdb.py run --gdb-exe arm-none-eabi-gdb --elf build/app.elf --interface interface/stlink.cfg --target target/stm32f4x.cfg --commands "break main" "continue" "backtrace" "info locals" --json
# 快捷获取调用栈
python <skill-dir>/scripts/openocd_gdb.py backtrace --gdb-exe arm-none-eabi-gdb --elf build/app.elf --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 快捷查看局部变量
python <skill-dir>/scripts/openocd_gdb.py locals --gdb-exe arm-none-eabi-gdb --elf build/app.elf --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
可选参数:--gdb-port、--telnet-port、--search、--adapter-speed、--transport、--board
openocd_telnet.py — Telnet 在线调试
# 暂停 CPU
python <skill-dir>/scripts/openocd_telnet.py halt --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 恢复运行
python <skill-dir>/scripts/openocd_telnet.py resume --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 单步 5 次
python <skill-dir>/scripts/openocd_telnet.py step --count 5 --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 查看寄存器
python <skill-dir>/scripts/openocd_telnet.py reg --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 读内存(32bit x 16 个字)
python <skill-dir>/scripts/openocd_telnet.py read-mem --address 0x20000000 --length 16 --width 32 --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 写内存
python <skill-dir>/scripts/openocd_telnet.py write-mem --address 0x20000000 --value 0xDEADBEEF --width 32 --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 设置硬件断点
python <skill-dir>/scripts/openocd_telnet.py bp --address 0x08001234 --bp-length 2 --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 移除断点
python <skill-dir>/scripts/openocd_telnet.py rbp --address 0x08001234 --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 运行到指定地址(设置断点 + resume + 等待)
python <skill-dir>/scripts/openocd_telnet.py run-to --address 0x08001234 --timeout-ms 3000 --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
通用可选参数:--board、--search、--adapter-speed、--transport、--gdb-port、--telnet-port
openocd_semihosting.py — Semihosting 输出捕获
# 捕获 semihosting 输出(持续到 Ctrl+C)
python <skill-dir>/scripts/openocd_semihosting.py --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 捕获 30 秒
python <skill-dir>/scripts/openocd_semihosting.py --timeout 30 --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
openocd_itm.py — ITM/SWO 观测
# 使用配置中的 TPIU 参数持续读取 ITM
python <skill-dir>/scripts/openocd_itm.py --interface interface/stlink.cfg --target target/stm32f4x.cfg --json
# 指定 TPIU 名称和端口
python <skill-dir>/scripts/openocd_itm.py \
--interface interface/stlink.cfg --target target/stm32f4x.cfg \
--tpiu-name stm32f4x.tpiu --traceclk 168000000 --pin-freq 2000000 \
--itm-port 0 --itm-port 1 --json
openocd_itm.py 会启动独立 OpenOCD Server,打开 TPIU/ITM 配置后,把 trace 输出统一包装成 JSON Lines。
调试典型工作流
快速检查(Telnet)
halt -> reg -> read-mem 0x20000000 -> step -> resume
适合快速查看当前 CPU 状态和内存内容。
断点调试(Telnet)
run-to 0x08001234 -> reg -> read-mem -> resume
运行到指定地址后暂停,检查寄存器和内存。
源码级调试(GDB)
gdb run --elf app.elf --commands "break main" "continue" "backtrace" "info locals"
使用 ELF 文件提供符号信息,进行函数级断点和变量查看。
Semihosting 输出
semihosting
捕获目标通过 printf(SVC 指令)输出的调试信息,类似 J-Link RTT。
输出格式
所有脚本以 JSON 格式返回,基础字段为 status(ok/error)、action、summary、details,并可能附带 context、artifacts、metrics、state、next_actions、timing。流式观测命令使用 JSON Lines,并统一输出 source、channel_type、stream_type。
成功示例:
{
"status": "ok",
"action": "halt",
"summary": "已暂停,PC=0x08000298",
"details": {
"pc": "0x08000298",
"xpsr": "0x01000000",
"msp": "0x20020000",
"halted": true
}
}
GDB 调用栈示例:
{
"status": "ok",
"action": "backtrace",
"summary": "GDB backtrace 执行成功",
"details": {
"gdb_port": 3333,
"frames": [
{"frame": 0, "function": "main", "location": "src/main.c:42"}
]
}
}
错误示例:
{
"status": "error",
"action": "halt",
"error": {
"code": "server_failed",
"message": "OpenOCD 启动失败或超时"
}
}
核心规则
- 不自动猜测
board、interface、target的组合,缺失时必须询问用户 - 已知
board时优先使用 board 配置,不再需要 interface+target - 参数解析优先级为:CLI 显式参数 >
.embeddedskills/config.json(工程级)>skill/config.json(环境级)>.embeddedskills/state.json> 默认值/报错 .bin文件必须显式提供烧录地址,缺失时报错- STM32F4 等已映射 target 在
erase --mode auto下会先reset halt,再优先使用 mass erase erase --mode mass在未命中映射时直接返回mass_erase_unsupported,避免误以为已做整片擦除- 检测到 Flash 锁保护时只提示,不自动解锁
- 连接失败时给出排查建议(检查连线、供电、驱动、cfg 路径),不自动尝试更激进参数
- 烧录、擦除、复位在参数完整且用户意图明确时直接执行
gdb-server启动后返回端口和连接方式,进程保持运行- GDB 调试(run/backtrace/locals)需要配置
gdb_exe(arm-none-eabi-gdb 路径) - Telnet 调试命令每次启动独立的 OpenOCD Server,执行完自动关闭
- Semihosting 通过 Telnet 启用后持续读取 OpenOCD stderr 输出
- 结果回显中始终包含 cfg 组合、端口和执行动作
- 产物路径(elf/file)不进入工程配置,仍只依赖
state.json last_flash/last_debug/last_observe等运行状态继续写入state.json
参考
遇到 board/interface/target 配置问题时可查阅 references/common_targets.md。
FAQ
What does the openocd skill do?
OpenOCD 下载与调试工具,用于探针探测、固件烧录、Flash 擦除、GDB Server 启动、目标复位控制、 Telnet 在线调试(halt/resume/step/寄存器/内存/断点)、GDB 源码级调试,以及 Semihosting/ITM 输出捕获和底层查询。 当用户提到 OpenOCD、ST-Link、CMSIS-DAP、DAPLink、FTDI、烧录固件、擦除 Flash、GDB Server、 reset、interface/target/board 配置、openocd.cfg、在线调试、单步、断点、寄存器查看、 内存读写、semihosting 时自动触发,也兼容 /openocd 显式调用。 即使用户只是说"烧录一下"、"启动 GDB Server"、"擦除芯片"、"看看寄存器"、"单步调试" 或"抓一下 semihosting",只要上下文涉及 OpenOCD 支持的开源调试器就应触发此 skill。
How do I install openocd?
Run npx skills add https://github.com/zhinkgit/embeddedskills --skill openocd in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/openocd/ (personal) or .claude/skills/openocd/ (project).
Which AI agents can use openocd?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is openocd safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains openocd?
It is published by zhinkgit in zhinkgit/embeddedskills. It has 673 recorded installs.
More from zhinkgit/embeddedskills
keil
zhinkgit/embeddedskills
Keil MDK 工程构建工具,用于扫描 .uvprojx/.uvproj/.uvmpw 工程、枚举 Target、执行 build/rebuild/clean 并解析构建日志,返回可供 jlink/openocd 复用的产物路径。 flash 子命令仅作为兼容入口保留。当用户提到 Keil、MDK、uVision、UV4、 Target 枚举、编译、重建、清理、烧录、下载固件、flash 时自动触发,也兼容 /keil 显式调用。 即使用户只是说"编译一下"或"烧录到板子上",只要上下文涉及嵌入式 Keil 工程就应触发此 skill。
serial
zhinkgit/embeddedskills
嵌入式串口调试工具,用于扫描串口、实时监控、发送数据、记录日志和 Hex 查看。 当用户提到串口、COM 口、UART、AT 命令调试、波特率、Hex 串流、串口抓日志、 串口监控、查看 MCU 输出、二进制协议联调时自动触发,也兼容 /serial 显式调用。 即使用户只是说"看看串口输出"、"发个 AT 命令"或"抓一下日志",只要上下文涉及 串口通信就应触发此 skill。
can
zhinkgit/embeddedskills
嵌入式 CAN / CAN-FD 调试工具,用于扫描接口、监控报文、发送测试帧、记录日志、数据库文件解码和总线统计。 当用户提到 CAN、CAN-FD、DBC 解码、总线抓包、USB-CAN 联调、报文发送、总线统计、 PCAN、Vector、slcan、CAN 接口扫描、CAN ID 过滤、ASC 日志、BLF 文件时自动触发, 也兼容 /can 显式调用。即使用户只是说"看看 CAN 报文"、"发一帧试试"或"解码一下 DBC", 只要上下文明确提到 CAN 总线通信的操作或问题就应触发此 skill。
jlink
zhinkgit/embeddedskills
J-Link 下载与在线调试工具,用于探测设备、烧录固件、读写内存、查看寄存器、复位目标、读取 RTT/SWO 日志, 以及在线调试(暂停/恢复/单步/断点运行/调用栈/变量查看)。 当用户提到 J-Link、JLink、RTT、烧录固件、写内存、读内存、寄存器查看、目标复位、探针连通性检查、 在线调试、单步、断点、调用栈时自动触发,也兼容 /jlink 显式调用。 即使用户只是说"烧录一下"、"看看 RTT 输出"或"调试一下",只要上下文涉及 J-Link 探针就应触发此 skill。
gcc
zhinkgit/embeddedskills
GCC 嵌入式工程构建工具(CMake + arm-none-eabi-gcc),用于扫描 CMake 型嵌入式工程、 列出预设、配置、编译、重建、清理和分析 ELF 大小。当用户提到 GCC、arm-none-eabi、 CMake 嵌入式编译、Ninja 构建、ELF 大小分析、arm-gcc、交叉编译、cmake --build、 cmake --preset 时自动触发,也兼容 /gcc 显式调用。即使用户只是说"编译一下"或 "看看固件多大",只要上下文涉及 CMake 嵌入式 GCC 工程就应触发此 skill。
workflow
zhinkgit/embeddedskills
embeddedskills 的薄编排层,用于在当前 workspace 中发现工程、选择 build/flash/debug/observe 后端、串联 .embeddedskills/state.json,并聚合底层 skill 的结果。 当用户明确输入以下命令之一:"一键构建烧录"、"自动诊断"、"串起 build - flash - debug - observe" 或显式调用 /workflow 时触发。
Popular backend & apis skills
find-skills
vercel-labs/skills
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
entra-app-registration
microsoft/azure-skills
Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.
google-agents-cli-adk-code
google/agents-cli
This skill should be used when the user wants to "write agent code", "build an agent with ADK", "add a tool", "create a callback", "define an agent", "use state management" — in a project that needs ADK (Agent Development Kit) API patterns and code examples. It provides a quick reference for agent types, tool definitions, orchestration patterns, callbacks, state management, the graph Workflow API, and reference recipes to study. Do NOT use for scaffolding (use google-agents-cli-scaffold) or deployment (use google-agents-cli-deploy).
embedded-captions
heygen-com/hyperframes
Add captions or subtitles to an existing single-subject talking-head video without editing the footage. Use for plain verbatim captions, cinematic captions embedded behind the subject, VFX captions, “炸/特效/酷炫字幕,” or a named identity from the 35-style catalog. Route by visual identity, not by backend engine. The quiet anchor rail is the default; embed every word only when the user explicitly wants a fully cinematic treatment. The workflow runs locally end to end, including transcription and subject matting; split multi-shot footage before applying it.
entra-agent-id
microsoft/azure-skills
Provision Microsoft Entra Agent Identity Blueprints, BlueprintPrincipals, and per-instance Agent Identities via Microsoft Graph, and configure OAuth 2.0 token exchange (fmipath, OBO, cross-tenant) including the Microsoft Entra SDK for AgentID sidecar. USE FOR: Agent Identity Blueprint, BlueprintPrincipal, agent OAuth, fmipath token exchange, agent OBO, Workload Identity Federation for agents, polyglot agent auth, Microsoft.Identity.Web.AgentIdentities. DO NOT USE FOR: standard Entra app registration (use entra-app-registration), Microsoft Foundry agent authoring (use microsoft-foundry).
neon
neondatabase/agent-skills
Overview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, the AI Gateway, and Realtime. Start here to choose Neon for undecided login, files, APIs, and LLM calls, set up the CLI or MCP server, and follow the branch-first workflow. Use when building an app or backend on Neon, or when "Neon" or "Lakebase Postgres" is mentioned. Child skill neon-postgres wins for an existing DATABASEURL, SQL, schema, inspect, or search. Child skill neon-auth wins for login, users, sessions, identity routing, and Managed Better Auth setup. Child skill neon-realtime wins for live queries in reactive apps and agents. Also use for object storage, S3, buckets, serverless functions, function triggers, cron, AI gateway, LLM calls, realtime, logs, Loki, Grafana, observability, postgres, database, backend, Claimable Neon, neon.new, or a no-signup database.