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
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P3:stm32_watch —— 变量监视(值采样)与硬件观察点。
|
|
3
|
+
*
|
|
4
|
+
* - action=add:kind=value 登记一个"每次 sample 求值"的表达式;kind=write/read/access 用真实观察点
|
|
5
|
+
* (gdb watch / rwatch / awatch,F1 有 4 个数据比较器,与硬件断点共用);
|
|
6
|
+
* - action=sample:目标在跑就先 -exec-interrupt 停住,逐项求值,给出与上次的差值,再按原状态放回去;
|
|
7
|
+
* - action=list / remove / clear:看登记表、按 id 删、全清。
|
|
8
|
+
*
|
|
9
|
+
* 为什么单独一个工具而不是塞进 stm32_debug_eval:观察点会消耗芯片比较器预算、值监视需要
|
|
10
|
+
* "停下→读→放回"这一整套语义,混进 eval 的裸命令里没人管得住上限。
|
|
11
|
+
* 登记表住在插件进程内(engine/watch.ts 的单例),会话一关就清空(观察点在 gdb 进程里随会话消失)。
|
|
12
|
+
*/
|
|
13
|
+
import { debugSessions } from "../engine/debug-session.js";
|
|
14
|
+
import { WATCH_KIND_LABELS, hardwareWatchpoints, isWatchKind, normalizeWatchExpression, registerWatch, watchState, } from "../engine/watch.js";
|
|
15
|
+
export const WATCH_TOOL = "stm32_watch";
|
|
16
|
+
const quotaSchema = {
|
|
17
|
+
type: "object",
|
|
18
|
+
additionalProperties: false,
|
|
19
|
+
properties: {
|
|
20
|
+
used: { type: "number" },
|
|
21
|
+
limit: { type: "number" },
|
|
22
|
+
remaining: { type: "number" },
|
|
23
|
+
},
|
|
24
|
+
required: ["used", "limit", "remaining"],
|
|
25
|
+
};
|
|
26
|
+
const entrySchema = {
|
|
27
|
+
type: "object",
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
properties: {
|
|
30
|
+
id: { type: "number" },
|
|
31
|
+
expression: { type: "string" },
|
|
32
|
+
kind: { type: "string" },
|
|
33
|
+
kindLabel: { type: "string" },
|
|
34
|
+
gdbNumber: { type: "number" },
|
|
35
|
+
lastValue: { type: "string" },
|
|
36
|
+
lastAt: { type: "number" },
|
|
37
|
+
lastError: { type: "string" },
|
|
38
|
+
delta: { type: "string" },
|
|
39
|
+
},
|
|
40
|
+
required: ["id", "expression", "kind", "kindLabel", "gdbNumber", "lastValue", "lastAt", "lastError", "delta"],
|
|
41
|
+
};
|
|
42
|
+
export const watchOutputSchema = {
|
|
43
|
+
type: "object",
|
|
44
|
+
additionalProperties: false,
|
|
45
|
+
properties: {
|
|
46
|
+
message: { type: "string" },
|
|
47
|
+
report: {
|
|
48
|
+
type: "object",
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
properties: {
|
|
51
|
+
ok: { type: "boolean" },
|
|
52
|
+
action: { type: "string" },
|
|
53
|
+
entries: { type: "array", items: entrySchema },
|
|
54
|
+
watchpoints: quotaSchema,
|
|
55
|
+
halted: { type: "boolean" },
|
|
56
|
+
resumed: { type: "boolean" },
|
|
57
|
+
durationMs: { type: "number" },
|
|
58
|
+
errors: { type: "array", items: { type: "string" } },
|
|
59
|
+
notes: { type: "array", items: { type: "string" } },
|
|
60
|
+
message: { type: "string" },
|
|
61
|
+
},
|
|
62
|
+
required: ["ok", "action", "entries", "watchpoints", "halted", "resumed", "durationMs", "errors", "notes", "message"],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
required: ["message", "report"],
|
|
66
|
+
};
|
|
67
|
+
function entryView(entry, delta = "") {
|
|
68
|
+
return {
|
|
69
|
+
id: entry.id,
|
|
70
|
+
expression: entry.expression,
|
|
71
|
+
kind: entry.kind,
|
|
72
|
+
kindLabel: WATCH_KIND_LABELS[entry.kind],
|
|
73
|
+
gdbNumber: entry.gdbNumber,
|
|
74
|
+
lastValue: entry.lastValue,
|
|
75
|
+
lastAt: entry.lastAt,
|
|
76
|
+
lastError: entry.lastError,
|
|
77
|
+
delta,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function currentQuota() {
|
|
81
|
+
return debugSessions.status().watchpoints;
|
|
82
|
+
}
|
|
83
|
+
/** 值监视清单的人话描述(limit=0 时别写成 "0/0" 让人以为超了)。 */
|
|
84
|
+
function describeQuota(quota) {
|
|
85
|
+
return "硬件观察点 " + String(quota.used) + "/" + String(quota.limit);
|
|
86
|
+
}
|
|
87
|
+
function emptyReport(action, message, errors = [], notes = []) {
|
|
88
|
+
return {
|
|
89
|
+
ok: errors.length === 0, action, entries: [], watchpoints: currentQuota(),
|
|
90
|
+
halted: false, resumed: false, durationMs: 0, errors, notes, message,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** 把 addWatchpoints 的报告翻成本工具的 report(entries 换成视图)。 */
|
|
94
|
+
function fromAddReport(report) {
|
|
95
|
+
return {
|
|
96
|
+
ok: report.ok, action: "add", entries: report.added.map((entry) => entryView(entry)),
|
|
97
|
+
watchpoints: report.budget, halted: false, resumed: report.resumed, durationMs: report.durationMs,
|
|
98
|
+
errors: report.errors, notes: report.notes, message: report.message,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** 把 sampleWatches 的报告翻成本工具的 report(值 + 差值一起给)。 */
|
|
102
|
+
function fromSampleReport(report) {
|
|
103
|
+
const byId = new Map();
|
|
104
|
+
for (const sample of report.samples)
|
|
105
|
+
byId.set(sample.id, sample.delta);
|
|
106
|
+
const errors = report.errors.slice();
|
|
107
|
+
for (const sample of report.samples) {
|
|
108
|
+
if (!sample.ok)
|
|
109
|
+
errors.push(sample.expression + ":" + sample.error);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
ok: report.ok, action: "sample", entries: watchState.entries.map((entry) => entryView(entry, byId.get(entry.id) ?? "")),
|
|
113
|
+
watchpoints: currentQuota(), halted: report.halted, resumed: report.resumed, durationMs: report.durationMs,
|
|
114
|
+
errors, notes: [], message: report.message,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export function registerWatchTool(ctx) {
|
|
118
|
+
ctx.tools.register({
|
|
119
|
+
name: WATCH_TOOL,
|
|
120
|
+
description: "变量监视与硬件观察点。action=add 登记表达式(kind=value 每次 sample 求值;kind=write/read/access 装真正的硬件观察点,F1 只有 4 个数据比较器,与硬件断点共用);action=sample 把目标停下读一遍、给与上次的差值、再按原状态放回去;action=list/remove/clear 管理登记表。值监视项每次 sample 都会求值,观察点是被动拦截(命中时由 gdb 报停)。会话关闭时登记表随之清空。",
|
|
121
|
+
parameters: {
|
|
122
|
+
type: "object",
|
|
123
|
+
additionalProperties: false,
|
|
124
|
+
properties: {
|
|
125
|
+
action: { type: "string", enum: ["add", "sample", "list", "remove", "clear"], description: "要做什么,默认 list(看登记表)。" },
|
|
126
|
+
expressions: { type: "array", items: { type: "string" }, description: "action=add 要监视的表达式,例如 g_tick_1k、g_adc_dma[0]、*(unsigned int *)0x4001100C。" },
|
|
127
|
+
kind: { type: "string", enum: ["value", "write", "read", "access"], description: "action=add 的类型:value(默认,采样求值)、write(写观察点)、read(读观察点)、access(读写观察点)。" },
|
|
128
|
+
ids: { type: "array", items: { type: "number" }, description: "action=remove 要删的 id(action=list 里能看到)。" },
|
|
129
|
+
timeoutMs: { type: "number", description: "单条求值/装观察点的超时毫秒数,默认 20000。" },
|
|
130
|
+
resume: { type: "boolean", description: "采样时目标原本在跑:采完是否放回去(默认 true)。" },
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
timeoutMs: 90_000,
|
|
134
|
+
isConcurrencySafe: () => false,
|
|
135
|
+
output: {
|
|
136
|
+
schema: watchOutputSchema,
|
|
137
|
+
render: (_args, value) => {
|
|
138
|
+
const typed = value;
|
|
139
|
+
const lines = [typed.report.message];
|
|
140
|
+
for (const entry of typed.report.entries) {
|
|
141
|
+
const delta = entry.delta === "" ? "" : "(Δ " + entry.delta + ")";
|
|
142
|
+
const where = entry.gdbNumber > 0 ? " [gdb #" + String(entry.gdbNumber) + "]" : "";
|
|
143
|
+
const value = entry.lastValue === "" ? "(还没采过)" : entry.lastValue;
|
|
144
|
+
lines.push("#" + String(entry.id) + " " + entry.expression + " = " + value + delta + where);
|
|
145
|
+
if (entry.lastError !== "")
|
|
146
|
+
lines.push(" x " + entry.lastError);
|
|
147
|
+
}
|
|
148
|
+
if (typed.report.entries.length === 0)
|
|
149
|
+
lines.push("(登记表是空的:先用 action=add 加表达式)");
|
|
150
|
+
lines.push("· " + describeQuota(typed.report.watchpoints));
|
|
151
|
+
for (const note of typed.report.notes.slice(0, 6))
|
|
152
|
+
lines.push("- " + note);
|
|
153
|
+
for (const error of typed.report.errors.slice(0, 6))
|
|
154
|
+
lines.push("x " + error);
|
|
155
|
+
return [{ type: "text", text: lines.join("\n") }];
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
async execute(rawArgs, exec) {
|
|
159
|
+
const args = rawArgs ?? {};
|
|
160
|
+
const action = args.action ?? "list";
|
|
161
|
+
const startedAt = Date.now();
|
|
162
|
+
const timeout = args.timeoutMs;
|
|
163
|
+
if (action === "add") {
|
|
164
|
+
const expressions = args.expressions ?? [];
|
|
165
|
+
const kind = args.kind === undefined ? "value" : args.kind;
|
|
166
|
+
if (!isWatchKind(kind)) {
|
|
167
|
+
return { message: "kind 不认识:" + String(kind) + "(只认 value/write/read/access)", report: emptyReport(action, "没加:kind 不认识", ["kind 不认识:" + String(kind)]) };
|
|
168
|
+
}
|
|
169
|
+
if (expressions.length === 0) {
|
|
170
|
+
return { message: "没给 expressions:例如 action=add,expressions 传 [g_tick_1k]", report: emptyReport(action, "没加:没给表达式", ["expressions 是空的"]) };
|
|
171
|
+
}
|
|
172
|
+
// 值监视只是登记(求值要等 sample),所以不需要会话;观察点必须现在装进 gdb。
|
|
173
|
+
if (kind === "value") {
|
|
174
|
+
const errors = [];
|
|
175
|
+
const added = [];
|
|
176
|
+
for (const text of expressions) {
|
|
177
|
+
const expression = normalizeWatchExpression(text);
|
|
178
|
+
if (expression === null) {
|
|
179
|
+
errors.push("表达式不合法:" + JSON.stringify(text));
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const registered = registerWatch(watchState, expression, "value", Date.now());
|
|
183
|
+
if (registered.entry === null) {
|
|
184
|
+
errors.push(registered.error);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
added.push(registered.entry);
|
|
188
|
+
}
|
|
189
|
+
const report = {
|
|
190
|
+
ok: errors.length === 0, action: "add", entries: added.map((entry) => entryView(entry)),
|
|
191
|
+
watchpoints: currentQuota(), halted: false, resumed: false, durationMs: Date.now() - startedAt,
|
|
192
|
+
errors, notes: [], message: errors.length === 0 ? "登记了 " + String(added.length) + " 个值监视项(用 action=sample 取值)" : "有 " + String(errors.length) + " 条没登记上",
|
|
193
|
+
};
|
|
194
|
+
return { message: report.message, report };
|
|
195
|
+
}
|
|
196
|
+
const entries = expressions.map((expression) => ({ expression, kind }));
|
|
197
|
+
const added = await debugSessions.addWatchpoints({ entries, ...(timeout === undefined ? {} : { timeoutMs: timeout }) });
|
|
198
|
+
const report = fromAddReport(added);
|
|
199
|
+
return { message: report.message, report };
|
|
200
|
+
}
|
|
201
|
+
if (action === "sample") {
|
|
202
|
+
const report = fromSampleReport(await debugSessions.sampleWatches({
|
|
203
|
+
...(timeout === undefined ? {} : { timeoutMs: timeout }),
|
|
204
|
+
...(args.resume === undefined ? {} : { resume: args.resume }),
|
|
205
|
+
signal: exec.signal,
|
|
206
|
+
}));
|
|
207
|
+
return { message: report.message, report };
|
|
208
|
+
}
|
|
209
|
+
if (action === "list") {
|
|
210
|
+
const entries = watchState.entries.map((entry) => entryView(entry));
|
|
211
|
+
const sampled = watchState.entries.filter((entry) => entry.kind === "value").length;
|
|
212
|
+
const message = entries.length === 0
|
|
213
|
+
? "登记表是空的:先用 action=add 加表达式"
|
|
214
|
+
: "登记了 " + String(entries.length) + " 项(值监视 " + String(sampled) + "、观察点 " + String(hardwareWatchpoints(watchState).length) + ")";
|
|
215
|
+
return {
|
|
216
|
+
message,
|
|
217
|
+
report: { ok: true, action: "list", entries, watchpoints: currentQuota(), halted: false, resumed: false, durationMs: Date.now() - startedAt, errors: [], notes: [], message },
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
if (action === "remove") {
|
|
221
|
+
const ids = args.ids ?? [];
|
|
222
|
+
if (ids.length === 0) {
|
|
223
|
+
return { message: "没给 ids:先 action=list 看编号,或 action=clear 全清", report: emptyReport(action, "没删:没给 ids", ["ids 是空的"]) };
|
|
224
|
+
}
|
|
225
|
+
const removed = await debugSessions.removeWatchpoints(ids);
|
|
226
|
+
return {
|
|
227
|
+
message: removed.message,
|
|
228
|
+
report: {
|
|
229
|
+
ok: removed.ok, action: "remove", entries: removed.removed.map((entry) => entryView(entry)),
|
|
230
|
+
watchpoints: removed.budget, halted: false, resumed: removed.resumed, durationMs: removed.durationMs,
|
|
231
|
+
errors: removed.errors, notes: [], message: removed.message,
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
if (action === "clear") {
|
|
236
|
+
const ids = watchState.entries.map((entry) => entry.id);
|
|
237
|
+
if (ids.length === 0) {
|
|
238
|
+
return { message: "登记表本来就是空的", report: emptyReport(action, "没清:登记表本来就是空的") };
|
|
239
|
+
}
|
|
240
|
+
const removed = await debugSessions.removeWatchpoints(ids);
|
|
241
|
+
const message = "清空了登记表(" + String(removed.removed.length) + " 项)";
|
|
242
|
+
return {
|
|
243
|
+
message: removed.ok ? message : message + ",但有问题:" + (removed.errors[0] ?? ""),
|
|
244
|
+
report: {
|
|
245
|
+
ok: removed.ok, action: "clear", entries: [], watchpoints: removed.budget, halted: false,
|
|
246
|
+
resumed: removed.resumed, durationMs: removed.durationMs, errors: removed.errors, notes: [], message,
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
message: "action 不认识:" + action + "(只认 add/sample/list/remove/clear)",
|
|
252
|
+
report: emptyReport(action, "没做:action 不认识", ["action 不认识:" + action]),
|
|
253
|
+
};
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-stm32",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "DSH 插件:STM32
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "DSH 插件:STM32 全流程工具层(HAL 多族 + 寄存器 13 族)—— 环境探测、.ioc 事务、生成工程、编译、烧录、调试;芯片事实与模板随包内置",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"lib",
|
|
14
14
|
"client",
|
|
15
15
|
"templates",
|
|
16
|
-
"
|
|
16
|
+
"assets",
|
|
17
|
+
"docs/reading-guide.md",
|
|
17
18
|
"cordis.patch.yml",
|
|
18
19
|
"README.md",
|
|
19
20
|
"README_EN.md",
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
"node": ">=20"
|
|
24
25
|
},
|
|
25
26
|
"scripts": {
|
|
26
|
-
"build": "tsc -p tsconfig.json && node scripts/copy-client.mjs",
|
|
27
|
+
"build": "tsc -p tsconfig.json && node scripts/copy-client.mjs && node scripts/copy-data.mjs",
|
|
27
28
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
28
29
|
"test": "node test/run-units.mjs",
|
|
29
30
|
"prepublishOnly": "npm run build",
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
2
|
+
#
|
|
3
|
+
# 来源:openocd 上游 master 的 tcl/target/stm32c0x.cfg(0.13 语法)。
|
|
4
|
+
# 为跑在 openocd 0.12 上,本插件改了三处(0.13 的写法在 0.12 上加载就报错):
|
|
5
|
+
# 1) 删掉 `transport select swd`,改 source target/swj-dp.tcl —— 0.12 的 st-link 驱动
|
|
6
|
+
# 没有名为 swd 的 transport(只有 hla_swd / dapdirect_swd),写死会直接报错;
|
|
7
|
+
# 2) `swd newdap` 改 `swj_newdap`(0.12 没有 0.13 的 swd 子命令);
|
|
8
|
+
# 3) dap create 的 -tap 改 -chain-position(0.12 没有 -tap 参数)。
|
|
9
|
+
# 其余内容(CPUTAPID / work-area /
|
|
10
|
+
# flash bank 用 stm32l4x 驱动 / DBGMCU 与看门狗停机设置)与上游一致。
|
|
11
|
+
# script for stm32c0x family
|
|
12
|
+
#
|
|
13
|
+
# stm32c0 devices support SWD transports only.
|
|
14
|
+
#
|
|
15
|
+
source [find target/swj-dp.tcl]
|
|
16
|
+
|
|
17
|
+
source [find mem_helper.tcl]
|
|
18
|
+
|
|
19
|
+
if { [info exists CHIPNAME] } {
|
|
20
|
+
set _CHIPNAME $CHIPNAME
|
|
21
|
+
} else {
|
|
22
|
+
set _CHIPNAME stm32c0x
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
set _ENDIAN little
|
|
26
|
+
|
|
27
|
+
# Work-area is a space in RAM used for flash programming
|
|
28
|
+
# By default use 6kB
|
|
29
|
+
if { [info exists WORKAREASIZE] } {
|
|
30
|
+
set _WORKAREASIZE $WORKAREASIZE
|
|
31
|
+
} else {
|
|
32
|
+
set _WORKAREASIZE 0x1800
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#jtag scan chain
|
|
36
|
+
if { [info exists CPUTAPID] } {
|
|
37
|
+
set _CPUTAPID $CPUTAPID
|
|
38
|
+
} else {
|
|
39
|
+
# SWD IDCODE (single drop, arm)
|
|
40
|
+
set _CPUTAPID 0x0bc11477
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
|
|
44
|
+
dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
|
|
45
|
+
|
|
46
|
+
set _TARGETNAME $_CHIPNAME.cpu
|
|
47
|
+
target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap
|
|
48
|
+
|
|
49
|
+
$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
|
|
50
|
+
|
|
51
|
+
flash bank $_CHIPNAME.flash stm32l4x 0x08000000 0 0 0 $_TARGETNAME
|
|
52
|
+
flash bank $_CHIPNAME.otp stm32l4x 0x1fff7000 0 0 0 $_TARGETNAME
|
|
53
|
+
|
|
54
|
+
# reasonable default
|
|
55
|
+
adapter speed 2000
|
|
56
|
+
|
|
57
|
+
adapter srst delay 100
|
|
58
|
+
if {[using_jtag]} {
|
|
59
|
+
jtag_ntrst_delay 100
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
reset_config srst_nogate
|
|
63
|
+
|
|
64
|
+
if {![using_hla]} {
|
|
65
|
+
# if srst is not fitted use SYSRESETREQ to
|
|
66
|
+
# perform a soft reset
|
|
67
|
+
cortex_m reset_config sysresetreq
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
$_TARGETNAME configure -event examine-end {
|
|
71
|
+
# Enable DBGMCU clock
|
|
72
|
+
# RCC_APB1ENR |= DBGMCUEN
|
|
73
|
+
mmw 0x4002103C 0x08000000 0
|
|
74
|
+
|
|
75
|
+
# Enable debug during low power modes (uses more power)
|
|
76
|
+
# DBGMCU_CR |= DBG_STANDBY | DBG_STOP
|
|
77
|
+
mmw 0x40015804 0x00000006 0
|
|
78
|
+
|
|
79
|
+
# Stop watchdog counters during halt
|
|
80
|
+
# DBGMCU_APB1_FZ |= DBG_WDGLS_STOP | DBG_WWDG_STOP
|
|
81
|
+
mmw 0x40015808 0x00001800 0
|
|
82
|
+
}
|
|
83
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
2
|
+
#
|
|
3
|
+
# 来源:openocd 上游 master 的 tcl/target/stm32u0x.cfg(0.13 语法)。
|
|
4
|
+
# 为跑在 openocd 0.12 上,本插件改了三处(0.13 的写法在 0.12 上加载就报错):
|
|
5
|
+
# 1) 删掉 `transport select swd`,改 source target/swj-dp.tcl —— 0.12 的 st-link 驱动
|
|
6
|
+
# 没有名为 swd 的 transport(只有 hla_swd / dapdirect_swd),写死会直接报错;
|
|
7
|
+
# 2) `swd newdap` 改 `swj_newdap`(0.12 没有 0.13 的 swd 子命令);
|
|
8
|
+
# 3) dap create 的 -tap 改 -chain-position(0.12 没有 -tap 参数)。
|
|
9
|
+
# 其余内容(CPUTAPID / work-area /
|
|
10
|
+
# flash bank 用 stm32l4x 驱动 / examine-end 里的低功耗与看门狗设置)与上游一致。
|
|
11
|
+
# Configuration file for STM32U0x series.
|
|
12
|
+
#
|
|
13
|
+
# STM32U0 devices support only SWD transport.
|
|
14
|
+
#
|
|
15
|
+
source [find target/swj-dp.tcl]
|
|
16
|
+
|
|
17
|
+
source [find mem_helper.tcl]
|
|
18
|
+
|
|
19
|
+
if { [info exists CHIPNAME] } {
|
|
20
|
+
set _CHIPNAME $CHIPNAME
|
|
21
|
+
} else {
|
|
22
|
+
set _CHIPNAME stm32u0x
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
# Work-area is a space in RAM used for flash programming, by default use 4 KiB.
|
|
26
|
+
if { [info exists WORKAREASIZE] } {
|
|
27
|
+
set _WORKAREASIZE $WORKAREASIZE
|
|
28
|
+
} else {
|
|
29
|
+
set _WORKAREASIZE 0x1000
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if { [info exists CPUTAPID] } {
|
|
33
|
+
set _CPUTAPID $CPUTAPID
|
|
34
|
+
} else {
|
|
35
|
+
set _CPUTAPID 0x6ba02477
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
|
|
39
|
+
dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
|
|
40
|
+
|
|
41
|
+
set _TARGETNAME $_CHIPNAME.cpu
|
|
42
|
+
target create $_TARGETNAME cortex_m -endian little -dap $_CHIPNAME.dap
|
|
43
|
+
|
|
44
|
+
$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
|
|
45
|
+
|
|
46
|
+
flash bank $_CHIPNAME.flash stm32l4x 0x08000000 0 0 0 $_TARGETNAME
|
|
47
|
+
flash bank $_CHIPNAME.otp stm32l4x 0x1FFF6800 0 0 0 $_TARGETNAME
|
|
48
|
+
|
|
49
|
+
adapter speed 2000
|
|
50
|
+
|
|
51
|
+
if {![using_hla]} {
|
|
52
|
+
# Use SYSRESETREQ to perform a soft reset if SRST is not fitted.
|
|
53
|
+
cortex_m reset_config sysresetreq
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
$_TARGETNAME configure -event examine-end {
|
|
57
|
+
# Enable debug during low power modes (uses more power).
|
|
58
|
+
# DBGMCU_CR |= DBG_STANDBY | DBG_STOP
|
|
59
|
+
mmw 0x40015804 0x00000006 0
|
|
60
|
+
|
|
61
|
+
# Stop watchdog counters when core is halted.
|
|
62
|
+
# DBGMCU_APB1_FZR |= DBG_IWDG_STOP | DBG_WWDG_STOP
|
|
63
|
+
mmw 0x40015808 0x00001800 0
|
|
64
|
+
}
|
|
@@ -32,11 +32,17 @@ message("Linker script: " ${DSH_LINKER_SCRIPT})
|
|
|
32
32
|
enable_language(C ASM)
|
|
33
33
|
|
|
34
34
|
# ---------------- 可执行文件 ----------------
|
|
35
|
-
#
|
|
35
|
+
# 编译四个源:用户 main.c、可选的 RTT(Core/Src/rtt.c)、CMSIS 的 system_<族>xx.c、启动文件。
|
|
36
36
|
# 设备头与内核头通过下面两个 include 目录提供,全部来自下载缓存。
|
|
37
|
+
#
|
|
38
|
+
# RTT 是"编进来但不默认启用":模板的 main.c 里 rtt_init() 是注释掉的,工具链又开了
|
|
39
|
+
# --gc-sections,所以没调用时 rtt.c 的代码和 3 KB 控制块缓冲会被链接器丢掉,不占
|
|
40
|
+
# RAM/Flash。要用就把 main.c 里 USER CODE BEGIN 2 的两行注释取消(RTT 不想要的话,
|
|
41
|
+
# 也可以把下面这一行删掉,main.c 里对应的 #include "rtt.h" 一起删)。
|
|
37
42
|
add_executable(${CMAKE_PROJECT_NAME}
|
|
38
43
|
Core/Src/main.c
|
|
39
|
-
|
|
44
|
+
Core/Src/rtt.c
|
|
45
|
+
Drivers/CMSIS/Device/ST/__FAMILY_DIR__/Source/Templates/__SYSTEM_C__
|
|
40
46
|
Drivers/CMSIS/Device/ST/__FAMILY_DIR__/Source/Templates/gcc/__STARTUP_FILE__
|
|
41
47
|
)
|
|
42
48
|
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 极简 RTT(Real Time Transfer)——寄存器版模板自带
|
|
3
|
+
*
|
|
4
|
+
* 它做三件事:
|
|
5
|
+
* 1) 在 RAM 里放一块**与 SEGGER RTT 兼容**的控制块(首 10 字节是 "SEGGER RTT"、
|
|
6
|
+
* 3 个上行通道、每个通道一个环形缓冲),这样 openocd 原生的 rtt 命令
|
|
7
|
+
* (rtt setup / rtt start / rtt server start)能直接认它;
|
|
8
|
+
* 2) 提供 rtt_printf()/rtt_write() 把一条记录写进通道 0;
|
|
9
|
+
* 3) 给出控制块地址,供 dsh-stm32 的 stm32_rtt action=start addr=... 使用。
|
|
10
|
+
*
|
|
11
|
+
* 记录格式是 dsh-stm32 自己的约定(不抄 SEGGER,SEGGER 没有级别和时间戳):
|
|
12
|
+
* [4B 长度 LE][1B 级别][8B 时间戳 ms LE][payload UTF-8]
|
|
13
|
+
* 长度字段 = 9 + payload 字节数(不含这 4 字节本身),级别 1..4 = error/warn/info/debug。
|
|
14
|
+
* src/engine/rtt.ts 里的 parseRttFrames() 就是按这个顺序解的。
|
|
15
|
+
*
|
|
16
|
+
* RAM 成本:RTT_UP_CHANNELS × RTT_BUF_SIZE = 3 × 1 KB = 3 KB(.bss)。
|
|
17
|
+
* C8T6 只有 20 KB,RAM 紧就把 RTT_UP_CHANNELS 改成 1,或把 RTT_BUF_SIZE 改成 256。
|
|
18
|
+
* (只用到通道 0 的话,先把 RTT_UP_CHANNELS 改成 1 省 2 KB,比扩环更划算。)
|
|
19
|
+
* 注意:模板默认**不调用** rtt_init(),工具链开了 --gc-sections,所以未启用时
|
|
20
|
+
* 这块内存与 rtt.c 的代码都会被链接器丢掉,不占 RAM/Flash;取消了 main.c 里
|
|
21
|
+
* USER CODE BEGIN 2 的注释才会真正进来。
|
|
22
|
+
*
|
|
23
|
+
* 环能撑多久(决定会不会丢):
|
|
24
|
+
* 可容纳记录数 = RTT_BUF_SIZE ÷ 单条帧字节数(13 + payload;一行 70 字符的日志约 83 B)
|
|
25
|
+
* 撑住的时长 = 可容纳记录数 × 打印间隔
|
|
26
|
+
* 例:1024 ÷ 83 ≈ 12 条、每 200 ms 一条 → 约 2.4 s。宿主不读的这段时间一过,环满,
|
|
27
|
+
* NO_BLOCK_SKIP 会**整条丢新记录**(绝不覆盖还没被读走的数据),rtt_dropped_count() 记数。
|
|
28
|
+
* 所以要么让宿主持续读(stm32_rtt 的 dump 只在窗口内读),要么拉长打印间隔 / 放大环。
|
|
29
|
+
*
|
|
30
|
+
* 偏移约定(踩过坑,别改):WrOff/RdOff 必须**永远**落在 [0, RTT_BUF_SIZE)。
|
|
31
|
+
* 曾经发布过 wr + len 这种"只增不减"的 WrOff,一旦 >= Size,openocd 就再也算不清还剩多少、
|
|
32
|
+
* 不再推进 RdOff,环从此永久冻结(现象:dump 每次都是同一块字节 + 重复记录刷屏 + drop 一直涨)。
|
|
33
|
+
*
|
|
34
|
+
* 并发:rtt_write 默认在**临界区**里写环 —— 裸机是关中断(保存/恢复 PRIMASK),
|
|
35
|
+
* RTOS 用强符号覆盖 rtt_lock()/rtt_unlock() 换成「mutex + 关中断」(示例见 rtt.c)。
|
|
36
|
+
* 所以主循环和中断同时打印也不会丢 WrOff 更新。
|
|
37
|
+
*
|
|
38
|
+
* 注意 RTT **不是 SWO**:SWO 是 SWD 的 trace 引脚协议(ITM/printf 用),要配 trace 时钟、
|
|
39
|
+
* 抓线、算带宽;RTT 是**纯内存轮询** —— openocd 通过 SWD 直接读写目标 RAM 里的环,
|
|
40
|
+
* 没有线协议、没有 trace 时钟、也不走 DMA。看到「给 RTT 调中断优先级 / 用 DMA 提速 /
|
|
41
|
+
* 抓 SWO 波形 / 加 CRC 校验」这类建议,那是把两者搞混了,本项目不适用。
|
|
42
|
+
*
|
|
43
|
+
* 地址怎么拿(start 时 addr 填它):
|
|
44
|
+
* arm-none-eabi-nm build/<preset>/<工程名>.elf | findstr _SEGGER_RTT
|
|
45
|
+
* 或 gdb 里:p &_SEGGER_RTT
|
|
46
|
+
* 也可以在运行时把 rtt_control_block_addr() 打出来看,但别把地址写死到别的工程里。
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
#ifndef DSH_STM32_RTT_H
|
|
50
|
+
#define DSH_STM32_RTT_H
|
|
51
|
+
|
|
52
|
+
#include <stdint.h>
|
|
53
|
+
|
|
54
|
+
#ifdef __cplusplus
|
|
55
|
+
extern "C" {
|
|
56
|
+
#endif
|
|
57
|
+
|
|
58
|
+
/* 级别:与 stm32_rtt 的 dump level 过滤一致(dump 的 level 是"保留到哪一级"的上限) */
|
|
59
|
+
#define RTT_LEVEL_ERROR 1u
|
|
60
|
+
#define RTT_LEVEL_WARN 2u
|
|
61
|
+
#define RTT_LEVEL_INFO 3u
|
|
62
|
+
#define RTT_LEVEL_DEBUG 4u
|
|
63
|
+
|
|
64
|
+
/* 上行通道数:通道 0 是 stm32_rtt 读的那一条("Terminal"),1/2 留给应用自己分用途。 */
|
|
65
|
+
#ifndef RTT_UP_CHANNELS
|
|
66
|
+
#define RTT_UP_CHANNELS 3u
|
|
67
|
+
#endif
|
|
68
|
+
|
|
69
|
+
/* 每个上行通道的环形缓冲字节数(3 × 1024 = 3 KB .bss)。 */
|
|
70
|
+
#ifndef RTT_BUF_SIZE
|
|
71
|
+
#define RTT_BUF_SIZE 1024u
|
|
72
|
+
#endif
|
|
73
|
+
|
|
74
|
+
/* 单条记录的 payload 上限(字节,不含结尾 0);超长截断,不会写半条帧。 */
|
|
75
|
+
#ifndef RTT_MSG_MAX
|
|
76
|
+
#define RTT_MSG_MAX 120u
|
|
77
|
+
#endif
|
|
78
|
+
|
|
79
|
+
/* 控制块起始地址:stm32_rtt action=start addr=<这个值>。 */
|
|
80
|
+
uint32_t rtt_control_block_addr(void);
|
|
81
|
+
|
|
82
|
+
/* 控制块占的字节数:给 rtt setup <addr> <size> 的 size 用(传大一点也无害)。 */
|
|
83
|
+
uint32_t rtt_control_block_size(void);
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* 初始化控制块:清空环、填好 3 个通道描述符,最后才写 ID 魔数
|
|
87
|
+
* (这样 openocd/stm32_rtt 看到魔数时描述符一定已经就绪)。
|
|
88
|
+
* 可重复调用。会打开 DWT 周期计数器给时间戳用,所以要在时钟初始化之后调用。
|
|
89
|
+
*/
|
|
90
|
+
void rtt_init(void);
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
* 写一条记录到通道 0。level 取 RTT_LEVEL_*(越界会被夹到 1..4)。
|
|
94
|
+
* text 是已经格式化好的字符串(结尾 0 会被 strlen 截掉,不写进环)。
|
|
95
|
+
* 返回写进去的 payload 字节数;环满/放不下完整一条时返回 0(整条丢,不写半条)。
|
|
96
|
+
* 可以从主循环和中断里调用:内部已经做了临界区保护(默认裸机关中断;RTOS 覆盖
|
|
97
|
+
* rtt_lock/rtt_unlock 换成 mutex,见 rtt.c)。
|
|
98
|
+
*/
|
|
99
|
+
uint32_t rtt_write(uint32_t level, const char *text);
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* 并发保护钩子(弱符号,默认实现见 rtt.c):
|
|
103
|
+
* 裸机默认:保存 PRIMASK → 关中断,unlock 时按原样恢复;
|
|
104
|
+
* RTOS:覆盖成「mutex(任务 vs 任务)+ 关中断(任务 vs ISR)」,缺一个都会漏。
|
|
105
|
+
* 返回的 token 由实现自己定,rtt_write 只原样回传。
|
|
106
|
+
*/
|
|
107
|
+
uint32_t rtt_lock(void);
|
|
108
|
+
void rtt_unlock(uint32_t token);
|
|
109
|
+
|
|
110
|
+
/*
|
|
111
|
+
* printf 风格:先 vsnprintf 到内部缓冲(最多 RTT_MSG_MAX 字节),再走 rtt_write。
|
|
112
|
+
*
|
|
113
|
+
* 链接提示:vsnprintf 会牵进 newlib 的 _sbrk(堆延伸)。寄存器版模板没有 syscalls.c,
|
|
114
|
+
* 所以 rtt.c 里给了一份**弱符号** _sbrk 兜底(直接失败,等于没有堆),保证只加
|
|
115
|
+
* rtt_init() + rtt_printf() 就能链接过。你自己有 syscalls.c 时那份强符号会自动覆盖它。
|
|
116
|
+
* 完全不想碰 newlib 就用 rtt_write(level, "已经格式化好的字符串")。
|
|
117
|
+
*/
|
|
118
|
+
uint32_t rtt_printf(uint32_t level, const char *fmt, ...);
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
* 时间戳(毫秒)。默认实现用 DWT 周期计数器按 SystemCoreClock 换算;
|
|
122
|
+
* 应用可以覆盖它(弱符号)来用 HAL_GetTick / 自己的 RTC:
|
|
123
|
+
* uint64_t rtt_time_ms(void) { return HAL_GetTick(); }
|
|
124
|
+
*/
|
|
125
|
+
uint64_t rtt_time_ms(void);
|
|
126
|
+
|
|
127
|
+
/*
|
|
128
|
+
* 因为环满而整条丢掉的记录数(dump 报的 dropped 只统计「按级别过滤掉」的,两者不同)。
|
|
129
|
+
* 只读一个 u32,可以在中断里调用。建议在周期日志里把它打出来(例如 drop=%u),
|
|
130
|
+
* 这样宿主端一眼能看出「环满丢了 N 条」,不用去猜。
|
|
131
|
+
*/
|
|
132
|
+
uint32_t rtt_dropped_count(void);
|
|
133
|
+
|
|
134
|
+
#ifdef __cplusplus
|
|
135
|
+
}
|
|
136
|
+
#endif
|
|
137
|
+
|
|
138
|
+
#endif /* DSH_STM32_RTT_H */
|