dsh-stm32 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -40
- package/README_EN.md +85 -36
- package/assets/README.md +85 -0
- package/assets/VERSION +1 -0
- package/assets/device/c0/chips.json +1108 -0
- package/assets/device/f0/chips.json +1570 -0
- package/assets/device/f1/chips.json +1238 -0
- package/assets/device/f1/svd/100.json +943 -0
- package/assets/device/f1/svd/101.json +901 -0
- package/assets/device/f1/svd/102.json +522 -0
- package/assets/device/f1/svd/103.json +1139 -0
- package/assets/device/f1/svd/105.json +1117 -0
- package/assets/device/f1/svd/107.json +1195 -0
- package/assets/device/f2/chips.json +674 -0
- package/assets/device/f3/chips.json +1318 -0
- package/assets/device/f4/chips.json +2942 -0
- package/assets/device/f7/chips.json +1710 -0
- package/assets/device/g0/chips.json +2102 -0
- package/assets/device/g4/chips.json +2494 -0
- package/assets/device/h5/chips.json +898 -0
- package/assets/device/h7/chips.json +1948 -0
- package/assets/device/l0/chips.json +2494 -0
- package/assets/device/l1/chips.json +1234 -0
- package/assets/device/l4/chips.json +2130 -0
- package/assets/device/l4+/chips.json +856 -0
- package/assets/device/l5/chips.json +226 -0
- package/assets/device/u0/chips.json +688 -0
- package/assets/device/u3/chips.json +310 -0
- package/assets/device/u5/chips.json +884 -0
- package/assets/device/wba/chips.json +506 -0
- package/assets/device/wl/chips.json +184 -0
- package/assets/headers/f1/stm32f100xb.h +5972 -0
- package/assets/headers/f1/stm32f100xe.h +6587 -0
- package/assets/headers/f1/stm32f101x6.h +5315 -0
- package/assets/headers/f1/stm32f101xb.h +5446 -0
- package/assets/headers/f1/stm32f101xe.h +6503 -0
- package/assets/headers/f1/stm32f101xg.h +6713 -0
- package/assets/headers/f1/stm32f102x6.h +6448 -0
- package/assets/headers/f1/stm32f102xb.h +6570 -0
- package/assets/headers/f1/stm32f103x6.h +10109 -0
- package/assets/headers/f1/stm32f103xb.h +10240 -0
- package/assets/headers/f1/stm32f103xe.h +11767 -0
- package/assets/headers/f1/stm32f103xg.h +11951 -0
- package/assets/headers/f1/stm32f105xc.h +14340 -0
- package/assets/headers/f1/stm32f107xc.h +15253 -0
- package/assets/headers/f1/stm32f1xx.h +273 -0
- package/assets/headers/f1/system_stm32f1xx.h +96 -0
- package/assets/ioc/family/C0.ioc +82 -0
- package/assets/ioc/family/F0.ioc +71 -0
- package/assets/ioc/family/F2.ioc +91 -0
- package/assets/ioc/family/F3.ioc +94 -0
- package/assets/ioc/family/F4.ioc +91 -0
- package/assets/ioc/family/F7.ioc +102 -0
- package/assets/ioc/family/G0.ioc +90 -0
- package/assets/ioc/family/G4.ioc +110 -0
- package/assets/ioc/family/H5.ioc +116 -0
- package/assets/ioc/family/H7.ioc +133 -0
- package/assets/ioc/family/L0.ioc +92 -0
- package/assets/ioc/family/L1.ioc +87 -0
- package/assets/ioc/family/L4+.ioc +92 -0
- package/assets/ioc/family/L4.ioc +93 -0
- package/assets/ioc/family/L5.ioc +91 -0
- package/assets/ioc/family/U0.ioc +103 -0
- package/assets/ioc/family/U3.ioc +113 -0
- package/assets/ioc/family/U5.ioc +102 -0
- package/assets/ioc/family/WBA.ioc +100 -0
- package/assets/ioc/family/WL.ioc +93 -0
- package/assets/ioc/minimal/STM32F100C8Tx.ioc +113 -0
- package/assets/ioc/minimal/STM32F100RCTx.ioc +113 -0
- package/assets/ioc/minimal/STM32F101C4Tx.ioc +113 -0
- package/assets/ioc/minimal/STM32F101C8Tx.ioc +113 -0
- package/assets/ioc/minimal/STM32F101RCTx.ioc +113 -0
- package/assets/ioc/minimal/STM32F101RFTx.ioc +113 -0
- package/assets/ioc/minimal/STM32F102C4Tx.ioc +113 -0
- package/assets/ioc/minimal/STM32F102C8Tx.ioc +113 -0
- package/assets/ioc/minimal/STM32F103C4Tx.ioc +113 -0
- package/assets/ioc/minimal/STM32F103C8Tx.ioc +113 -0
- package/assets/ioc/minimal/STM32F103RCTx.ioc +113 -0
- package/assets/ioc/minimal/STM32F103RFTx.ioc +113 -0
- package/assets/ioc/minimal/STM32F105RCTx.ioc +113 -0
- package/assets/ioc/minimal/STM32F107RCTx.ioc +113 -0
- package/assets/ld/f1/STM32F100C8Tx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F100RCTx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F101C4Tx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F101C8Tx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F101RCTx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F101RFTx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F102C4Tx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F102C8Tx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F103C4Tx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F103C8Tx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F103RCTx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F103RFTx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F105RCTx_FLASH.ld +249 -0
- package/assets/ld/f1/STM32F107RCTx_FLASH.ld +249 -0
- package/assets/manifest.json +1130 -0
- package/assets/startup/f1/startup_stm32f100xb.s +407 -0
- package/assets/startup/f1/startup_stm32f100xe.s +449 -0
- package/assets/startup/f1/startup_stm32f101x6.s +322 -0
- package/assets/startup/f1/startup_stm32f101xb.s +338 -0
- package/assets/startup/f1/startup_stm32f101xe.s +423 -0
- package/assets/startup/f1/startup_stm32f101xg.s +439 -0
- package/assets/startup/f1/startup_stm32f102x6.s +330 -0
- package/assets/startup/f1/startup_stm32f102xb.s +346 -0
- package/assets/startup/f1/startup_stm32f103x6.s +348 -0
- package/assets/startup/f1/startup_stm32f103xb.s +364 -0
- package/assets/startup/f1/startup_stm32f103xe.s +470 -0
- package/assets/startup/f1/startup_stm32f103xg.s +466 -0
- package/assets/startup/f1/startup_stm32f105xc.s +463 -0
- package/assets/startup/f1/startup_stm32f107xc.s +472 -0
- package/assets/templates/family/C0.ioc +82 -0
- package/assets/templates/family/F0.ioc +71 -0
- package/assets/templates/family/F2.ioc +91 -0
- package/assets/templates/family/F3.ioc +94 -0
- package/assets/templates/family/F4.ioc +91 -0
- package/assets/templates/family/F7.ioc +102 -0
- package/assets/templates/family/G0.ioc +90 -0
- package/assets/templates/family/G4.ioc +110 -0
- package/assets/templates/family/H5.ioc +116 -0
- package/assets/templates/family/H7.ioc +133 -0
- package/assets/templates/family/L0.ioc +92 -0
- package/assets/templates/family/L1.ioc +87 -0
- package/assets/templates/family/L4+.ioc +92 -0
- package/assets/templates/family/L4.ioc +93 -0
- package/assets/templates/family/L5.ioc +91 -0
- package/assets/templates/family/U0.ioc +103 -0
- package/assets/templates/family/U3.ioc +113 -0
- package/assets/templates/family/U5.ioc +102 -0
- package/assets/templates/family/WB.ioc +81 -0
- package/assets/templates/family/WBA.ioc +100 -0
- package/assets/templates/family/WL.ioc +93 -0
- package/docs/reading-guide.md +94 -71
- package/lib/data/chips.js +38 -51
- package/lib/data/clock-db.js +830 -0
- package/lib/data/clock-f1.js +12 -45
- package/lib/data/cmsis-sources.js +264 -17
- package/lib/data/db-presets.js +252 -0
- package/lib/data/device-facts.js +274 -0
- package/lib/data/family.js +515 -0
- package/lib/data/firmware-packages.js +562 -0
- package/lib/data/install-guides.js +2 -2
- package/lib/data/ioc-presets.js +248 -0
- package/lib/data/ioc-schema.js +1058 -0
- package/lib/data/rm-topics/stm32c0.json +227 -0
- package/lib/data/rm-topics.js +103 -0
- package/lib/data/search-roots.js +42 -1
- package/lib/data/stm32f1.js +95 -150
- package/lib/data/svd.js +643 -0
- package/lib/data/toolchain-config.js +0 -14
- package/lib/engine/assets.js +659 -0
- package/lib/engine/breakpoints.js +297 -0
- package/lib/engine/clock-derived.js +101 -0
- package/lib/engine/clock-direct.js +313 -0
- package/lib/engine/clock-plan.js +96 -52
- package/lib/engine/clock-pllmn.js +319 -0
- package/lib/engine/cmake-sources.js +67 -13
- package/lib/engine/cube-mx-guard.js +44 -0
- package/lib/engine/cube-programmer.js +137 -0
- package/lib/engine/cubemx-db.js +273 -0
- package/lib/engine/debug-session.js +576 -22
- package/lib/engine/debug.js +99 -46
- package/lib/engine/doctor.js +162 -19
- package/lib/engine/facts-acquire.js +416 -0
- package/lib/engine/facts.js +134 -0
- package/lib/engine/firmware-install.js +176 -5
- package/lib/engine/firmware-official.js +451 -0
- package/lib/engine/flash.js +317 -76
- package/lib/engine/gdb-mi.js +476 -0
- package/lib/engine/generate.js +9 -2
- package/lib/engine/hal-chip.js +124 -41
- package/lib/engine/ioc-plan.js +1247 -63
- package/lib/engine/ioc-rules.js +698 -0
- package/lib/engine/ioc-verify.js +706 -0
- package/lib/engine/ioc.js +43 -4
- package/lib/engine/msys2-install.js +4 -4
- package/lib/engine/probe-error.js +231 -0
- package/lib/engine/probe-session.js +347 -0
- package/lib/engine/probe.js +18 -3
- package/lib/engine/register-clock.js +41 -0
- package/lib/engine/register-gpio.js +115 -0
- package/lib/engine/register-linker.js +12 -7
- package/lib/engine/register-template.js +130 -45
- package/lib/engine/regs.js +43 -8
- package/lib/engine/rm-extract.js +144 -0
- package/lib/engine/rm-sources.js +360 -0
- package/lib/engine/rm-text.js +56 -0
- package/lib/engine/rtt.js +758 -0
- package/lib/engine/scaffold.js +185 -18
- package/lib/engine/toolchain-gate.js +0 -4
- package/lib/engine/watch.js +227 -0
- package/lib/index.js +12 -2
- package/lib/skill/stm32-workflow.js +2 -2
- package/lib/tools/assets.js +272 -0
- package/lib/tools/cache.js +8 -0
- package/lib/tools/debug-session.js +41 -6
- package/lib/tools/debug.js +41 -11
- package/lib/tools/doctor.js +65 -4
- package/lib/tools/firmware-install.js +31 -6
- package/lib/tools/flash.js +47 -10
- package/lib/tools/generate.js +25 -0
- package/lib/tools/ioc-apply.js +2 -0
- package/lib/tools/ioc-inspect.js +2 -0
- package/lib/tools/ioc-plan.js +59 -2
- package/lib/tools/ioc-verify.js +237 -0
- package/lib/tools/project-create.js +63 -3
- package/lib/tools/regs.js +453 -61
- package/lib/tools/route-plan.js +3 -0
- package/lib/tools/rtt.js +470 -0
- package/lib/tools/watch.js +256 -0
- package/package.json +5 -4
- package/templates/openocd/stm32c0x.cfg +83 -0
- package/templates/openocd/stm32u0x.cfg +64 -0
- package/templates/register/CMakeLists.txt +8 -2
- package/templates/register/Core/Inc/rtt.h +138 -0
- package/templates/register/Core/Src/main.c +42 -25
- package/templates/register/Core/Src/rtt.c +373 -0
- package/templates/scaffold/RTT.md +90 -0
- package/templates/scaffold/STM32F103XX_FLASH.ld +3 -0
- package/templates/scaffold/cmake/user/CMakeLists.txt +7 -0
- package/templates/scaffold/openocd.cfg +5 -3
- package/templates/scaffold/vscode/launch.json +8 -4
- package/docs/development-notes.md +0 -2116
- package/docs/dsh-stm32-plugin-/350/247/204/346/240/274.md +0 -673
- package/docs/logic-audit.md +0 -607
- package/lib/data/f1-ram.generated.js +0 -34
package/lib/tools/debug.js
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* 与 stm32_flash 的分工:flash 只写不调;debug_run 只调不写(不 load),
|
|
5
5
|
* 停在 breakAt(默认 main)后抓寄存器/调用栈,收尾 monitor reset run + detach。
|
|
6
6
|
*/
|
|
7
|
+
import { F1_BREAKPOINT_BUDGET, quotaOf } from "../engine/breakpoints.js";
|
|
7
8
|
import { runDebugRun } from "../engine/debug.js";
|
|
9
|
+
import { PROBE_ERROR_SCHEMA, formatProbeError } from "../engine/probe-error.js";
|
|
8
10
|
import { releaseProbeFor } from "../engine/debug-session.js";
|
|
9
11
|
import { ensureToolchain, gateReportNotes } from "../engine/toolchain-gate.js";
|
|
10
12
|
import { resolveProjectDir } from "./project-dir.js";
|
|
@@ -18,6 +20,17 @@ const registerSchema = {
|
|
|
18
20
|
},
|
|
19
21
|
required: ["name", "value"],
|
|
20
22
|
};
|
|
23
|
+
/** 断点预算三元组(B4):硬件断点与观察点各一条。 */
|
|
24
|
+
const quotaSchema = {
|
|
25
|
+
type: "object",
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
properties: {
|
|
28
|
+
used: { type: "number" },
|
|
29
|
+
limit: { type: "number" },
|
|
30
|
+
remaining: { type: "number" },
|
|
31
|
+
},
|
|
32
|
+
required: ["used", "limit", "remaining"],
|
|
33
|
+
};
|
|
21
34
|
const reportSchema = {
|
|
22
35
|
type: "object",
|
|
23
36
|
additionalProperties: false,
|
|
@@ -29,23 +42,23 @@ const reportSchema = {
|
|
|
29
42
|
breakAt: { type: "string" },
|
|
30
43
|
hitBreakpoint: { type: "boolean" },
|
|
31
44
|
location: { type: "string" },
|
|
45
|
+
// B4:断点预算(芯片的上限与实际占用),超限时 used 停在上限、remaining=0。
|
|
46
|
+
breakpoints: quotaSchema,
|
|
47
|
+
watchpoints: quotaSchema,
|
|
32
48
|
registers: { type: "array", items: registerSchema },
|
|
33
49
|
backtrace: { type: "array", items: { type: "string" } },
|
|
34
50
|
locals: { type: "array", items: { type: "string" } },
|
|
35
51
|
gdbCommand: { type: "string" },
|
|
36
52
|
gdbOutput: { type: "string" },
|
|
37
53
|
openOcdLogTail: { type: "string" },
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
type: "string",
|
|
41
|
-
enum: ["", "no-probe", "probe-busy", "swd-locked", "flash-protected", "no-power", "target-mismatch", "unknown"],
|
|
42
|
-
},
|
|
54
|
+
// B2:失败时带结构化探针错误(与 stm32_flash 同一份分类)。可选对象,成功路径不出现。
|
|
55
|
+
probeError: PROBE_ERROR_SCHEMA,
|
|
43
56
|
durationMs: { type: "number" },
|
|
44
57
|
errors: { type: "array", items: { type: "string" } },
|
|
45
58
|
message: { type: "string" },
|
|
46
59
|
notes: { type: "array", items: { type: "string" } },
|
|
47
60
|
},
|
|
48
|
-
required: ["ok", "projectDir", "elfPath", "port", "breakAt", "hitBreakpoint", "location", "registers", "backtrace", "locals", "durationMs", "errors", "message", "notes"],
|
|
61
|
+
required: ["ok", "projectDir", "elfPath", "port", "breakAt", "hitBreakpoint", "location", "breakpoints", "watchpoints", "registers", "backtrace", "locals", "durationMs", "errors", "message", "notes"],
|
|
49
62
|
};
|
|
50
63
|
export const outputSchema = {
|
|
51
64
|
type: "object",
|
|
@@ -62,17 +75,26 @@ const ENV_CHECK_SCHEMA = {
|
|
|
62
75
|
enum: ["block", "warn", "off"],
|
|
63
76
|
description: "工具链检查:block 缺件就拒绝(默认)、warn 只警告、off 不检查",
|
|
64
77
|
};
|
|
78
|
+
export function debugReportForHost(report) {
|
|
79
|
+
const { probeError, ...rest } = report;
|
|
80
|
+
return probeError === null ? rest : { ...rest, probeError };
|
|
81
|
+
}
|
|
65
82
|
export function formatDebugReport(report) {
|
|
66
83
|
const lines = [];
|
|
67
84
|
lines.push((report.ok ? "调试快照完成" : "调试失败") + ":" + report.message);
|
|
68
85
|
if (report.elfPath !== "")
|
|
69
86
|
lines.push("固件:" + report.elfPath);
|
|
70
|
-
|
|
71
|
-
|
|
87
|
+
const probeError = report.probeError ?? null;
|
|
88
|
+
if (probeError !== null)
|
|
89
|
+
lines.push(formatProbeError(probeError));
|
|
72
90
|
if (report.port !== 0)
|
|
73
91
|
lines.push("端口:" + String(report.port) + ",断点:" + report.breakAt);
|
|
74
92
|
if (report.location !== "")
|
|
75
93
|
lines.push("位置:" + report.location);
|
|
94
|
+
if (report.breakpoints.limit > 0) {
|
|
95
|
+
lines.push("断点预算:" + String(report.breakpoints.used) + "/" + String(report.breakpoints.limit)
|
|
96
|
+
+ "(还剩 " + String(report.breakpoints.remaining) + ");观察点 " + String(report.watchpoints.used) + "/" + String(report.watchpoints.limit));
|
|
97
|
+
}
|
|
76
98
|
if (report.registers.length > 0)
|
|
77
99
|
lines.push("寄存器:" + report.registers.map((item) => item.name + "=" + item.value).join(" "));
|
|
78
100
|
if (report.backtrace.length > 0) {
|
|
@@ -102,6 +124,9 @@ function blockedReport(projectDir, gate) {
|
|
|
102
124
|
ok: false, projectDir, elfPath: "", port: 0, breakAt: "main",
|
|
103
125
|
hitBreakpoint: false, location: "", registers: [], backtrace: [], locals: [],
|
|
104
126
|
gdbCommand: "", gdbOutput: "", openOcdLogTail: "", durationMs: 0,
|
|
127
|
+
breakpoints: quotaOf(0, F1_BREAKPOINT_BUDGET.code),
|
|
128
|
+
watchpoints: quotaOf(0, F1_BREAKPOINT_BUDGET.data),
|
|
129
|
+
probeError: null,
|
|
105
130
|
errors: [], message: gate.message, notes: gateReportNotes(gate),
|
|
106
131
|
};
|
|
107
132
|
}
|
|
@@ -110,6 +135,9 @@ function emptyReport(message) {
|
|
|
110
135
|
ok: false, projectDir: "", elfPath: "", port: 0, breakAt: "main",
|
|
111
136
|
hitBreakpoint: false, location: "", registers: [], backtrace: [], locals: [],
|
|
112
137
|
gdbCommand: "", gdbOutput: "", openOcdLogTail: "", durationMs: 0,
|
|
138
|
+
breakpoints: quotaOf(0, F1_BREAKPOINT_BUDGET.code),
|
|
139
|
+
watchpoints: quotaOf(0, F1_BREAKPOINT_BUDGET.data),
|
|
140
|
+
probeError: null,
|
|
113
141
|
errors: [message], message, notes: [],
|
|
114
142
|
};
|
|
115
143
|
}
|
|
@@ -126,6 +154,7 @@ export function registerDebugRun(ctx) {
|
|
|
126
154
|
buildDir: { type: "string", description: "显式构建目录;缺省自动推断(优先 Debug)。" },
|
|
127
155
|
breakAt: { type: "string", description: "断点位置,默认 main;none 表示只连上读现状不停。" },
|
|
128
156
|
preCommands: { type: "array", items: { type: "string" }, description: "在 break 之后、continue 之前执行的 gdb 命令。" },
|
|
157
|
+
breakpoints: { type: "array", items: { type: "string" }, description: "额外断点(和 breakAt、preCommands 一起算硬件断点预算):\"main\"、\"HAL_Delay\"、\"watch:g_count\"(观察点)。F1 上限 6 个硬件断点 / 4 个观察点,超了会在起 openocd 之前直接失败并说明删哪个。" },
|
|
129
158
|
port: { type: "number", description: "gdb 端口;缺省 3333,占用则顺延。" },
|
|
130
159
|
configFile: { type: "string", description: "openocd 配置文件(相对工程目录)。" },
|
|
131
160
|
adapterSpeed: { type: "number", description: "adapter speed(kHz)。" },
|
|
@@ -149,7 +178,7 @@ export function registerDebugRun(ctx) {
|
|
|
149
178
|
const subprocess = ctx.get("subprocess");
|
|
150
179
|
if (subprocess === undefined) {
|
|
151
180
|
const report = emptyReport("宿主缺少 subprocess 服务,无法调试");
|
|
152
|
-
return { message: report.message, report };
|
|
181
|
+
return { message: report.message, report: debugReportForHost(report) };
|
|
153
182
|
}
|
|
154
183
|
const resolution = await resolveProjectDir(ctx, args.projectDir, exec);
|
|
155
184
|
// 门禁:调试要 openocd + GDB 两件。缺件且 envCheck=block 时不占探针、不起进程。
|
|
@@ -161,7 +190,7 @@ export function registerDebugRun(ctx) {
|
|
|
161
190
|
});
|
|
162
191
|
if (!gate.ok && gate.mode === "block") {
|
|
163
192
|
const blocked = blockedReport(resolution.projectDir, gate);
|
|
164
|
-
return { message: blocked.message, report: blocked };
|
|
193
|
+
return { message: blocked.message, report: debugReportForHost(blocked) };
|
|
165
194
|
}
|
|
166
195
|
// debug_run 自己也要独占探针;缺件退出时不动别人的会话(B16)。
|
|
167
196
|
const released = await releaseProbeFor("stm32_debug_run");
|
|
@@ -171,6 +200,7 @@ export function registerDebugRun(ctx) {
|
|
|
171
200
|
...(args.buildDir === undefined ? {} : { buildDir: args.buildDir }),
|
|
172
201
|
...(args.breakAt === undefined ? {} : { breakAt: args.breakAt }),
|
|
173
202
|
...(args.preCommands === undefined ? {} : { preCommands: args.preCommands }),
|
|
203
|
+
...(args.breakpoints === undefined ? {} : { breakpoints: args.breakpoints }),
|
|
174
204
|
...(args.port === undefined ? {} : { port: args.port }),
|
|
175
205
|
...(args.configFile === undefined ? {} : { configFile: args.configFile }),
|
|
176
206
|
...(args.adapterSpeed === undefined ? {} : { adapterSpeed: args.adapterSpeed }),
|
|
@@ -184,7 +214,7 @@ export function registerDebugRun(ctx) {
|
|
|
184
214
|
report.notes.push(released);
|
|
185
215
|
if (resolution.note !== null)
|
|
186
216
|
report.notes.push(resolution.note);
|
|
187
|
-
return { message: report.message, report };
|
|
217
|
+
return { message: report.message, report: debugReportForHost(report) };
|
|
188
218
|
},
|
|
189
219
|
});
|
|
190
220
|
}
|
package/lib/tools/doctor.js
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* 只读工具(除了跑一下 tasklist/版本命令)。回答的是"为什么现在烧不了/调不了",
|
|
5
5
|
* 特别是"探针被谁占着"这个在 VS Code 调试与命令行工具之间最容易互相踩的问题。
|
|
6
6
|
*/
|
|
7
|
+
import { ensureAssets } from "../engine/assets.js";
|
|
7
8
|
import { runDoctor } from "../engine/doctor.js";
|
|
9
|
+
import { describeFacts, mcuFromIoc, readFactsFor } from "../engine/facts.js";
|
|
8
10
|
import { resolveProjectDir } from "./project-dir.js";
|
|
9
11
|
export const DOCTOR_TOOL = "stm32_doctor";
|
|
10
12
|
const toolSchema = {
|
|
@@ -61,14 +63,41 @@ export const outputSchema = {
|
|
|
61
63
|
durationMs: { type: "number" },
|
|
62
64
|
missingRequired: { type: "array", items: { type: "string" } },
|
|
63
65
|
tools: { type: "array", items: toolSchema },
|
|
66
|
+
capabilities: {
|
|
67
|
+
type: "object",
|
|
68
|
+
additionalProperties: false,
|
|
69
|
+
properties: {
|
|
70
|
+
build: { type: "boolean", description: "gcc + cmake + ninja 齐全" },
|
|
71
|
+
flash: { type: "boolean", description: "openocd 可用(只烧录)" },
|
|
72
|
+
debug: { type: "boolean", description: "openocd + gdb 可用(烧录并调试)" },
|
|
73
|
+
generate: { type: "boolean", description: "CubeMX + 内置 JRE 可用(建工程/重新生成)" },
|
|
74
|
+
},
|
|
75
|
+
required: ["build", "flash", "debug", "generate"],
|
|
76
|
+
},
|
|
77
|
+
recommendations: { type: "array", items: { type: "string" }, description: "缺什么、按什么顺序装、装完怎么自检" },
|
|
78
|
+
searched: { type: "array", items: { type: "string" }, description: "工具链 / CubeMX 的搜索范围(报「明明装了却找不到」时看这个)" },
|
|
64
79
|
processes: { type: "array", items: processSchema },
|
|
65
80
|
usb: {
|
|
66
81
|
type: "object",
|
|
67
82
|
properties: {
|
|
68
83
|
kind: { type: "string", enum: ["no-usb", "no-dap", "driver-error", "ok", "unknown"] },
|
|
69
84
|
detail: { type: "string" },
|
|
85
|
+
/** 按 VID:PID 认出的探针清单(含非 SWD 的 ST/CH341 设备,供人核对)。 */
|
|
86
|
+
probes: {
|
|
87
|
+
type: "array",
|
|
88
|
+
items: {
|
|
89
|
+
type: "object",
|
|
90
|
+
properties: {
|
|
91
|
+
vid: { type: "string" },
|
|
92
|
+
pid: { type: "string" },
|
|
93
|
+
kind: { type: "string", enum: ["st-link", "cmsis-dap", "daplink", "ch341-serial", "unknown"] },
|
|
94
|
+
label: { type: "string" },
|
|
95
|
+
},
|
|
96
|
+
required: ["vid", "pid", "kind", "label"],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
70
99
|
},
|
|
71
|
-
required: ["kind", "detail"],
|
|
100
|
+
required: ["kind", "detail", "probes"],
|
|
72
101
|
},
|
|
73
102
|
port: { type: "number" },
|
|
74
103
|
portBusy: { type: "boolean" },
|
|
@@ -81,7 +110,8 @@ export const outputSchema = {
|
|
|
81
110
|
notes: { type: "array", items: { type: "string" } },
|
|
82
111
|
},
|
|
83
112
|
required: [
|
|
84
|
-
"ok", "projectDir", "message", "durationMs", "missingRequired", "tools",
|
|
113
|
+
"ok", "projectDir", "message", "durationMs", "missingRequired", "tools",
|
|
114
|
+
"capabilities", "recommendations", "searched", "processes",
|
|
85
115
|
"port", "portBusy", "buildDir", "elfPath", "elfSize", "iocPath", "iocWarnings", "usb", "blockers", "notes",
|
|
86
116
|
],
|
|
87
117
|
},
|
|
@@ -92,6 +122,9 @@ function formatReport(report) {
|
|
|
92
122
|
const lines = [];
|
|
93
123
|
lines.push((report.ok ? "环境就绪" : "有阻塞项") + ":" + report.message);
|
|
94
124
|
lines.push("工程:" + report.projectDir);
|
|
125
|
+
const caps = report.capabilities;
|
|
126
|
+
lines.push("能力:" + (caps.build ? "可编译" : "编译缺组件") + " / " + (caps.flash ? "可烧录" : "烧录缺组件") +
|
|
127
|
+
" / " + (caps.debug ? "可调试" : "调试缺组件") + " / " + (caps.generate ? "可建工程" : "建工程需装 CubeMX(可选)"));
|
|
95
128
|
for (const tool of report.tools) {
|
|
96
129
|
lines.push((tool.found ? " OK " : " MISS ") + tool.id + (tool.version === "" ? "" : " " + tool.version) +
|
|
97
130
|
(tool.found ? "" : " → " + tool.hint));
|
|
@@ -115,12 +148,23 @@ function formatReport(report) {
|
|
|
115
148
|
}
|
|
116
149
|
for (const note of report.notes)
|
|
117
150
|
lines.push("· " + note);
|
|
151
|
+
if (report.recommendations.length > 0) {
|
|
152
|
+
lines.push("");
|
|
153
|
+
lines.push("下一步:");
|
|
154
|
+
for (const line of report.recommendations)
|
|
155
|
+
lines.push("- " + line);
|
|
156
|
+
}
|
|
157
|
+
if (report.searched.length > 0) {
|
|
158
|
+
lines.push("");
|
|
159
|
+
for (const line of report.searched)
|
|
160
|
+
lines.push(line);
|
|
161
|
+
}
|
|
118
162
|
return lines;
|
|
119
163
|
}
|
|
120
164
|
export function registerDoctor(ctx) {
|
|
121
165
|
ctx.tools.register({
|
|
122
166
|
name: DOCTOR_TOOL,
|
|
123
|
-
description: "STM32 环境体检(只读):工具链版本是否齐全、有没有残留的 openocd/gdb
|
|
167
|
+
description: "STM32 环境体检(只读):工具链版本是否齐全、有没有残留的 openocd/gdb 占着探针(CMSIS-DAP / ST-Link)、gdb 端口是否被占、构建目录与 .elf 是否就位、.ioc 有没有致命告警(例如没启用 Serial Wire)。烧录/调试失败时先跑它。",
|
|
124
168
|
parameters: {
|
|
125
169
|
type: "object",
|
|
126
170
|
additionalProperties: false,
|
|
@@ -150,12 +194,20 @@ export function registerDoctor(ctx) {
|
|
|
150
194
|
message: "宿主缺少 subprocess 服务,无法体检",
|
|
151
195
|
report: {
|
|
152
196
|
ok: false, projectDir: args.projectDir ?? "", message: "宿主缺少 subprocess 服务", durationMs: 0,
|
|
153
|
-
missingRequired: ["subprocess"], tools: [],
|
|
197
|
+
missingRequired: ["subprocess"], tools: [],
|
|
198
|
+
capabilities: { build: false, flash: false, debug: false, generate: false },
|
|
199
|
+
recommendations: ["宿主缺少 subprocess 服务:插件没法跑任何外部程序,先确认 DSH 宿主正常启动。"],
|
|
200
|
+
searched: [],
|
|
201
|
+
processes: [], usb: { kind: "unknown", probes: [], detail: "宿主没有 subprocess 服务,无法诊断 USB/探针形态。" }, port: args.port ?? 3333, portBusy: false,
|
|
154
202
|
buildDir: "", elfPath: "", elfSize: 0, iocPath: "", iocWarnings: [], blockers: ["宿主缺少 subprocess 服务"], notes: [],
|
|
155
203
|
},
|
|
156
204
|
};
|
|
157
205
|
}
|
|
158
206
|
const resolution = await resolveProjectDir(ctx, args.projectDir, exec);
|
|
207
|
+
// 芯片型号 / 启动文件 / 引脚一致性都要设备事实:插件不再内置芯片表,事实来自内置资源。
|
|
208
|
+
// 这里**不硬失败**——体检本来就是用来回答"为什么现在烧不了",网络不通不该让整张报告消失;
|
|
209
|
+
// 拿不到事实就把原因写进 notes,其余检查(工具链/探针/端口/构建产物)照跑。
|
|
210
|
+
const assets = await ensureAssets({ signal: exec.signal });
|
|
159
211
|
const report = await runDoctor(subprocess, {
|
|
160
212
|
projectDir: resolution.projectDir,
|
|
161
213
|
...(args.binDirs === undefined ? {} : { binDirs: args.binDirs }),
|
|
@@ -166,6 +218,15 @@ export function registerDoctor(ctx) {
|
|
|
166
218
|
});
|
|
167
219
|
if (resolution.note !== null)
|
|
168
220
|
report.notes.push(resolution.note);
|
|
221
|
+
if (!assets.ok) {
|
|
222
|
+
report.notes.push("设备事实不可用:" + assets.message + " —— 型号↔启动文件/设备宏/链接脚本的一致性检查会跳过(其余检查不受影响)");
|
|
223
|
+
}
|
|
224
|
+
else if (assets.status === "refreshed") {
|
|
225
|
+
report.notes.push(assets.message);
|
|
226
|
+
}
|
|
227
|
+
const factsMcu = mcuFromIoc(report.projectDir);
|
|
228
|
+
if (factsMcu !== null)
|
|
229
|
+
report.notes.push(...describeFacts(readFactsFor(factsMcu)));
|
|
169
230
|
return { message: report.message, report };
|
|
170
231
|
},
|
|
171
232
|
});
|
|
@@ -73,6 +73,12 @@ const reportSchema = {
|
|
|
73
73
|
},
|
|
74
74
|
required: ["files", "bytes"],
|
|
75
75
|
},
|
|
76
|
+
source: {
|
|
77
|
+
type: "string",
|
|
78
|
+
enum: ["official", "github", "existing", ""],
|
|
79
|
+
description: "包从哪来:official=ST 官网 zip 经 CubeMX 装进 Repository;github=拼包;existing=本机已有",
|
|
80
|
+
},
|
|
81
|
+
downloadUrl: { type: "string", description: "官网通道实际用的下载地址(github 通道为空串)" },
|
|
76
82
|
notes: { type: "array", items: { type: "string" } },
|
|
77
83
|
message: { type: "string" },
|
|
78
84
|
nextStep: { type: "string" },
|
|
@@ -116,6 +122,12 @@ export function formatFirmwareReport(report) {
|
|
|
116
122
|
if (report.targetDir !== "") {
|
|
117
123
|
lines.push("位置:" + report.targetDir + "(" + report.targetKind + ")");
|
|
118
124
|
}
|
|
125
|
+
if (report.source === "official" && report.downloadUrl !== "") {
|
|
126
|
+
lines.push("来源:ST 官网 " + report.downloadUrl + "(经 CubeMX 装进 Repository)");
|
|
127
|
+
}
|
|
128
|
+
else if (report.source === "github") {
|
|
129
|
+
lines.push("来源:GitHub 拼包(HAL 驱动 + CMSIS 设备支持 + 内核头)");
|
|
130
|
+
}
|
|
119
131
|
if (report.steps.length > 0) {
|
|
120
132
|
lines.push("步骤:");
|
|
121
133
|
for (const step of report.steps) {
|
|
@@ -146,8 +158,9 @@ export function registerFirmwareInstall(ctx) {
|
|
|
146
158
|
ctx.tools.register({
|
|
147
159
|
name: FIRMWARE_INSTALL_TOOL,
|
|
148
160
|
description: "下载并组装 STM32 固件包(STM32Cube_FW_<族>_V<版本>),默认装到 <CubeMX>/dsh-firmware(与 Repository 并列,不动官方包)。" +
|
|
149
|
-
"
|
|
150
|
-
"
|
|
161
|
+
"两条通道(source 默认 auto):官网直取 = 按 db 的 FwLibrary 拼官网 zip 地址(sw-center.st.com),校验 Content-Length 与每条 CRC32 后交给 CubeMX 的 swmgr install 装进 Repository(许可按「族+版本」记账,首装要先在 CubeMX 里点一次同意:插件从 CubeMX 日志读 Accepted Firmware Licenses,缺 FW.<族>.<版本> 就直接告诉你缺哪个标签并回退 GitHub 拼包,不再干等;等 CubeMX 的上限 5 分钟);" +
|
|
162
|
+
"回退通道 = 从 GitHub 拉 HAL 驱动与 CMSIS 设备支持两个子模块仓库 + 5 个内核头,自己补 package.xml。" +
|
|
163
|
+
"重要:拼包落点若在 Repository 之外,实测 CubeMX 会静默忽略自造版本号,真正生效的是生成脚本里的 project setCustomFWPath —— 那一步由 stm32_generate 自动做。" +
|
|
151
164
|
"默认只出计划:列出装到哪、下多大、做哪几步,不下载、不建目录。真装必须同时给 dryRun:false 与 confirm:true。已有官方包时什么都不做。",
|
|
152
165
|
parameters: {
|
|
153
166
|
type: "object",
|
|
@@ -163,6 +176,11 @@ export function registerFirmwareInstall(ctx) {
|
|
|
163
176
|
},
|
|
164
177
|
targetDir: { type: "string", description: "直接指定包目录(自定义布局用,跳过自动选址)" },
|
|
165
178
|
cubeMxRoot: { type: "string", description: "CubeMX 安装根;不给就用配置/自动发现" },
|
|
179
|
+
source: {
|
|
180
|
+
type: "string",
|
|
181
|
+
enum: ["auto", "official", "github"],
|
|
182
|
+
description: "走哪条通道:auto(默认,先官网直取、失败回退 GitHub 拼包)/ official(只走官网;失败就报错不换源)/ github(只拼包)",
|
|
183
|
+
},
|
|
166
184
|
dryRun: { type: "boolean", description: "默认 true:只出计划。必须是 false 才可能真下" },
|
|
167
185
|
confirm: { type: "boolean", description: "确认真的联网下载并写磁盘;默认 false" },
|
|
168
186
|
foreground: { type: "boolean", description: "true = 同步等装完;默认后台 job" },
|
|
@@ -193,15 +211,24 @@ export function registerFirmwareInstall(ctx) {
|
|
|
193
211
|
...(args.version === undefined ? {} : { version: args.version }),
|
|
194
212
|
...(args.target === undefined ? {} : { target: args.target }),
|
|
195
213
|
...(args.targetDir === undefined ? {} : { targetDir: args.targetDir }),
|
|
214
|
+
...(args.source === undefined ? {} : { source: args.source }),
|
|
196
215
|
cubeMxRoots: config.cubeMxRoots,
|
|
197
216
|
};
|
|
217
|
+
const subprocess = ctx.get("subprocess");
|
|
218
|
+
const installOptions = {
|
|
219
|
+
...base,
|
|
220
|
+
mode: "install",
|
|
221
|
+
env: process.env,
|
|
222
|
+
...(subprocess === undefined ? {} : { subprocess }),
|
|
223
|
+
...(args.cubeMxRoot === undefined ? {} : { cubeMxRoot: args.cubeMxRoot }),
|
|
224
|
+
};
|
|
198
225
|
const plan = firmwareInstallPlan({ ...base, env: process.env });
|
|
199
226
|
if (!realInstall || plan.targetKind === "existing" || !plan.ok) {
|
|
200
227
|
return { mode: "report", jobId: "", message: plan.message, report: plan };
|
|
201
228
|
}
|
|
202
229
|
const jobs = ctx.get("jobs");
|
|
203
230
|
if (args.foreground === true || jobs === undefined) {
|
|
204
|
-
const report = await installFirmware({ ...
|
|
231
|
+
const report = await installFirmware({ ...installOptions, signal: exec.signal });
|
|
205
232
|
return { mode: "report", jobId: "", message: report.message, report };
|
|
206
233
|
}
|
|
207
234
|
const controller = new AbortController();
|
|
@@ -214,9 +241,7 @@ export function registerFirmwareInstall(ctx) {
|
|
|
214
241
|
run: (handle) => {
|
|
215
242
|
handle.append("开始下载 " + plan.packageName + " → " + plan.targetDir + "\n");
|
|
216
243
|
const done = installFirmware({
|
|
217
|
-
...
|
|
218
|
-
mode: "install",
|
|
219
|
-
env: process.env,
|
|
244
|
+
...installOptions,
|
|
220
245
|
signal: controller.signal,
|
|
221
246
|
onProgress: (line) => handle.append(line + "\n"),
|
|
222
247
|
})
|
package/lib/tools/flash.js
CHANGED
|
@@ -6,9 +6,12 @@
|
|
|
6
6
|
* 这个工具阻塞执行(通常 3–10 s),跑完立刻释放探针。
|
|
7
7
|
*/
|
|
8
8
|
import { runFlash } from "../engine/flash.js";
|
|
9
|
+
import { PROBE_ERROR_SCHEMA, formatProbeError } from "../engine/probe-error.js";
|
|
9
10
|
import { releaseProbeFor } from "../engine/debug-session.js";
|
|
10
11
|
import { ensureToolchain, gateReportNotes } from "../engine/toolchain-gate.js";
|
|
11
12
|
import { resolveProjectDir } from "./project-dir.js";
|
|
13
|
+
import { describeFacts, mcuFromIoc } from "../engine/facts.js";
|
|
14
|
+
import { ensureFacts } from "../engine/facts-acquire.js";
|
|
12
15
|
export const FLASH_TOOL = "stm32_flash";
|
|
13
16
|
const reportSchema = {
|
|
14
17
|
type: "object",
|
|
@@ -30,7 +33,8 @@ const reportSchema = {
|
|
|
30
33
|
logTail: { type: "string" },
|
|
31
34
|
notes: { type: "array", items: { type: "string" } },
|
|
32
35
|
guard: { type: "string" },
|
|
33
|
-
|
|
36
|
+
// B2:结构化探针错误(旧错误码字段已删除,不做兼容别名)。成功路径不出现该字段。
|
|
37
|
+
probeError: PROBE_ERROR_SCHEMA,
|
|
34
38
|
},
|
|
35
39
|
required: ["ok", "projectDir", "elfPath", "elfSize", "command", "args", "durationMs", "programmed", "verified", "errors", "message", "logTail", "notes"],
|
|
36
40
|
};
|
|
@@ -49,6 +53,10 @@ const ENV_CHECK_SCHEMA = {
|
|
|
49
53
|
enum: ["block", "warn", "off"],
|
|
50
54
|
description: "工具链检查:block 缺件就拒绝(默认)、warn 只警告、off 不检查",
|
|
51
55
|
};
|
|
56
|
+
export function flashReportForHost(report) {
|
|
57
|
+
const { probeError, ...rest } = report;
|
|
58
|
+
return probeError === null ? rest : { ...rest, probeError };
|
|
59
|
+
}
|
|
52
60
|
export function formatFlashReport(report) {
|
|
53
61
|
const lines = [];
|
|
54
62
|
lines.push((report.ok ? "烧录成功" : "烧录失败") + ":" + report.message);
|
|
@@ -59,8 +67,9 @@ export function formatFlashReport(report) {
|
|
|
59
67
|
if (report.command !== "")
|
|
60
68
|
lines.push("命令:" + report.command);
|
|
61
69
|
lines.push("写入=" + (report.programmed ? "是" : "否") + ",校验=" + (report.verified ? "是" : "否"));
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
const probeError = report.probeError ?? null;
|
|
71
|
+
if (probeError !== null)
|
|
72
|
+
lines.push(formatProbeError(probeError));
|
|
64
73
|
for (const note of report.notes)
|
|
65
74
|
lines.push("· " + note);
|
|
66
75
|
for (const error of report.errors.slice(0, 10))
|
|
@@ -75,7 +84,7 @@ export function formatFlashReport(report) {
|
|
|
75
84
|
export function registerFlash(ctx) {
|
|
76
85
|
ctx.tools.register({
|
|
77
86
|
name: FLASH_TOOL,
|
|
78
|
-
description: "
|
|
87
|
+
description: "只烧录不调试,烧完复位运行并立刻释放探针(不拉调试会话、不停在 main)。后端三选一(backend):auto(默认)= openocd 先烧、失败再试 STM32CubeProgrammer CLI;openocd = 只用 openocd;cubeprogrammer = 直接用 CLI(只认 ST-LINK,不依赖 openocd 的 target/flash 脚本——H5/WBA/WB0/WL3 只能走它)。烧录前过三道门禁:工具链缺件直接拒(cubeprogrammer 后端不看 openocd);.ioc 没启用 Serial Wire 也拒(会把 SWD 烧失联,确实要烧带 allowNoDebug=true);这颗芯片有 rm-topics 主题清单但 facts 机检没过同样拒(allowUnknownFacts=true 强制)。openocd 路径按 USB 实见探针选 interface(ST-Link → interface/stlink-dap.cfg,DAPLink/CMSIS-DAP → interface/cmsis-dap.cfg),工程自带 openocd.cfg 时以它为准;没自带时驱动不匹配会自动换另一个 interface 重试一次。成功证据:openocd 是 Programming Finished + Verified OK,CLI 是 Data downloaded successfully + Download verified successfully。",
|
|
79
88
|
parameters: {
|
|
80
89
|
type: "object",
|
|
81
90
|
additionalProperties: false,
|
|
@@ -83,12 +92,18 @@ export function registerFlash(ctx) {
|
|
|
83
92
|
projectDir: { type: "string", description: "工程根目录;缺省为当前工作目录。" },
|
|
84
93
|
elfPath: { type: "string", description: "显式指定要烧的 .elf;缺省从构建目录推断。" },
|
|
85
94
|
buildDir: { type: "string", description: "显式构建目录;缺省自动推断(优先 Debug)。" },
|
|
86
|
-
configFile: { type: "string", description: "openocd 配置文件(相对工程目录);缺省找 openocd.cfg
|
|
95
|
+
configFile: { type: "string", description: "openocd 配置文件(相对工程目录);缺省找 openocd.cfg。给了且存在时以它为准:不按探针改 interface,也不自动换 interface 重试。" },
|
|
87
96
|
iocPath: { type: "string", description: "SWD 守卫要看的 .ioc(工程里有多个 .ioc 时用它指定)。" },
|
|
88
|
-
adapterSpeed: { type: "number", description: "adapter speed(kHz);连不上时可降到 1000 或 100。" },
|
|
97
|
+
adapterSpeed: { type: "number", description: "adapter speed(kHz);连不上时可降到 1000 或 100。openocd 与 CubeProgrammer 兜底都用它。" },
|
|
89
98
|
timeoutMs: { type: "number", description: "超时毫秒数,默认 120000。" },
|
|
90
99
|
allowNoDebug: { type: "boolean", description: ".ioc 里没有 Serial Wire 时是否仍然烧录(默认 false:拒绝,避免烧掉 SWD)。" },
|
|
100
|
+
allowUnknownFacts: { type: "boolean", description: "这颗芯片有 rm-topics 主题清单(踩过坑)但 facts 语义没机检通过时,是否仍然烧录(默认 false:拒绝)。" },
|
|
91
101
|
binDirs: { type: "array", items: { type: "string" }, description: "工具链目录候选,优先于默认值。" },
|
|
102
|
+
backend: {
|
|
103
|
+
type: "string",
|
|
104
|
+
enum: ["auto", "openocd", "cubeprogrammer"],
|
|
105
|
+
description: "烧录后端:auto(默认,openocd 失败再试 CubeProgrammer CLI 兜底)/ openocd(只用 openocd)/ cubeprogrammer(直接走 STM32_Programmer_CLI,只认 ST-LINK)。",
|
|
106
|
+
},
|
|
92
107
|
envCheck: ENV_CHECK_SCHEMA,
|
|
93
108
|
},
|
|
94
109
|
required: [],
|
|
@@ -107,7 +122,7 @@ export function registerFlash(ctx) {
|
|
|
107
122
|
const subprocess = ctx.get("subprocess");
|
|
108
123
|
if (subprocess === undefined) {
|
|
109
124
|
const report = emptyReport("宿主缺少 subprocess 服务,无法烧录");
|
|
110
|
-
return { message: report.message, report };
|
|
125
|
+
return { message: report.message, report: flashReportForHost(report) };
|
|
111
126
|
}
|
|
112
127
|
const resolution = await resolveProjectDir(ctx, args.projectDir, exec);
|
|
113
128
|
// 门禁:烧录只需要 openocd。缺件且 envCheck=block 时连 openocd 都不起,
|
|
@@ -115,12 +130,27 @@ export function registerFlash(ctx) {
|
|
|
115
130
|
const gate = await ensureToolchain(ctx, {
|
|
116
131
|
capability: "flash",
|
|
117
132
|
...(args.binDirs === undefined ? {} : { binDirs: args.binDirs }),
|
|
118
|
-
envCheck: args.envCheck,
|
|
133
|
+
envCheck: args.backend === "cubeprogrammer" ? "off" : args.envCheck,
|
|
119
134
|
signal: exec.signal,
|
|
120
135
|
});
|
|
121
136
|
if (!gate.ok && gate.mode === "block") {
|
|
122
137
|
const blocked = blockedReport(resolution.projectDir, gate);
|
|
123
|
-
return { message: blocked.message, report: blocked };
|
|
138
|
+
return { message: blocked.message, report: flashReportForHost(blocked) };
|
|
139
|
+
}
|
|
140
|
+
let flashFactsNote = "";
|
|
141
|
+
// 事实层门禁(2026-11-07 用户决定改成三态):先自愈补书,再按「这颗芯片有没有
|
|
142
|
+
// rm-topics 主题清单」判——有清单必须机检过(verified)才烧;没清单直接放行,
|
|
143
|
+
// 载体照下、路径照报(族级判据太粗:坑是芯片级的,用户踩坑就给他这颗建 spec)。
|
|
144
|
+
const mcu = mcuFromIoc(resolution.projectDir);
|
|
145
|
+
const ensured = mcu === null ? null : await ensureFacts(mcu, process.env, { timeoutMs: 150_000, signal: exec.signal });
|
|
146
|
+
const facts = ensured === null ? null : ensured.summary;
|
|
147
|
+
if (ensured !== null && ensured.built.attempted) {
|
|
148
|
+
flashFactsNote = (ensured.built.ok ? "facts 已自动补齐" : "facts 自动补齐没成功(不拦烧录,除非这颗芯片有主题清单):" + ensured.built.message);
|
|
149
|
+
}
|
|
150
|
+
if (facts !== null && facts.hasSpec && !facts.verified && args.allowUnknownFacts !== true) {
|
|
151
|
+
const blocked = emptyReport("没烧:" + facts.line + " 有 rm-topics 主题清单但机检没过——这颗芯片的 RM 结论没被逐字核实,烧下去出坑没人兜底。修清单/重跑 build-facts,或传 allowUnknownFacts=true 强制烧。");
|
|
152
|
+
blocked.notes.push(...describeFacts(facts));
|
|
153
|
+
return { message: blocked.message, report: flashReportForHost(blocked) };
|
|
124
154
|
}
|
|
125
155
|
// 探针只有一块:门禁通过后才让调试会话让出来(B16:缺件时不该把别人的探针收走)。
|
|
126
156
|
const released = await releaseProbeFor("stm32_flash");
|
|
@@ -134,15 +164,20 @@ export function registerFlash(ctx) {
|
|
|
134
164
|
...(args.timeoutMs === undefined ? {} : { timeoutMs: args.timeoutMs }),
|
|
135
165
|
...(args.binDirs === undefined ? {} : { binDirs: args.binDirs }),
|
|
136
166
|
...(args.allowNoDebug === undefined ? {} : { allowNoDebug: args.allowNoDebug }),
|
|
167
|
+
...(args.backend === "auto" || args.backend === "openocd" || args.backend === "cubeprogrammer" ? { backend: args.backend } : {}),
|
|
137
168
|
signal: exec.signal,
|
|
138
169
|
});
|
|
170
|
+
if (flashFactsNote !== "")
|
|
171
|
+
report.notes.push(flashFactsNote);
|
|
172
|
+
if (facts !== null)
|
|
173
|
+
report.notes.push(...describeFacts(facts));
|
|
139
174
|
if (!gate.ok)
|
|
140
175
|
report.notes.unshift(gate.message);
|
|
141
176
|
if (released !== null)
|
|
142
177
|
report.notes.push(released);
|
|
143
178
|
if (resolution.note !== null)
|
|
144
179
|
report.notes.push(resolution.note);
|
|
145
|
-
return { message: report.message, report };
|
|
180
|
+
return { message: report.message, report: flashReportForHost(report) };
|
|
146
181
|
},
|
|
147
182
|
});
|
|
148
183
|
}
|
|
@@ -151,6 +186,7 @@ function blockedReport(projectDir, gate) {
|
|
|
151
186
|
return {
|
|
152
187
|
ok: false, projectDir, elfPath: "", elfSize: 0, command: "", args: [], configs: [],
|
|
153
188
|
durationMs: 0, programmed: false, verified: false,
|
|
189
|
+
probeError: null,
|
|
154
190
|
errors: [], message: gate.message, logTail: "", notes: gateReportNotes(gate),
|
|
155
191
|
};
|
|
156
192
|
}
|
|
@@ -158,6 +194,7 @@ function emptyReport(message) {
|
|
|
158
194
|
return {
|
|
159
195
|
ok: false, projectDir: "", elfPath: "", elfSize: 0, command: "", args: [], configs: [],
|
|
160
196
|
durationMs: 0, programmed: false, verified: false,
|
|
197
|
+
probeError: null,
|
|
161
198
|
errors: [message], message, logTail: "", notes: [],
|
|
162
199
|
};
|
|
163
200
|
}
|
package/lib/tools/generate.js
CHANGED
|
@@ -3,11 +3,16 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 默认走后台 job(3–4 分钟,超过工具超时阈值),进度可读;foreground=true 时
|
|
5
5
|
* 同步等待并直接返回完整报告(调试用)。
|
|
6
|
+
*
|
|
7
|
+
* 不需要设备事实(型号 → 启动文件/容量只在 build_project/doctor 那些地方用;这里只跑 CubeMX
|
|
8
|
+
* 并搬运产物),所以**不**在这里调 ensureAssets —— 生成代码不该因为没网而先卡一次超时。
|
|
6
9
|
*/
|
|
7
10
|
import { runGenerate } from "../engine/generate.js";
|
|
8
11
|
import { releaseProbeFor } from "../engine/debug-session.js";
|
|
9
12
|
import { ensureToolchain, gateReportNotes } from "../engine/toolchain-gate.js";
|
|
10
13
|
import { resolveProjectDir } from "./project-dir.js";
|
|
14
|
+
import { generationRiskNotes, mcuFromIoc } from "../engine/facts.js";
|
|
15
|
+
import { ensureFacts } from "../engine/facts-acquire.js";
|
|
11
16
|
export const GENERATE_TOOL = "stm32_generate";
|
|
12
17
|
const verdictSchema = {
|
|
13
18
|
type: "object",
|
|
@@ -203,6 +208,18 @@ export function registerGenerate(ctx) {
|
|
|
203
208
|
}
|
|
204
209
|
const resolution = await resolveProjectDir(ctx, args.projectDir, exec);
|
|
205
210
|
const projectDir = resolution.projectDir;
|
|
211
|
+
// R5:生成前把「这块板烧录门禁会怎样」摆出来——CubeMX 跑 3–4 分钟之前,
|
|
212
|
+
// 用户/agent 就该知道 facts 缺不缺、烧录会不会被只读门禁拦。
|
|
213
|
+
let riskNotes = [];
|
|
214
|
+
{
|
|
215
|
+
const mcu = mcuFromIoc(projectDir);
|
|
216
|
+
if (mcu !== null) {
|
|
217
|
+
// 自愈:没书当场补(有主题的还要连语义一起抽)。失败不拦生成,风险行会照实说。
|
|
218
|
+
const ensured = await ensureFacts(mcu, process.env, { timeoutMs: 180_000, signal: exec.signal });
|
|
219
|
+
riskNotes = generationRiskNotes(mcu);
|
|
220
|
+
void ensured;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
206
223
|
// 门禁:无头生成要 CubeMX 启动器 + 它自带的 JRE。缺件时不必等 3–4 分钟才报错。
|
|
207
224
|
const gate = await ensureToolchain(ctx, {
|
|
208
225
|
capability: "generate",
|
|
@@ -212,6 +229,10 @@ export function registerGenerate(ctx) {
|
|
|
212
229
|
});
|
|
213
230
|
if (!gate.ok && gate.mode === "block") {
|
|
214
231
|
const blocked = blockedReport(projectDir, gate);
|
|
232
|
+
// R5:block 时也要带事实行——用户接下来多半是去装 CubeMX 再重跑,
|
|
233
|
+
// 「这块板烧录会不会被只读门禁拦」应该在同一个报告里一起看到。
|
|
234
|
+
for (const n of generationRiskNotes(mcuFromIoc(projectDir)))
|
|
235
|
+
blocked.notes.push(n);
|
|
215
236
|
return { mode: "report", jobId: "", message: blocked.message, report: blocked };
|
|
216
237
|
}
|
|
217
238
|
const gateNote = gate.ok ? null : gate.message;
|
|
@@ -237,6 +258,8 @@ export function registerGenerate(ctx) {
|
|
|
237
258
|
report.notes.push(released);
|
|
238
259
|
if (resolution.note !== null)
|
|
239
260
|
report.notes.push(resolution.note);
|
|
261
|
+
for (const n of riskNotes)
|
|
262
|
+
report.notes.push(n);
|
|
240
263
|
return { mode: "report", jobId: "", message: summarize(report), report };
|
|
241
264
|
}
|
|
242
265
|
const registry = jobs;
|
|
@@ -252,6 +275,8 @@ export function registerGenerate(ctx) {
|
|
|
252
275
|
if (released !== null)
|
|
253
276
|
handle.append(released + "\n");
|
|
254
277
|
handle.append("开始无头生成:" + projectDir + "\n" + (resolution.note === null ? "" : resolution.note + "\n"));
|
|
278
|
+
for (const n of riskNotes)
|
|
279
|
+
handle.append(n + "\n");
|
|
255
280
|
const done = runGenerate(subprocess, {
|
|
256
281
|
projectDir,
|
|
257
282
|
...(args.iocPath === undefined ? {} : { iocPath: args.iocPath }),
|
package/lib/tools/ioc-apply.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* 两道闸:① 源文件 SHA-256 必须与 plan 时一致;② 候选文件 SHA-256 必须与 plan 时一致。
|
|
5
5
|
* 任一不符直接拒绝(宁可让人重新 plan,也不把没确认过的内容写进去)。
|
|
6
6
|
* rollbackFrom 走回滚路径,把某次备份的 .ioc 写回去(写前再备份当前文件)。
|
|
7
|
+
*
|
|
8
|
+
* 不需要设备事实(只搬 .ioc 字节),所以不 ensureAssets。
|
|
7
9
|
*/
|
|
8
10
|
import { applyIocPlan, rollbackIoc } from "../engine/ioc-plan.js";
|
|
9
11
|
import { resolveProjectDir } from "./project-dir.js";
|
package/lib/tools/ioc-inspect.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* 不写盘、不起进程,毫秒级返回。重点是派生判断:Serial Wire 调试口是否启用
|
|
5
5
|
* (没启用会生成 __HAL_AFIO_REMAP_SWJ_DISABLE(),烧录后 SWD 连不上)、
|
|
6
6
|
* KeepUserCode 是否开启、目标工具链/落位目录是否与 CMake 工程一致。
|
|
7
|
+
*
|
|
8
|
+
* 不需要设备事实:只读 .ioc 文本,型号就是文件里的 Mcu.CPN,不查内置资源,所以不 ensureAssets。
|
|
7
9
|
*/
|
|
8
10
|
import { readFileSync } from "node:fs";
|
|
9
11
|
import { resolve } from "node:path";
|