dsh-stm32 0.1.0 → 0.1.2
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 +127 -29
- package/README_EN.md +125 -29
- package/client/client.js +682 -0
- package/docs/development-notes.md +1385 -5
- package/docs/logic-audit.md +607 -0
- package/docs/reading-guide.md +738 -0
- package/lib/client.js +682 -0
- package/lib/commands/register.js +214 -12
- package/lib/data/chips.js +134 -4
- package/lib/data/clock-f1.js +158 -0
- package/lib/data/cmsis-sources.js +316 -0
- package/lib/data/f1-ram.generated.js +34 -0
- package/lib/data/firmware-packages.js +352 -0
- package/lib/data/install-guides.js +190 -0
- package/lib/data/search-roots.js +135 -15
- package/lib/data/stm32f1.js +186 -0
- package/lib/data/toolchain-config.js +310 -0
- package/lib/engine/build.js +121 -16
- package/lib/engine/cache.js +336 -0
- package/lib/engine/clock-plan.js +608 -0
- package/lib/engine/cmake-sources.js +428 -0
- package/lib/engine/code-patch.js +18 -6
- package/lib/engine/debug-session.js +163 -4
- package/lib/engine/debug.js +84 -19
- package/lib/engine/doctor.js +395 -4
- package/lib/engine/fetch.js +287 -0
- package/lib/engine/firmware-install.js +668 -0
- package/lib/engine/flash.js +145 -15
- package/lib/engine/fs-longpath.js +107 -0
- package/lib/engine/generate-cache.js +118 -0
- package/lib/engine/generate-script.js +30 -8
- package/lib/engine/generate.js +296 -14
- package/lib/engine/hal-chip.js +230 -0
- package/lib/engine/ioc-plan.js +47 -8
- package/lib/engine/msys2-install.js +1870 -0
- package/lib/engine/probe.js +57 -6
- 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 +449 -0
- package/lib/engine/regs.js +18 -4
- package/lib/engine/route-plan.js +553 -0
- package/lib/engine/scaffold.js +303 -72
- package/lib/engine/subprocess-runner.js +2 -0
- package/lib/engine/tar.js +250 -0
- package/lib/engine/text-file.js +150 -0
- package/lib/engine/thirdparty.js +243 -0
- package/lib/engine/tool-env.js +51 -0
- package/lib/engine/toolchain-gate.js +386 -0
- package/lib/engine/vscode-config.js +99 -0
- package/lib/engine/web-api.js +375 -0
- package/lib/engine/web-routes.js +100 -0
- package/lib/engine/xcube-catalog.js +102 -0
- package/lib/engine/xcube.js +254 -0
- package/lib/engine/zip.js +142 -0
- package/lib/index.js +44 -2
- package/lib/skill/stm32-workflow.js +3 -3
- package/lib/tools/build.js +55 -3
- package/lib/tools/cache.js +250 -0
- package/lib/tools/code-patch.js +29 -2
- package/lib/tools/debug-session.js +56 -14
- package/lib/tools/debug.js +43 -2
- package/lib/tools/doctor.js +16 -3
- package/lib/tools/env-install.js +472 -0
- package/lib/tools/env-probe.js +6 -2
- package/lib/tools/firmware-install.js +255 -0
- package/lib/tools/flash.js +41 -2
- package/lib/tools/generate.js +96 -10
- package/lib/tools/ioc-apply.js +27 -11
- package/lib/tools/ioc-inspect.js +4 -2
- package/lib/tools/ioc-plan.js +209 -11
- package/lib/tools/project-create.js +229 -21
- package/lib/tools/project-dir.js +95 -0
- package/lib/tools/project-export.js +100 -0
- package/lib/tools/regs.js +82 -7
- package/lib/tools/route-plan.js +467 -0
- package/package.json +11 -4
- package/templates/register/CMakeLists.txt +52 -0
- package/templates/register/Core/Src/main.c +72 -0
- package/templates/scaffold/openocd.cfg +8 -0
- package/templates/scaffold/vscode/launch.json +8 -6
- package/templates/scaffold/vscode/settings.json +5 -11
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L3:stm32_route_plan —— 这个工程该走 HAL 还是寄存器。
|
|
3
|
+
*
|
|
4
|
+
* 与"通用对照表"的区别:必须绑到一个真工程 + 一句真需求。同一个外设,读一次温度和
|
|
5
|
+
* 多通道 DMA 连续采样不是一件事,抽象评分会逼用户在他没想清的场景上做选择。
|
|
6
|
+
*
|
|
7
|
+
* 它不做三件事:不写盘、不起进程(除了门禁的版本探测)、不替用户改 .ioc。
|
|
8
|
+
* 输出是"每个外设的代价/风险 + 一条建议",外加工具链分流:
|
|
9
|
+
* · pacman 能补的(gcc/gdb/openocd/cmake/ninja)→ 可代装,给 stm32_env_install 的路
|
|
10
|
+
* · CubeMX / 固件包 → 只能人装,给 guides[](含离线整目录拷贝的做法)
|
|
11
|
+
*/
|
|
12
|
+
import { readFileSync } from "node:fs";
|
|
13
|
+
import { resolveSearchConfig } from "../data/search-roots.js";
|
|
14
|
+
import { firmwareGuide } from "../data/install-guides.js";
|
|
15
|
+
import { findIocFile } from "../engine/generate.js";
|
|
16
|
+
import { summarizeIoc } from "../engine/ioc.js";
|
|
17
|
+
import { assessRoute, familyOf, findFirmwarePackage, } from "../engine/route-plan.js";
|
|
18
|
+
import { ensureToolchain } from "../engine/toolchain-gate.js";
|
|
19
|
+
import { resolveProjectDir } from "./project-dir.js";
|
|
20
|
+
export const ROUTE_PLAN_TOOL = "stm32_route_plan";
|
|
21
|
+
/** CubeMX 在 .ioc 里会写这三条虚拟条目,它们不是外设,不能当"已使能"的证据。 */
|
|
22
|
+
const VIRTUAL_IOC_IPS = new Set(["nvic", "rcc", "sys"]);
|
|
23
|
+
const deviceSchema = {
|
|
24
|
+
type: "object",
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
properties: {
|
|
27
|
+
id: { type: "string" },
|
|
28
|
+
label: { type: "string" },
|
|
29
|
+
matchedBy: { type: "array", items: { type: "string" } },
|
|
30
|
+
advice: { type: "string", enum: ["hal", "register", "hal-required"] },
|
|
31
|
+
halEffort: { type: "number" },
|
|
32
|
+
halRisk: { type: "number" },
|
|
33
|
+
halSetup: { type: "string" },
|
|
34
|
+
regEffort: { type: "number" },
|
|
35
|
+
regRisk: { type: "number" },
|
|
36
|
+
regSetup: { type: "string" },
|
|
37
|
+
reason: { type: "string" },
|
|
38
|
+
},
|
|
39
|
+
required: [
|
|
40
|
+
"id",
|
|
41
|
+
"label",
|
|
42
|
+
"matchedBy",
|
|
43
|
+
"advice",
|
|
44
|
+
"halEffort",
|
|
45
|
+
"halRisk",
|
|
46
|
+
"halSetup",
|
|
47
|
+
"regEffort",
|
|
48
|
+
"regRisk",
|
|
49
|
+
"regSetup",
|
|
50
|
+
"reason",
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
const missingSchema = {
|
|
54
|
+
type: "object",
|
|
55
|
+
additionalProperties: false,
|
|
56
|
+
properties: {
|
|
57
|
+
id: { type: "string" },
|
|
58
|
+
label: { type: "string" },
|
|
59
|
+
installability: { type: "string", enum: ["auto", "manual"] },
|
|
60
|
+
hint: { type: "string" },
|
|
61
|
+
firstInstall: { type: "string" },
|
|
62
|
+
verify: { type: "string" },
|
|
63
|
+
},
|
|
64
|
+
required: ["id", "label", "installability", "hint", "firstInstall", "verify"],
|
|
65
|
+
};
|
|
66
|
+
const firmwareSchema = {
|
|
67
|
+
type: "object",
|
|
68
|
+
additionalProperties: false,
|
|
69
|
+
properties: {
|
|
70
|
+
found: { type: "boolean" },
|
|
71
|
+
family: { type: "string" },
|
|
72
|
+
packageName: { type: "string" },
|
|
73
|
+
path: { type: "string" },
|
|
74
|
+
incomplete: { type: "boolean" },
|
|
75
|
+
message: { type: "string" },
|
|
76
|
+
},
|
|
77
|
+
required: ["found", "family", "packageName", "path", "incomplete", "message"],
|
|
78
|
+
};
|
|
79
|
+
const stepSchema = {
|
|
80
|
+
type: "object",
|
|
81
|
+
additionalProperties: false,
|
|
82
|
+
properties: {
|
|
83
|
+
title: { type: "string" },
|
|
84
|
+
detail: { type: "string" },
|
|
85
|
+
command: { type: "string" },
|
|
86
|
+
},
|
|
87
|
+
required: ["title", "detail", "command"],
|
|
88
|
+
};
|
|
89
|
+
const guideSchema = {
|
|
90
|
+
type: "object",
|
|
91
|
+
additionalProperties: false,
|
|
92
|
+
properties: {
|
|
93
|
+
component: { type: "string" },
|
|
94
|
+
label: { type: "string" },
|
|
95
|
+
why: { type: "string" },
|
|
96
|
+
sizeHint: { type: "string" },
|
|
97
|
+
needsAccount: { type: "boolean" },
|
|
98
|
+
steps: { type: "array", items: stepSchema },
|
|
99
|
+
verify: { type: "string" },
|
|
100
|
+
portable: { type: "string" },
|
|
101
|
+
},
|
|
102
|
+
required: ["component", "label", "why", "sizeHint", "needsAccount", "steps", "verify", "portable"],
|
|
103
|
+
};
|
|
104
|
+
export const outputSchema = {
|
|
105
|
+
type: "object",
|
|
106
|
+
additionalProperties: false,
|
|
107
|
+
properties: {
|
|
108
|
+
ok: { type: "boolean" },
|
|
109
|
+
message: { type: "string" },
|
|
110
|
+
projectDir: { type: "string" },
|
|
111
|
+
mcu: { type: "string" },
|
|
112
|
+
family: { type: "string" },
|
|
113
|
+
requirement: { type: "string" },
|
|
114
|
+
verdict: { type: "string", enum: ["hal-only", "both-viable", "register-ok", "unclear"] },
|
|
115
|
+
verdictLabel: { type: "string" },
|
|
116
|
+
devices: { type: "array", items: deviceSchema },
|
|
117
|
+
unknown: { type: "array", items: { type: "string" } },
|
|
118
|
+
delta: { type: "array", items: { type: "string" } },
|
|
119
|
+
halSteps: { type: "array", items: { type: "string" } },
|
|
120
|
+
regSteps: { type: "array", items: { type: "string" } },
|
|
121
|
+
toolchainCapability: { type: "string" },
|
|
122
|
+
toolchainOk: { type: "boolean" },
|
|
123
|
+
toolchainMessage: { type: "string" },
|
|
124
|
+
toolchainDetail: { type: "string" },
|
|
125
|
+
missing: { type: "array", items: missingSchema },
|
|
126
|
+
firmware: firmwareSchema,
|
|
127
|
+
guides: { type: "array", items: guideSchema },
|
|
128
|
+
recommendations: { type: "array", items: { type: "string" } },
|
|
129
|
+
notes: { type: "array", items: { type: "string" } },
|
|
130
|
+
},
|
|
131
|
+
required: [
|
|
132
|
+
"ok",
|
|
133
|
+
"message",
|
|
134
|
+
"projectDir",
|
|
135
|
+
"mcu",
|
|
136
|
+
"family",
|
|
137
|
+
"requirement",
|
|
138
|
+
"verdict",
|
|
139
|
+
"verdictLabel",
|
|
140
|
+
"devices",
|
|
141
|
+
"unknown",
|
|
142
|
+
"delta",
|
|
143
|
+
"halSteps",
|
|
144
|
+
"regSteps",
|
|
145
|
+
"toolchainCapability",
|
|
146
|
+
"toolchainOk",
|
|
147
|
+
"toolchainMessage",
|
|
148
|
+
"toolchainDetail",
|
|
149
|
+
"missing",
|
|
150
|
+
"firmware",
|
|
151
|
+
"guides",
|
|
152
|
+
"recommendations",
|
|
153
|
+
"notes",
|
|
154
|
+
],
|
|
155
|
+
};
|
|
156
|
+
const ADVICE_LABEL = {
|
|
157
|
+
hal: "用 HAL",
|
|
158
|
+
register: "可以寄存器",
|
|
159
|
+
"hal-required": "必须 HAL",
|
|
160
|
+
};
|
|
161
|
+
function emptyFirmware(family, message) {
|
|
162
|
+
return { found: false, family, packageName: "", path: "", incomplete: false, message };
|
|
163
|
+
}
|
|
164
|
+
/** 早退也得是完整形状(宿主按 output.schema 校验)。 */
|
|
165
|
+
function emptyValue(message, projectDir = "") {
|
|
166
|
+
return {
|
|
167
|
+
ok: false,
|
|
168
|
+
message,
|
|
169
|
+
projectDir,
|
|
170
|
+
mcu: "",
|
|
171
|
+
family: "",
|
|
172
|
+
requirement: "",
|
|
173
|
+
verdict: "unclear",
|
|
174
|
+
verdictLabel: "还没看出要做什么外设",
|
|
175
|
+
devices: [],
|
|
176
|
+
unknown: [],
|
|
177
|
+
delta: [],
|
|
178
|
+
halSteps: [],
|
|
179
|
+
regSteps: [],
|
|
180
|
+
toolchainCapability: "",
|
|
181
|
+
toolchainOk: false,
|
|
182
|
+
toolchainMessage: "",
|
|
183
|
+
toolchainDetail: "",
|
|
184
|
+
missing: [],
|
|
185
|
+
firmware: emptyFirmware("", ""),
|
|
186
|
+
guides: [],
|
|
187
|
+
recommendations: [],
|
|
188
|
+
notes: [],
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function toGuideValue(guide) {
|
|
192
|
+
return {
|
|
193
|
+
component: guide.component,
|
|
194
|
+
label: guide.label,
|
|
195
|
+
why: guide.why,
|
|
196
|
+
sizeHint: guide.sizeHint,
|
|
197
|
+
needsAccount: guide.needsAccount,
|
|
198
|
+
steps: guide.steps.map((step) => ({ title: step.title, detail: step.detail, command: step.command ?? "" })),
|
|
199
|
+
verify: guide.verify,
|
|
200
|
+
portable: guide.portable ?? "",
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function toFirmwareValue(check) {
|
|
204
|
+
return {
|
|
205
|
+
found: check.found,
|
|
206
|
+
family: check.family,
|
|
207
|
+
packageName: check.packageName,
|
|
208
|
+
path: check.path,
|
|
209
|
+
incomplete: check.incomplete,
|
|
210
|
+
message: check.message,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function toDevices(assessment) {
|
|
214
|
+
return assessment.devices.map((device) => ({
|
|
215
|
+
id: device.id,
|
|
216
|
+
label: device.label,
|
|
217
|
+
matchedBy: [...device.matchedBy],
|
|
218
|
+
advice: device.advice,
|
|
219
|
+
halEffort: device.hal.effort,
|
|
220
|
+
halRisk: device.hal.risk,
|
|
221
|
+
halSetup: device.hal.setup,
|
|
222
|
+
regEffort: device.reg?.effort ?? 0,
|
|
223
|
+
regRisk: device.reg?.risk ?? 0,
|
|
224
|
+
regSetup: device.reg?.setup ?? "",
|
|
225
|
+
reason: device.reason,
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
function toMissing(gate) {
|
|
229
|
+
return gate.missing.map((item) => ({
|
|
230
|
+
id: item.id,
|
|
231
|
+
label: item.label,
|
|
232
|
+
installability: item.installability,
|
|
233
|
+
hint: item.hint,
|
|
234
|
+
firstInstall: item.install[0] ?? "",
|
|
235
|
+
verify: item.verify,
|
|
236
|
+
}));
|
|
237
|
+
}
|
|
238
|
+
/** 卡片正文:先给结论,再给每个外设一行,最后给路线步骤与缺件。 */
|
|
239
|
+
function formatValue(value) {
|
|
240
|
+
const lines = [];
|
|
241
|
+
lines.push(value.message);
|
|
242
|
+
lines.push("");
|
|
243
|
+
lines.push("MCU:" + (value.mcu === "" ? "(没说)" : value.mcu) + (value.family === "" ? "" : ",族 " + value.family) + " 工程:" + value.projectDir);
|
|
244
|
+
lines.push("需求:" + value.requirement);
|
|
245
|
+
if (value.devices.length > 0) {
|
|
246
|
+
lines.push("");
|
|
247
|
+
lines.push("外设(代价/风险 1 最省 → 5 最费):");
|
|
248
|
+
for (const device of value.devices) {
|
|
249
|
+
const reg = device.advice === "hal-required" ? "寄存器:不做" : "寄存器:" + String(device.regEffort) + "/" + String(device.regRisk);
|
|
250
|
+
lines.push(" " + device.label.padEnd(28) + (ADVICE_LABEL[device.advice] ?? device.advice).padEnd(12)
|
|
251
|
+
+ "HAL:" + String(device.halEffort) + "/" + String(device.halRisk) + " " + reg);
|
|
252
|
+
lines.push(" " + device.reason);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (value.delta.length > 0) {
|
|
256
|
+
lines.push("");
|
|
257
|
+
lines.push("两条路的差别:");
|
|
258
|
+
for (const line of value.delta)
|
|
259
|
+
lines.push(" · " + line);
|
|
260
|
+
}
|
|
261
|
+
const steps = value.verdict === "register-ok" ? value.regSteps : value.halSteps;
|
|
262
|
+
if (steps.length > 0) {
|
|
263
|
+
lines.push("");
|
|
264
|
+
lines.push(value.verdict === "register-ok" ? "寄存器版怎么落地:" : "HAL 版怎么落地:");
|
|
265
|
+
for (const [index, step] of steps.entries())
|
|
266
|
+
lines.push(" " + String(index + 1) + ". " + step);
|
|
267
|
+
}
|
|
268
|
+
lines.push("");
|
|
269
|
+
lines.push("工具链(" + value.toolchainCapability + "):" + value.toolchainMessage);
|
|
270
|
+
if (value.toolchainCapability === "generate" || value.firmware.family !== "") {
|
|
271
|
+
lines.push("固件包:" + value.firmware.message);
|
|
272
|
+
}
|
|
273
|
+
if (value.missing.length > 0) {
|
|
274
|
+
lines.push("");
|
|
275
|
+
lines.push("缺件:");
|
|
276
|
+
for (const item of value.missing) {
|
|
277
|
+
lines.push(" · " + item.label + "(" + (item.installability === "auto" ? "可代装" : "只能人装") + "):" + item.hint);
|
|
278
|
+
if (item.firstInstall !== "")
|
|
279
|
+
lines.push(" " + item.firstInstall);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (value.guides.length > 0) {
|
|
283
|
+
lines.push("");
|
|
284
|
+
lines.push("要你自己装的部分:");
|
|
285
|
+
for (const guide of value.guides) {
|
|
286
|
+
lines.push(" 【" + guide.label + "】" + guide.why);
|
|
287
|
+
lines.push(" 体积:" + guide.sizeHint);
|
|
288
|
+
for (const [index, step] of guide.steps.entries()) {
|
|
289
|
+
lines.push(" " + String(index + 1) + ". " + step.title + " —— " + step.detail);
|
|
290
|
+
}
|
|
291
|
+
lines.push(" 自检:" + guide.verify);
|
|
292
|
+
if (guide.portable !== "")
|
|
293
|
+
lines.push(" 免安装:" + guide.portable);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (value.recommendations.length > 0) {
|
|
297
|
+
lines.push("");
|
|
298
|
+
for (const line of value.recommendations)
|
|
299
|
+
lines.push("→ " + line);
|
|
300
|
+
}
|
|
301
|
+
for (const note of value.notes)
|
|
302
|
+
lines.push("· " + note);
|
|
303
|
+
return lines;
|
|
304
|
+
}
|
|
305
|
+
export function registerRoutePlan(ctx) {
|
|
306
|
+
ctx.tools.register({
|
|
307
|
+
name: ROUTE_PLAN_TOOL,
|
|
308
|
+
description: "评估一个具体工程该走 HAL(.ioc + CubeMX 生成)还是寄存器(手写 main.c):按这句需求逐个外设给出开发代价与出错风险,并对工具链缺件分流(pacman 能补的 vs 只能人装的 CubeMX/固件包)。必须绑具体工程与一句需求;不做通用对照表。只读:不写盘、不改 .ioc。",
|
|
309
|
+
parameters: {
|
|
310
|
+
type: "object",
|
|
311
|
+
additionalProperties: false,
|
|
312
|
+
properties: {
|
|
313
|
+
requirement: {
|
|
314
|
+
type: "string",
|
|
315
|
+
description: "一句话说清要做什么,例如「按键控制 LED,串口每秒打印状态」。识别外设靠这句话。",
|
|
316
|
+
},
|
|
317
|
+
peripherals: {
|
|
318
|
+
type: "array",
|
|
319
|
+
items: { type: "string" },
|
|
320
|
+
description: "显式点名的外设(可选),例如 [\"usart-poll\", \"tim-pwm\", \"adc-single\"] 或中文「串口」「PWM」。",
|
|
321
|
+
},
|
|
322
|
+
projectDir: { type: "string", description: "工程根目录;缺省为会话工作目录。" },
|
|
323
|
+
mcu: { type: "string", description: "芯片型号,例如 STM32F103C8T6;缺省取 .ioc 里的 Mcu.CPN。" },
|
|
324
|
+
envCheck: {
|
|
325
|
+
type: "string",
|
|
326
|
+
enum: ["block", "warn", "off"],
|
|
327
|
+
description: "工具链检查档位:block(默认,缺就明确告诉你)/warn(只警告)/off(不查)。",
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
required: ["requirement"],
|
|
331
|
+
},
|
|
332
|
+
output: {
|
|
333
|
+
schema: outputSchema,
|
|
334
|
+
render: (_args, value) => {
|
|
335
|
+
const typed = value;
|
|
336
|
+
if (typed.devices.length === 0 && typed.message !== "")
|
|
337
|
+
return [{ type: "text", text: typed.message }];
|
|
338
|
+
return [{ type: "text", text: formatValue(typed).join("\n") }];
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
timeoutMs: 60_000,
|
|
342
|
+
// A16:execute 会读工程目录并起子进程探版本命令,不是并发安全的。
|
|
343
|
+
isConcurrencySafe: () => false,
|
|
344
|
+
async execute(rawArgs, exec) {
|
|
345
|
+
const args = rawArgs ?? {};
|
|
346
|
+
const requirement = typeof args.requirement === "string" ? args.requirement.trim() : "";
|
|
347
|
+
if (requirement === "") {
|
|
348
|
+
return emptyValue("requirement 必填:一句话说清要做什么,例如「按键控制 LED,串口每秒打印一次状态」。"
|
|
349
|
+
+ "只有把要用的外设说出来,才能判断 HAL 与寄存器哪条划算。");
|
|
350
|
+
}
|
|
351
|
+
const resolution = await resolveProjectDir(ctx, args.projectDir, exec);
|
|
352
|
+
const projectDir = resolution.projectDir;
|
|
353
|
+
const notes = [];
|
|
354
|
+
if (resolution.note !== null)
|
|
355
|
+
notes.push(resolution.note);
|
|
356
|
+
let iocPeripherals = [];
|
|
357
|
+
let iocMcu = "";
|
|
358
|
+
const iocPath = findIocFile(projectDir);
|
|
359
|
+
if (iocPath === null) {
|
|
360
|
+
notes.push("工程里没有 .ioc(寄存器版工程本来就没有):外设只按需求这句话和 peripherals 识别。");
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
try {
|
|
364
|
+
const summary = summarizeIoc(readFileSync(iocPath, "utf8"), iocPath);
|
|
365
|
+
// .ioc 里的 NVIC / RCC / SYS 是 CubeMX 的虚拟系统条目,不是用户外设:
|
|
366
|
+
// 当成"证据"会让 notes 说「已把 3 个外设算作证据」而表里只有 2 个,纯噪声。
|
|
367
|
+
iocPeripherals = summary.peripherals.filter((name) => !VIRTUAL_IOC_IPS.has(name.toLowerCase()));
|
|
368
|
+
iocMcu = summary.mcu.cpn;
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
notes.push("读 .ioc 失败,已跳过它的外设证据:" + String(error));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const mcu = typeof args.mcu === "string" && args.mcu.trim() !== "" ? args.mcu.trim() : iocMcu;
|
|
375
|
+
const family = familyOf(mcu);
|
|
376
|
+
const assessment = assessRoute({
|
|
377
|
+
requirement,
|
|
378
|
+
peripherals: Array.isArray(args.peripherals) ? args.peripherals : [],
|
|
379
|
+
iocPeripherals,
|
|
380
|
+
});
|
|
381
|
+
// 寄存器版只要编译器;HAL 版必须有 CubeMX(生成代码的人不是我们)。
|
|
382
|
+
const capability = assessment.verdict === "register-ok" ? "build" : "generate";
|
|
383
|
+
// A16:连外设都没认出来(unclear)时先别探工具链 —— 用户这会儿要补的是需求,不是装工具。
|
|
384
|
+
const gate = assessment.verdict === "unclear" ? null : await ensureToolchain(ctx, {
|
|
385
|
+
capability,
|
|
386
|
+
...(args.envCheck === undefined ? {} : { envCheck: args.envCheck }),
|
|
387
|
+
signal: exec.signal,
|
|
388
|
+
});
|
|
389
|
+
const searchConfig = resolveSearchConfig(process.env);
|
|
390
|
+
const firmwareCheck = findFirmwarePackage(searchConfig.cubeMxRoots, mcu);
|
|
391
|
+
const firmware = toFirmwareValue(firmwareCheck);
|
|
392
|
+
const guides = gate === null ? [] : gate.guides.map(toGuideValue);
|
|
393
|
+
const needsHal = assessment.verdict !== "register-ok" && assessment.verdict !== "unclear";
|
|
394
|
+
if (needsHal && !firmwareCheck.found) {
|
|
395
|
+
const fallbackRepository = firmwareCheck.repositoryDir !== ""
|
|
396
|
+
? firmwareCheck.repositoryDir
|
|
397
|
+
: (searchConfig.cubeMxRoots[0] === undefined ? "" : searchConfig.cubeMxRoots[0] + "/Repository");
|
|
398
|
+
if (fallbackRepository === "") {
|
|
399
|
+
notes.push("本机没探测到 CubeMX 安装根:guide 里的固件包落位要你自己填 <CubeMX安装目录>/Repository。");
|
|
400
|
+
}
|
|
401
|
+
const guide = firmwareGuide({
|
|
402
|
+
family: firmwareCheck.family === "" ? family : firmwareCheck.family,
|
|
403
|
+
packageName: firmwareCheck.packageName,
|
|
404
|
+
repositoryDir: fallbackRepository,
|
|
405
|
+
});
|
|
406
|
+
guides.push(toGuideValue(guide));
|
|
407
|
+
}
|
|
408
|
+
const recommendations = [...assessment.recommendations];
|
|
409
|
+
if (assessment.verdict !== "register-ok" && !firmwareCheck.found) {
|
|
410
|
+
recommendations.push("固件包还没有:CubeMX 的包管理器里装一次(guide 里有步骤),装完 route_plan 会自己认出来。");
|
|
411
|
+
}
|
|
412
|
+
if (gate !== null && gate.missing.some((item) => item.installability === "auto")) {
|
|
413
|
+
recommendations.push("能代装的缺件:回一句「装」,我先跑 stm32_env_install 出计划(只列大小与步骤,不下载)。");
|
|
414
|
+
}
|
|
415
|
+
// A16:ok 只回答「路线评估本身成了吗」。缺工具链只进 notes / guides / recommendations,
|
|
416
|
+
// 以前和 gate.ok 相与会把「评估成功、只是这台机器还没装工具」吞成 ok:false。
|
|
417
|
+
const ok = assessment.verdict !== "unclear"
|
|
418
|
+
&& (assessment.verdict === "register-ok" || firmwareCheck.found);
|
|
419
|
+
if (gate !== null && !gate.ok)
|
|
420
|
+
notes.push(gate.message);
|
|
421
|
+
const parts = [];
|
|
422
|
+
if (assessment.verdict === "unclear") {
|
|
423
|
+
parts.push("这句需求里我没认出外设,先说说要用什么(或直接列 peripherals)。");
|
|
424
|
+
}
|
|
425
|
+
else if (assessment.verdict === "hal-only") {
|
|
426
|
+
parts.push("这条只能走 HAL(.ioc + CubeMX 生成):"
|
|
427
|
+
+ assessment.devices.filter((device) => device.advice === "hal-required").map((device) => device.label).join("、")
|
|
428
|
+
+ " 的寄存器版等于重写协议栈/内核。");
|
|
429
|
+
}
|
|
430
|
+
else if (assessment.verdict === "register-ok") {
|
|
431
|
+
parts.push("寄存器版够用:" + String(assessment.devices.length) + " 个外设都能直接写寄存器,不需要 CubeMX 与固件包。");
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
parts.push("两条路都能走,建议 HAL(省事、可读),寄存器版只在代价低的那几项上划算。");
|
|
435
|
+
}
|
|
436
|
+
if (assessment.verdict !== "register-ok" && assessment.verdict !== "unclear") {
|
|
437
|
+
parts.push(firmwareCheck.found ? "固件包已就位。" : "固件包还没装(CubeMX 包管理器装一次)。");
|
|
438
|
+
}
|
|
439
|
+
if (gate !== null && !gate.ok)
|
|
440
|
+
parts.push("工具链缺 " + gate.missing.map((item) => item.label).join("、") + "。");
|
|
441
|
+
return {
|
|
442
|
+
ok,
|
|
443
|
+
message: parts.join(""),
|
|
444
|
+
projectDir,
|
|
445
|
+
mcu,
|
|
446
|
+
family,
|
|
447
|
+
requirement,
|
|
448
|
+
verdict: assessment.verdict,
|
|
449
|
+
verdictLabel: assessment.verdictLabel,
|
|
450
|
+
devices: toDevices(assessment),
|
|
451
|
+
unknown: [...assessment.unknown],
|
|
452
|
+
delta: [...assessment.delta],
|
|
453
|
+
halSteps: [...assessment.halSteps],
|
|
454
|
+
regSteps: [...assessment.regSteps],
|
|
455
|
+
toolchainCapability: gate === null ? "none" : capability,
|
|
456
|
+
toolchainOk: gate === null ? false : gate.ok,
|
|
457
|
+
toolchainMessage: gate === null ? "没检查:需求里的外设还没认出来,先补需求。" : gate.message,
|
|
458
|
+
toolchainDetail: gate === null ? "unclear:按审计 A16 跳过工具链探测。" : gate.detail,
|
|
459
|
+
missing: gate === null ? [] : toMissing(gate),
|
|
460
|
+
firmware,
|
|
461
|
+
guides,
|
|
462
|
+
recommendations,
|
|
463
|
+
notes: [...notes, ...assessment.notes],
|
|
464
|
+
};
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-stm32",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "DSH 插件:STM32(F103C8T6)全流程工具层 —— 环境探测、.ioc 事务、生成工程、编译、只烧录、按需调试",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./lib/index.js",
|
|
9
|
+
"./client": "./lib/client.js",
|
|
9
10
|
"./package.json": "./package.json"
|
|
10
11
|
},
|
|
11
12
|
"files": [
|
|
12
13
|
"lib",
|
|
14
|
+
"client",
|
|
13
15
|
"templates",
|
|
14
|
-
"docs",
|
|
16
|
+
"docs/*.md",
|
|
15
17
|
"cordis.patch.yml",
|
|
16
18
|
"README.md",
|
|
17
19
|
"README_EN.md",
|
|
@@ -21,10 +23,12 @@
|
|
|
21
23
|
"node": ">=20"
|
|
22
24
|
},
|
|
23
25
|
"scripts": {
|
|
24
|
-
"build": "tsc -p tsconfig.json",
|
|
26
|
+
"build": "tsc -p tsconfig.json && node scripts/copy-client.mjs",
|
|
25
27
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
26
28
|
"test": "node test/run-units.mjs",
|
|
27
|
-
"prepublishOnly": "npm run build"
|
|
29
|
+
"prepublishOnly": "npm run build",
|
|
30
|
+
"test:pack": "node scripts/pack-smoke.mjs",
|
|
31
|
+
"test:size": "node scripts/pack-size.mjs"
|
|
28
32
|
},
|
|
29
33
|
"keywords": [
|
|
30
34
|
"dsh-plugin",
|
|
@@ -53,6 +57,9 @@
|
|
|
53
57
|
"dsh": {
|
|
54
58
|
"bundle": {
|
|
55
59
|
"patch": "./cordis.patch.yml"
|
|
60
|
+
},
|
|
61
|
+
"client": {
|
|
62
|
+
"platform": "web"
|
|
56
63
|
}
|
|
57
64
|
},
|
|
58
65
|
"devDependencies": {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.22)
|
|
2
|
+
|
|
3
|
+
# ======== 由 STM32CubeMX 生成的工程结构,但这份 CMakeLists 是手写的模板 ========
|
|
4
|
+
set(CMAKE_C_STANDARD 11)
|
|
5
|
+
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
6
|
+
set(CMAKE_C_EXTENSIONS ON)
|
|
7
|
+
|
|
8
|
+
if(NOT CMAKE_BUILD_TYPE)
|
|
9
|
+
set(CMAKE_BUILD_TYPE "Debug")
|
|
10
|
+
endif()
|
|
11
|
+
|
|
12
|
+
set(CMAKE_PROJECT_NAME __PROJECT_NAME__)
|
|
13
|
+
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
|
|
14
|
+
|
|
15
|
+
project(${CMAKE_PROJECT_NAME})
|
|
16
|
+
message("Build type: " ${CMAKE_BUILD_TYPE})
|
|
17
|
+
|
|
18
|
+
# ---------------- 链接脚本:按型号渲染的那一份 ----------------
|
|
19
|
+
# 工具链文件(cmake/gcc-arm-none-eabi.cmake)为了兼容 CubeMX 工程,默认已经塞了
|
|
20
|
+
# -T "<源码目录>/STM32F103XX_FLASH.ld"
|
|
21
|
+
# 寄存器路线不用那份写死 C8T6(64K/20K)的脚本,而是用生成时按芯片 Flash/RAM 渲染的
|
|
22
|
+
# <DeviceId>_FLASH.ld。这里把链接参数里那条 -T 换掉:不换的话会出现两个 -T,
|
|
23
|
+
# 先命中的是那份 C8T6 脚本,尺寸不对的芯片(例如 F103ZE 512K)会被截断或越界。
|
|
24
|
+
set(DSH_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/__LINKER_SCRIPT__")
|
|
25
|
+
if(NOT EXISTS "${DSH_LINKER_SCRIPT}")
|
|
26
|
+
message(FATAL_ERROR "链接脚本不存在:${DSH_LINKER_SCRIPT}(stm32_project_create route=register 会按型号生成它)")
|
|
27
|
+
endif()
|
|
28
|
+
string(REGEX REPLACE "-T[ ]+(\"[^\"]*\"|[^ ]+)" "-T \"${DSH_LINKER_SCRIPT}\"" DSH_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
|
|
29
|
+
set(CMAKE_EXE_LINKER_FLAGS "${DSH_EXE_LINKER_FLAGS}")
|
|
30
|
+
message("Linker script: " ${DSH_LINKER_SCRIPT})
|
|
31
|
+
|
|
32
|
+
enable_language(C ASM)
|
|
33
|
+
|
|
34
|
+
# ---------------- 可执行文件 ----------------
|
|
35
|
+
# 只编译三个源:用户 main.c、CMSIS 的 system_stm32f1xx.c、启动文件。
|
|
36
|
+
# 设备头与内核头通过下面两个 include 目录提供,全部来自下载缓存。
|
|
37
|
+
add_executable(${CMAKE_PROJECT_NAME}
|
|
38
|
+
Core/Src/main.c
|
|
39
|
+
Drivers/CMSIS/Device/ST/__FAMILY_DIR__/Source/Templates/system_stm32f1xx.c
|
|
40
|
+
Drivers/CMSIS/Device/ST/__FAMILY_DIR__/Source/Templates/gcc/__STARTUP_FILE__
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
|
|
44
|
+
Core/Inc
|
|
45
|
+
Drivers/CMSIS/Include
|
|
46
|
+
Drivers/CMSIS/Device/ST/__FAMILY_DIR__/Include
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
# __DEVICE_DEFINE__ 由 stm32f1xx.h 用来选中具体型号头(stm32f103xb.h 之类)
|
|
50
|
+
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE __DEVICE_DEFINE__)
|
|
51
|
+
|
|
52
|
+
target_link_libraries(${CMAKE_PROJECT_NAME} ${TOOLCHAIN_LINK_LIBRARIES})
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 寄存器版 main.c(dsh-stm32 生成,模板来源 templates/register/Core/Src/main.c)
|
|
3
|
+
*
|
|
4
|
+
* 目标芯片:__MCU_BANNER__
|
|
5
|
+
* 板子假设:板载 LED 在 PC13(低电平点亮),引脚不同只改下面两行。
|
|
6
|
+
*
|
|
7
|
+
* 这条路线不用 HAL、不用 CubeMX 生成物、也不需要 STM32Cube 固件包:
|
|
8
|
+
* 设备头 + 启动文件 + CMSIS 内核头都在 dsh-stm32 的下载缓存里(第一次联网,之后复用)。
|
|
9
|
+
* 换芯片用 stm32_project_create(route="register", mcu=<型号>):
|
|
10
|
+
* 启动文件、设备宏、链接脚本(Flash/RAM 尺寸)、时钟初始化都会跟着型号重算。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#include <stdint.h>
|
|
14
|
+
|
|
15
|
+
#include "stm32f1xx.h"
|
|
16
|
+
|
|
17
|
+
/* 换板子改这两行 */
|
|
18
|
+
#define LED_PORT GPIOC
|
|
19
|
+
#define LED_PIN 13u
|
|
20
|
+
|
|
21
|
+
/* 便于用 gdb / 串口观察:每闪一次 +1 */
|
|
22
|
+
volatile uint32_t g_led_blink_count = 0u;
|
|
23
|
+
|
|
24
|
+
__CLOCK_INIT__
|
|
25
|
+
/* 忙等延时:SysTick 数到 SystemCoreClock/1000 个时钟算 1 ms。
|
|
26
|
+
* clock_init() 之后 SystemCoreClock 已经是真实频率,所以不需要手动填数字。 */
|
|
27
|
+
static void delay_ms(uint32_t ms)
|
|
28
|
+
{
|
|
29
|
+
SysTick->LOAD = (uint32_t)(SystemCoreClock / 1000u) - 1u;
|
|
30
|
+
SysTick->VAL = 0u;
|
|
31
|
+
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
|
|
32
|
+
|
|
33
|
+
while (ms-- > 0u) {
|
|
34
|
+
while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0u) {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
SysTick->CTRL = 0u;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static void led_init(void)
|
|
42
|
+
{
|
|
43
|
+
#if LED_PIN == 13u
|
|
44
|
+
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
|
|
45
|
+
GPIOC->CRH &= ~(GPIO_CRH_MODE13 | GPIO_CRH_CNF13);
|
|
46
|
+
GPIOC->CRH |= GPIO_CRH_MODE13_0; /* 推挽输出 10 MHz */
|
|
47
|
+
GPIOC->BSRR = GPIO_BSRR_BS13; /* 先给高电平:PC13 低电平点亮 → LED 灭 */
|
|
48
|
+
#else
|
|
49
|
+
#error "只写好了 PC13 的初始化;换引脚请在 led_init() 里补对应的 CRL/CRH 设置"
|
|
50
|
+
#endif
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static void led_toggle(void)
|
|
54
|
+
{
|
|
55
|
+
#if LED_PIN == 13u
|
|
56
|
+
GPIOC->ODR ^= GPIO_ODR_ODR13;
|
|
57
|
+
#else
|
|
58
|
+
#error "只写好了 PC13 的翻转;换引脚请改这里"
|
|
59
|
+
#endif
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
int main(void)
|
|
63
|
+
{
|
|
64
|
+
clock_init(); /* 先把频率提到芯片能跑的上限,再配外设 */
|
|
65
|
+
led_init();
|
|
66
|
+
|
|
67
|
+
while (1) {
|
|
68
|
+
led_toggle();
|
|
69
|
+
g_led_blink_count++;
|
|
70
|
+
delay_ms(500u);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# CMSIS-DAP 探针 + SWD。stm32_project_create 生成;换 ST-Link 就把 source 换成
|
|
2
|
+
# interface/stlink.cfg,J-Link 用 interface/jlink.cfg。adapter speed 可在 1000~5000 之间调。
|
|
3
|
+
# transport 必须写 swd:hla_swd 只有 st-link 系适配器支持,CMSIS-DAP 会报
|
|
4
|
+
# 「Debug adapter doesn't support 'hla_swd' transport」直接连不上。
|
|
5
|
+
source [find interface/cmsis-dap.cfg]
|
|
6
|
+
transport select swd
|
|
7
|
+
source [find target/stm32f1x.cfg]
|
|
8
|
+
adapter speed 2000
|
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
"interface/cmsis-dap.cfg",
|
|
17
17
|
"target/stm32f1x.cfg"
|
|
18
18
|
],
|
|
19
|
-
"svdPath": "
|
|
20
|
-
|
|
21
|
-
"
|
|
19
|
+
// 想看外设寄存器(可选):自己加一行 "svdPath": "<对应芯片的 .svd 绝对路径>"。
|
|
20
|
+
// 不给也能调试,只是没有外设寄存器视图;插件不替你选 SVD。
|
|
21
|
+
"armToolchainPath": "__ARM_TOOLCHAIN_PATH__",
|
|
22
|
+
"gdbPath": "__GDB_PATH__",
|
|
22
23
|
"toolchainPrefix": "arm-none-eabi",
|
|
23
24
|
"showDevDebugOutput": "none",
|
|
24
25
|
"breakAfterReset": false
|
|
@@ -36,9 +37,10 @@
|
|
|
36
37
|
"interface/cmsis-dap.cfg",
|
|
37
38
|
"target/stm32f1x.cfg"
|
|
38
39
|
],
|
|
39
|
-
"svdPath": "
|
|
40
|
-
|
|
41
|
-
"
|
|
40
|
+
// 想看外设寄存器(可选):自己加一行 "svdPath": "<对应芯片的 .svd 绝对路径>"。
|
|
41
|
+
// 不给也能调试,只是没有外设寄存器视图;插件不替你选 SVD。
|
|
42
|
+
"armToolchainPath": "__ARM_TOOLCHAIN_PATH__",
|
|
43
|
+
"gdbPath": "__GDB_PATH__",
|
|
42
44
|
"toolchainPrefix": "arm-none-eabi",
|
|
43
45
|
"showDevDebugOutput": "none",
|
|
44
46
|
"runToEntryPoint": "main"
|