dsh-stm32 0.1.1 → 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 +52 -23
- package/README_EN.md +50 -21
- package/docs/development-notes.md +466 -4
- package/docs/reading-guide.md +738 -0
- package/lib/commands/register.js +49 -0
- package/lib/data/chips.js +134 -4
- package/lib/data/clock-f1.js +158 -0
- package/lib/data/cmsis-sources.js +211 -42
- package/lib/data/f1-ram.generated.js +34 -0
- package/lib/data/stm32f1.js +186 -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.js +75 -10
- package/lib/engine/doctor.js +395 -4
- package/lib/engine/fetch.js +174 -30
- package/lib/engine/flash.js +95 -6
- package/lib/engine/generate.js +11 -0
- package/lib/engine/hal-chip.js +230 -0
- package/lib/engine/ioc-plan.js +28 -2
- package/lib/engine/msys2-install.js +332 -61
- 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 +88 -17
- package/lib/engine/scaffold.js +104 -28
- package/lib/engine/zip.js +142 -0
- package/lib/index.js +2 -0
- package/lib/skill/stm32-workflow.js +3 -3
- package/lib/tools/build.js +12 -0
- package/lib/tools/cache.js +39 -8
- package/lib/tools/debug.js +7 -0
- package/lib/tools/doctor.js +11 -2
- package/lib/tools/flash.js +3 -0
- package/lib/tools/ioc-plan.js +195 -4
- package/lib/tools/project-create.js +26 -1
- package/lib/tools/project-export.js +100 -0
- package/package.json +5 -3
- package/templates/register/CMakeLists.txt +19 -6
- package/templates/register/Core/Src/main.c +18 -9
- package/templates/scaffold/openocd.cfg +8 -0
package/lib/commands/register.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* /stm32-build [<工程目录>] [--clean] 编译(默认走 CMake+Ninja 的 build/Debug)
|
|
13
13
|
* /stm32-doctor [<工程目录>] 体检:工具链 / 残留进程 / 端口 / .elf / .ioc 告警
|
|
14
14
|
* /stm32-env [<工程目录>] 工具链体检卡:编译/烧录/调试/生成各缺什么、装在哪、怎么装
|
|
15
|
+
* /stm32-setup [<工程目录>] 一条龙:体检 → 出计划 → 真装(要确认)→ 自检,每步给下一句
|
|
15
16
|
*
|
|
16
17
|
* 工程目录缺省取会话当前工作目录;也可以直接写路径(相对路径按当前目录解析)。
|
|
17
18
|
* 带空格的路径要整段用引号包起来(`"C:/Program Files/.../demo proj"`):切词是引号感知的,
|
|
@@ -339,6 +340,54 @@ export function registerCommands(ctx) {
|
|
|
339
340
|
}
|
|
340
341
|
},
|
|
341
342
|
});
|
|
343
|
+
commands.register({
|
|
344
|
+
definitionId: "dsh-stm32/stm32-setup",
|
|
345
|
+
name: "stm32-setup",
|
|
346
|
+
description: "一条龙:体检 → 出计划 → 真装(要确认)→ 自检;缺什么补什么,齐了就直接说齐了",
|
|
347
|
+
input: { hint: "[<工程目录>] [装]" },
|
|
348
|
+
handler: async (invocation) => {
|
|
349
|
+
try {
|
|
350
|
+
const subprocess = needSubprocess(ctx);
|
|
351
|
+
if (typeof subprocess === "string")
|
|
352
|
+
return err(subprocess);
|
|
353
|
+
const wantsInstall = /(^|\s)装(\s|$)/u.test(invocation.rawInput.trim());
|
|
354
|
+
const lines = ["stm32-setup:"];
|
|
355
|
+
// 1) 体检(与 /stm32-env 同一套门禁)
|
|
356
|
+
const rows = [];
|
|
357
|
+
for (const capability of ENV_CAPABILITIES) {
|
|
358
|
+
const gate = await ensureToolchain(ctx, { capability, envCheck: "warn", signal: invocation.signal });
|
|
359
|
+
rows.push({ capability, gate });
|
|
360
|
+
}
|
|
361
|
+
const allOk = rows.every((row) => row.gate.ok);
|
|
362
|
+
if (allOk) {
|
|
363
|
+
lines.push("1/3 体检:四项能力全齐,不用装。");
|
|
364
|
+
lines.push("2/3 下一步:/stm32-build 就能编译(板子接好时 /stm32-doctor 再看一眼硬件)。");
|
|
365
|
+
return { kind: "success", text: lines.join("\n") };
|
|
366
|
+
}
|
|
367
|
+
// 2) 缺件 → 出计划(与 stm32_env_install 同一个引擎,零副作用)
|
|
368
|
+
const { planOrInstallMsys2 } = await import("../engine/msys2-install.js");
|
|
369
|
+
const plan = await planOrInstallMsys2(subprocess, { mode: "plan", writePath: true, ...(invocation.signal === undefined ? {} : { signal: invocation.signal }) });
|
|
370
|
+
lines.push("2/3 计划:" + plan.message);
|
|
371
|
+
if (!wantsInstall) {
|
|
372
|
+
lines.push("3/3 确认:回「/stm32-setup 装」开始真装(只补缺的包,不升级已装的);装完会自动自检。");
|
|
373
|
+
return { kind: "success", text: lines.join("\n") };
|
|
374
|
+
}
|
|
375
|
+
// 3) 真装(第二次带「装」才走到这里)
|
|
376
|
+
const install = await planOrInstallMsys2(subprocess, { mode: "install", writePath: true, ...(invocation.signal === undefined ? {} : { signal: invocation.signal }) });
|
|
377
|
+
if (!install.ok) {
|
|
378
|
+
lines.push("3/3 安装未完成:" + install.message);
|
|
379
|
+
lines.push(" 下一步:" + install.nextStep);
|
|
380
|
+
return { kind: "success", text: lines.join("\n") };
|
|
381
|
+
}
|
|
382
|
+
lines.push("3/3 安装完成:" + install.message);
|
|
383
|
+
lines.push(" 下一步:/stm32-build 编译;/stm32-doctor 做全量体检。");
|
|
384
|
+
return { kind: "success", text: lines.join("\n") };
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
return err("stm32-setup 异常:" + (error instanceof Error ? error.message : String(error)));
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
});
|
|
342
391
|
commands.register({
|
|
343
392
|
definitionId: "dsh-stm32/stm32-env",
|
|
344
393
|
name: "stm32-env",
|
package/lib/data/chips.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* L1:芯片型号 →
|
|
2
|
+
* L1:芯片型号 → 可用引脚表。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 两条来源,优先本机 CubeMX 的数据库:
|
|
5
|
+
* 1. `<CubeMX 安装根>/db/mcu/<Mcu.Name>.xml` 里的 `<Pin Name="PA1" Position="3"/>`——
|
|
6
|
+
* Position>0 才是真实封装引脚(Position=0 是虚拟引脚,例如 VP_SYS_VS_Systick 的占位)。
|
|
7
|
+
* 名字常带功能后缀(`PA0-WKUP`、`PC13-TAMPER-RTC`、`PD0-OSC_IN`),这里归一化成 PA0/PC13/PD0。
|
|
8
|
+
* 2. 内置表(CHIPS):机器上没装 CubeMX 时兜底,能跑但**没有跟本机 db 校验过**,
|
|
9
|
+
* deriveChipPinTable 会在 notes 里把这件事说清楚。
|
|
10
|
+
*
|
|
11
|
+
* 放行语义(从第一天就在,不能变):isKnownPin 只认内置表;未知型号、虚拟引脚(VP_*)一律 true。
|
|
12
|
+
* 校验是为了拦住手误,不是为了当数据源;没校验过的东西绝不当"不存在"。
|
|
7
13
|
*/
|
|
14
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
15
|
+
import { join } from "node:path";
|
|
8
16
|
function port(prefix, from, to) {
|
|
9
17
|
const out = [];
|
|
10
18
|
for (let index = from; index <= to; index += 1)
|
|
@@ -34,3 +42,125 @@ export function isKnownPin(cpn, pin) {
|
|
|
34
42
|
return chip.pins.includes(pin.toUpperCase());
|
|
35
43
|
}
|
|
36
44
|
export const KNOWN_CHIPS = CHIPS;
|
|
45
|
+
// ── 本机 CubeMX db/mcu 派生 ─────────────────────────────────────────────────
|
|
46
|
+
/** db 里 Pin 的 Name 形如 `PA0-WKUP` / `PC13-TAMPER-RTC` / `PD0-OSC_IN` / `PA13` / `VDD_1`。 */
|
|
47
|
+
function normalizeDbPinName(raw) {
|
|
48
|
+
const head = (raw.split(/[-/]/u)[0] ?? "").trim().toUpperCase();
|
|
49
|
+
return /^P[A-K]\d{1,2}$/u.test(head) ? head : "";
|
|
50
|
+
}
|
|
51
|
+
function pinOrder(pin) {
|
|
52
|
+
const matched = /^P([A-K])(\d{1,2})$/u.exec(pin);
|
|
53
|
+
return [matched?.[1] ?? "", Number(matched?.[2] ?? 0)];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 解析 db/mcu/<Mcu.Name>.xml,取出这个封装上真实存在的 GPIO 引脚(PA0…,已排序去重)。
|
|
57
|
+
*
|
|
58
|
+
* 只认 Position>0:CubeMX 把虚拟引脚也写进 <Pin>,Position=0,拿来当"这个型号有这根脚"会误判。
|
|
59
|
+
* 兼容多行标签(真实 db 里属性经常换行)与自闭合/带子节点的写法。
|
|
60
|
+
*/
|
|
61
|
+
export function parseMcuDbXmlPins(xml) {
|
|
62
|
+
const pins = [];
|
|
63
|
+
const seen = new Set();
|
|
64
|
+
for (const tag of xml.match(/<Pin\b[^>]*>/gu) ?? []) {
|
|
65
|
+
const name = /\bName\s*=\s*"([^"]*)"/u.exec(tag)?.[1] ?? "";
|
|
66
|
+
const positionText = /\bPosition\s*=\s*"([^"]*)"/u.exec(tag)?.[1] ?? "";
|
|
67
|
+
const position = Number.parseInt(positionText.trim(), 10);
|
|
68
|
+
if (!Number.isFinite(position) || position <= 0)
|
|
69
|
+
continue;
|
|
70
|
+
const pin = normalizeDbPinName(name);
|
|
71
|
+
if (pin === "" || seen.has(pin))
|
|
72
|
+
continue;
|
|
73
|
+
seen.add(pin);
|
|
74
|
+
pins.push(pin);
|
|
75
|
+
}
|
|
76
|
+
pins.sort((left, right) => {
|
|
77
|
+
const [leftPort, leftNumber] = pinOrder(left);
|
|
78
|
+
const [rightPort, rightNumber] = pinOrder(right);
|
|
79
|
+
if (leftPort !== rightPort)
|
|
80
|
+
return leftPort < rightPort ? -1 : 1;
|
|
81
|
+
return leftNumber - rightNumber;
|
|
82
|
+
});
|
|
83
|
+
return pins;
|
|
84
|
+
}
|
|
85
|
+
/** 本机 CubeMX 的 db/mcu 目录(<CubeMX 安装根>/db/mcu);没有返回 null。 */
|
|
86
|
+
export function findMcuDbDir(cubeMxRoots) {
|
|
87
|
+
for (const root of cubeMxRoots ?? []) {
|
|
88
|
+
if (root.trim() === "")
|
|
89
|
+
continue;
|
|
90
|
+
const dir = join(root, "db", "mcu");
|
|
91
|
+
if (existsSync(dir))
|
|
92
|
+
return dir;
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 在 db/mcu 下按候选文件名找 XML(CubeMX 用 Mcu.Name,例如 STM32F103C(8-B)Tx.xml;
|
|
98
|
+
* 也可能有人按完整型号存成 STM32F103RCT6.xml),读到就解析,读不到返回 null。
|
|
99
|
+
*/
|
|
100
|
+
export function readMcuDbPins(dbMcuDir, names) {
|
|
101
|
+
if (dbMcuDir === null || dbMcuDir === undefined || dbMcuDir.trim() === "")
|
|
102
|
+
return null;
|
|
103
|
+
for (const name of names) {
|
|
104
|
+
const wanted = name.trim();
|
|
105
|
+
if (wanted === "")
|
|
106
|
+
continue;
|
|
107
|
+
const xmlPath = join(dbMcuDir, wanted + ".xml");
|
|
108
|
+
if (!existsSync(xmlPath))
|
|
109
|
+
continue;
|
|
110
|
+
try {
|
|
111
|
+
const pins = parseMcuDbXmlPins(readFileSync(xmlPath, "utf8"));
|
|
112
|
+
if (pins.length > 0)
|
|
113
|
+
return { xmlPath, pins };
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// 读不了/不是合法 db:退回内置表,notes 里会说明没校验。
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 型号 → 引脚表(db 优先,退回内置表)。
|
|
123
|
+
*
|
|
124
|
+
* "没校验"这件事必须写进 notes:内置表只收了 C8T6 一款,别的型号拿它当"真实引脚"会误判,
|
|
125
|
+
* 所以内置表路径只说"这里是内置表,未与本机 db 校验",不假装校验过。
|
|
126
|
+
*/
|
|
127
|
+
export function deriveChipPinTable(input) {
|
|
128
|
+
const cpn = input.cpn.trim();
|
|
129
|
+
const mcuName = (input.mcuName ?? "").trim();
|
|
130
|
+
const names = [mcuName, cpn].filter((name) => name !== "");
|
|
131
|
+
const dbHit = readMcuDbPins(input.dbMcuDir ?? null, names);
|
|
132
|
+
if (dbHit !== null) {
|
|
133
|
+
return {
|
|
134
|
+
kind: "db",
|
|
135
|
+
cpn,
|
|
136
|
+
mcuName,
|
|
137
|
+
pins: dbHit.pins,
|
|
138
|
+
notes: [
|
|
139
|
+
"引脚表:来自本机 CubeMX db(" + dbHit.xmlPath + "," + String(dbHit.pins.length) + " 个封装引脚)",
|
|
140
|
+
],
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const builtin = findChip(cpn);
|
|
144
|
+
const why = input.dbMcuDir === null || input.dbMcuDir === undefined
|
|
145
|
+
? "本机没找到 CubeMX 的 db/mcu"
|
|
146
|
+
: "db/mcu 下没有 " + (names.length === 0 ? "该型号" : names.join(" / ")) + ".xml";
|
|
147
|
+
if (builtin !== null) {
|
|
148
|
+
return {
|
|
149
|
+
kind: "builtin",
|
|
150
|
+
cpn,
|
|
151
|
+
mcuName,
|
|
152
|
+
pins: builtin.pins,
|
|
153
|
+
notes: ["引脚表:内置表(" + String(builtin.pins.length) + " 个引脚,未与本机 db 校验:" + why + ")"],
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
kind: "unknown",
|
|
158
|
+
cpn,
|
|
159
|
+
mcuName,
|
|
160
|
+
pins: [],
|
|
161
|
+
notes: [
|
|
162
|
+
"引脚表:型号 " + (cpn === "" ? "(空)" : cpn) + " 不在内置表,也没有本机 CubeMX db(未与本机 db 校验:" + why +
|
|
163
|
+
");未知引脚一律放行(isKnownPin 语义不变)",
|
|
164
|
+
],
|
|
165
|
+
};
|
|
166
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* STM32F1 时钟树事实表(只放"书上写的数字",不放算法)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独一张表:F1 的时钟上限、PLL 可选倍频、外设挂在哪条总线,这些是芯片事实,
|
|
5
|
+
* 而"给定目标频率怎么挑组合"是策略(src/engine/clock-plan.ts)。事实和策略分开,
|
|
6
|
+
* 以后扩 F0/F4 只换这张表,算法不用动。
|
|
7
|
+
*
|
|
8
|
+
* 依据:RM0008 §7(RCC)、DS5319(F103x8/xB)电气特性。F1 全系(value / connectivity)
|
|
9
|
+
* 的 SYSCLK 上限都是 72 MHz;connectivity(105/107)多一级 PREDIV1,本插件暂不规划。
|
|
10
|
+
*/
|
|
11
|
+
export const F1_PLL_SOURCES = [
|
|
12
|
+
{
|
|
13
|
+
id: "hse",
|
|
14
|
+
label: "HSE 8 MHz",
|
|
15
|
+
iocValue: "RCC_PLLSOURCE_HSE",
|
|
16
|
+
defaultHz: 8_000_000,
|
|
17
|
+
selectable: true,
|
|
18
|
+
note: "外部晶振(板上 8 MHz,值料号 HSE 范围 4–16 MHz)。精度由晶振决定,通常 ≤50 ppm,UART 波特率靠它就够准。",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: "hsi-div2",
|
|
22
|
+
label: "HSI÷2 4 MHz",
|
|
23
|
+
iocValue: "RCC_PLLSOURCE_HSI_DIV2",
|
|
24
|
+
defaultHz: 4_000_000,
|
|
25
|
+
selectable: true,
|
|
26
|
+
note: "内部 RC 8 MHz ÷2。全温区 ±1%,UART 波特率会跟着漂,只在不接晶振时用。",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "hsi",
|
|
30
|
+
label: "HSI 8 MHz",
|
|
31
|
+
iocValue: "RCC_PLLSOURCE_HSI",
|
|
32
|
+
defaultHz: 8_000_000,
|
|
33
|
+
selectable: false,
|
|
34
|
+
note: "F1 值料号的 PLLSRC 只有 HSE / HSI÷2 两档;HSI 直接进 PLL 是互联型(105/107)经 PREDIV1 才有的路,本插件不规划。",
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
export function pllSourceById(id) {
|
|
38
|
+
return F1_PLL_SOURCES.find((source) => source.id === id) ?? null;
|
|
39
|
+
}
|
|
40
|
+
export const F1_PLL_MULS = Array.from({ length: 15 }, (_unused, index) => {
|
|
41
|
+
const mul = index + 2;
|
|
42
|
+
return { mul, iocValue: "RCC_PLL_MUL" + String(mul) };
|
|
43
|
+
});
|
|
44
|
+
export function pllMulValue(mul) {
|
|
45
|
+
return "RCC_PLL_MUL" + String(mul);
|
|
46
|
+
}
|
|
47
|
+
/** 从 RCC.PLLMUL 的值(RCC_PLL_MUL9)反解倍频;认不出来返回 null。 */
|
|
48
|
+
export function pllMulFromValue(value) {
|
|
49
|
+
const matched = /^RCC_PLL_MUL(\d{1,2})$/u.exec(value.trim());
|
|
50
|
+
if (matched === null)
|
|
51
|
+
return null;
|
|
52
|
+
const mul = Number.parseInt(matched[1], 10);
|
|
53
|
+
return Number.isFinite(mul) && mul >= 2 && mul <= 16 ? mul : null;
|
|
54
|
+
}
|
|
55
|
+
/** AHB / APB1 / APB2 分频:÷1、2、4、8、16(RM0008 RCC_CFGR.HPRE/PPRE1/PPRE2)。 */
|
|
56
|
+
export const F1_APB_DIVS = [1, 2, 4, 8, 16].map((div) => ({
|
|
57
|
+
div,
|
|
58
|
+
iocValue: "RCC_HCLK_DIV" + String(div),
|
|
59
|
+
}));
|
|
60
|
+
/** ADC 预分频:÷2、4、6、8(RCC_CFGR.ADCPRE)。 */
|
|
61
|
+
export const F1_ADC_DIVS = [2, 4, 6, 8].map((div) => ({
|
|
62
|
+
div,
|
|
63
|
+
iocValue: "RCC_ADCPCLK2_DIV" + String(div),
|
|
64
|
+
}));
|
|
65
|
+
/** USB 时钟:只能从 PLLCLK ÷1.5 来,所以 PLLCLK 必须是 72 MHz(→48 MHz)。 */
|
|
66
|
+
export const F1_USB_PRESCALER = {
|
|
67
|
+
iocValue: "RCC_USBCLKSOURCE_PLL_DIV1_5",
|
|
68
|
+
hz: 48_000_000,
|
|
69
|
+
requiresPllClkHz: 72_000_000,
|
|
70
|
+
note: "F1 的 USB 只有 PLLCLK÷1.5 一路:PLLCLK=72 MHz 时 48 MHz 可用,其它频率下 USB 跑不起来。",
|
|
71
|
+
};
|
|
72
|
+
export function apbDivValue(div) {
|
|
73
|
+
return "RCC_HCLK_DIV" + String(div);
|
|
74
|
+
}
|
|
75
|
+
export function adcDivValue(div) {
|
|
76
|
+
return "RCC_ADCPCLK2_DIV" + String(div);
|
|
77
|
+
}
|
|
78
|
+
export function apbDivFromValue(value) {
|
|
79
|
+
const matched = /^RCC_HCLK_DIV(\d{1,2})$/u.exec(value.trim());
|
|
80
|
+
if (matched === null)
|
|
81
|
+
return null;
|
|
82
|
+
const div = Number.parseInt(matched[1], 10);
|
|
83
|
+
return [1, 2, 4, 8, 16].includes(div) ? div : null;
|
|
84
|
+
}
|
|
85
|
+
export function adcDivFromValue(value) {
|
|
86
|
+
const matched = /^RCC_ADCPCLK2_DIV(\d{1,2})$/u.exec(value.trim());
|
|
87
|
+
if (matched === null)
|
|
88
|
+
return null;
|
|
89
|
+
const div = Number.parseInt(matched[1], 10);
|
|
90
|
+
return [2, 4, 6, 8].includes(div) ? div : null;
|
|
91
|
+
}
|
|
92
|
+
/** 上限(Hz)。USB 不是"上限"而是"必须等于":必须正好 48 MHz。 */
|
|
93
|
+
export const F1_CLOCK_LIMITS = {
|
|
94
|
+
sysclkHz: 72_000_000,
|
|
95
|
+
apb1Hz: 36_000_000,
|
|
96
|
+
apb2Hz: 72_000_000,
|
|
97
|
+
adcHz: 14_000_000,
|
|
98
|
+
usbHz: 48_000_000,
|
|
99
|
+
};
|
|
100
|
+
/** 上限的人读标签,报告里拼错误消息用。 */
|
|
101
|
+
export const F1_CLOCK_LIMIT_LABELS = {
|
|
102
|
+
sysclkHz: "SYSCLK",
|
|
103
|
+
apb1Hz: "APB1",
|
|
104
|
+
apb2Hz: "APB2",
|
|
105
|
+
adcHz: "ADC",
|
|
106
|
+
usbHz: "USB",
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* 外设 → 总线(RM0008 的 memory map 与 RCC 使能寄存器分组):
|
|
110
|
+
* APB2 = USART1 / SPI1 / ADC1-3 / TIM1 / TIM8 / GPIO / AFIO;
|
|
111
|
+
* APB1 = USART2-5 / SPI2-3 / I2C1-2 / TIM2-7 / USB / CAN / DAC。
|
|
112
|
+
* 这里只列报告要展示的那批,够覆盖 F1 值料号常见的用法。
|
|
113
|
+
*/
|
|
114
|
+
export const F1_PERIPHERAL_CLOCKS = [
|
|
115
|
+
{ id: "USART1", label: "USART1", bus: "apb2", kind: "usart" },
|
|
116
|
+
{ id: "USART2", label: "USART2", bus: "apb1", kind: "usart" },
|
|
117
|
+
{ id: "USART3", label: "USART3", bus: "apb1", kind: "usart" },
|
|
118
|
+
{ id: "SPI1", label: "SPI1", bus: "apb2", kind: "spi" },
|
|
119
|
+
{ id: "SPI2", label: "SPI2", bus: "apb1", kind: "spi" },
|
|
120
|
+
{ id: "I2C1", label: "I2C1", bus: "apb1", kind: "i2c" },
|
|
121
|
+
{ id: "I2C2", label: "I2C2", bus: "apb1", kind: "i2c" },
|
|
122
|
+
{ id: "ADC1", label: "ADC1/2", bus: "apb2", kind: "adc" },
|
|
123
|
+
{ id: "TIM1", label: "TIM1", bus: "apb2", kind: "tim" },
|
|
124
|
+
{ id: "TIM2", label: "TIM2", bus: "apb1", kind: "tim" },
|
|
125
|
+
{ id: "TIM3", label: "TIM3", bus: "apb1", kind: "tim" },
|
|
126
|
+
{ id: "TIM4", label: "TIM4", bus: "apb1", kind: "tim" },
|
|
127
|
+
{ id: "USB", label: "USB", bus: "apb1", kind: "usb" },
|
|
128
|
+
{ id: "Cortex", label: "Cortex-SysTick", bus: "ahb", kind: "core" },
|
|
129
|
+
];
|
|
130
|
+
/** UART 波特率整除误差默认算这几档(F1 值料号常用档)。 */
|
|
131
|
+
export const F1_BAUD_LIST = [9600, 19200, 38400, 57600, 115200, 230400];
|
|
132
|
+
/**
|
|
133
|
+
* templates/scaffold/demo.ioc 里 RCC.IPParameters 列出的那 20 个键。
|
|
134
|
+
* 改时钟时必须成套重算——只改 RCC.PLLMUL 会让 CubeMX 下次打开按旧 Freq_Value 生成
|
|
135
|
+
* SystemClock_Config,HAL_RCC_ClockConfig 直接算错(这是本插件最容易埋雷的地方)。
|
|
136
|
+
*/
|
|
137
|
+
export const F1_RCC_IP_KEYS = [
|
|
138
|
+
"ADCFreqValue",
|
|
139
|
+
"AHBFreq_Value",
|
|
140
|
+
"APB1CLKDivider",
|
|
141
|
+
"APB1Freq_Value",
|
|
142
|
+
"APB1TimFreq_Value",
|
|
143
|
+
"APB2Freq_Value",
|
|
144
|
+
"APB2TimFreq_Value",
|
|
145
|
+
"FCLKCortexFreq_Value",
|
|
146
|
+
"FamilyName",
|
|
147
|
+
"HCLKFreq_Value",
|
|
148
|
+
"MCOFreq_Value",
|
|
149
|
+
"PLLCLKFreq_Value",
|
|
150
|
+
"PLLMCOFreq_Value",
|
|
151
|
+
"PLLMUL",
|
|
152
|
+
"PLLSourceVirtual",
|
|
153
|
+
"SYSCLKFreq_VALUE",
|
|
154
|
+
"SYSCLKSource",
|
|
155
|
+
"TimSysFreq_Value",
|
|
156
|
+
"USBFreq_Value",
|
|
157
|
+
"VCOOutput2Freq_Value",
|
|
158
|
+
];
|