dsh-stm32 0.1.2 → 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 +59 -21
- package/README_EN.md +59 -21
- package/docs/development-notes.md +374 -3
- package/docs/reading-guide.md +87 -66
- package/lib/data/chips.js +38 -51
- package/lib/data/cmsis-sources.js +27 -1
- package/lib/data/device-facts.js +201 -0
- package/lib/data/stm32f1.js +94 -150
- package/lib/data/svd.js +627 -0
- package/lib/engine/assets.js +924 -0
- package/lib/engine/breakpoints.js +242 -0
- package/lib/engine/debug-session.js +153 -5
- package/lib/engine/debug.js +75 -41
- package/lib/engine/doctor.js +2 -2
- package/lib/engine/flash.js +31 -59
- package/lib/engine/ioc-plan.js +5 -5
- package/lib/engine/probe-error.js +212 -0
- package/lib/engine/probe-session.js +311 -0
- package/lib/engine/register-template.js +32 -8
- package/lib/engine/regs.js +2 -0
- package/lib/engine/rtt.js +600 -0
- package/lib/index.js +8 -0
- package/lib/tools/assets.js +341 -0
- package/lib/tools/cache.js +8 -0
- package/lib/tools/debug-session.js +40 -5
- package/lib/tools/debug.js +41 -11
- package/lib/tools/doctor.js +11 -0
- package/lib/tools/flash.js +15 -6
- 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 +3 -0
- package/lib/tools/project-create.js +24 -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 +1 -1
- package/templates/register/CMakeLists.txt +7 -1
- package/templates/register/Core/Inc/rtt.h +103 -0
- package/templates/register/Core/Src/main.c +25 -0
- 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/lib/data/f1-ram.generated.js +0 -34
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";
|
|
@@ -156,6 +157,10 @@ export function registerDoctor(ctx) {
|
|
|
156
157
|
};
|
|
157
158
|
}
|
|
158
159
|
const resolution = await resolveProjectDir(ctx, args.projectDir, exec);
|
|
160
|
+
// 芯片型号 / 启动文件 / 引脚一致性都要设备事实:插件不再内置芯片表,事实来自资源包缓存。
|
|
161
|
+
// 这里**不硬失败**——体检本来就是用来回答"为什么现在烧不了",网络不通不该让整张报告消失;
|
|
162
|
+
// 拿不到事实就把原因写进 notes,其余检查(工具链/探针/端口/构建产物)照跑。
|
|
163
|
+
const assets = await ensureAssets({ signal: exec.signal });
|
|
159
164
|
const report = await runDoctor(subprocess, {
|
|
160
165
|
projectDir: resolution.projectDir,
|
|
161
166
|
...(args.binDirs === undefined ? {} : { binDirs: args.binDirs }),
|
|
@@ -166,6 +171,12 @@ export function registerDoctor(ctx) {
|
|
|
166
171
|
});
|
|
167
172
|
if (resolution.note !== null)
|
|
168
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
|
+
}
|
|
169
180
|
return { message: report.message, report };
|
|
170
181
|
},
|
|
171
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,7 +31,8 @@ const reportSchema = {
|
|
|
30
31
|
logTail: { type: "string" },
|
|
31
32
|
notes: { type: "array", items: { type: "string" } },
|
|
32
33
|
guard: { type: "string" },
|
|
33
|
-
|
|
34
|
+
// B2:结构化探针错误(旧错误码字段已删除,不做兼容别名)。成功路径不出现该字段。
|
|
35
|
+
probeError: PROBE_ERROR_SCHEMA,
|
|
34
36
|
},
|
|
35
37
|
required: ["ok", "projectDir", "elfPath", "elfSize", "command", "args", "durationMs", "programmed", "verified", "errors", "message", "logTail", "notes"],
|
|
36
38
|
};
|
|
@@ -49,6 +51,10 @@ const ENV_CHECK_SCHEMA = {
|
|
|
49
51
|
enum: ["block", "warn", "off"],
|
|
50
52
|
description: "工具链检查:block 缺件就拒绝(默认)、warn 只警告、off 不检查",
|
|
51
53
|
};
|
|
54
|
+
export function flashReportForHost(report) {
|
|
55
|
+
const { probeError, ...rest } = report;
|
|
56
|
+
return probeError === null ? rest : { ...rest, probeError };
|
|
57
|
+
}
|
|
52
58
|
export function formatFlashReport(report) {
|
|
53
59
|
const lines = [];
|
|
54
60
|
lines.push((report.ok ? "烧录成功" : "烧录失败") + ":" + report.message);
|
|
@@ -59,8 +65,9 @@ export function formatFlashReport(report) {
|
|
|
59
65
|
if (report.command !== "")
|
|
60
66
|
lines.push("命令:" + report.command);
|
|
61
67
|
lines.push("写入=" + (report.programmed ? "是" : "否") + ",校验=" + (report.verified ? "是" : "否"));
|
|
62
|
-
|
|
63
|
-
|
|
68
|
+
const probeError = report.probeError ?? null;
|
|
69
|
+
if (probeError !== null)
|
|
70
|
+
lines.push(formatProbeError(probeError));
|
|
64
71
|
for (const note of report.notes)
|
|
65
72
|
lines.push("· " + note);
|
|
66
73
|
for (const error of report.errors.slice(0, 10))
|
|
@@ -107,7 +114,7 @@ export function registerFlash(ctx) {
|
|
|
107
114
|
const subprocess = ctx.get("subprocess");
|
|
108
115
|
if (subprocess === undefined) {
|
|
109
116
|
const report = emptyReport("宿主缺少 subprocess 服务,无法烧录");
|
|
110
|
-
return { message: report.message, report };
|
|
117
|
+
return { message: report.message, report: flashReportForHost(report) };
|
|
111
118
|
}
|
|
112
119
|
const resolution = await resolveProjectDir(ctx, args.projectDir, exec);
|
|
113
120
|
// 门禁:烧录只需要 openocd。缺件且 envCheck=block 时连 openocd 都不起,
|
|
@@ -120,7 +127,7 @@ export function registerFlash(ctx) {
|
|
|
120
127
|
});
|
|
121
128
|
if (!gate.ok && gate.mode === "block") {
|
|
122
129
|
const blocked = blockedReport(resolution.projectDir, gate);
|
|
123
|
-
return { message: blocked.message, report: blocked };
|
|
130
|
+
return { message: blocked.message, report: flashReportForHost(blocked) };
|
|
124
131
|
}
|
|
125
132
|
// 探针只有一块:门禁通过后才让调试会话让出来(B16:缺件时不该把别人的探针收走)。
|
|
126
133
|
const released = await releaseProbeFor("stm32_flash");
|
|
@@ -142,7 +149,7 @@ export function registerFlash(ctx) {
|
|
|
142
149
|
report.notes.push(released);
|
|
143
150
|
if (resolution.note !== null)
|
|
144
151
|
report.notes.push(resolution.note);
|
|
145
|
-
return { message: report.message, report };
|
|
152
|
+
return { message: report.message, report: flashReportForHost(report) };
|
|
146
153
|
},
|
|
147
154
|
});
|
|
148
155
|
}
|
|
@@ -151,6 +158,7 @@ function blockedReport(projectDir, gate) {
|
|
|
151
158
|
return {
|
|
152
159
|
ok: false, projectDir, elfPath: "", elfSize: 0, command: "", args: [], configs: [],
|
|
153
160
|
durationMs: 0, programmed: false, verified: false,
|
|
161
|
+
probeError: null,
|
|
154
162
|
errors: [], message: gate.message, logTail: "", notes: gateReportNotes(gate),
|
|
155
163
|
};
|
|
156
164
|
}
|
|
@@ -158,6 +166,7 @@ function emptyReport(message) {
|
|
|
158
166
|
return {
|
|
159
167
|
ok: false, projectDir: "", elfPath: "", elfSize: 0, command: "", args: [], configs: [],
|
|
160
168
|
durationMs: 0, programmed: false, verified: false,
|
|
169
|
+
probeError: null,
|
|
161
170
|
errors: [message], message, logTail: "", notes: [],
|
|
162
171
|
};
|
|
163
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
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
* 时钟(clock 入参)走同一个 plan:时钟就是 .ioc 里的一段键,单开工具会让"改引脚"和"改时钟"
|
|
8
8
|
* 变成两次 plan/apply,中间还可能留下 PLL 与 APB 分频不自洽的中间态。详见 engine/clock-plan.ts。
|
|
9
|
+
*
|
|
10
|
+
* 不需要设备事实:引脚只查"名字是否合法"(src/data/chips.ts 的 isKnownPin,不再有内置引脚表),
|
|
11
|
+
* 时钟/句柄/标签全是 .ioc 自己的键,所以不在这里 ensureAssets(改 .ioc 不该依赖网络)。
|
|
9
12
|
*/
|
|
10
13
|
import { planIocChanges } from "../engine/ioc-plan.js";
|
|
11
14
|
import { formatHz } from "../engine/clock-plan.js";
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* 两条路线的门禁不同:HAL 路线要 CubeMX(capability=generate),
|
|
13
13
|
* 寄存器路线只要编译工具链(capability=build)——这正是"缺 CubeMX 也能干活"的落点。
|
|
14
14
|
*/
|
|
15
|
+
import { ensureAssets } from "../engine/assets.js";
|
|
15
16
|
import { createProjectScaffold, preflightTarget } from "../engine/scaffold.js";
|
|
16
17
|
import { createRegisterProject } from "../engine/register-template.js";
|
|
17
18
|
import { ensureToolchain, gateReportNotes } from "../engine/toolchain-gate.js";
|
|
@@ -207,6 +208,25 @@ export function registerProjectCreate(ctx) {
|
|
|
207
208
|
},
|
|
208
209
|
};
|
|
209
210
|
}
|
|
211
|
+
// 设备事实(型号 → 启动文件/设备宏/Flash/RAM)只从资源包缓存读:插件不再内置芯片表,
|
|
212
|
+
// 第一次用在这里自动装一次(缓存命中时最坏只是几次 stat,不发网络请求)。
|
|
213
|
+
const assets = await ensureAssets({ signal: exec.signal });
|
|
214
|
+
if (!assets.ok) {
|
|
215
|
+
const message = "设备事实还没就绪,型号 → 启动文件/设备宏/容量都算不出来:插件不再内置芯片表,这些事实只从资源包缓存读。" +
|
|
216
|
+
assets.message;
|
|
217
|
+
const blocked = {
|
|
218
|
+
ok: false,
|
|
219
|
+
route,
|
|
220
|
+
targetDir: args.targetDir,
|
|
221
|
+
projectName: args.projectName ?? "",
|
|
222
|
+
message,
|
|
223
|
+
templateFiles: 0,
|
|
224
|
+
driverFiles: 0,
|
|
225
|
+
durationMs: 0,
|
|
226
|
+
warnings: [message],
|
|
227
|
+
};
|
|
228
|
+
return { message, report: blocked };
|
|
229
|
+
}
|
|
210
230
|
// 门禁:两条路线要的东西不一样。
|
|
211
231
|
// register(寄存器版)建完就能编译 → 按 build 能力查 gcc/cmake/ninja。
|
|
212
232
|
// hal(默认)这一步**只拷文件**(CMake 工程文件 / 链接脚本 / Drivers),既不需要
|
|
@@ -259,6 +279,8 @@ export function registerProjectCreate(ctx) {
|
|
|
259
279
|
};
|
|
260
280
|
if (gate !== null && !gate.ok)
|
|
261
281
|
normalized.warnings.unshift(gate.message);
|
|
282
|
+
if (assets.status === "refreshed")
|
|
283
|
+
normalized.warnings.unshift(assets.message);
|
|
262
284
|
return { message: normalized.message, report: normalized };
|
|
263
285
|
}
|
|
264
286
|
const config = resolveSearchConfig(process.env, args.cubeMxRoots === undefined ? {} : { cubeMxRoots: args.cubeMxRoots });
|
|
@@ -274,6 +296,8 @@ export function registerProjectCreate(ctx) {
|
|
|
274
296
|
// ScaffoldReport 没有 notes 字段,warn 档的警告并进 warnings(卡片照样打出来)。
|
|
275
297
|
if (gate !== null && !gate.ok)
|
|
276
298
|
scaffold.warnings.unshift(gate.message);
|
|
299
|
+
if (assets.status === "refreshed")
|
|
300
|
+
scaffold.warnings.unshift(assets.message);
|
|
277
301
|
const halReport = {
|
|
278
302
|
ok: scaffold.ok,
|
|
279
303
|
route: "hal",
|