dsh-stm32 0.1.1 → 0.1.3
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 +98 -31
- package/README_EN.md +96 -29
- package/docs/development-notes.md +837 -4
- package/docs/reading-guide.md +759 -0
- package/lib/commands/register.js +49 -0
- package/lib/data/chips.js +147 -30
- package/lib/data/clock-f1.js +158 -0
- package/lib/data/cmsis-sources.js +237 -42
- package/lib/data/device-facts.js +201 -0
- package/lib/data/stm32f1.js +130 -0
- package/lib/data/svd.js +627 -0
- package/lib/engine/assets.js +924 -0
- package/lib/engine/breakpoints.js +242 -0
- package/lib/engine/build.js +115 -16
- package/lib/engine/cache.js +56 -0
- package/lib/engine/clock-plan.js +608 -0
- package/lib/engine/cmake-sources.js +428 -0
- package/lib/engine/debug-session.js +153 -5
- package/lib/engine/debug.js +114 -15
- package/lib/engine/doctor.js +395 -4
- package/lib/engine/fetch.js +174 -30
- package/lib/engine/flash.js +70 -9
- package/lib/engine/generate.js +11 -0
- package/lib/engine/hal-chip.js +230 -0
- package/lib/engine/ioc-plan.js +33 -7
- package/lib/engine/msys2-install.js +332 -61
- package/lib/engine/probe-error.js +212 -0
- package/lib/engine/probe-session.js +311 -0
- package/lib/engine/project-export.js +129 -0
- package/lib/engine/register-clock.js +132 -0
- package/lib/engine/register-linker.js +129 -0
- package/lib/engine/register-template.js +115 -20
- package/lib/engine/regs.js +2 -0
- package/lib/engine/rtt.js +600 -0
- package/lib/engine/scaffold.js +104 -28
- package/lib/engine/zip.js +142 -0
- package/lib/index.js +10 -0
- package/lib/skill/stm32-workflow.js +3 -3
- package/lib/tools/assets.js +341 -0
- package/lib/tools/build.js +12 -0
- package/lib/tools/cache.js +47 -8
- package/lib/tools/debug-session.js +40 -5
- package/lib/tools/debug.js +41 -4
- package/lib/tools/doctor.js +22 -2
- package/lib/tools/flash.js +15 -3
- package/lib/tools/generate.js +3 -0
- package/lib/tools/ioc-apply.js +2 -0
- package/lib/tools/ioc-inspect.js +2 -0
- package/lib/tools/ioc-plan.js +198 -4
- package/lib/tools/project-create.js +50 -1
- package/lib/tools/project-export.js +100 -0
- package/lib/tools/regs.js +453 -61
- package/lib/tools/route-plan.js +3 -0
- package/lib/tools/rtt.js +347 -0
- package/package.json +5 -3
- package/templates/register/CMakeLists.txt +25 -6
- package/templates/register/Core/Inc/rtt.h +103 -0
- package/templates/register/Core/Src/main.c +43 -9
- package/templates/register/Core/Src/rtt.c +297 -0
- package/templates/scaffold/RTT.md +86 -0
- package/templates/scaffold/cmake/user/CMakeLists.txt +7 -0
- package/templates/scaffold/openocd.cfg +8 -0
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,18 +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" },
|
|
54
|
+
// B2:失败时带结构化探针错误(与 stm32_flash 同一份分类)。可选对象,成功路径不出现。
|
|
55
|
+
probeError: PROBE_ERROR_SCHEMA,
|
|
38
56
|
durationMs: { type: "number" },
|
|
39
57
|
errors: { type: "array", items: { type: "string" } },
|
|
40
58
|
message: { type: "string" },
|
|
41
59
|
notes: { type: "array", items: { type: "string" } },
|
|
42
60
|
},
|
|
43
|
-
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"],
|
|
44
62
|
};
|
|
45
63
|
export const outputSchema = {
|
|
46
64
|
type: "object",
|
|
@@ -57,15 +75,26 @@ const ENV_CHECK_SCHEMA = {
|
|
|
57
75
|
enum: ["block", "warn", "off"],
|
|
58
76
|
description: "工具链检查:block 缺件就拒绝(默认)、warn 只警告、off 不检查",
|
|
59
77
|
};
|
|
78
|
+
export function debugReportForHost(report) {
|
|
79
|
+
const { probeError, ...rest } = report;
|
|
80
|
+
return probeError === null ? rest : { ...rest, probeError };
|
|
81
|
+
}
|
|
60
82
|
export function formatDebugReport(report) {
|
|
61
83
|
const lines = [];
|
|
62
84
|
lines.push((report.ok ? "调试快照完成" : "调试失败") + ":" + report.message);
|
|
63
85
|
if (report.elfPath !== "")
|
|
64
86
|
lines.push("固件:" + report.elfPath);
|
|
87
|
+
const probeError = report.probeError ?? null;
|
|
88
|
+
if (probeError !== null)
|
|
89
|
+
lines.push(formatProbeError(probeError));
|
|
65
90
|
if (report.port !== 0)
|
|
66
91
|
lines.push("端口:" + String(report.port) + ",断点:" + report.breakAt);
|
|
67
92
|
if (report.location !== "")
|
|
68
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
|
+
}
|
|
69
98
|
if (report.registers.length > 0)
|
|
70
99
|
lines.push("寄存器:" + report.registers.map((item) => item.name + "=" + item.value).join(" "));
|
|
71
100
|
if (report.backtrace.length > 0) {
|
|
@@ -95,6 +124,9 @@ function blockedReport(projectDir, gate) {
|
|
|
95
124
|
ok: false, projectDir, elfPath: "", port: 0, breakAt: "main",
|
|
96
125
|
hitBreakpoint: false, location: "", registers: [], backtrace: [], locals: [],
|
|
97
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,
|
|
98
130
|
errors: [], message: gate.message, notes: gateReportNotes(gate),
|
|
99
131
|
};
|
|
100
132
|
}
|
|
@@ -103,6 +135,9 @@ function emptyReport(message) {
|
|
|
103
135
|
ok: false, projectDir: "", elfPath: "", port: 0, breakAt: "main",
|
|
104
136
|
hitBreakpoint: false, location: "", registers: [], backtrace: [], locals: [],
|
|
105
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,
|
|
106
141
|
errors: [message], message, notes: [],
|
|
107
142
|
};
|
|
108
143
|
}
|
|
@@ -119,6 +154,7 @@ export function registerDebugRun(ctx) {
|
|
|
119
154
|
buildDir: { type: "string", description: "显式构建目录;缺省自动推断(优先 Debug)。" },
|
|
120
155
|
breakAt: { type: "string", description: "断点位置,默认 main;none 表示只连上读现状不停。" },
|
|
121
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 之前直接失败并说明删哪个。" },
|
|
122
158
|
port: { type: "number", description: "gdb 端口;缺省 3333,占用则顺延。" },
|
|
123
159
|
configFile: { type: "string", description: "openocd 配置文件(相对工程目录)。" },
|
|
124
160
|
adapterSpeed: { type: "number", description: "adapter speed(kHz)。" },
|
|
@@ -142,7 +178,7 @@ export function registerDebugRun(ctx) {
|
|
|
142
178
|
const subprocess = ctx.get("subprocess");
|
|
143
179
|
if (subprocess === undefined) {
|
|
144
180
|
const report = emptyReport("宿主缺少 subprocess 服务,无法调试");
|
|
145
|
-
return { message: report.message, report };
|
|
181
|
+
return { message: report.message, report: debugReportForHost(report) };
|
|
146
182
|
}
|
|
147
183
|
const resolution = await resolveProjectDir(ctx, args.projectDir, exec);
|
|
148
184
|
// 门禁:调试要 openocd + GDB 两件。缺件且 envCheck=block 时不占探针、不起进程。
|
|
@@ -154,7 +190,7 @@ export function registerDebugRun(ctx) {
|
|
|
154
190
|
});
|
|
155
191
|
if (!gate.ok && gate.mode === "block") {
|
|
156
192
|
const blocked = blockedReport(resolution.projectDir, gate);
|
|
157
|
-
return { message: blocked.message, report: blocked };
|
|
193
|
+
return { message: blocked.message, report: debugReportForHost(blocked) };
|
|
158
194
|
}
|
|
159
195
|
// debug_run 自己也要独占探针;缺件退出时不动别人的会话(B16)。
|
|
160
196
|
const released = await releaseProbeFor("stm32_debug_run");
|
|
@@ -164,6 +200,7 @@ export function registerDebugRun(ctx) {
|
|
|
164
200
|
...(args.buildDir === undefined ? {} : { buildDir: args.buildDir }),
|
|
165
201
|
...(args.breakAt === undefined ? {} : { breakAt: args.breakAt }),
|
|
166
202
|
...(args.preCommands === undefined ? {} : { preCommands: args.preCommands }),
|
|
203
|
+
...(args.breakpoints === undefined ? {} : { breakpoints: args.breakpoints }),
|
|
167
204
|
...(args.port === undefined ? {} : { port: args.port }),
|
|
168
205
|
...(args.configFile === undefined ? {} : { configFile: args.configFile }),
|
|
169
206
|
...(args.adapterSpeed === undefined ? {} : { adapterSpeed: args.adapterSpeed }),
|
|
@@ -177,7 +214,7 @@ export function registerDebugRun(ctx) {
|
|
|
177
214
|
report.notes.push(released);
|
|
178
215
|
if (resolution.note !== null)
|
|
179
216
|
report.notes.push(resolution.note);
|
|
180
|
-
return { message: report.message, report };
|
|
217
|
+
return { message: report.message, report: debugReportForHost(report) };
|
|
181
218
|
},
|
|
182
219
|
});
|
|
183
220
|
}
|
package/lib/tools/doctor.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* 只读工具(除了跑一下 tasklist/版本命令)。回答的是"为什么现在烧不了/调不了",
|
|
5
5
|
* 特别是"探针被谁占着"这个在 VS Code 调试与命令行工具之间最容易互相踩的问题。
|
|
6
6
|
*/
|
|
7
|
+
import { ensureAssets } from "../engine/assets.js";
|
|
7
8
|
import { runDoctor } from "../engine/doctor.js";
|
|
8
9
|
import { resolveProjectDir } from "./project-dir.js";
|
|
9
10
|
export const DOCTOR_TOOL = "stm32_doctor";
|
|
@@ -62,6 +63,14 @@ export const outputSchema = {
|
|
|
62
63
|
missingRequired: { type: "array", items: { type: "string" } },
|
|
63
64
|
tools: { type: "array", items: toolSchema },
|
|
64
65
|
processes: { type: "array", items: processSchema },
|
|
66
|
+
usb: {
|
|
67
|
+
type: "object",
|
|
68
|
+
properties: {
|
|
69
|
+
kind: { type: "string", enum: ["no-usb", "no-dap", "driver-error", "ok", "unknown"] },
|
|
70
|
+
detail: { type: "string" },
|
|
71
|
+
},
|
|
72
|
+
required: ["kind", "detail"],
|
|
73
|
+
},
|
|
65
74
|
port: { type: "number" },
|
|
66
75
|
portBusy: { type: "boolean" },
|
|
67
76
|
buildDir: { type: "string" },
|
|
@@ -74,7 +83,7 @@ export const outputSchema = {
|
|
|
74
83
|
},
|
|
75
84
|
required: [
|
|
76
85
|
"ok", "projectDir", "message", "durationMs", "missingRequired", "tools", "processes",
|
|
77
|
-
"port", "portBusy", "buildDir", "elfPath", "elfSize", "iocPath", "iocWarnings", "blockers", "notes",
|
|
86
|
+
"port", "portBusy", "buildDir", "elfPath", "elfSize", "iocPath", "iocWarnings", "usb", "blockers", "notes",
|
|
78
87
|
],
|
|
79
88
|
},
|
|
80
89
|
},
|
|
@@ -92,6 +101,7 @@ function formatReport(report) {
|
|
|
92
101
|
lines.push("可疑进程:" + report.processes.map((process) => process.name + "(" + String(process.pid) + ")").join(" "));
|
|
93
102
|
}
|
|
94
103
|
lines.push("gdb 端口:" + String(report.port) + (report.portBusy ? "(被占用)" : "(空闲)"));
|
|
104
|
+
lines.push("USB:" + report.usb.kind + " — " + report.usb.detail);
|
|
95
105
|
if (report.buildDir !== "")
|
|
96
106
|
lines.push("构建目录:" + report.buildDir);
|
|
97
107
|
if (report.elfPath !== "")
|
|
@@ -141,12 +151,16 @@ export function registerDoctor(ctx) {
|
|
|
141
151
|
message: "宿主缺少 subprocess 服务,无法体检",
|
|
142
152
|
report: {
|
|
143
153
|
ok: false, projectDir: args.projectDir ?? "", message: "宿主缺少 subprocess 服务", durationMs: 0,
|
|
144
|
-
missingRequired: ["subprocess"], tools: [], processes: [], port: args.port ?? 3333, portBusy: false,
|
|
154
|
+
missingRequired: ["subprocess"], tools: [], processes: [], usb: { kind: "unknown", detail: "宿主没有 subprocess 服务,无法诊断 USB/探针形态。" }, port: args.port ?? 3333, portBusy: false,
|
|
145
155
|
buildDir: "", elfPath: "", elfSize: 0, iocPath: "", iocWarnings: [], blockers: ["宿主缺少 subprocess 服务"], notes: [],
|
|
146
156
|
},
|
|
147
157
|
};
|
|
148
158
|
}
|
|
149
159
|
const resolution = await resolveProjectDir(ctx, args.projectDir, exec);
|
|
160
|
+
// 芯片型号 / 启动文件 / 引脚一致性都要设备事实:插件不再内置芯片表,事实来自资源包缓存。
|
|
161
|
+
// 这里**不硬失败**——体检本来就是用来回答"为什么现在烧不了",网络不通不该让整张报告消失;
|
|
162
|
+
// 拿不到事实就把原因写进 notes,其余检查(工具链/探针/端口/构建产物)照跑。
|
|
163
|
+
const assets = await ensureAssets({ signal: exec.signal });
|
|
150
164
|
const report = await runDoctor(subprocess, {
|
|
151
165
|
projectDir: resolution.projectDir,
|
|
152
166
|
...(args.binDirs === undefined ? {} : { binDirs: args.binDirs }),
|
|
@@ -157,6 +171,12 @@ export function registerDoctor(ctx) {
|
|
|
157
171
|
});
|
|
158
172
|
if (resolution.note !== null)
|
|
159
173
|
report.notes.push(resolution.note);
|
|
174
|
+
if (!assets.ok) {
|
|
175
|
+
report.notes.push("设备事实不可用:" + assets.message + " —— 型号↔启动文件/设备宏/链接脚本的一致性检查会跳过(其余检查不受影响)");
|
|
176
|
+
}
|
|
177
|
+
else if (assets.status === "refreshed") {
|
|
178
|
+
report.notes.push(assets.message);
|
|
179
|
+
}
|
|
160
180
|
return { message: report.message, report };
|
|
161
181
|
},
|
|
162
182
|
});
|
package/lib/tools/flash.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
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";
|
|
@@ -30,6 +31,8 @@ const reportSchema = {
|
|
|
30
31
|
logTail: { type: "string" },
|
|
31
32
|
notes: { type: "array", items: { type: "string" } },
|
|
32
33
|
guard: { type: "string" },
|
|
34
|
+
// B2:结构化探针错误(旧错误码字段已删除,不做兼容别名)。成功路径不出现该字段。
|
|
35
|
+
probeError: PROBE_ERROR_SCHEMA,
|
|
33
36
|
},
|
|
34
37
|
required: ["ok", "projectDir", "elfPath", "elfSize", "command", "args", "durationMs", "programmed", "verified", "errors", "message", "logTail", "notes"],
|
|
35
38
|
};
|
|
@@ -48,6 +51,10 @@ const ENV_CHECK_SCHEMA = {
|
|
|
48
51
|
enum: ["block", "warn", "off"],
|
|
49
52
|
description: "工具链检查:block 缺件就拒绝(默认)、warn 只警告、off 不检查",
|
|
50
53
|
};
|
|
54
|
+
export function flashReportForHost(report) {
|
|
55
|
+
const { probeError, ...rest } = report;
|
|
56
|
+
return probeError === null ? rest : { ...rest, probeError };
|
|
57
|
+
}
|
|
51
58
|
export function formatFlashReport(report) {
|
|
52
59
|
const lines = [];
|
|
53
60
|
lines.push((report.ok ? "烧录成功" : "烧录失败") + ":" + report.message);
|
|
@@ -58,6 +65,9 @@ export function formatFlashReport(report) {
|
|
|
58
65
|
if (report.command !== "")
|
|
59
66
|
lines.push("命令:" + report.command);
|
|
60
67
|
lines.push("写入=" + (report.programmed ? "是" : "否") + ",校验=" + (report.verified ? "是" : "否"));
|
|
68
|
+
const probeError = report.probeError ?? null;
|
|
69
|
+
if (probeError !== null)
|
|
70
|
+
lines.push(formatProbeError(probeError));
|
|
61
71
|
for (const note of report.notes)
|
|
62
72
|
lines.push("· " + note);
|
|
63
73
|
for (const error of report.errors.slice(0, 10))
|
|
@@ -104,7 +114,7 @@ export function registerFlash(ctx) {
|
|
|
104
114
|
const subprocess = ctx.get("subprocess");
|
|
105
115
|
if (subprocess === undefined) {
|
|
106
116
|
const report = emptyReport("宿主缺少 subprocess 服务,无法烧录");
|
|
107
|
-
return { message: report.message, report };
|
|
117
|
+
return { message: report.message, report: flashReportForHost(report) };
|
|
108
118
|
}
|
|
109
119
|
const resolution = await resolveProjectDir(ctx, args.projectDir, exec);
|
|
110
120
|
// 门禁:烧录只需要 openocd。缺件且 envCheck=block 时连 openocd 都不起,
|
|
@@ -117,7 +127,7 @@ export function registerFlash(ctx) {
|
|
|
117
127
|
});
|
|
118
128
|
if (!gate.ok && gate.mode === "block") {
|
|
119
129
|
const blocked = blockedReport(resolution.projectDir, gate);
|
|
120
|
-
return { message: blocked.message, report: blocked };
|
|
130
|
+
return { message: blocked.message, report: flashReportForHost(blocked) };
|
|
121
131
|
}
|
|
122
132
|
// 探针只有一块:门禁通过后才让调试会话让出来(B16:缺件时不该把别人的探针收走)。
|
|
123
133
|
const released = await releaseProbeFor("stm32_flash");
|
|
@@ -139,7 +149,7 @@ export function registerFlash(ctx) {
|
|
|
139
149
|
report.notes.push(released);
|
|
140
150
|
if (resolution.note !== null)
|
|
141
151
|
report.notes.push(resolution.note);
|
|
142
|
-
return { message: report.message, report };
|
|
152
|
+
return { message: report.message, report: flashReportForHost(report) };
|
|
143
153
|
},
|
|
144
154
|
});
|
|
145
155
|
}
|
|
@@ -148,6 +158,7 @@ function blockedReport(projectDir, gate) {
|
|
|
148
158
|
return {
|
|
149
159
|
ok: false, projectDir, elfPath: "", elfSize: 0, command: "", args: [], configs: [],
|
|
150
160
|
durationMs: 0, programmed: false, verified: false,
|
|
161
|
+
probeError: null,
|
|
151
162
|
errors: [], message: gate.message, logTail: "", notes: gateReportNotes(gate),
|
|
152
163
|
};
|
|
153
164
|
}
|
|
@@ -155,6 +166,7 @@ function emptyReport(message) {
|
|
|
155
166
|
return {
|
|
156
167
|
ok: false, projectDir: "", elfPath: "", elfSize: 0, command: "", args: [], configs: [],
|
|
157
168
|
durationMs: 0, programmed: false, verified: false,
|
|
169
|
+
probeError: null,
|
|
158
170
|
errors: [message], message, logTail: "", notes: [],
|
|
159
171
|
};
|
|
160
172
|
}
|
package/lib/tools/generate.js
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
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";
|
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";
|
package/lib/tools/ioc-plan.js
CHANGED
|
@@ -3,8 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 返回 planId + 源文件 SHA-256 + 逐键 diff。确认之后必须调用 stm32_ioc_apply({ planId }),
|
|
5
5
|
* apply 会核对源文件 SHA-256 是否还是 plan 时那份(期间你若用 CubeMX GUI 改过就会被拒绝)。
|
|
6
|
+
*
|
|
7
|
+
* 时钟(clock 入参)走同一个 plan:时钟就是 .ioc 里的一段键,单开工具会让"改引脚"和"改时钟"
|
|
8
|
+
* 变成两次 plan/apply,中间还可能留下 PLL 与 APB 分频不自洽的中间态。详见 engine/clock-plan.ts。
|
|
9
|
+
*
|
|
10
|
+
* 不需要设备事实:引脚只查"名字是否合法"(src/data/chips.ts 的 isKnownPin,不再有内置引脚表),
|
|
11
|
+
* 时钟/句柄/标签全是 .ioc 自己的键,所以不在这里 ensureAssets(改 .ioc 不该依赖网络)。
|
|
6
12
|
*/
|
|
7
13
|
import { planIocChanges } from "../engine/ioc-plan.js";
|
|
14
|
+
import { formatHz } from "../engine/clock-plan.js";
|
|
8
15
|
import { resolveProjectDir } from "./project-dir.js";
|
|
9
16
|
export const IOC_PLAN_TOOL = "stm32_ioc_plan";
|
|
10
17
|
const changeSchema = {
|
|
@@ -18,6 +25,129 @@ const changeSchema = {
|
|
|
18
25
|
},
|
|
19
26
|
required: ["key", "kind", "before", "after"],
|
|
20
27
|
};
|
|
28
|
+
const clockRequestedSchema = {
|
|
29
|
+
type: "object",
|
|
30
|
+
additionalProperties: false,
|
|
31
|
+
properties: {
|
|
32
|
+
targetHz: { type: "number" },
|
|
33
|
+
pllSource: { type: "string" },
|
|
34
|
+
pllMul: { type: "number" },
|
|
35
|
+
apb1Div: { type: "number" },
|
|
36
|
+
apb2Div: { type: "number" },
|
|
37
|
+
adcDiv: { type: "number" },
|
|
38
|
+
},
|
|
39
|
+
required: ["targetHz", "pllSource", "pllMul", "apb1Div", "apb2Div", "adcDiv"],
|
|
40
|
+
};
|
|
41
|
+
const clockChainSchema = {
|
|
42
|
+
type: "object",
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
properties: {
|
|
45
|
+
pllSource: { type: "string" },
|
|
46
|
+
pllSourceLabel: { type: "string" },
|
|
47
|
+
pllInHz: { type: "number" },
|
|
48
|
+
pllMul: { type: "number" },
|
|
49
|
+
pllClkHz: { type: "number" },
|
|
50
|
+
sysclkHz: { type: "number" },
|
|
51
|
+
hclkHz: { type: "number" },
|
|
52
|
+
apb1Div: { type: "number" },
|
|
53
|
+
apb1Hz: { type: "number" },
|
|
54
|
+
apb1TimHz: { type: "number" },
|
|
55
|
+
apb2Div: { type: "number" },
|
|
56
|
+
apb2Hz: { type: "number" },
|
|
57
|
+
apb2TimHz: { type: "number" },
|
|
58
|
+
adcDiv: { type: "number" },
|
|
59
|
+
adcHz: { type: "number" },
|
|
60
|
+
usbHz: { type: "number" },
|
|
61
|
+
usbAvailable: { type: "boolean" },
|
|
62
|
+
usbPrescaled: { type: "boolean" },
|
|
63
|
+
mcoHz: { type: "number" },
|
|
64
|
+
},
|
|
65
|
+
required: [
|
|
66
|
+
"pllSource", "pllSourceLabel", "pllInHz", "pllMul", "pllClkHz", "sysclkHz", "hclkHz",
|
|
67
|
+
"apb1Div", "apb1Hz", "apb1TimHz", "apb2Div", "apb2Hz", "apb2TimHz", "adcDiv", "adcHz",
|
|
68
|
+
"usbHz", "usbAvailable", "usbPrescaled", "mcoHz",
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
const clockAlternativeSchema = {
|
|
72
|
+
type: "object",
|
|
73
|
+
additionalProperties: false,
|
|
74
|
+
properties: {
|
|
75
|
+
sysclkHz: { type: "number" },
|
|
76
|
+
pllSource: { type: "string" },
|
|
77
|
+
pllSourceLabel: { type: "string" },
|
|
78
|
+
pllMul: { type: "number" },
|
|
79
|
+
apb1Div: { type: "number" },
|
|
80
|
+
adcDiv: { type: "number" },
|
|
81
|
+
usbAvailable: { type: "boolean" },
|
|
82
|
+
deltaHz: { type: "number" },
|
|
83
|
+
},
|
|
84
|
+
required: ["sysclkHz", "pllSource", "pllSourceLabel", "pllMul", "apb1Div", "adcDiv", "usbAvailable", "deltaHz"],
|
|
85
|
+
};
|
|
86
|
+
const clockPeripheralSchema = {
|
|
87
|
+
type: "object",
|
|
88
|
+
additionalProperties: false,
|
|
89
|
+
properties: {
|
|
90
|
+
id: { type: "string" },
|
|
91
|
+
label: { type: "string" },
|
|
92
|
+
bus: { type: "string" },
|
|
93
|
+
clockHz: { type: "number" },
|
|
94
|
+
note: { type: "string" },
|
|
95
|
+
},
|
|
96
|
+
required: ["id", "label", "bus", "clockHz", "note"],
|
|
97
|
+
};
|
|
98
|
+
const clockBaudRowSchema = {
|
|
99
|
+
type: "object",
|
|
100
|
+
additionalProperties: false,
|
|
101
|
+
properties: {
|
|
102
|
+
baud: { type: "number" },
|
|
103
|
+
brr: { type: "number" },
|
|
104
|
+
actualBaud: { type: "number" },
|
|
105
|
+
errorPercent: { type: "number" },
|
|
106
|
+
},
|
|
107
|
+
required: ["baud", "brr", "actualBaud", "errorPercent"],
|
|
108
|
+
};
|
|
109
|
+
const clockBaudTableSchema = {
|
|
110
|
+
type: "object",
|
|
111
|
+
additionalProperties: false,
|
|
112
|
+
properties: {
|
|
113
|
+
id: { type: "string" },
|
|
114
|
+
clockHz: { type: "number" },
|
|
115
|
+
worstBaud: { type: "number" },
|
|
116
|
+
worstErrorPercent: { type: "number" },
|
|
117
|
+
rows: { type: "array", items: clockBaudRowSchema },
|
|
118
|
+
},
|
|
119
|
+
required: ["id", "clockHz", "worstBaud", "worstErrorPercent", "rows"],
|
|
120
|
+
};
|
|
121
|
+
const clockEntrySchema = {
|
|
122
|
+
type: "object",
|
|
123
|
+
additionalProperties: false,
|
|
124
|
+
properties: { key: { type: "string" }, value: { type: "string" } },
|
|
125
|
+
required: ["key", "value"],
|
|
126
|
+
};
|
|
127
|
+
const clockPlanSchema = {
|
|
128
|
+
type: "object",
|
|
129
|
+
additionalProperties: false,
|
|
130
|
+
properties: {
|
|
131
|
+
mode: { type: "string", enum: ["snapshot", "nearest", "explicit", "none"] },
|
|
132
|
+
ok: { type: "boolean" },
|
|
133
|
+
reachable: { type: "boolean" },
|
|
134
|
+
deltaHz: { type: "number" },
|
|
135
|
+
note: { type: "string" },
|
|
136
|
+
requested: clockRequestedSchema,
|
|
137
|
+
achieved: clockChainSchema,
|
|
138
|
+
alternatives: { type: "array", items: clockAlternativeSchema },
|
|
139
|
+
peripherals: { type: "array", items: clockPeripheralSchema },
|
|
140
|
+
bauds: { type: "array", items: clockBaudTableSchema },
|
|
141
|
+
entries: { type: "array", items: clockEntrySchema },
|
|
142
|
+
unset: { type: "array", items: { type: "string" } },
|
|
143
|
+
warnings: { type: "array", items: { type: "string" } },
|
|
144
|
+
errors: { type: "array", items: { type: "string" } },
|
|
145
|
+
},
|
|
146
|
+
required: [
|
|
147
|
+
"mode", "ok", "reachable", "deltaHz", "note", "requested", "achieved", "alternatives",
|
|
148
|
+
"peripherals", "bauds", "entries", "unset", "warnings", "errors",
|
|
149
|
+
],
|
|
150
|
+
};
|
|
21
151
|
export const outputSchema = {
|
|
22
152
|
type: "object",
|
|
23
153
|
additionalProperties: false,
|
|
@@ -35,10 +165,11 @@ export const outputSchema = {
|
|
|
35
165
|
notes: { type: "array", items: { type: "string" } },
|
|
36
166
|
errors: { type: "array", items: { type: "string" } },
|
|
37
167
|
nextStep: { type: "string" },
|
|
168
|
+
clockPlan: clockPlanSchema,
|
|
38
169
|
},
|
|
39
170
|
required: [
|
|
40
171
|
"message", "ok", "projectDir", "iocPath", "planId", "sourceSha256", "candidateSha256",
|
|
41
|
-
"changes", "pinsAfter", "warnings", "notes", "errors", "nextStep",
|
|
172
|
+
"changes", "pinsAfter", "warnings", "notes", "errors", "nextStep", "clockPlan",
|
|
42
173
|
],
|
|
43
174
|
};
|
|
44
175
|
/** 宿主不接受 null(声明为 string 的字段给 null 会被拒),所以"不存在"用空串表达。 */
|
|
@@ -50,7 +181,52 @@ function toViews(changes) {
|
|
|
50
181
|
after: change.after ?? "",
|
|
51
182
|
}));
|
|
52
183
|
}
|
|
53
|
-
|
|
184
|
+
/** 时钟段落:一行结论 + 总线/外设/波特率/备选,数字都从 clockPlan 里取,不重算。 */
|
|
185
|
+
function formatClock(plan) {
|
|
186
|
+
if (plan.mode === "none" && plan.achieved.sysclkHz === 0) {
|
|
187
|
+
return ["时钟:" + plan.note];
|
|
188
|
+
}
|
|
189
|
+
const chain = plan.achieved;
|
|
190
|
+
const lines = [];
|
|
191
|
+
lines.push("时钟:" + plan.note);
|
|
192
|
+
lines.push(" " + (plan.mode === "snapshot" ? "现状" : "结果") + ":SYSCLK " + formatHz(chain.sysclkHz) +
|
|
193
|
+
" / HCLK " + formatHz(chain.hclkHz) +
|
|
194
|
+
"(" + chain.pllSourceLabel + " ×" + String(chain.pllMul) + " = " + formatHz(chain.pllClkHz) + ")");
|
|
195
|
+
if (chain.sysclkHz > 0) {
|
|
196
|
+
lines.push(" 总线:APB1 " + formatHz(chain.apb1Hz) + "(÷" + String(chain.apb1Div) + ",定时器 " + formatHz(chain.apb1TimHz) + ")" +
|
|
197
|
+
" / APB2 " + formatHz(chain.apb2Hz) + "(÷" + String(chain.apb2Div) + ",定时器 " + formatHz(chain.apb2TimHz) + ")" +
|
|
198
|
+
" / ADC " + formatHz(chain.adcHz) + "(÷" + String(chain.adcDiv) + ")" +
|
|
199
|
+
" / USB " + (chain.usbAvailable ? formatHz(chain.usbHz) : "不可用") +
|
|
200
|
+
" / MCO " + formatHz(chain.mcoHz));
|
|
201
|
+
for (const bus of ["apb2", "apb1", "ahb"]) {
|
|
202
|
+
const rows = plan.peripherals.filter((item) => item.bus === bus);
|
|
203
|
+
if (rows.length === 0)
|
|
204
|
+
continue;
|
|
205
|
+
const parts = rows.map((item) => {
|
|
206
|
+
const tag = item.note.includes("未在 .ioc 启用") ? "(未启用)" : "";
|
|
207
|
+
const clock = item.id === "USB" && !chain.usbAvailable ? "—" : formatHz(item.clockHz);
|
|
208
|
+
return item.label + " " + clock + tag;
|
|
209
|
+
});
|
|
210
|
+
lines.push(" " + bus.toUpperCase() + " 外设:" + parts.join(" / "));
|
|
211
|
+
}
|
|
212
|
+
const baud = plan.bauds
|
|
213
|
+
.filter((table) => table.clockHz > 0 && table.rows.length > 0)
|
|
214
|
+
.map((table) => table.id + "@" + formatHz(table.clockHz) + " 最差 " + String(table.worstBaud) + " " +
|
|
215
|
+
(table.worstErrorPercent > 0 ? "+" : "") + table.worstErrorPercent.toFixed(3) + "%");
|
|
216
|
+
if (baud.length > 0)
|
|
217
|
+
lines.push(" 波特率误差(16 倍过采样,BRR=round(fCK/baud)):" + baud.join(" / "));
|
|
218
|
+
}
|
|
219
|
+
if (!plan.reachable && plan.alternatives.length > 0) {
|
|
220
|
+
const parts = plan.alternatives.map((item) => formatHz(item.sysclkHz) + "(差 " + (item.deltaHz >= 0 ? "+" : "-") + formatHz(Math.abs(item.deltaHz)) + ")");
|
|
221
|
+
lines.push(" 备选(按接近程度):" + parts.join(" / "));
|
|
222
|
+
}
|
|
223
|
+
if (plan.entries.length > 0) {
|
|
224
|
+
lines.push(" 写入 " + String(plan.entries.length) + " 个 RCC 键(含 RCC.IPParameters 合并);" +
|
|
225
|
+
(plan.unset.length > 0 ? "删除 " + plan.unset.join("、") + ";" : "") + "逐个值见上面的 diff。");
|
|
226
|
+
}
|
|
227
|
+
return lines;
|
|
228
|
+
}
|
|
229
|
+
function format(changes, message, warnings, errors, nextStep, clockPlan) {
|
|
54
230
|
const lines = [message];
|
|
55
231
|
for (const change of changes.slice(0, 40)) {
|
|
56
232
|
if (change.kind === "added")
|
|
@@ -62,6 +238,7 @@ function format(changes, message, warnings, errors, nextStep) {
|
|
|
62
238
|
}
|
|
63
239
|
if (changes.length > 40)
|
|
64
240
|
lines.push(" … 还有 " + String(changes.length - 40) + " 个键");
|
|
241
|
+
lines.push(...formatClock(clockPlan));
|
|
65
242
|
for (const warning of warnings)
|
|
66
243
|
lines.push("! " + warning);
|
|
67
244
|
for (const error of errors.slice(0, 8))
|
|
@@ -73,7 +250,7 @@ function format(changes, message, warnings, errors, nextStep) {
|
|
|
73
250
|
export function registerIocPlan(ctx) {
|
|
74
251
|
ctx.tools.register({
|
|
75
252
|
name: IOC_PLAN_TOOL,
|
|
76
|
-
description: "改 STM32CubeMX .ioc 的第一步:只读源文件、算出逐键 diff 与源 SHA-256,返回 planId,不写盘。支持 entries(设键)/unset(删键)/pins(加 GPIO 引脚)/serialWire(补 Serial Wire 调试口)。确认 diff 之后必须用 stm32_ioc_apply({planId}) 才真正写入。",
|
|
253
|
+
description: "改 STM32CubeMX .ioc 的第一步:只读源文件、算出逐键 diff 与源 SHA-256,返回 planId,不写盘。支持 entries(设键)/unset(删键)/pins(加 GPIO 引脚)/serialWire(补 Serial Wire 调试口)/clock(改时钟:targetHz 就近或 pllMul 定点,自动重算整套 RCC 派生键并给逐外设频率与 UART 波特率误差)。确认 diff 之后必须用 stm32_ioc_apply({planId}) 才真正写入。",
|
|
77
254
|
parameters: {
|
|
78
255
|
type: "object",
|
|
79
256
|
additionalProperties: false,
|
|
@@ -108,6 +285,21 @@ export function registerIocPlan(ctx) {
|
|
|
108
285
|
},
|
|
109
286
|
},
|
|
110
287
|
serialWire: { type: "boolean", description: "确保 PA13/PA14 是 Serial Wire,并清掉 No_Debug(VP_SYS_VS_ND)残留。" },
|
|
288
|
+
clock: {
|
|
289
|
+
type: "object",
|
|
290
|
+
additionalProperties: false,
|
|
291
|
+
description: "改时钟:给 targetHz 就近取最接近的合法档(不可达时报告明写「不可达,已选 X MHz」),或给 pllMul 定点;只会重算 RCC 的派生键,不动引脚。",
|
|
292
|
+
properties: {
|
|
293
|
+
targetHz: { type: "number", description: "目标 SYSCLK(Hz),例如 60000000。" },
|
|
294
|
+
pllSource: { type: "string", enum: ["hse", "hsi-div2", "hsi"], description: "PLL 输入源;缺省按 .ioc 有没有配 HSE 晶振决定。" },
|
|
295
|
+
pllMul: { type: "number", minimum: 2, maximum: 16, description: "定点倍频 ×2..×16;给了就不再就近搜。" },
|
|
296
|
+
apb1Div: { type: "number", description: "APB1 分频 1/2/4/8/16;缺省取满足 APB1≤36 MHz 的最小分频。" },
|
|
297
|
+
apb2Div: { type: "number", description: "APB2 分频;缺省 1(降频只会拖慢外设)。" },
|
|
298
|
+
adcDiv: { type: "number", description: "ADC 预分频 2/4/6/8;缺省取满足 ADC≤14 MHz 的最小分频。" },
|
|
299
|
+
usb: { type: "boolean", description: "按「要用 USB」规划(写 RCC.USBPrescaler=÷1.5,只有 PLLCLK=72 MHz 才给得出 48 MHz)。" },
|
|
300
|
+
bauds: { type: "array", items: { type: "number" }, description: "要算整除误差的波特率档,缺省 9600…230400。" },
|
|
301
|
+
},
|
|
302
|
+
},
|
|
111
303
|
},
|
|
112
304
|
},
|
|
113
305
|
timeoutMs: 30_000,
|
|
@@ -116,7 +308,7 @@ export function registerIocPlan(ctx) {
|
|
|
116
308
|
schema: outputSchema,
|
|
117
309
|
render: (_args, value) => {
|
|
118
310
|
const typed = value;
|
|
119
|
-
return [{ type: "text", text: format(typed.changes, typed.message, typed.warnings, typed.errors, typed.nextStep).join("\n") }];
|
|
311
|
+
return [{ type: "text", text: format(typed.changes, typed.message, typed.warnings, typed.errors, typed.nextStep, typed.clockPlan).join("\n") }];
|
|
120
312
|
},
|
|
121
313
|
},
|
|
122
314
|
async execute(rawArgs, exec) {
|
|
@@ -131,6 +323,7 @@ export function registerIocPlan(ctx) {
|
|
|
131
323
|
...(args.unset === undefined ? {} : { unset: args.unset }),
|
|
132
324
|
...(args.pins === undefined ? {} : { pins: args.pins }),
|
|
133
325
|
...(args.serialWire === undefined ? {} : { serialWire: args.serialWire }),
|
|
326
|
+
...(args.clock === undefined ? {} : { clock: args.clock }),
|
|
134
327
|
});
|
|
135
328
|
if (resolution.note !== null)
|
|
136
329
|
report.notes.push(resolution.note);
|
|
@@ -152,6 +345,7 @@ export function registerIocPlan(ctx) {
|
|
|
152
345
|
notes: report.notes,
|
|
153
346
|
errors: report.errors,
|
|
154
347
|
nextStep,
|
|
348
|
+
clockPlan: report.clockPlan,
|
|
155
349
|
};
|
|
156
350
|
},
|
|
157
351
|
});
|