{"id":50587350,"url":"https://github.com/coloz/openocd-tool","last_synced_at":"2026-06-05T07:03:13.778Z","repository":{"id":348677132,"uuid":"1198544804","full_name":"coloz/openocd-tool","owner":"coloz","description":null,"archived":false,"fork":false,"pushed_at":"2026-04-02T09:21:44.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-02T23:29:08.118Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coloz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-01T14:22:09.000Z","updated_at":"2026-04-02T09:21:48.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/coloz/openocd-tool","commit_stats":null,"previous_names":["coloz/openocd-tool"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/coloz/openocd-tool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coloz%2Fopenocd-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coloz%2Fopenocd-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coloz%2Fopenocd-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coloz%2Fopenocd-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coloz","download_url":"https://codeload.github.com/coloz/openocd-tool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coloz%2Fopenocd-tool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33932048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-05T02:00:06.157Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-05T07:03:11.368Z","updated_at":"2026-06-05T07:03:13.770Z","avatar_url":"https://github.com/coloz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# openocd-tool\n\nSTM32/GD32 调试器检测与固件烧录 CLI 工具，基于 [OpenOCD](https://openocd.org/) 实现。\n\n支持 **ST-Link** 和 **DAPLink (CMSIS-DAP)** 调试器，可自动检测设备并烧录固件。\n\n安装时会自动下载当前平台对应的 OpenOCD 二进制文件，无需手动配置。\n\n## 支持平台\n\n- Windows x64\n- Linux x64 / arm64\n- macOS x64 / arm64 (Apple Silicon)\n\n## 安装\n\n```bash\n# 全局安装（推荐，可直接使用 openocd-tool 命令）\nnpm install -g openocd-tool\n\n# 或作为项目依赖\nnpm install openocd-tool\n```\n\n安装过程中会自动从 GitHub 下载对应平台的 OpenOCD 预编译包。\n\n## 使用\n\n### 检测调试器\n\n扫描已连接的 ST-Link 和 DAPLink 设备：\n\n```bash\nopenocd-tool detect\n```\n\n以 JSON 格式输出：\n\n```bash\nopenocd-tool detect --json\n```\n\n或直接运行：\n\n```bash\nnode bin/cli.js detect\n```\n\n输出示例：\n\n```\n正在检测已连接的调试器设备...\n\n共检测到 1 个调试器设备：\n\n  [1] ST-Link\n      描述: STLINK V2J14S0 (API v2)\n      VID:PID = 0483:3748\n      序列号: 066FFF535752877167253530\n      目标电压: 3.24V\n```\n\n### 烧录固件\n\n```bash\nopenocd-tool flash \u003c固件文件\u003e -t \u003c目标芯片\u003e [选项]\n```\n\n#### 基本用法\n\n```bash\n# 烧录 HEX 文件到 STM32F103\nopenocd-tool flash firmware.hex -t stm32f1x\n\n# 烧录 BIN 文件到 STM32F407（需指定基地址）\nopenocd-tool flash firmware.bin -t stm32f4x -a 0x08000000\n\n# 烧录 ELF 文件到 GD32E230\nopenocd-tool flash app.elf -t gd32e23x\n```\n\n#### 使用 DAPLink 调试器\n\n```bash\nopenocd-tool flash firmware.hex -t stm32f1x -i cmsis-dap\n```\n\n#### 更多选项\n\n```bash\n# 全片擦除后烧录\nopenocd-tool flash firmware.hex -t stm32f1x --erase-all\n\n# 烧录后不复位\nopenocd-tool flash firmware.hex -t stm32f1x --no-reset\n\n# 跳过校验\nopenocd-tool flash firmware.hex -t stm32f1x --no-verify\n\n# 使用 JTAG 传输协议，调整速度\nopenocd-tool flash firmware.hex -t stm32f1x -p jtag -s 1000\n```\n\n### 完整参数列表\n\n| 参数 | 说明 | 默认值 |\n|------|------|--------|\n| `-t, --target \u003cname\u003e` | 目标芯片配置（必须） | - |\n| `-i, --interface \u003ctype\u003e` | 调试器接口：`stlink` 或 `cmsis-dap` | `stlink` |\n| `-p, --transport \u003ctype\u003e` | 传输协议：`swd` 或 `jtag` | `swd` |\n| `-s, --speed \u003ckHz\u003e` | 适配器速度 | `4000` |\n| `-a, --address \u003chex\u003e` | `.bin` 文件基地址 | `0x08000000` |\n| `--no-verify` | 烧录后不校验 | - |\n| `--no-reset` | 烧录后不复位 | - |\n| `--json` | 以 JSON 格式输出检测结果（仅 detect） | - |\n| `--erase-all` | 全片擦除 | - |\n| `--timeout \u003cms\u003e` | 超时时间 | `60000` |\n| `-h, --help` | 显示帮助 | - |\n| `-v, --version` | 显示版本 | - |\n\n### 支持的目标芯片\n\n**STM32 系列：**\n`stm32f0x` `stm32f1x` `stm32f2x` `stm32f3x` `stm32f4x` `stm32f7x`\n`stm32g0x` `stm32g4x` `stm32h7x` `stm32l0` `stm32l1` `stm32l4x` `stm32l5x`\n`stm32u0x` `stm32u5x` `stm32c0x` `stm32wbx` `stm32wlx`\n\n**GD32 系列：**\n`gd32e23x` `gd32vf103`\n\n## 编程接口\n\n也可以作为 Node.js 模块使用：\n\n```js\nconst { detect, detectStlink, detectDaplink, flashFirmware } = require(\"openocd-tool\");\n```\n\n### detect()\n\n检测所有已连接的调试器设备（ST-Link + DAPLink），返回设备数组。\n\n```js\nconst devices = await detect();\n// [\n//   {\n//     type: \"ST-Link\",\n//     description: \"STLINK V2J14S0 (API v2)\",\n//     vid: \"0483\",\n//     pid: \"3748\",\n//     serial: \"066FFF535752877167253530\",\n//     targetVoltage: \"3.24V\"\n//   }\n// ]\n```\n\n也可以单独检测某一类调试器：\n\n```js\nconst stlinks = await detectStlink();   // 仅 ST-Link\nconst daplinks = await detectDaplink(); // 仅 DAPLink (CMSIS-DAP)\n```\n\n### flashFirmware(options)\n\n烧录固件到目标芯片，返回 `{ success: boolean, output: string }`。\n\n```js\nconst result = await flashFirmware({\n  firmwarePath: \"./firmware.hex\",  // 支持 .hex / .bin / .elf\n  target: \"stm32f1x\",             // 必须，目标芯片\n  interface: \"stlink\",             // 可选，\"stlink\" | \"cmsis-dap\"，默认 \"stlink\"\n  transport: \"swd\",                // 可选，\"swd\" | \"jtag\"，默认 \"swd\"\n  speed: 4000,                     // 可选，适配器速度 (kHz)，默认 4000\n  baseAddress: 0x08000000,         // 可选，.bin 文件基地址，默认 0x08000000\n  verify: true,                    // 可选，烧录后校验，默认 true\n  reset: true,                     // 可选，烧录后复位，默认 true\n  eraseAll: false,                 // 可选，全片擦除，默认 false\n  timeout: 60000,                  // 可选，超时 (ms)，默认 60000\n});\n\nif (result.success) {\n  console.log(\"烧录成功\");\n} else {\n  console.error(\"烧录失败:\", result.output);\n}\n```\n\n## 常见问题\n\n**设备未检测到？**\n- 确认设备已通过 USB 连接\n- ST-Link：需安装 [ST-LINK USB Driver](https://www.st.com/en/development-tools/stsw-link009.html)\n- DAPLink：Windows 通常免驱动\n\n**烧录失败？**\n- 检查 `-t` 参数是否与芯片型号匹配\n- 确认固件文件路径正确\n- `.bin` 文件需通过 `-a` 指定正确的基地址\n\n## License\n\nISC\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoloz%2Fopenocd-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoloz%2Fopenocd-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoloz%2Fopenocd-tool/lists"}