@protoboardai/ext-drone 0.0.0-stage → 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,13 @@
1
+ Protoboard Stack: @protoboardai/ext-drone
2
+ Copyright 2026 Delta Robotics, Inc.
3
+
4
+ This product includes software developed at Delta Robotics, Inc.
5
+ (https://deltaroboticsinc.com).
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License").
8
+ See the LICENSE file in this package for full terms.
9
+
10
+ "Protoboard", the Protoboard logo and the "0" mark are trademarks of
11
+ Delta Robotics, Inc. The License grants no rights to them (section 6);
12
+ see TRADEMARKS.md in the Protoboard Stack repository
13
+ (https://github.com/Delta-Robotics-Inc/protoboard-stack).
@@ -0,0 +1,32 @@
1
+ {
2
+ "schema": "protoboard.eval-case/v0",
3
+ "title": "Update the flight-controller configuration after the GPS moved to UART3",
4
+ "skills": ["firmware-config"],
5
+ "tags": ["firmware"],
6
+ "fixture": {
7
+ "from": "../../../../examples/quadcopter-5in",
8
+ "exclude": ["docs"],
9
+ "steps": [
10
+ {
11
+ "note": "the model change: the GNSS lead's UART wires are soldered to the UART3 pads (the configuration still says UART1)",
12
+ "replace": { "file": "src/quadcopter.uhd.ts", "find": "p2: \"fc:uart1_tx\", p3: \"fc:uart1_rx\"", "with": "p2: \"fc:uart3_tx\", p3: \"fc:uart3_rx\"", "count": 1 }
13
+ }
14
+ ]
15
+ },
16
+ "instruction": "We re-soldered the GPS lead to the flight controller's UART3 pads, and the model (src/quadcopter.uhd.ts) already says so. Bring the flight controller's Betaflight configuration in firmware/ up to date with the model, and tell me which serial port lines changed.",
17
+ "tools": { "read": true, "edit": true, "commands": ["npx protoboard *"] },
18
+ "budget": { "turns": 15, "seconds": 600, "usd": 2 },
19
+ "graders": [
20
+ { "id": "check-clean", "kind": "check", "maxErrors": 0 },
21
+ { "id": "gps-on-uart3", "kind": "text", "file": "firmware/betaflight/cli.txt", "matches": ["serial UART3 2 115200", "set gps_provider = UBLOX"], "notMatches": ["serial UART1 2 "] },
22
+ { "id": "rest-unchanged", "kind": "text", "file": "firmware/betaflight/cli.txt", "matches": ["serial UART2 64 115200 57600 0 115200", "serial UART5 131073 ", "set motor_pwm_protocol = DSHOT600"] },
23
+ { "id": "reference-generated", "kind": "operation", "run": ["betaflight-cli", "--input", "out=firmware/betaflight/regenerated.txt"], "status": "succeeded", "weight": 0, "description": "the generator's output for the model, as the reference for the next grader" },
24
+ { "id": "matches-generator", "kind": "digest", "file": "firmware/betaflight/cli.txt", "sameAs": "firmware/betaflight/regenerated.txt", "description": "cli.txt is exactly what the generator makes from the model: regenerated, not patched by hand" },
25
+ { "id": "answer", "kind": "text", "matches": ["UART3", "UART1"] },
26
+ { "id": "model-untouched", "kind": "digest", "file": "src/quadcopter.uhd.ts", "changed": false }
27
+ ],
28
+ "solution": [
29
+ { "protoboard": ["run", "betaflight-cli"], "expect": { "status": "succeeded" } },
30
+ { "say": "Regenerated firmware/betaflight/cli.txt from the model (run betaflight-cli): the GPS serial line moved from `serial UART1 2 …` to `serial UART3 2 115200 115200 0 115200`; UART1 is now unused. The receiver (UART2) and DJI MSP (UART5) lines are unchanged." }
31
+ ]
32
+ }
@@ -0,0 +1,244 @@
1
+ /**
2
+ * Betaflight configuration for the 5-inch quadcopter, derived from its UHD
3
+ * links and part facts (PB-792). CLI syntax and values follow
4
+ * ../skills/firmware-config/references/betaflight-reference.md (verified
5
+ * against Betaflight 4.5.5, 2025.12.5
6
+ * and 2026.6.2 sources). Output targets Betaflight >= 2025.12.1, which the
7
+ * M9N-5883's QMC5883P compass requires.
8
+ *
9
+ * Every line is emitted with a comment naming the link or part fact it
10
+ * comes from. Nothing here is flight-tested: verify on hardware.
11
+ */
12
+ import type { InterfaceDef, ModuleDef, TraitDef } from "@deltarobotics/uhd";
13
+ import { systemLinks, type LinkResult, type ModuleLookup, type ResolvedEndpoint } from "@deltarobotics/uhd";
14
+ import { resolveSpins } from "@deltarobotics/uhd";
15
+ import type { SpinDirection } from "@deltarobotics/uhd";
16
+
17
+ /** serialPortFunction_e values (betaflight-reference.md §1). */
18
+ const FUNCTION = { MSP: 1, GPS: 2, RX_SERIAL: 64, VTX_MSP: 131072 } as const;
19
+
20
+ interface Line {
21
+ text: string;
22
+ why: string;
23
+ }
24
+
25
+ const traitsOf = (x: { traits?: TraitDef[] }) => x.traits ?? [];
26
+
27
+ /** All trait params of a module and its interfaces, flattened. */
28
+ function facts(def: ModuleDef): Record<string, unknown>[] {
29
+ return [def, ...def.interfaces].flatMap(traitsOf).map((t) => (t.params ?? {}) as Record<string, unknown>);
30
+ }
31
+
32
+ function textOf(def: ModuleDef): string {
33
+ return JSON.stringify(facts(def));
34
+ }
35
+
36
+ const hasProtocol = (iface: InterfaceDef, type: string) => iface.protocols.some((p) => p.type === type);
37
+
38
+ function kindOf(end: ResolvedEndpoint): "receiver" | "gnss" | "dji" | "other" {
39
+ const words = `${end.owner.name} ${(end.owner.tags ?? []).join(" ")} ${(end.owner.categories ?? []).join(" ")}`.toLowerCase();
40
+ if (hasProtocol(end.iface, "crsf")) return "receiver";
41
+ if (/gnss|gps/.test(words)) return "gnss";
42
+ if (/dji|air unit/.test(words)) return "dji";
43
+ return "other";
44
+ }
45
+
46
+ /** "uart5" → 5, from the flight controller's interface id. */
47
+ const uartNumber = (iface: InterfaceDef) => Number(/^uart(\d+)$/.exec(iface.id)?.[1]);
48
+
49
+ function isFlightController(def: ModuleDef): boolean {
50
+ return /flight controller/i.test(def.name) || (def.categories ?? []).some((c) => /flight/i.test(c));
51
+ }
52
+
53
+ function param(iface: InterfaceDef, id: string) {
54
+ return iface.parameters?.find((p) => p.id === id);
55
+ }
56
+
57
+ export interface BetaflightConfig {
58
+ target?: string;
59
+ minFirmware: string;
60
+ buildOptions: string[];
61
+ lines: Line[];
62
+ warnings: string[];
63
+ }
64
+
65
+ export function betaflightConfig(system: ModuleDef, lookup: ModuleLookup): BetaflightConfig {
66
+ const links = systemLinks(system, lookup); // stored + derived through cables (PB-805)
67
+ const lines: Line[] = [];
68
+ const warnings: string[] = [];
69
+ const features = new Set<string>();
70
+ const buildOptions = new Set<string>(["DSHOT"]);
71
+ let minFirmware = "4.5.5";
72
+
73
+ const fcEnd = (r: LinkResult): [ResolvedEndpoint, ResolvedEndpoint] | undefined => {
74
+ if (r.protocol === "connector") return undefined; // positions, not functions: the derived links carry them
75
+ if (isFlightController(r.a.owner)) return [r.a, r.b];
76
+ if (isFlightController(r.b.owner)) return [r.b, r.a];
77
+ return undefined;
78
+ };
79
+
80
+ // --- target -------------------------------------------------------------
81
+ const fcDef = links.map(fcEnd).find(Boolean)?.[0].owner;
82
+ const target = fcDef ? /\b(MATEK[A-Z0-9]+|[A-Z0-9]{6,}(?=\b[^"]*target))/.exec(textOf(fcDef) + fcDef.description)?.[1] : undefined;
83
+
84
+ // --- serial ports ---------------------------------------------------------
85
+ for (const r of links) {
86
+ const ends = fcEnd(r);
87
+ if (!ends || r.protocol !== "uart") continue;
88
+ const [fc, other] = ends;
89
+ const n = uartNumber(fc.iface);
90
+ if (!Number.isFinite(n)) continue;
91
+ const kind = kindOf(other);
92
+ const why = `link ${r.link.id}: ${fc.path} ↔ ${other.path}`;
93
+ if (kind === "receiver") {
94
+ lines.push({ text: `serial UART${n} ${FUNCTION.RX_SERIAL} 115200 57600 0 115200`, why: `${why} (CRSF receiver → RX_SERIAL)` });
95
+ lines.push({ text: "set serialrx_provider = CRSF", why: `${other.path} speaks crsf` });
96
+ features.add("TELEMETRY");
97
+ buildOptions.add("SERIALRX_CRSF");
98
+ } else if (kind === "gnss") {
99
+ lines.push({ text: `serial UART${n} ${FUNCTION.GPS} 115200 115200 0 115200`, why: `${why} (GNSS → GPS)` });
100
+ lines.push({ text: "set gps_provider = UBLOX", why: `${other.owner.name}: u-blox receiver` });
101
+ lines.push({ text: "set gps_auto_config = ON", why: "auto-config sets the module's baud/protocol from its default" });
102
+ features.add("GPS");
103
+ buildOptions.add("GPS");
104
+ } else if (kind === "dji") {
105
+ lines.push({ text: `serial UART${n} ${FUNCTION.MSP + FUNCTION.VTX_MSP} 115200 57600 0 115200`, why: `${why} (DJI MSP DisplayPort → MSP + VTX_MSP)` });
106
+ lines.push({ text: "set osd_displayport_device = MSP", why: "DJI O4 OSD via MSP DisplayPort (onboard analog OSD chip must not win on AUTO)" });
107
+ lines.push({ text: "set vcd_video_system = HD", why: "HD digital video system" });
108
+ features.add("OSD");
109
+ buildOptions.add("OSD_HD");
110
+ } else {
111
+ warnings.push(`${why}: no Betaflight serial function derived for ${other.owner.name}`);
112
+ }
113
+ }
114
+
115
+ // Every other hardware UART the flight controller has is reset to no
116
+ // function, so a pasted configuration is complete: a port the model no
117
+ // longer uses (the GPS moved from UART1 to UART3) does not keep its old
118
+ // function from the board's saved settings. The baud fields are the
119
+ // per-port defaults (betaflight-reference.md §1).
120
+ const used = new Set(lines.map((l) => Number(/^serial UART(\d+) /.exec(l.text)?.[1])).filter(Number.isFinite));
121
+ for (const n of (fcDef?.interfaces ?? []).map(uartNumber).filter(Number.isFinite).sort((a, b) => a - b)) {
122
+ if (used.has(n)) continue;
123
+ lines.push({ text: `serial UART${n} 0 115200 57600 0 115200`, why: `${fcDef!.id}: UART${n} has no link in the model, reset to no function` });
124
+ }
125
+
126
+ // --- motors ---------------------------------------------------------------
127
+ const phaseLinks = links.filter((r) => r.protocol === "bldc_3phase");
128
+ const escDef = phaseLinks[0] && (param(phaseLinks[0].a.iface, "max_current") ? phaseLinks[0].a.owner : phaseLinks[0].b.owner);
129
+ const fcRates = fcDef?.interfaces.find((i) => i.capabilities?.includes("esc_signal"))?.parameters?.find((p) => p.id === "esc_signal_rate");
130
+ const escRates = escDef?.interfaces.find((i) => i.capabilities?.includes("esc_signal"))?.parameters?.find((p) => p.id === "esc_signal_rate");
131
+ const maxRate = (p?: { value?: number; range?: [number, number] }) => p?.range?.[1] ?? p?.value;
132
+ const rate = Math.min(maxRate(fcRates) ?? 0, maxRate(escRates) ?? 0);
133
+ if (rate >= 150) {
134
+ const protocol = rate >= 600 ? "DSHOT600" : rate >= 300 ? "DSHOT300" : "DSHOT150";
135
+ lines.push({ text: `set motor_pwm_protocol = ${protocol}`, why: `highest DShot rate both ${fcDef?.id} and ${escDef?.id} state (${rate} kbit/s)` });
136
+ } else {
137
+ warnings.push("no common DShot rate between the FC motor outputs and the ESC inputs");
138
+ }
139
+ const bidir = (def?: ModuleDef) => Boolean(def?.interfaces.some((i) => i.capabilities?.includes("dshot_bidirectional")));
140
+ if (bidir(fcDef) && bidir(escDef)) {
141
+ lines.push({ text: "set dshot_bidir = ON", why: `both ${fcDef?.id} and ${escDef?.id} state bidirectional DShot (source: DolphinRC review blog only — verify)` });
142
+ }
143
+ const motorEnd = phaseLinks[0] && (param(phaseLinks[0].a.iface, "max_current") ? phaseLinks[0].b : phaseLinks[0].a);
144
+ const config = motorEnd && /(\d+)N(\d+)P/.exec(textOf(motorEnd.owner));
145
+ if (config) {
146
+ lines.push({ text: `set motor_poles = ${config[2]}`, why: `${motorEnd.owner.id}: ${config[0]} stator (${config[2]} magnet poles)` });
147
+ }
148
+
149
+ // Quad-X motor order check (betaflight-reference.md §3)
150
+ const expected: Record<number, string> = { 1: "rr", 2: "fr", 3: "rl", 4: "fl" };
151
+ for (const r of phaseLinks) {
152
+ const escSide = param(r.a.iface, "max_current") ? r.a : r.b;
153
+ const armSide = escSide === r.a ? r.b : r.a;
154
+ const n = Number(/(\d+)$/.exec(escSide.iface.id)?.[1]);
155
+ const corner = /arm_(\w\w)/.exec(armSide.path)?.[1];
156
+ if (expected[n] && corner && expected[n] !== corner) {
157
+ warnings.push(`motor ${n} is wired to arm_${corner}; Betaflight Quad-X expects arm_${expected[n]} (remap with the resource command or rewire)`);
158
+ }
159
+ }
160
+
161
+ // Motor direction (betaflight-reference.md §3a): Quad-X "props in" is
162
+ // M1 CW, M2 CCW, M3 CCW, M4 CW from above with yaw_motors_reversed OFF
163
+ // (the default); "props out" is every motor reversed with it ON.
164
+ const propsIn: Record<number, SpinDirection> = { 1: "cw", 2: "ccw", 3: "ccw", 4: "cw" };
165
+ const spins = resolveSpins(system, lookup);
166
+ const motorSpin = new Map<number, SpinDirection | undefined>();
167
+ for (const r of phaseLinks) {
168
+ const escSide = param(r.a.iface, "max_current") ? r.a : r.b;
169
+ const armSide = escSide === r.a ? r.b : r.a;
170
+ const n = Number(/(\d+)$/.exec(escSide.iface.id)?.[1]);
171
+ const armPath = armSide.path.split(":")[0];
172
+ const motor = [...spins.values()].find((x) => x.path.startsWith(`${armPath}/`) && x.def.id === armSide.owner.id) ?? spins.get(armPath);
173
+ motorSpin.set(n, motor?.spin);
174
+ }
175
+ const known = [...motorSpin.entries()].filter(([n, sp]) => propsIn[n] && sp);
176
+ if (known.length && known.length === motorSpin.size) {
177
+ const inward = known.every(([n, sp]) => propsIn[n] === sp);
178
+ const outward = known.every(([n, sp]) => propsIn[n] !== sp);
179
+ const list = known.sort(([a], [b]) => a - b).map(([n, sp]) => `M${n} ${sp!.toUpperCase()}`).join(", ");
180
+ if (inward) lines.push({ text: "set yaw_motors_reversed = OFF", why: `motor spins in the model (${list}) are Quad-X "props in", the default` });
181
+ else if (outward) lines.push({ text: "set yaw_motors_reversed = ON", why: `motor spins in the model (${list}) are Quad-X "props out"` });
182
+ else warnings.push(`motor spins (${list}) are neither Quad-X props-in nor props-out: diagonal motors must turn the same way`);
183
+ } else if (phaseLinks.length) {
184
+ warnings.push("no spin direction on some motors: set ChildModuleRef.spin so the prop direction can be derived");
185
+ }
186
+
187
+ // --- current meter ----------------------------------------------------------
188
+ const scale = escDef && /scale[^0-9]{0,12}(\d{2,4})/i.exec(textOf(escDef));
189
+ if (scale) {
190
+ lines.push({ text: "set current_meter = ADC", why: `${escDef?.id}: analog current sensor on the FC connector` });
191
+ lines.push({ text: `set ibata_scale = ${scale[1]}`, why: `${escDef?.id}: manufacturer current scale` });
192
+ lines.push({ text: "set ibata_offset = 0", why: `${escDef?.id}: manufacturer current offset` });
193
+ }
194
+
195
+ // --- compass -----------------------------------------------------------------
196
+ const compass = links.find((r) => r.protocol === "i2c" && fcEnd(r));
197
+ if (compass) {
198
+ const [, other] = fcEnd(compass)!;
199
+ const address = param(other.iface, "i2c_address")?.value;
200
+ lines.push({ text: "set mag_hardware = AUTO", why: `link ${compass.link.id}: compass at 0x${address?.toString(16).toUpperCase()} on ${compass.a.path}` });
201
+ buildOptions.add("MAG");
202
+ if (address === 0x2c) {
203
+ minFirmware = "2025.12.1";
204
+ warnings.push(`${other.owner.id}: QMC5883P compass (0x2C) is detected only by Betaflight >= 2025.12.1`);
205
+ }
206
+ const align = /CW\s?(\d+)°?\s*Flip/i.exec(textOf(other.owner));
207
+ if (align) {
208
+ lines.push({ text: `set align_mag = CW${align[1]}FLIP`, why: `${other.owner.id}: manufacturer alignment for arrow-forward mounting — confirm in the Sensors tab` });
209
+ }
210
+ }
211
+
212
+ // --- features ------------------------------------------------------------------
213
+ const featureLines = [...features].map((f) => ({ text: `feature ${f}`, why: "required by the serial functions above" }));
214
+ return {
215
+ target,
216
+ minFirmware,
217
+ buildOptions: [...buildOptions].sort(),
218
+ lines: [
219
+ ...lines
220
+ .filter((l) => l.text.startsWith("serial"))
221
+ .sort((a, b) => Number(/UART(\d+)/.exec(a.text)?.[1]) - Number(/UART(\d+)/.exec(b.text)?.[1])),
222
+ ...featureLines,
223
+ ...lines.filter((l) => !l.text.startsWith("serial")),
224
+ ],
225
+ warnings,
226
+ };
227
+ }
228
+
229
+ export function betaflightCli(system: ModuleDef, cfg: BetaflightConfig): string {
230
+ const width = Math.max(...cfg.lines.map((l) => l.text.length)) + 2;
231
+ return [
232
+ `# Betaflight configuration — ${system.name}`,
233
+ `# Generated from the UHD model by @protoboardai/ext-drone (protoboard run betaflight-cli). Do not edit by hand.`,
234
+ `# Target: ${cfg.target ?? "unknown"} · firmware >= ${cfg.minFirmware} · cloud build options: ${cfg.buildOptions.join(", ")}`,
235
+ `# Syntax and values verified against @protoboardai/ext-drone skills/firmware-config/references/betaflight-reference.md.`,
236
+ `# NOT FLIGHT-TESTED. Verify motor order, directions and compass alignment on the bench before flight.`,
237
+ `# Every hardware UART is set below (unused ports reset to function 0), so pasting this file needs no prior reset.`,
238
+ ...cfg.warnings.map((w) => `# WARNING: ${w}`),
239
+ "",
240
+ ...cfg.lines.map((l) => `${l.text.padEnd(width)}# ${l.why}`),
241
+ "save",
242
+ "",
243
+ ].join("\n");
244
+ }
@@ -0,0 +1,16 @@
1
+ import type { OperationFn } from "@protoboardai/core";
2
+ import { betaflightCli, betaflightConfig } from "../lib/betaflight.ts";
3
+
4
+ /** Betaflight CLI from the resolved system; warnings are returned as data for the agent to act on. */
5
+ export const betaflightCliOp: OperationFn = (ctx) => {
6
+ const { rootDef, lookup } = ctx.project;
7
+ if (!rootDef) return { status: "failed", summary: "project has no root system" };
8
+ const cfg = betaflightConfig(rootDef, lookup);
9
+ const out = ctx.inputs.out ?? "firmware/betaflight/cli.txt";
10
+ ctx.writeOutput(out, betaflightCli(rootDef, cfg), `Betaflight CLI (min firmware ${cfg.minFirmware})`);
11
+ return {
12
+ status: "succeeded",
13
+ summary: `${cfg.lines.length} CLI lines for ${cfg.target ?? "unknown target"}, firmware ≥ ${cfg.minFirmware}${cfg.warnings.length ? `, ${cfg.warnings.length} warning(s)` : ""}`,
14
+ data: { target: cfg.target, minFirmware: cfg.minFirmware, buildOptions: cfg.buildOptions, warnings: cfg.warnings },
15
+ };
16
+ };
package/ops/package.ts ADDED
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Contributions to the Manufacturing Package (@protoboardai/ext-release section
3
+ * contract): the flight-controller configuration, in the root unit's work
4
+ * order (it depends on the whole system's wiring, so it is loaded at final
5
+ * assembly, once everything is connected) and its bench check in the root
6
+ * unit's test plan. Flashing and loading are contributed as "configure"
7
+ * operations: the release numbers them after the assembly steps, inside the
8
+ * bench test and before the propellers go on.
9
+ *
10
+ * The configuration file is the one `protoboard run betaflight-cli` wrote.
11
+ * It is regenerated here in memory and compared: a file that no longer
12
+ * matches the model stops the release.
13
+ */
14
+ import { existsSync, readFileSync } from "node:fs";
15
+ import { join } from "node:path";
16
+ import { listOperationRecords, type Project } from "@protoboardai/core";
17
+ import type { SectionContribution, SectionFn } from "@protoboardai/ext-release";
18
+ import { betaflightCli, betaflightConfig } from "../lib/betaflight.ts";
19
+
20
+ const DEFAULT_OUT = "firmware/betaflight/cli.txt";
21
+
22
+ /** The configuration file: where the last betaflight-cli run wrote it. */
23
+ function cliFile(p: Project): string {
24
+ const rec = listOperationRecords(p).filter((r) => r.record.operation === "betaflight-cli" && r.record.status === "succeeded").pop();
25
+ return rec?.record.outputs[0]?.path ?? DEFAULT_OUT;
26
+ }
27
+
28
+ function configuration(p: Project) {
29
+ if (!p.rootDef) return undefined;
30
+ const cfg = betaflightConfig(p.rootDef, p.lookup);
31
+ if (!cfg.target && !cfg.lines.length) return undefined; // no flight controller in this system
32
+ return { cfg, text: betaflightCli(p.rootDef, cfg), file: cliFile(p) };
33
+ }
34
+
35
+ export const workOrder: SectionFn = ({ project: p, unit }) => {
36
+ if (unit?.kind !== "root") return undefined;
37
+ const c = configuration(p);
38
+ if (!c) return undefined;
39
+ const abs = join(p.root, c.file);
40
+ const rerun = "run `protoboard run betaflight-cli` and commit the result";
41
+ if (!existsSync(abs)) return { title: "Flight controller configuration", blocks: [], diagnostics: [{ code: "DRONE_CLI_MISSING", severity: "error", message: `${c.file} does not exist; ${rerun}` }] };
42
+ if (readFileSync(abs, "utf8") !== c.text) return { title: "Flight controller configuration", blocks: [], diagnostics: [{ code: "DRONE_CLI_STALE", severity: "error", message: `${c.file} no longer matches the model; ${rerun}` }] };
43
+ const out: SectionContribution = {
44
+ title: "Flight controller configuration",
45
+ order: 60,
46
+ blocks: [
47
+ { kind: "paragraph", text: "Load the configuration once the receiver, video transmitter and GNSS are connected, before the propellers go on: the operations above flash the firmware and load this file after the power-up checks and before the rest of the bench test. Every line of the file cites the link or part fact it comes from." },
48
+ {
49
+ kind: "keyvalues",
50
+ rows: [
51
+ { label: "Firmware", value: `Betaflight ${c.cfg.minFirmware} or later` },
52
+ { label: "Target", value: c.cfg.target ?? "unknown" },
53
+ { label: "Build options", value: c.cfg.buildOptions.join(", ") },
54
+ { label: "File", value: "files/firmware/betaflight-cli.txt", note: `${c.cfg.lines.length} settings, from ${c.file}` },
55
+ ],
56
+ },
57
+ ...c.cfg.warnings.map((w) => ({ kind: "note" as const, level: "caution" as const, text: w })),
58
+ ],
59
+ operations: [
60
+ { stage: "configure", title: "Flash the flight controller", actions: [`Propellers off. Flash Betaflight ${c.cfg.minFirmware} or later for ${c.cfg.target ?? "the flight controller's target"} with the cloud build options ${c.cfg.buildOptions.join(", ")}.`], tools: ["Betaflight Configurator", "USB-C cable"], inspect: "the configurator connects and shows the target", test: "the configurator connects and shows the target" },
61
+ { stage: "configure", title: "Load the flight controller configuration", actions: ["Open the CLI tab, paste files/firmware/betaflight-cli.txt and press Enter; the board saves and reboots."], tools: ["Betaflight Configurator", "USB-C cable"], inspect: "the CLI echoes no error lines", test: "the flight controller bench check (test plan)" },
62
+ ],
63
+ files: [{ path: "files/firmware/betaflight-cli.txt", from: c.file, role: "firmware-config", description: "Betaflight CLI configuration" }],
64
+ };
65
+ return out;
66
+ };
67
+
68
+ export const testPlan: SectionFn = ({ project: p, unit }) => {
69
+ if (unit?.kind !== "root" || !configuration(p)) return undefined;
70
+ return {
71
+ title: "Flight controller bench check",
72
+ order: 60,
73
+ blocks: [
74
+ { kind: "paragraph", text: "After bring-up and the configuration, before the propellers go on: props off, powered through a current-limited supply or a smoke stopper. The configuration is generated from the model and has not been flight-tested." },
75
+ {
76
+ kind: "table",
77
+ columns: [
78
+ { key: "check", label: "Check" },
79
+ { key: "how", label: "How" },
80
+ { key: "pass", label: "Pass" },
81
+ ],
82
+ rows: [
83
+ { check: "Motor order and direction", how: "Motors tab, spin each motor at low throttle", pass: "M1–M4 at the positions and directions of the model's Quad-X layout" },
84
+ { check: "Receiver", how: "Receiver tab with the transmitter bound", pass: "all channels follow the sticks" },
85
+ { check: "Video and OSD", how: "goggles on, power cycle", pass: "image and OSD elements shown" },
86
+ { check: "GNSS and compass", how: "outdoors, Sensors and GPS tabs", pass: "satellite fix; heading follows the frame's nose" },
87
+ { check: "Current sensor", how: "compare the OSD current with the supply's", pass: "within the supply's resolution at idle" },
88
+ ],
89
+ },
90
+ ],
91
+ };
92
+ };
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@protoboardai/ext-drone",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Protoboard extension: multirotor flight-controller configuration from UHD",
5
+ "license": "Apache-2.0",
6
+ "author": "Delta Robotics, Inc.",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Delta-Robotics-Inc/protoboard-stack.git",
10
+ "directory": "packages/ext-drone"
11
+ },
12
+ "type": "module",
13
+ "files": [
14
+ "protoboard-extension.json",
15
+ "ops",
16
+ "lib",
17
+ "skills",
18
+ "evals",
19
+ "LICENSE",
20
+ "NOTICE"
21
+ ],
22
+ "engines": {
23
+ "node": ">=22"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "peerDependencies": {
29
+ "@protoboardai/core": "^0.2.0",
30
+ "@deltarobotics/uhd": ">=0.3.0",
31
+ "@protoboardai/ext-release": "^0.2.0"
32
+ },
33
+ "peerDependenciesMeta": {
34
+ "@protoboardai/ext-release": {
35
+ "optional": true
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "schema": "protoboard.extension/v0",
3
+ "id": "@protoboardai/ext-drone",
4
+ "version": "0.2.0",
5
+ "description": "Multirotor domain pack: flight-controller configuration (Betaflight) generated from the UHD model.",
6
+ "compatibility": {
7
+ "protoboard": "^0.2.0",
8
+ "uhd": ">=0.3.0"
9
+ },
10
+ "skills": [
11
+ {
12
+ "id": "firmware-config",
13
+ "summary": "Derive a flight-controller configuration from UHD links and part facts, every line cited, every setting checked against pinned firmware sources",
14
+ "path": "skills/firmware-config/SKILL.md",
15
+ "verifiedBy": "firmware-verify"
16
+ },
17
+ {
18
+ "id": "firmware-verify",
19
+ "summary": "Bench-verify a generated FC configuration on hardware (props off) and record the result as measured test data",
20
+ "path": "skills/firmware-verify/SKILL.md"
21
+ }
22
+ ],
23
+ "operations": [
24
+ {
25
+ "id": "betaflight-cli",
26
+ "summary": "Generate a Betaflight CLI dump (serial ports, receiver, OSD/VTX, GPS, compass) from the model's links; every line cites its link or part fact",
27
+ "entry": "./ops/betaflight.ts#betaflightCliOp",
28
+ "effect": "export",
29
+ "inputs": {
30
+ "out": {
31
+ "description": "output file, project-relative",
32
+ "default": "firmware/betaflight/cli.txt"
33
+ }
34
+ }
35
+ },
36
+ {
37
+ "id": "package:work-order",
38
+ "summary": "Manufacturing Package: the flight-controller configuration (file and loading steps) in the root unit's work order; refuses a configuration that no longer matches the model",
39
+ "entry": "./ops/package.ts#workOrder",
40
+ "effect": "pure"
41
+ },
42
+ {
43
+ "id": "package:test-plan",
44
+ "summary": "Manufacturing Package: the props-off bench check of the flight controller in the root unit's test plan",
45
+ "entry": "./ops/package.ts#testPlan",
46
+ "effect": "pure"
47
+ }
48
+ ]
49
+ }
@@ -0,0 +1,178 @@
1
+ ---
2
+ name: firmware-config
3
+ description: Derive a controller's firmware configuration from a UHD system's links and part facts — Betaflight CLI for flight controllers today (protoboard run betaflight-cli; the same method for INAV, ArduPilot or PX4), and the firmware capability's pin and peripheral configuration for microcontroller boards as it lands — with every line citing the link or fact it comes from and every setting checked against the firmware's own source at a pinned version. Use when a system has a controller and its wiring is modelled, when wiring changes, or when moving firmware versions; follow with firmware-verify on the bench.
4
+ ---
5
+
6
+ # Firmware configuration from the model
7
+
8
+ ```
9
+ UHD links + part facts ──► reference doc (settings verified in firmware source, pinned) ──► generator
10
+ │
11
+ firmware/<fw>/cli.txt (every line: "# link <id>: …" or "# <part>: <fact>") ◄──────┘
12
+ │
13
+ firmware-verify (bench) ◄────────┘
14
+ ```
15
+
16
+ The configuration is a *view* of the model: which UART the receiver is wired
17
+ to is a link, the current-sensor scale is an ESC fact, the compass address is
18
+ a GNSS fact. Nothing is typed from memory, and nothing is claimed flight-ready.
19
+
20
+ ## Purpose
21
+
22
+ Produce the controller configuration a unit is flashed with, derived from the
23
+ model so it cannot disagree with the wiring silently. Use it when a system
24
+ has a flight controller or a microcontroller board and its wiring is
25
+ modelled, whenever wiring changes, and when moving firmware versions. In
26
+ **build-a-project** it is stage 9, after the checks are clean; the
27
+ configuration goes into the Manufacturing Package's `files/` and its
28
+ UNVERIFIED items into the test plan. **firmware-verify** follows on the
29
+ bench, performed by a person.
30
+
31
+ ## Inputs
32
+
33
+ | Input | Where | From |
34
+ | --- | --- | --- |
35
+ | The links to the controller (UARTs, I2C, motor outputs) | the root system and sub-assemblies, `npx protoboard inspect <fc instance>` | **system-compose**, **harness-author** |
36
+ | Part facts (firmware target, sensor scale, I2C address, motor poles, DShot rates) | the parts' definitions and evidence | **uhd-part-author**, the catalog |
37
+ | The firmware reference, source-pinned | `references/betaflight-reference.md` (this skill) | step 2 |
38
+ | A board's nets and pin assignment (microcontroller boards) | `src/boards/<module>/<module>.uhd.ts` | **circuit-board** |
39
+
40
+ ## Steps
41
+
42
+ ### 1. Generate (Betaflight)
43
+
44
+ ```bash
45
+ npx protoboard run betaflight-cli # → firmware/betaflight/cli.txt + operation record
46
+ npx protoboard run betaflight-cli --format json # data: target, minFirmware, buildOptions, warnings
47
+ ```
48
+
49
+ Look at `data.warnings`: each is something the model could not decide (an
50
+ unknown peer on a UART, a motor-order mismatch, a target claimed only by
51
+ compatibility) and goes on the **firmware-verify** list.
52
+
53
+ Implementation: `@protoboardai/ext-drone` `lib/betaflight.ts`; reference:
54
+ [betaflight-reference.md](references/betaflight-reference.md) (every setting
55
+ checked against Betaflight 4.5.5, 2025.12.5 and 2026.6.2 sources, commits
56
+ pinned, UNVERIFIED items marked). Read the reference's gotchas before trusting
57
+ any output.
58
+
59
+ What the configuration is derived from:
60
+
61
+ | Setting family | Model input | Rule |
62
+ | --- | --- | --- |
63
+ | Target | FC part facts (target name in traits/description, e.g. `MATEKF405TE`) | The FC must state its firmware target with a source; if it only claims compatibility (DolphinRC → MATEKF405TE), that is UNVERIFIED and goes to the bench list. |
64
+ | Serial ports | every `uart` link with the FC on one end: FC interface id `uartN` → port N; the other end's protocol/kind → function | CRSF receiver → `RX_SERIAL` (64) + `feature TELEMETRY`; u-blox GNSS → `GPS` (2) + provider; DJI air unit → `MSP + VTX_MSP` (131073) + HD OSD settings. An unknown peer is a warning, never a guess. |
65
+ | Motor protocol | FC motor outputs' and ESC inputs' `esc_signal_rate` | highest DShot rate both state; bidirectional only if both state the capability (cite it). |
66
+ | Unused UARTs | every `uartN` interface of the FC with no link | `serial UARTn 0 115200 57600 0 115200` (function 0, per-port default bauds), so a pasted file is complete: a port the model stopped using (the GPS moved from UART1 to UART3) is cleared, not left with its old function. |
67
+ | Motor poles | motor stator/magnet config fact (`12N14P`) | magnet poles. |
68
+ | Motor order | `bldc_3phase` links: ESC channel n → arm | compare with the firmware's mixer order (Quad-X: M1 rear-right, M2 front-right, M3 rear-left, M4 front-left); mismatch → warning (remap or rewire). |
69
+ | Current meter | ESC current-sensor fact (scale, offset) | `current_meter = ADC`, `ibata_scale`, `ibata_offset` from the ESC's manufacturer values. |
70
+ | Compass | `i2c` link to the FC; the peer's `i2c_address` and alignment fact | driver per address (0x2C QMC5883P needs ≥ 2025.12.1 → `minFirmware`), `align_mag` from the maker's mounting statement. |
71
+ | Build options | whatever the lines above need | e.g. `GPS`, `MAG`, `OSD_HD`, `SERIALRX_CRSF`, `DSHOT` for a cloud build. |
72
+
73
+ Each emitted line carries its reason: `serial UART2 64 … # link rx_crsf: stack:uart2 ↔ receiver:crsf (CRSF receiver → RX_SERIAL)`.
74
+
75
+ ### 2. Add or change a rule
76
+
77
+ 1. **Verify the setting first** in the firmware source at a pinned tag: the
78
+ CLI parser, the setting's table, value ranges, defaults, the target's
79
+ `config.h`. Add a section to the reference with `file#Lx-Ly` links, the
80
+ commit, and a **Δ** note for version differences. What cannot be checked in
81
+ source is marked **UNVERIFIED** and becomes a firmware-verify item.
82
+ 2. **Find the model input.** If the fact is not in the model (a pad label, a
83
+ scale factor), add it to the part with its source (**uhd-part-author**,
84
+ repair mode) instead of hard-coding it in the generator.
85
+ 3. **Emit with a reason** naming the link id or `<part id>: <fact>`, and a
86
+ warning when the model cannot decide.
87
+ 4. Regenerate, diff `firmware/<fw>/cli.txt`, commit output and operation
88
+ record together.
89
+
90
+ ### 3. Another firmware
91
+
92
+ Same pattern, new files in `@protoboardai/ext-drone`: `lib/<fw>.ts` (pure:
93
+ model → lines with reasons + warnings), `ops/<fw>.ts` (writes
94
+ `firmware/<fw>/…`), an operation in the manifest, and
95
+ `skills/firmware-config/references/<fw>-reference.md` written *before* the
96
+ generator, with the same verification standard (source-pinned, UNVERIFIED
97
+ marked, version deltas). Parameter names and serial-function values differ per
98
+ firmware; the link → function mapping in step 1 does not.
99
+
100
+ ### 4. Microcontroller boards (the firmware capability, planned)
101
+
102
+ Custom boards with a microcontroller (Zephyr devicetree overlays and Kconfig
103
+ for nRF52840, ESP-IDF pin headers and sdkconfig for ESP32-C3) get their
104
+ starting configuration from a `firmware` capability provider, being built
105
+ now. It follows the capability pattern, so expect:
106
+
107
+ ```bash
108
+ npx protoboard run firmware:generate --module <board> # planned
109
+ npx protoboard run firmware:check --module <board> # planned: pins exist and are assigned once, peripherals match buses, strapping pins respected, I2C addresses match parts
110
+ ```
111
+
112
+ Until it is in your CLI (`npx protoboard capabilities` lists `firmware`),
113
+ write the board's pin and peripheral assignment as a table from the board
114
+ module's nets (each row citing its net and part fact) in the board's notes,
115
+ and list the configuration as an open item for the release.
116
+
117
+ ### 5. What the output does not establish
118
+
119
+ A generated configuration is consistent with the model and the checked
120
+ firmware sources. It does not prove the pads are labelled as the target
121
+ expects, that motor directions are right, that the compass alignment matches
122
+ the physical mounting, or that bidirectional DShot works on this ESC. Those
123
+ are bench checks: **firmware-verify**. The CLI header says NOT FLIGHT-TESTED
124
+ until they pass and are recorded.
125
+
126
+ ## Decision points
127
+
128
+ | Decision | Rule |
129
+ | --- | --- |
130
+ | The model cannot decide a setting | Emit a warning, never a guess; it goes on the bench list. |
131
+ | A fact is missing from the model | Add it to the part with its source (**uhd-part-author**), not to the generator. |
132
+ | A setting not checkable in source | Mark it **UNVERIFIED** in the reference; it becomes a **firmware-verify** item. |
133
+ | Firmware version | The lowest version every emitted line needs (`minFirmware`), recorded in the header and the release manifest. |
134
+ | Motor order mismatch | Remap in firmware or rewire; decide and record it in `docs/decisions.md`. |
135
+
136
+ ## Outputs
137
+
138
+ | Output | Where |
139
+ | --- | --- |
140
+ | Betaflight configuration (generated; never edit) | `firmware/betaflight/cli.txt` |
141
+ | Operation record | `operations/` |
142
+ | Reference, source-pinned | `references/<fw>-reference.md` in this skill |
143
+ | Board pin and peripheral configuration | `firmware/<fw>/` from the firmware capability (planned) |
144
+
145
+ ## Verification
146
+
147
+ ```bash
148
+ npx protoboard run betaflight-cli --format json # succeeded; data.warnings reviewed, each on the bench list
149
+ git diff --stat firmware/ # only the changes the model change explains
150
+ ```
151
+
152
+ Every line of `cli.txt` carries a `# link …` or `# <part>: …` reason. Then
153
+ **firmware-verify** on the bench.
154
+
155
+ ## Failure handling
156
+
157
+ | Code or symptom | Means | Do |
158
+ | --- | --- | --- |
159
+ | `run betaflight-cli` fails: "project has no root system" | `protoboard.config.ts` names no loadable root | Fix `root` (`PB_ROOT_NOT_FOUND`) |
160
+ | Summary says "unknown target" | The FC part states no firmware target | Add the target to the FC part with its source; until then a bench item |
161
+ | Warning: "no Betaflight serial function derived" | A UART link to something the generator has no rule for | Add the rule (step 2) or set it on the bench and record it |
162
+ | Warning: "no common DShot rate" | FC outputs and ESC inputs state no shared rate | Add the rates from the datasheets, or choose compatible parts |
163
+ | Warning: no spin, or spins not Quad-X | `spin` missing on the arms, or diagonal motors disagree | Set `ChildModuleRef.spin` once per arm (**system-compose**) |
164
+ | Warning: motor order differs from the mixer | ESC channels and arms disagree | Remap or rewire; record the decision |
165
+ | `UHD_LINK_STATE` on a link to the FC | The wiring the configuration would encode is wrong | Fix the system first (**system-compose**) |
166
+ | `UHD_INTERFACE_REUSE` on an FC UART | Two devices on one UART | Fix the wiring; the generator cannot assign one port twice |
167
+ | `UHD_BUS_ADDRESS` on the FC's I2C | Two devices share an address | Fix the system |
168
+ | `run firmware:generate` not available | The firmware capability has not landed | Step 4's interim table and an open item |
169
+
170
+ Every other code: **system-compose** [diagnostic codes](../system-compose/references/diagnostic-codes.md).
171
+
172
+ ## Hard rules
173
+
174
+ 1. Every emitted line cites the link or part fact it comes from.
175
+ 2. Never hand-edit a generated configuration; change the model or the
176
+ generator and regenerate.
177
+ 3. Nothing generated is flight-ready until **firmware-verify** passes on the
178
+ recorded firmware version and unit.
@@ -0,0 +1,258 @@
1
+ # Betaflight CLI reference: 5" quad (DolphinRC F405 V3 / MATEKF405TE)
2
+
3
+ Every item below was checked against the Betaflight source or the official docs. Nothing here comes from memory. Anything that could not be checked is marked **UNVERIFIED**.
4
+
5
+ ## 0. Versions checked
6
+
7
+ | Source | Ref | Commit |
8
+ |---|---|---|
9
+ | Firmware (primary) | `betaflight/betaflight` tag **4.5.5**, the newest 4.5.x tag | `4adbd3ef7cb546947600e5f747bd5453c9573063` |
10
+ | Firmware (delta check) | tag **2025.12.5** | `7348054f268f0058574719c134e9f149565bb8ea` |
11
+ | Firmware (delta check) | tag **2026.6.2**, the newest stable release on 2026-09-26 | `e0b7bb01b17b21351057e9ead2d1ab39dd44fa16` |
12
+ | Target config (4.5) | `betaflight/config` branch `4.5-config`, `configs/MATEKF405TE/config.h` | `7b1f01a25d8cb6379ebeeeca9f0e91c24925e907` |
13
+ | Target config (master) | `betaflight/config` branch `master`, `configs/MTKS/MATEKF405TE/config.h` (the file has moved into a manufacturer folder) | `96910e90881573589b2a6c41f7392b7afad63973` |
14
+ | Docs | `betaflight/betaflight.com` master | `0589eb3b938ca3b9782aae6eb91f323604b9a39c` |
15
+
16
+ The `config.h` for MATEKF405TE is **byte-identical** on `4.5-config` and `master`. The `2025.12-config` branch points at the same commit as `4.5-config`.
17
+
18
+ Note: 4.5.x is **no longer the current stable line**. 2025.12.x and 2026.6.x have both shipped since. Where they differ from 4.5.5, the difference is flagged with a **Δ** marker.
19
+
20
+ Short link prefixes used below:
21
+ - `BF` = `https://github.com/betaflight/betaflight/blob/4.5.5/`
22
+ - `BF25` = `https://github.com/betaflight/betaflight/blob/2025.12.5/`
23
+ - `BF26` = `https://github.com/betaflight/betaflight/blob/2026.6.2/`
24
+ - `CFG` = `https://github.com/betaflight/config/blob/4.5-config/configs/MATEKF405TE/config.h`
25
+
26
+ ---
27
+
28
+ ## Final CLI block (4.5.5)
29
+
30
+ ```
31
+ # ports: serial <identifier> <functionMask> <msp_baud> <gps_baud> <telem_baud> <blackbox_baud>
32
+ serial 0 2 115200 115200 0 115200 # UART1 -> GPS (FUNCTION_GPS=2), GPS baud 115200
33
+ serial 1 64 115200 57600 0 115200 # UART2 -> Serial RX (FUNCTION_RX_SERIAL=64) (already the target default)
34
+ serial 4 131073 115200 57600 0 115200 # UART5 -> MSP(1) + VTX_MSP(131072) = MSP DisplayPort for DJI O4
35
+
36
+ feature GPS
37
+ feature TELEMETRY # needed for CRSF/ELRS telemetry back to the TX
38
+ feature OSD
39
+
40
+ set serialrx_provider = CRSF
41
+ set gps_provider = UBLOX
42
+ set gps_auto_config = ON
43
+ set osd_displayport_device = MSP
44
+ set vcd_video_system = HD
45
+ set motor_pwm_protocol = DSHOT600 # or DSHOT300
46
+ set dshot_bidir = ON
47
+ set motor_poles = 14
48
+ set current_meter = ADC
49
+ set ibata_scale = 150
50
+ set ibata_offset = 0
51
+ set mag_hardware = QMC5883 # AUTO also works; needs a MAG-enabled build (see section 4)
52
+ set align_mag = CW270FLIP
53
+ save
54
+ ```
55
+
56
+ **Δ 2025.12.x / 2026.6.x:** the `serial` command takes a port *name* instead: `serial UART1 2 115200 115200 0 115200`, `serial UART2 64 ...`, `serial UART5 131073 ...`. The old numeric identifiers 0-19 are still accepted and are remapped as legacy values (see section 1). All the `set` lines are unchanged.
57
+
58
+ ---
59
+
60
+ ## 1. `serial` command, function bitmask, UART mapping
61
+
62
+ ### Syntax (4.5.5)
63
+
64
+ `serial <identifier> <functionMask> <msp_baud> <gps_baud> <telemetry_baud> <blackbox_baud>`. All **6 arguments** are required.
65
+
66
+ - Parser: `BF src/main/cli/cli.c#L1288-L1375`. Output format `"serial %d %d %ld %ld %ld %ld"` is at L1290. The command fails with an invalid-argument error when `validArgumentCount < 6` (L1361-L1364).
67
+ - Baud limits the parser enforces (`cli.c#L1320-L1359`):
68
+ - MSP: 9600 to 1000000
69
+ - GPS: 9600 to **115200**
70
+ - Telemetry: `0` (= AUTO) or up to 115200
71
+ - Blackbox: 19200 to 2470000
72
+ - Baud table: `baudRates[] = {0, 9600, 19200, 38400, 57600, 115200, 230400, 250000, 400000, 460800, 500000, 921600, 1000000, 1500000, 2000000, 2470000}` at `BF src/main/io/serial.c#L114-L115`. `0` is `BAUD_AUTO` (`src/main/io/serial.h#L60`).
73
+ - Per-port defaults: MSP 115200, GPS 57600, telemetry AUTO, blackbox 115200 (`BF src/main/io/serial.c#L136-L142`).
74
+ - Docs: https://betaflight.com/docs/wiki/guides/current/Serial ("The `serial` CLI command takes 6 arguments").
75
+
76
+ ### Unused ports
77
+
78
+ `serial` changes only the port it names, and every other port keeps its saved
79
+ function. A generated block is complete only when it also writes the ports it
80
+ does not use: `serial UARTn 0 115200 57600 0 115200` (function 0 with the
81
+ per-port default bauds above). ext-drone writes such a line for every hardware
82
+ UART of the flight controller that the model does not link. This is safer than
83
+ a `defaults nosave` preamble, which would also reset modes, rates and PIDs.
84
+
85
+ ### Function bitmask (`serialPortFunction_e`, `BF src/main/io/serial.h#L35-L54`)
86
+
87
+ | Function | Value |
88
+ |---|---|
89
+ | FUNCTION_MSP | 1 (L37) |
90
+ | FUNCTION_GPS | 2 (L38) |
91
+ | FUNCTION_TELEMETRY_SMARTPORT | 32 (L42) |
92
+ | FUNCTION_RX_SERIAL | 64 (L43) |
93
+ | FUNCTION_BLACKBOX | 128 (L44) |
94
+ | FUNCTION_VTX_MSP | 131072 (L53) |
95
+
96
+ The values are identical in 2025.12.5 and 2026.6.2 (`serial.h` L37, L38, L43, L53).
97
+
98
+ **TELEMETRY for ELRS:** there is **no CRSF telemetry function bit**. CRSF telemetry runs on the RX_SERIAL port itself:
99
+ - `initCrsfTelemetry()` enables only if `crsfRxIsActive()` (`BF src/main/telemetry/crsf.c#L731-L739`).
100
+ - It only runs when `FEATURE_TELEMETRY` is on (`BF src/main/fc/init.c#L976-L980`).
101
+
102
+ So ELRS needs `64` on the RX port plus `feature TELEMETRY`, and no extra bit. The docs confirm: "CRSF, GHST and F.Port receivers cannot share their port with a telemetry slot — they carry telemetry over the receiver protocol itself" (Serial guide, "Validation and Recovery").
103
+
104
+ ### UART to identifier mapping (4.5.5)
105
+
106
+ `serialPortIdentifier_e` (`BF src/main/io/serial.h#L81-L101`):
107
+ - `SERIAL_PORT_USART1 = 0`, USART2 = 1, USART3 = 2, UART4 = 3, **UART5 = 4**, USART6 = 5
108
+ - `SERIAL_PORT_USB_VCP = 20`, SOFTSERIAL1 = 30
109
+
110
+ So in 4.5.5 **UART1 = 0, UART2 = 1, UART5 = 4**. These are fixed identifiers, not array positions. The `portConfigs[]` array puts VCP first (`serial.c#L69-L90`), but the CLI takes the identifier.
111
+
112
+ **Δ 2025.12+:**
113
+ - UART identifiers moved to 51+ (`SERIAL_PORT_USART1 = SERIAL_PORT_UART_FIRST = 51`, `BF25 src/main/io/serial.h#L97-L105`).
114
+ - The CLI prints and accepts names (`"serial %s %d ..."`, `BF25 src/main/cli/cli.c#L1292`). Names come from `serialPortNames[]` (`"UART1"`, `"UART5"`, ..., `BF25 src/main/io/serial.c#L147-L170`).
115
+ - Numeric 0-19 is still accepted: `identifier += SERIAL_PORT_UART1` for the legacy range 0..19 (`BF25 src/main/cli/cli.c#L1306-L1316`, `serial.h#L86-L87`). 2026.6.2 behaves the same (`BF26 src/main/cli/cli.c#L1414-L1509`).
116
+
117
+ **Δ future 2026.12 (unreleased):** the docs say `serial` becomes read-only and ports are assigned with `rx_uart`, `gps_uart`, `msp_uart_N`, `vtx_uart` and similar settings (Serial guide, "Per-Feature Port Assignment"). This does not apply to 4.5.5, 2025.12 or 2026.6.
118
+
119
+ ### MATEKF405TE hardware UARTs
120
+
121
+ - The MCU target enables `USE_UART1` through `USE_UART6` plus VCP and softserial (`BF src/main/target/STM32F405/target.h#L35-L50`).
122
+ - The config defines pins for UART1 to UART6 (`CFG#L52-L63`):
123
+
124
+ | UART | TX | RX |
125
+ |---|---|---|
126
+ | UART1 | PA9 | PA10 |
127
+ | UART2 | PA2 | PA3 |
128
+ | UART3 | PC10 | PC11 |
129
+ | UART4 | PA0 | PA1 |
130
+ | UART5 | PC12 | PD2 |
131
+ | UART6 | PC6 | PC7 |
132
+
133
+ - No special or remapped UART numbering. The only target serial default is `SERIALRX_UART SERIAL_PORT_USART2` (`CFG#L123`). That makes UART2 = RX_SERIAL by default through `pgResetFn_serialConfig` (`BF src/main/io/serial.c#L160-L165`).
134
+ - **UNVERIFIED:** that the DolphinRC F405 V3 pads are labelled to match MATEK's UART numbering. Check the DolphinRC wiring diagram.
135
+
136
+ ---
137
+
138
+ ## 2. Settings
139
+
140
+ ### Serial RX (ELRS)
141
+ - `set serialrx_provider = CRSF`. The setting is at `BF src/main/cli/settings.c#L769`, and the name comes from `src/main/fc/parameter_names.h#L45`.
142
+ - Allowed values (`lookupTableSerialRX`, `settings.c#L239-L256`): `NONE, SPEK2048, SBUS, SUMD, SUMH, XB-B, XB-B-RJ01, IBUS, JETIEXBUS, CRSF, SRXL, CUSTOM, FPORT, SRXL2, GHST, SPEK1024`.
143
+ - The default is already CRSF when the build includes `USE_SERIALRX_CRSF` (`BF src/main/pg/rx.c#L37-L40`, `L84`). Setting it explicitly is harmless.
144
+ - `feature RX_SERIAL` is already the target default (`DEFAULT_RX_FEATURE FEATURE_RX_SERIAL`, `CFG#L124`, applied at `BF src/main/config/feature.c#L35`).
145
+
146
+ ### GPS (u-blox M10)
147
+ - `feature GPS` (feature name list `BF src/main/cli/cli.c#L234-L237`). GPS init is gated on `FEATURE_GPS` (`BF src/main/fc/init.c#L762-L763`).
148
+ - `set gps_provider = UBLOX`. Values are `NMEA, UBLOX, MSP` (`settings.c#L201-L203`, setting at `L1020`). UBLOX is the default (`BF src/main/pg/gps.c#L35`). **Δ** 2025.12 adds `VIRTUAL` (`BF25 settings.c#L254-L256`).
149
+ - `gps_auto_config` defaults to ON (`pg/gps.c#L37`). With UBLOX and auto-config on, the FC probes baud rates with MON-VER and then commands the module to the port's configured GPS baud (`BF src/main/io/gps.c#L425-L452`, `#L1044-L1052`). M10 is recognised (`gps.c#L479`, `UBX_VERSION_M10`).
150
+ - `gps_auto_baud` defaults to OFF (`pg/gps.c#L38`). In 4.5.5 it is referenced only by CLI GPS passthrough (`cli.c#L4813`), so you do not need to set it.
151
+ - Optional settings:
152
+ - `gps_ublox_use_galileo` (ON/OFF, default OFF, `settings.c#L1028`)
153
+ - `gps_ublox_flight_model` (default `AIRBORNE_4G`; values `PORTABLE, STATIONARY, PEDESTRIAN, AUTOMOTIVE, AT_SEA, AIRBORNE_1G, AIRBORNE_2G, AIRBORNE_4G`, `settings.c#L209-L211`)
154
+ - `gps_update_rate_hz` (default 10)
155
+ - GPS baud goes in the `serial` line's 4th field. The CLI accepts at most 115200.
156
+ - **UNVERIFIED:** the Matek M10Q-5883 factory baud rate. It does not matter much because UBLOX auto-config probes for it.
157
+
158
+ ### MSP DisplayPort OSD (DJI O4)
159
+ - **`displayport_msp_serial` does not exist in 4.5.5.** A grep of `src/main` finds no hits. The DisplayPort UART is chosen as the **first non-VCP port whose mask includes both `FUNCTION_MSP` and `FUNCTION_VTX_MSP`** (`BF src/main/config/config.c#L616-L630`). So the port setting is the `serial ... 131073 ...` line. The same logic is in 2025.12.5 (`config.c#L537`) and 2026.6.2 (`config.c#L576`).
160
+ - `set osd_displayport_device = MSP`. Values are `NONE, AUTO, MAX7456, MSP, FRSKYOSD` (`settings.c#L491-L493`, setting at `L1514`). **Δ** 2026.6 adds `FBOSD`.
161
+ - `set vcd_video_system = HD`. Values are `AUTO, PAL, NTSC, HD` (`settings.c#L392-L394`, setting at `L1570`). When `vcd_video_system == HD`, init forces the MSP device (`BF src/main/fc/init.c#L896-L900`) and uses the canvas size (`src/main/io/displayport_msp.c#L215-L217`).
162
+ - **Why both settings matter on this board:** MATEKF405TE has an onboard MAX7456 (`USE_MAX7456`, `CFG#L34`). With `AUTO`, init falls through to the MAX7456 case before MSP (`init.c#L920-L937`).
163
+ - Firmware defaults are already MSP and HD when `USE_OSD_HD` is built (`BF src/main/osd/osd.c#L415-L419`, `src/main/pg/vcd.c#L33-L37`), but set them explicitly anyway.
164
+ - The 4.4 release notes give exactly these two lines: https://betaflight.com/docs/wiki/release/Betaflight-4-4-Release-Notes (section "2. HD OSD").
165
+ - `displayport_msp_fonts` (`settings.c#L1588`) is **not required**.
166
+ - HD canvas defaults to 53x20 and is renegotiated by the VTX (`osd.h#L89-L90`; 4.4 notes).
167
+ - **UNVERIFIED (not in Betaflight sources):** DJI "Canvas mode" is a goggle/O4 menu option on the DJI side and needs no extra Betaflight setting beyond the above.
168
+
169
+ ### Motor protocol, bidirectional DShot, poles
170
+ - `set motor_pwm_protocol = DSHOT600` (or `DSHOT300`). Values are `PWM, ONESHOT125, ONESHOT42, MULTISHOT, BRUSHED, DSHOT150, DSHOT300, DSHOT600, PROSHOT1000, DISABLED` (`settings.c#L302-L306`, setting at `L865`). The default is DSHOT600 (`BF src/main/pg/motor.c#L71`). **Δ** 2026.6 appends `DRONECAN`.
171
+ - `set dshot_bidir = ON`. Values are OFF/ON (`settings.c#L856`). The default is OFF (`pg/motor.c#L47-L48`, `L118`).
172
+ - `USE_DSHOT_TELEMETRY` is defined whenever `USE_DSHOT` is (`BF src/main/target/common_pre.h#L56-L60`). That block is outside the `CLOUD_BUILD` guard, so selecting DSHOT in a cloud build includes bidir.
173
+ - `set motor_poles = 14`. The range is 4 to 255 (`settings.c#L868`), and the default is already 14 (`pg/motor.c#L107`).
174
+ - **UNVERIFIED:** AM32 bidirectional DShot support on this particular ESC. Confirm in the Motors tab (RPM readout / 0% error) after setup.
175
+
176
+ ### Current and voltage meter
177
+ - `set current_meter = ADC`. Values are `NONE, ADC, VIRTUAL, ESC, MSP` (`BF src/main/sensors/current.c#L45-L47`, setting at `settings.c#L902`). The target default is already ADC (`CFG#L108`).
178
+ - `battery_meter` values are `NONE, ADC, ESC` (`src/main/sensors/voltage.c#L51-L53`). The target default is ADC (`CFG#L109`). `vbat_scale` target default is 210 (`CFG#L110`).
179
+ - `set ibata_scale = 150`. The range is -16000 to 16000 (`settings.c#L924`). The target default is already 150 (`CFG#L111`).
180
+ - `set ibata_offset = 0`. The range is -32000 to 32000 (`settings.c#L925`). The default is 0 (`BF src/main/sensors/current.c#L97-L105`).
181
+
182
+ ### Compass (QMC5883L on I2C1, 0x0D)
183
+ - `set mag_hardware = QMC5883` (or `AUTO`). Values are `AUTO, NONE, HMC5883, AK8975, AK8963, QMC5883, LIS2MDL, LIS3MDL, MPU925X_AK8963, IST8310` (`BF src/main/cli/settings.c#L159-L161`, setting at `L731`). The docs recommend `AUTO` (https://betaflight.com/docs/wiki/guides/current/Magnetometer, "set mag_hardware = AUTO").
184
+ - `set align_mag = CW270FLIP`. Values are `DEFAULT, CW0, CW90, CW180, CW270, CW0FLIP, CW90FLIP, CW180FLIP, CW270FLIP, CUSTOM` (`settings.c#L181-L192`, setting at `L723`). Enum value 8 is `CW270_DEG_FLIP` (`src/main/common/sensor_alignment.h#L39`). "Flip" means a 180 degree rotation about Y (Magnetometer doc). **UNVERIFIED:** that CW270FLIP is right for this mounting. It comes from the module vendor, so verify it in the Sensors tab.
185
+ - Bus settings need **no change**:
186
+ - The target sets `MAG_I2C_INSTANCE I2CDEV_1` (`CFG#L105`).
187
+ - `pgResetFn_compassConfig` sets `mag_bustype = I2C`, `mag_i2c_device = I2C_DEV_TO_CFG(I2CDEV_1) = 1`, `mag_i2c_address = 0` (`BF src/main/sensors/compass.c#L125-L130`; `I2C_DEV_TO_CFG(x) = x+1`, `src/main/drivers/bus_i2c.h#L50`).
188
+ - Address 0 makes the QMC driver use `0x0D` (`src/main/drivers/compass/compass_qmc5883l.c#L43`, `#L148-L149`).
189
+ - If you set them explicitly: `set mag_bustype = I2C`, `set mag_i2c_device = 1`, `set mag_i2c_address = 13` (`settings.c#L727-L729`).
190
+ - `USE_MAG` is **not** defined by the target config. `CFG` defines only `MAG_I2C_INSTANCE`. I2C1 (PB8 SCL / PB7 SDA, `CFG#L64-L65`) is the only I2C bus defined, and it is **shared with the onboard DPS310 baro** (`BARO_I2C_INSTANCE I2CDEV_1`, `CFG#L106-L107`). **UNVERIFIED:** which physical pads on the DolphinRC board expose I2C1.
191
+
192
+ ---
193
+
194
+ ## 3. Motor order (Quad-X) and motor resources
195
+
196
+ `mixerQuadX[]` (`BF src/main/flight/mixer_init.c#L72-L77`). The row comments give the positions:
197
+
198
+ | Motor | Position |
199
+ |---|---|
200
+ | Motor 1 | REAR_R (rear-right) |
201
+ | Motor 2 | FRONT_R (front-right) |
202
+ | Motor 3 | REAR_L (rear-left) |
203
+ | Motor 4 | FRONT_L (front-left) |
204
+
205
+ The order is identical in 2025.12.5 and 2026.6.2 (`mixer_init.c#L85-L88`). QUADX is the default mixer (`DEFAULT_MIXER MIXER_QUADX`, `BF src/main/target/common_defaults_post.h#L108`), so no `mixer` line is needed. The docs point to the same expected mapping (https://betaflight.com/docs/wiki/getting-started/troubleshooting, motor order section).
206
+
207
+ Motor pin defaults (`CFG#L39-L46`):
208
+
209
+ | Motor | Pin | Timer map (`CFG#L86-L94`) |
210
+ |---|---|---|
211
+ | M1 | PC9 | timer index 2 |
212
+ | M2 | PC8 | timer index 2 |
213
+ | M3 | PB15 | timer index 1 |
214
+ | M4 | PA8 | timer index 1 |
215
+
216
+ M5 to M8 are PB11, PB10, PB3 and PA15. The pins are loaded into `motorConfig->dev.ioTags[]` (`BF src/main/pg/motor.c#L81-L104`). **No `resource` changes are needed** unless the ESC harness order differs. In that case remap with `resource MOTOR n <pin>`, or use the Motors tab reorder (`motorOutputReordering`, `pg/motor.c#L109-L110`).
217
+
218
+ ### 3a. Motor spin direction (fetched 2026-09-26 from `master`)
219
+
220
+ Quad-X default, viewed from above: **M1 rear-right CW, M2 front-right CCW, M3 rear-left CCW, M4 front-left CW** ("props in"). `set yaw_motors_reversed = ON` reverses every motor ("props out").
221
+
222
+ - `yaw_motors_reversed` is an OFF/ON setting on `mixerConfig_t` (`BF src/main/cli/settings.c`, `{ "yaw_motors_reversed", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MIXER_CONFIG, ... }`). The default comes from `#define YAW_MOTORS_REVERSED 0` (`BF src/main/flight/mixer_init.c#L50-L51`), and `configs/MATEKF405TE/config.h` does not override it. So the default is OFF.
223
+ - `mixerQuadX[]` yaw column (`mixer_init.c#L84-L89`): REAR_R −1, FRONT_R +1, REAR_L +1, FRONT_L −1. In the same file, `mixerY4[]` labels its rows `// REAR_TOP CW` (yaw −1) and `// REAR_BOTTOM CCW` (yaw +1). With that sign convention, M1 and M4 turn CW and M2 and M3 turn CCW. Source file sha256 `0b080d762403ca067fc4c5728d9dd5651a68311bcc1407f2ade9a6cf278d8418`.
224
+ - Docs, motors tab (https://github.com/betaflight/betaflight.com, `docs/wiki/app/motors-tab.md`): "The normal setting assumes your props will spin in towards the camera at the front of your quad "props in"".
225
+ - Docs, reversed motor direction (`docs/wiki/guides/current/Reversed-motor-direction.md`): "Reversed motors would be spinning outwards (contrary to the standard inwards), that is the front left spins counterclockwise, front right clockwise". The default is the opposite: front-left CW, front-right CCW. Diagonal motors share a direction.
226
+ - The setup guide's props-in/props-out diagram is `static/img/betaflight_props_in_out.png` in the same repo.
227
+
228
+ The UHD model records direction as `ChildModuleRef.spin` on each arm instance. `betaflight.ts` emits `yaw_motors_reversed` from it, and the `prop_handedness` check compares it with the prop variant on each motor.
229
+
230
+ ---
231
+
232
+ ## 4. Target defaults, compatibility, gotchas
233
+
234
+ | Item | Target default | Source |
235
+ |---|---|---|
236
+ | Serial RX on UART2 | Yes (`SERIALRX_UART SERIAL_PORT_USART2`, mask 64) | `CFG#L123`, `BF serial.c#L160-L165` |
237
+ | RX feature | `FEATURE_RX_SERIAL` | `CFG#L124` |
238
+ | serialrx_provider | Not set by target. The firmware default is CRSF if built in. | `BF pg/rx.c#L37-L40` |
239
+ | Blackbox | `BLACKBOX_DEVICE_FLASH` (M25P16 on SPI2) | `CFG#L116`, `#L35-L36`, `#L118` |
240
+ | Current/voltage source | ADC / ADC, scale 150 / 210 | `CFG#L108-L111` |
241
+ | Gyro | ICM42688P, SPI1, `GYRO_1_ALIGN CW270_DEG_FLIP` (the gyro, not the mag) | `CFG#L29-L32`, `#L120-L121` |
242
+ | Baro | DPS310 on I2C1 | `CFG#L33`, `#L106-L107` |
243
+ | OSD chip | MAX7456 on SPI1 | `CFG#L34`, `#L117` |
244
+ | GPS / MSP UART | None defined (no `GPS_UART` / `MSP_UART`) | `CFG` |
245
+
246
+ Gotchas:
247
+
248
+ 1. **The compass needs a custom build with `MAG`.**
249
+ - `USE_MAG` is only auto-defined for builds *without* a board config (`#if !defined(USE_CONFIG)` inside `#if !defined(CLOUD_BUILD)`, `BF src/main/target/common_pre.h#L72-L77`).
250
+ - MATEKF405TE does not define it, so `mag_hardware` and the QMC driver are compiled out unless you select **"MAG"** under "Other Options" in the cloud build (`https://betaflight.com/docs/development/API/Cloud-Build-API`, "Other Options" list). For local builds use `-DUSE_MAG` (Magnetometer doc: "Betaflight's build system must include `Magnetometers`... or `-DUSE_MAG`").
251
+ - With `USE_MAG`, the QMC5883 driver is pulled in automatically (`BF src/main/target/common_post.h#L88-L101`).
252
+ - Also select `GPS`, `OSD_HD` (or both SD and HD), `SERIALRX_CRSF` and `DSHOT`. CRSF telemetry is included automatically (Cloud-Build-API note).
253
+ 2. **Onboard MAX7456.** Because of it, `osd_displayport_device = MSP` and `vcd_video_system = HD` must be set explicitly (section 2).
254
+ 3. **UART5 mask must be 131073, not 131072.** A port with VTX_MSP alone is not picked for DisplayPort (`config.c#L625`), and the docs say "MSP VTX is alone on a port — it has to share with MSP" (Serial guide).
255
+ 4. **Features.** `feature TELEMETRY` is required for ELRS telemetry (`init.c#L978`). `feature GPS` is required for GPS init (`init.c#L762`). `DEFAULT_FEATURES` is 0 (`BF src/main/config/feature.h#L25-L26`). FEATURE_OSD is auto-enabled only on an unconfigured board (`BF src/main/config/config.c#L484-L494`), so add `feature OSD` to be safe.
256
+ 5. **QMC5883P variant.** 4.5.5 supports only the QMC5883**L** (`compass_qmc5883l.c`, address 0x0D). 2025.12+ adds a QMC5883**P** driver at address 0x2C (`BF25 src/main/drivers/compass/compass_qmc5883.c#L82-L83`). The Magnetometer doc notes the L was "Discontinued in 2025 and replaced by the QMC5883P". If a newer M10Q-5883 ships with the P variant, 4.5.5 will not detect it. **UNVERIFIED:** which chip this unit carries. The user states 0x0D, which is the L variant.
257
+ 6. **Target file path.** The user-supplied path `configs/MATEKF405TE/config.h` is correct only on the `4.5-config` / `2025.12-config` branches. On `master` the file is at `configs/MTKS/MATEKF405TE/config.h`. Contents are identical.
258
+ 7. **DolphinRC F405 V3 → MATEKF405TE.** **UNVERIFIED** from Betaflight sources. DolphinRC is a registered manufacturer (`DOLP`, `Manufacturers.md#L44`), but its only config is `configs/DOLP/DOLPHINRC_F722`. There is no DolphinRC F405 config, so the pin compatibility is taken from the vendor's claim.
@@ -0,0 +1,126 @@
1
+ ---
2
+ name: firmware-verify
3
+ description: Verify a generated flight-controller configuration on the real hardware, props off — apply the CLI, diff the result, then check ports, receiver and telemetry, OSD, GPS, compass alignment, motor order and direction, bidirectional DShot and the current sensor, resolving every UNVERIFIED item in the firmware reference — and record the result as measured test data. Use after firmware-config, before any flight, and after any firmware or wiring change. Physical effects: a person performs or authorises each step.
4
+ ---
5
+
6
+ # Firmware verify (bench)
7
+
8
+ Everything here happens on a physical unit. An agent can prepare the
9
+ checklist, read dumps and logs, and record results; a person connects the
10
+ battery and spins motors. **Props off for every step.** First power through a
11
+ current limiter (smoke stopper or bench supply at ~1 A).
12
+
13
+ ## Purpose
14
+
15
+ Close the gap between a configuration that agrees with the model and one
16
+ that works on the unit: pads, directions, alignment and sensor scales can
17
+ only be confirmed on hardware. Use it after **firmware-config**, before any
18
+ flight, and after any firmware or wiring change. In **build-a-project** it
19
+ comes after the release (stage 11): the unit under test is built from a
20
+ release, and the result is recorded against it. An agent prepares and
21
+ records; a person performs or authorises every physical step.
22
+
23
+ ## Inputs
24
+
25
+ | Input | Where | From |
26
+ | --- | --- | --- |
27
+ | The release and unit under test | release name and unit serial | **release** |
28
+ | The generated configuration and its record | `firmware/<fw>/cli.txt`, `operations/` | **firmware-config** |
29
+ | Firmware version and build options it asks for | the CLI header (`# Target … firmware >= … cloud build options …`) | **firmware-config** |
30
+ | The UNVERIFIED list | `firmware-config/references/betaflight-reference.md` | **firmware-config** |
31
+ | The generator's warnings | `npx protoboard run betaflight-cli --format json` → `data.warnings` | **firmware-config** |
32
+ | A person at the bench | with the unit, a current-limited supply, a clamp meter, a multimeter | the operator |
33
+
34
+ ## Steps
35
+
36
+ ### 1. Prepare
37
+
38
+ - The release/revision and unit serial under test (**release**).
39
+ - `firmware/<fw>/cli.txt` and its operation record; the firmware version and
40
+ build options it asks for.
41
+ - The UNVERIFIED list from the reference
42
+ ([betaflight-reference.md](../firmware-config/references/betaflight-reference.md))
43
+ and the generator's warnings:
44
+
45
+ ```bash
46
+ npx protoboard run betaflight-cli --format json # data.warnings; the run must not change cli.txt (git diff firmware/)
47
+ ```
48
+
49
+ ### 2. Flash and apply (a person does this)
50
+
51
+ 1. Flash the stated firmware with the stated build options (a missing `MAG`
52
+ option silently compiles the compass driver out).
53
+ 2. CLI: `diff all` → save as `firmware/<fw>/bench/<date>-before.txt`.
54
+ 3. Paste `cli.txt`; the FC reboots on `save`.
55
+ 4. `diff all` again → `…-after.txt`. Every generated line must appear (or be
56
+ the firmware default, which `diff` omits); any rejected line is a finding
57
+ against the reference.
58
+
59
+ ### 3. Checks (each: expected from the model, observed, pass/fail)
60
+
61
+ | Check | Expected (model) | How |
62
+ | --- | --- | --- |
63
+ | Pads = UARTs | the link's UART is the pad you soldered | Ports tab lists the functions on the right UARTs; each peripheral works (below). Resolves "pads labelled as the target expects". |
64
+ | Receiver | CRSF on the receiver link's UART | Receiver tab: sticks move the right channels; telemetry (RSSI, battery) reaches the radio. |
65
+ | OSD | MSP DisplayPort on the air-unit link's UART | OSD elements visible in the goggles, HD canvas. |
66
+ | GPS | GNSS on its UART, auto-config | Sats and fix in the GPS tab (outdoors); the module's baud was negotiated. |
67
+ | Compass | detected at the model's I2C address; `align_mag` per the maker | Sensors tab shows MAG; rotate the craft: heading follows (N-E-S-W), no mirror. Resolves the alignment item. |
68
+ | Motor order | Quad-X order from the phase links | Motors tab, props off: M1 rear-right, M2 front-right, M3 rear-left, M4 front-left spin. |
69
+ | Motor direction | the spin the model states for each arm | Each motor's direction matches its prop's handedness; fix with the ESC tool (AM32) or `motor_direction` per the firmware, then record. |
70
+ | Bidirectional DShot | both parts state it (weak source: say which) | Motors tab shows RPM with ~0 % error. Otherwise turn it off and record the finding against the part. |
71
+ | Current sensor | the ESC's `ibata_scale` | Compare the FC's current with a clamp meter at 2–3 loads; adjust scale only with a recorded measurement. |
72
+ | Voltage | `vbat_scale` default | FC voltage vs multimeter within 0.05 V/cell. |
73
+
74
+ ### 4. Record
75
+
76
+ Write `docs/test-data/firmware-bench.json` (status `measured`; **test-and-measure**):
77
+ conditions (release, unit, firmware version, build options, cli.txt sha256),
78
+ columns `check`, `expected`, `observed`, `pass`, one row per check, raw files
79
+ (`before`/`after` dumps, screenshots, Blackbox logs). Validate it:
80
+
81
+ ```bash
82
+ npx tsx node_modules/@protoboardai/ext-hardware/skills/test-and-measure/scripts/test-data.ts docs/test-data/firmware-bench.json
83
+ ```
84
+
85
+ Feed every failure back: a wrong pad mapping or alignment becomes a model fix
86
+ (part fact or link), then regenerate the CLI — never a hand edit of
87
+ `cli.txt`.
88
+
89
+ ## Decision points
90
+
91
+ | Decision | Rule |
92
+ | --- | --- |
93
+ | Continue after a failed check | Stop before anything that spins or powers more: fix the model, regenerate, re-apply, re-check. |
94
+ | A rejected CLI line | A finding against the reference; correct the reference (source-pinned) and the generator, not the dump. |
95
+ | Adjust a scale | Only with a recorded measurement at two or more loads. |
96
+ | The NOT FLIGHT-TESTED header | May be reconsidered only when every check passes, and only for the recorded firmware version and unit. |
97
+ | Who acts | A person performs every physical step; an agent prepares, reads and records. |
98
+
99
+ ## Outputs
100
+
101
+ | Output | Where |
102
+ | --- | --- |
103
+ | Before/after dumps | `firmware/<fw>/bench/<date>-before.txt`, `<date>-after.txt` |
104
+ | The measured result | `docs/test-data/firmware-bench.json` |
105
+ | Model fixes | the parts and links (through **uhd-part-author**, **system-compose**), then a regenerated `cli.txt` |
106
+
107
+ ## Verification
108
+
109
+ `test-data.ts` passes on `firmware-bench.json`; every row of the checks table
110
+ has an observed value and pass/fail; every UNVERIFIED item in the reference
111
+ is resolved or still listed with the reason; the release and unit are named
112
+ in the file's conditions.
113
+
114
+ ## Failure handling
115
+
116
+ | Code or symptom | Means | Do |
117
+ | --- | --- | --- |
118
+ | A generated line rejected by the CLI | The reference is wrong for this version | Fix the reference and generator (**firmware-config** step 2) |
119
+ | A peripheral works on another UART than the link says | Pads not labelled as the target expects, or the link is wrong | Fix the link or the FC part's pad facts; regenerate |
120
+ | Heading mirrored or rotated | `align_mag` is wrong for the mounting | Fix the GNSS part's alignment fact from the maker; regenerate |
121
+ | A motor in the wrong position or direction | Phase links or spins disagree with the mixer | Remap or rewire, record the decision; fix the model to match |
122
+ | RPM telemetry errors | Bidirectional DShot does not work with this ESC firmware | Turn it off; record the finding against the part |
123
+ | `test-data.ts` fails | The record is incomplete or has placeholders | Complete it; never commit a placeholder as measured |
124
+ | `UHD_PROP_HANDEDNESS` | Spins not set or mismatched in the model | **system-compose**: set `spin` per arm |
125
+
126
+ Every other code: **system-compose** [diagnostic codes](../system-compose/references/diagnostic-codes.md).
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.