@typecad/framework-zephyr 1.0.0-alpha.14 → 1.0.0-alpha.15

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.
Files changed (185) hide show
  1. package/README.md +22 -47
  2. package/dist/as-built.d.ts +33 -0
  3. package/dist/as-built.js +188 -0
  4. package/dist/async/timer-polyfill.js +1 -1
  5. package/dist/boardgen.d.ts +128 -0
  6. package/dist/boardgen.js +1366 -0
  7. package/dist/chips/board-overrides.d.ts +7 -0
  8. package/dist/chips/board-overrides.js +11 -0
  9. package/dist/chips/esp32s3.js +49 -0
  10. package/dist/chips/index.d.ts +6 -12
  11. package/dist/chips/index.js +18 -34
  12. package/dist/chips/resolve.d.ts +16 -2
  13. package/dist/chips/resolve.js +267 -10
  14. package/dist/chips/soc/.d.ts +2 -0
  15. package/dist/chips/soc/.js +129 -0
  16. package/dist/chips/soc/esp32.d.ts +2 -0
  17. package/dist/chips/soc/esp32.js +120 -0
  18. package/dist/chips/soc/esp32c3.d.ts +2 -0
  19. package/dist/chips/soc/esp32c3.js +90 -0
  20. package/dist/chips/soc/esp32c6.d.ts +2 -0
  21. package/dist/chips/soc/esp32c6.js +109 -0
  22. package/dist/chips/soc/esp32s3.d.ts +2 -0
  23. package/dist/chips/soc/esp32s3.js +189 -0
  24. package/dist/chips/soc/index.d.ts +2 -0
  25. package/dist/chips/soc/index.js +23 -0
  26. package/dist/chips/soc/nrf52840.d.ts +2 -0
  27. package/dist/chips/soc/nrf52840.js +130 -0
  28. package/dist/chips/soc/rp2040.d.ts +2 -0
  29. package/dist/chips/soc/rp2040.js +141 -0
  30. package/dist/chips/soc/rp2350a.d.ts +2 -0
  31. package/dist/chips/soc/rp2350a.js +145 -0
  32. package/dist/chips/soc/samd21g18a.d.ts +2 -0
  33. package/dist/chips/soc/samd21g18a.js +143 -0
  34. package/dist/chips/soc/stm32f411xe.d.ts +2 -0
  35. package/dist/chips/soc/stm32f411xe.js +251 -0
  36. package/dist/chips/types.d.ts +319 -0
  37. package/dist/chips/xiao-ble.js +21 -0
  38. package/dist/display/profiles.js +1 -1
  39. package/dist/doctor.js +38 -4
  40. package/dist/dt-config/custom-board.d.ts +23 -0
  41. package/dist/dt-config/custom-board.js +227 -0
  42. package/dist/dt-config/kconfig.d.ts +72 -1
  43. package/dist/dt-config/kconfig.js +115 -26
  44. package/dist/dt-config/overlay.js +548 -28
  45. package/dist/framework.manifest.d.ts +3 -3
  46. package/dist/framework.manifest.js +122 -185
  47. package/dist/index.d.ts +4 -1
  48. package/dist/index.js +8 -2
  49. package/dist/lowering/adc.d.ts +20 -2
  50. package/dist/lowering/adc.js +121 -29
  51. package/dist/lowering/ble.js +31 -28
  52. package/dist/lowering/dac.js +9 -9
  53. package/dist/lowering/fs.js +18 -10
  54. package/dist/lowering/gpio.d.ts +2 -0
  55. package/dist/lowering/gpio.js +82 -5
  56. package/dist/lowering/http.js +39 -14
  57. package/dist/lowering/hwtimer.d.ts +4 -0
  58. package/dist/lowering/hwtimer.js +35 -10
  59. package/dist/lowering/i2c.js +46 -54
  60. package/dist/lowering/index.d.ts +5 -5
  61. package/dist/lowering/index.js +15 -16
  62. package/dist/lowering/interrupts.d.ts +22 -5
  63. package/dist/lowering/interrupts.js +104 -22
  64. package/dist/lowering/mqtt.js +3 -5
  65. package/dist/lowering/power.js +0 -4
  66. package/dist/lowering/preferences.js +49 -77
  67. package/dist/lowering/pulse.js +0 -31
  68. package/dist/lowering/pwm.d.ts +12 -1
  69. package/dist/lowering/pwm.js +78 -14
  70. package/dist/lowering/random.js +3 -3
  71. package/dist/lowering/sensor.d.ts +37 -0
  72. package/dist/lowering/sensor.js +119 -0
  73. package/dist/lowering/spi.d.ts +12 -0
  74. package/dist/lowering/spi.js +65 -40
  75. package/dist/lowering/thread.d.ts +14 -0
  76. package/dist/lowering/thread.js +55 -0
  77. package/dist/lowering/timing.js +20 -46
  78. package/dist/lowering/tone.js +16 -4
  79. package/dist/lowering/uart.d.ts +13 -0
  80. package/dist/lowering/uart.js +72 -51
  81. package/dist/lowering/usb.d.ts +34 -0
  82. package/dist/lowering/usb.js +206 -0
  83. package/dist/lowering/wdt.d.ts +1 -1
  84. package/dist/lowering/wdt.js +17 -7
  85. package/dist/lowering/wifi.d.ts +3 -2
  86. package/dist/lowering/wifi.js +97 -111
  87. package/dist/sdk/board-catalog-sync.d.ts +16 -0
  88. package/dist/sdk/board-catalog-sync.js +41 -0
  89. package/dist/sdk/board-data.generated.d.ts +2 -0
  90. package/dist/sdk/board-data.generated.js +4 -0
  91. package/dist/sdk/catalog-walker.d.ts +90 -0
  92. package/dist/sdk/catalog-walker.js +682 -0
  93. package/dist/sdk/dts-reader.d.ts +83 -0
  94. package/dist/sdk/dts-reader.js +596 -0
  95. package/dist/strategy.d.ts +136 -17
  96. package/dist/strategy.js +839 -222
  97. package/dist/toolchain/bossac-touch.d.ts +18 -0
  98. package/dist/toolchain/bossac-touch.js +88 -0
  99. package/dist/toolchain/compat.d.ts +2 -2
  100. package/dist/toolchain/compat.js +8 -3
  101. package/dist/toolchain/debug-config.d.ts +21 -26
  102. package/dist/toolchain/debug-config.js +211 -71
  103. package/dist/toolchain/env-check.d.ts +4 -4
  104. package/dist/toolchain/env-check.js +5 -5
  105. package/dist/toolchain/index.d.ts +66 -1
  106. package/dist/toolchain/index.js +650 -70
  107. package/dist/toolchain/scaffold.js +39 -7
  108. package/dist/toolchain/west-discover.d.ts +4 -0
  109. package/dist/toolchain/west-discover.js +17 -6
  110. package/installer/CHANGELOG.md +473 -0
  111. package/installer/README.md +328 -0
  112. package/installer/environment.yml +46 -0
  113. package/installer/etc/conda/activate.d/zephyr.bat +7 -0
  114. package/installer/etc/conda/activate.d/zephyr.ps1 +12 -0
  115. package/installer/etc/conda/activate.d/zephyr.sh +20 -0
  116. package/installer/etc/conda/deactivate.d/zephyr.bat +6 -0
  117. package/installer/etc/conda/deactivate.d/zephyr.ps1 +6 -0
  118. package/installer/etc/conda/deactivate.d/zephyr.sh +4 -0
  119. package/installer/install.mjs +580 -0
  120. package/installer/install.ps1 +619 -0
  121. package/installer/install.sh +310 -0
  122. package/installer/lib/detect-platform.sh +62 -0
  123. package/installer/lib/fetch-sdk.sh +304 -0
  124. package/installer/lib/init-workspace.sh +153 -0
  125. package/installer/lib/write-activation.sh +76 -0
  126. package/installer/patches/tfm-c-include-separators.patch +19 -0
  127. package/installer/patches/zephyr-tfm-nordic-zephyr-include.patch +24 -0
  128. package/installer/templates/project/.typecad/activate-zephyr.ps1 +31 -0
  129. package/installer/templates/project/.typecad/activate-zephyr.sh +31 -0
  130. package/installer/templates/project/.vscode/settings.json +30 -0
  131. package/installer/templates/project/README.md +58 -0
  132. package/installer/versions.env +110 -0
  133. package/package.json +15 -15
  134. package/src/as-built.ts +206 -0
  135. package/src/boardgen.ts +1428 -0
  136. package/src/chips/index.ts +35 -54
  137. package/src/chips/resolve.ts +285 -10
  138. package/src/chips/types.ts +325 -1
  139. package/src/display/profiles.ts +1 -1
  140. package/src/doctor.ts +110 -77
  141. package/src/dt-config/custom-board.ts +325 -0
  142. package/src/dt-config/kconfig.ts +165 -18
  143. package/src/dt-config/overlay.ts +537 -25
  144. package/src/framework.manifest.ts +123 -185
  145. package/src/index.ts +57 -41
  146. package/src/lowering/adc.ts +222 -118
  147. package/src/lowering/ble.ts +32 -28
  148. package/src/lowering/dac.ts +82 -82
  149. package/src/lowering/fs.ts +18 -10
  150. package/src/lowering/gpio.ts +242 -155
  151. package/src/lowering/http.ts +512 -488
  152. package/src/lowering/hwtimer.ts +139 -101
  153. package/src/lowering/i2c.ts +116 -126
  154. package/src/lowering/index.ts +91 -93
  155. package/src/lowering/interrupts.ts +113 -21
  156. package/src/lowering/mqtt.ts +3 -5
  157. package/src/lowering/preferences.ts +327 -354
  158. package/src/lowering/pwm.ts +167 -99
  159. package/src/lowering/random.ts +3 -3
  160. package/src/lowering/sensor.ts +155 -0
  161. package/src/lowering/spi.ts +164 -124
  162. package/src/lowering/thread.ts +63 -0
  163. package/src/lowering/timing.ts +46 -72
  164. package/src/lowering/uart.ts +73 -51
  165. package/src/lowering/usb.ts +221 -0
  166. package/src/lowering/wdt.ts +95 -84
  167. package/src/lowering/wifi.ts +97 -112
  168. package/src/sdk/board-catalog-sync.ts +62 -0
  169. package/src/strategy.ts +848 -237
  170. package/src/toolchain/bossac-touch.ts +112 -0
  171. package/src/toolchain/compat.ts +8 -3
  172. package/src/toolchain/debug-config.ts +666 -522
  173. package/src/toolchain/env-check.ts +9 -9
  174. package/src/toolchain/index.ts +1286 -645
  175. package/src/toolchain/scaffold.ts +38 -7
  176. package/src/toolchain/west-discover.ts +19 -6
  177. package/src/async/timer-polyfill.ts +0 -107
  178. package/src/chips/esp32.ts +0 -74
  179. package/src/chips/esp32s3.ts +0 -57
  180. package/src/chips/xiao-ble.ts +0 -82
  181. package/src/lowering/power.ts +0 -70
  182. package/src/lowering/pulse.ts +0 -93
  183. package/src/lowering/tone.ts +0 -60
  184. package/src/lowering/worker-backing.ts +0 -94
  185. package/src/lowering/worker.ts +0 -17
@@ -59,6 +59,49 @@ export interface ZephyrGpioController {
59
59
  export interface ZephyrBusController {
60
60
  /** Devicetree nodelabel, e.g. 'i2c1', 'spi2', 'uart0'. */
61
61
  readonly nodeLabel: string;
62
+ /**
63
+ * Counter child form only: the labeled TIMER PARENT's nodelabel (ESP32
64
+ * timer0-3). The counter device is an unlabeled `counter {}` child; the
65
+ * nodeLabel above is a label the generated overlay defines on that child,
66
+ * and this field tells the overlay which parent to attach it to.
67
+ */
68
+ readonly counterParent?: string;
69
+ /**
70
+ * Synthesized pinctrl group, for controllers whose board DT ships no
71
+ * default group (e.g. uart1 on rpi_pico/rpi_pico2 — the mainline board DT
72
+ * only pins uart0). When present, the overlay generator emits the group
73
+ * under `&pinctrl` and wires `pinctrl-0`/`pinctrl-names` onto the
74
+ * controller when enabling it. RP2xxx pinmux is fully muxable per pad, so
75
+ * the group is pure data: which pads carry the signals.
76
+ */
77
+ readonly pinctrl?: {
78
+ /** Pinmux header to #include (token definitions). */
79
+ readonly include: string;
80
+ /** Output-signal pinmux tokens (emitted as group1). */
81
+ readonly pinmux: readonly string[];
82
+ /** Input-signal pinmux tokens (emitted as group2 with input-enable). */
83
+ readonly inputPinmux?: readonly string[];
84
+ /**
85
+ * `#define` lines emitted (ifndef-guarded) BEFORE the include — for
86
+ * upstream header bugs where a token's macro body references an
87
+ * undefined helper (e.g. RP2_PINCTRL_GPIO_FUNC_UART_ALT in Zephyr's
88
+ * rp2350 pinctrl headers, unreferenced by mainline so never noticed).
89
+ */
90
+ readonly defines?: readonly string[];
91
+ };
92
+ /**
93
+ * Reference an EXISTING pinctrl group (defined in the board's pinctrl
94
+ * dtsi but not attached to the node) instead of synthesizing one — e.g.
95
+ * uart1_default on esp32s3_devkitc. The overlay wires
96
+ * `pinctrl-0 = <&<group>>` when enabling the controller.
97
+ */
98
+ readonly pinctrlRef?: string;
99
+ /**
100
+ * Raw devicetree property lines emitted inside the enable block — for
101
+ * bindings with required properties the board DTS only sets on its own
102
+ * wired-up nodes (e.g. `current-speed` on the Picos' PL011 UARTs).
103
+ */
104
+ readonly props?: readonly string[];
62
105
  }
63
106
 
64
107
  /**
@@ -95,6 +138,45 @@ export interface ZephyrPwmSpec {
95
138
  readonly periodNs?: number;
96
139
  /** Synthesized form: PWM polarity flag. Default PWM_POLARITY_NORMAL. */
97
140
  readonly polarity?: string;
141
+ /**
142
+ * SoC pinctrl dtsi token muxing this channel's pin to the timer (e.g.
143
+ * 'tim4_ch1_pb6' on STM32). Required on custom boards — the st,stm32-pwm
144
+ * binding demands pinctrl-0 on an enabled node and only a board DTS (or
145
+ * the custom-board generator, fed by this token) can provide it. Also
146
+ * gates the generated board's `pwmN: pwm { }` label declaration: the
147
+ * overlay references `&<controller>`, a label that otherwise exists only
148
+ * when a board DTS defines it.
149
+ */
150
+ readonly pinctrl?: string;
151
+ }
152
+
153
+ /**
154
+ * A "PWM matrix" controller: any listed pin can carry any channel, routed by
155
+ * the SoC's GPIO matrix rather than a fixed timer-channel↔pad map.
156
+ *
157
+ * ESP32 LEDC is the shape (espressif,esp32-ledc): 8 channels, each routable
158
+ * to (almost) any pad via a pinctrl pinmux token (`LEDC_CH<ch>_GPIO<pin>`).
159
+ * A static `specs` list cannot express this — two arbitrary pins would
160
+ * collide on a statically assigned channel — so the channel assignment is
161
+ * made at build time: the pins the program actually drives are assigned
162
+ * channels 0..N-1 (ascending pin order, capped at `channelCount`), and the
163
+ * overlay generator emits the pinctrl group + per-channel child nodes the
164
+ * espressif,esp32-ledc binding requires. The emitted C++ is channel-blind:
165
+ * it addresses each pin via the same `DT_ALIAS(tc-pwm<pin>)` the synthesized
166
+ * static form uses, so the two paths share the lowering.
167
+ */
168
+ export interface ZephyrPwmMatrix {
169
+ /** PWM controller DT nodelabel, e.g. 'ledc0'. */
170
+ readonly controller: string;
171
+ /** Channels the controller exposes (ESP32-S3 LEDC: 8). */
172
+ readonly channelCount: number;
173
+ /**
174
+ * HAL pins usable as PWM outputs. This is the safety filter as much as the
175
+ * capability list — on the ESP32-S3 it excludes the boot-strap pin, the
176
+ * USB D+/D− pads, the flash/PSRAM pins (GPIO 26–32), the octal-PSRAM pins
177
+ * (GPIO 33–37), and the console UART pads (GPIO 43/44).
178
+ */
179
+ readonly pins: readonly number[];
98
180
  }
99
181
 
100
182
  /**
@@ -122,6 +204,14 @@ export interface ZephyrAdcChannel {
122
204
  readonly pin: number;
123
205
  /** ADC channel index (nRF SAADC AIN0–AIN7; STM32 ADC1_IN0–IN9). */
124
206
  readonly channel: number;
207
+ /**
208
+ * ADC device node label that OWNS this channel when the SoC has more than
209
+ * one ADC controller (STM32 adc1/adc2, ESP32 units), e.g. 'adc2'. Omitted
210
+ * for channels on the descriptor's primary controller (`adc.nodeLabel`) —
211
+ * a single-controller manifest is unchanged. Channel indices are unique
212
+ * only WITHIN a controller; the pair (controller, channel) is the key.
213
+ */
214
+ readonly controller?: string;
125
215
  /**
126
216
  * Pinctrl node label that muxes this pin to analog mode, e.g.
127
217
  * 'adc1_in0_pa0' (STM32). When present, the overlay generator rewrites the
@@ -143,6 +233,8 @@ export interface ZephyrDacChannel {
143
233
  readonly channel: number;
144
234
  /** DAC resolution in bits (ESP32 DAC is 8-bit). */
145
235
  readonly resolution: number;
236
+ /** Pinctrl node name routing the channel to its pad (STM32 harvest). */
237
+ readonly pinctrl?: string;
146
238
  }
147
239
 
148
240
  /**
@@ -153,6 +245,33 @@ export interface ZephyrChipDescriptor {
153
245
  readonly id: string;
154
246
  /** SoC family, e.g. 'nrf52840'. */
155
247
  readonly soc: string;
248
+ /**
249
+ * How confident the framework is in this descriptor's facts.
250
+ * - 'validated' — the soc is part of the hardware-tested set; every field
251
+ * was verified against the pinned Zephyr tree and real hardware.
252
+ * - 'derived' — reconstructed from data (board/MCU packages, DTS reading)
253
+ * but never hardware-verified; capability errors may be less precise.
254
+ */
255
+ readonly tier?: 'validated' | 'derived';
256
+ /**
257
+ * Datasheet pin-naming convention — how a controller/pin pair becomes the
258
+ * schematic-facing name the generated board module exports (the
259
+ * `Pin.fromPort()` identity). One of:
260
+ * - 'esp32-gpio' — flat numbering, `GPION` (esp32, esp32s3, esp32c*)
261
+ * - 'stm32-port' — one controller per port, `P<port><bit>` (PA5, PB12)
262
+ * - 'nrf-port' — P0.28 / P1.11 style (`P<port>.<bit>`)
263
+ * - 'rp-gpio' — `GP<n>` flat numbering
264
+ * - 'samd-port' — PA/PB ports like stm32-port
265
+ * Absent on tier-3 socs with no known convention (the generated board
266
+ * exposes only connector/alias pins + LED/BUTTON).
267
+ */
268
+ readonly pinNaming?: 'esp32-gpio' | 'stm32-port' | 'nrf-port' | 'rp-gpio' | 'samd-port';
269
+ /**
270
+ * Pins that exist in the controller ranges but must NOT be exported as
271
+ * usable GPIOs — strapping pads, flash/PSRAM, USB D+/-. The generated
272
+ * board module's pin list subtracts these.
273
+ */
274
+ readonly excludedPins?: readonly number[];
156
275
  /**
157
276
  * Default GPIO controller nodelabel for the raw-pin fallback. Pins not in
158
277
  * `gpio.dtSpecs` are addressed via
@@ -191,8 +310,69 @@ export interface ZephyrChipDescriptor {
191
310
  readonly spi?: { readonly controllers: readonly ZephyrBusController[] };
192
311
  /** UART controllers (board-wired). Index 0 = the primary port. */
193
312
  readonly uart?: { readonly controllers: readonly ZephyrBusController[] };
313
+ /**
314
+ * USB device (CDC-ACM serial) capability. Zephyr "next" USB device stack:
315
+ * the UDC controller node (uniformly `zephyr_udc0` on every USB-capable
316
+ * board) plus `cdcInstances` CDC-ACM class child nodes, both composed in
317
+ * the generated overlay. The lowering addresses instance N as
318
+ * DT_NODELABEL(cdc_acm_uart<N>) — a UART-class device driven with the
319
+ * plain uart_* API. Boards without USB device support omit this field;
320
+ * usb.* HAL ops then fail with a clear "board does not expose USB" error.
321
+ */
322
+ readonly usb?: {
323
+ /** UDC controller nodelabel (convention: 'zephyr_udc0'). */
324
+ readonly controller: string;
325
+ /** How many CDC-ACM serial instances to compose (≥1). */
326
+ readonly cdcInstances: number;
327
+ /** USB vendor ID for the device descriptor ('0x2fe3' Zephyr-test default). */
328
+ readonly vid?: string;
329
+ /** USB product ID for the device descriptor ('0x0001' default). */
330
+ readonly pid?: string;
331
+ /**
332
+ * 1200-baud touch-to-reset (BOSSA-bootloader boards, e.g. SAM D21).
333
+ *
334
+ * Present = two things happen automatically:
335
+ * - Device side: the emitted USB shim registers a usbd message callback;
336
+ * when the host sets the CDC baud rate to 1200, the shim writes the
337
+ * bootloader's "stay resident" magic to the flag address and reboots —
338
+ * the board lands in the bootloader with no button press.
339
+ * - Host side: the bossac upload path opens the app's console port at
340
+ * 1200 baud to trigger the above, waits for the bootloader's USB
341
+ * identity, and points bossac at that port.
342
+ * Omit on boards without a cooperative bootloader (probe- or
343
+ * UF2-flashed boards don't need it).
344
+ */
345
+ readonly touchReset?: {
346
+ /** RAM address of the bootloader's stay-resident flag word
347
+ * (SAMD21G18A: 0x20007FFC — the last word of the 32 KB SRAM). */
348
+ readonly flagAddress: number;
349
+ /** Magic word the bootloader checks there (Arduino SAMD: 0x07738135). */
350
+ readonly magic: number;
351
+ /** Bootloader USB vendor id, hex string ('0x2341') — host-side watch. */
352
+ readonly bootloaderVid?: string;
353
+ /** Bootloader USB product id, hex string ('0x0057') — host-side watch. */
354
+ readonly bootloaderPid?: string;
355
+ };
356
+ };
194
357
  /** PWM channels with DT specs. */
195
- readonly pwm?: { readonly specs: readonly ZephyrPwmSpec[] };
358
+ readonly pwm?: {
359
+ readonly specs: readonly ZephyrPwmSpec[];
360
+ /**
361
+ * Matrix PWM capability (ESP32 LEDC) — channels assigned to the driven
362
+ * pins at build time instead of enumerated statically. `specs` may be
363
+ * empty when only the matrix is declared.
364
+ */
365
+ readonly matrix?: ZephyrPwmMatrix;
366
+ /**
367
+ * Timer input clock (Hz) for the synthesized specs' controllers — the
368
+ * number the 16-bit overflow check divides by (STM32: APB clock × the
369
+ * timer multiplier; blackpill TIM4 = 96 MHz). When set, the overlay
370
+ * generator derives an `st,prescaler` for the timers node so slow
371
+ * periods (servo 20 ms) fit the 16-bit ARR — without it pwm_stm32
372
+ * rejects the channel ("period cycles exceeds 16-bit timer limit").
373
+ */
374
+ readonly clockHz?: number;
375
+ };
196
376
  /** ADC: the ADC device node label + the pin→channel map. */
197
377
  readonly adc?: {
198
378
  readonly nodeLabel: string;
@@ -226,6 +406,25 @@ export interface ZephyrChipDescriptor {
226
406
  };
227
407
  /** Watchdog node label, e.g. 'wdt0'. */
228
408
  readonly wdt?: { readonly nodeLabel: string };
409
+ /**
410
+ * Storage partition to synthesize when the board DTS ships none. Boards
411
+ * with an MCUboot-style partition map (most STM32s) define boot/slot
412
+ * partitions but no `storage_partition`, which the Preferences/FS backends
413
+ * (ZMS/littlefs) require. Present = "the overlay generator must declare
414
+ * this partition under &flash0"; boards whose DTS already carries one
415
+ * (ESP32 devkits) omit it — the overlay only adds the /chosen pointer.
416
+ * The region must cover ≥2 flash pages (ZMS minimum) and stay clear of
417
+ * the linked application image.
418
+ */
419
+ readonly storage?: {
420
+ /** Partition start offset in flash, page-aligned. */
421
+ readonly offset: number;
422
+ /** Partition size in bytes, a multiple of the flash page size. */
423
+ readonly size: number;
424
+ /** True when the board's own DTS already declares this partition — the
425
+ * overlay must only point /chosen at it, never redeclare the node. */
426
+ readonly preexisting?: boolean;
427
+ };
229
428
  /**
230
429
  * Hardware timers exposed as Zephyr counter devices. `instance` (the HAL
231
430
  * hwtimer.* op's instance index) maps to `controllers[instance].nodeLabel`.
@@ -239,5 +438,130 @@ export interface ZephyrChipDescriptor {
239
438
  * Omit on radioless chips (nRF52840) — its absence is the "no WiFi" signal.
240
439
  */
241
440
  readonly wifi?: { readonly supported: true };
441
+ /**
442
+ * Probe methods the board supports, in user-facing terms. Each entry maps a
443
+ * friendly id (`stlink`, `dfu`, `jlink`, …) to the west runner it drives
444
+ * plus any args the method always needs — the hardware quirks (e.g. openocd
445
+ * needing `reset_config none` when the SRST line is unwired) live here,
446
+ * verified with the board, instead of in user configs. One probe method
447
+ * serves BOTH flashing and debugging (the same attach session); entries
448
+ * that cannot debug (bootloaders) set `debug: false`. Users select one via
449
+ * `zephyr.probe` in cuttlefish.config.ts or `--probe` on the CLI;
450
+ * `zephyr.runner`/`runnerArgs` remain the raw escape hatch underneath.
451
+ */
452
+ readonly probeMethods?: readonly ZephyrProbeMethod[];
453
+ /**
454
+ * Silicon-level inputs for the custom-board generator — present when the
455
+ * chip was resolved from an MCU package's `zephyr` block (an MCU-only
456
+ * config with no board package). The generator emits an out-of-tree Zephyr
457
+ * board (`boards/typecad/<name>/` in the project) from exactly this data:
458
+ * SoC name, devicetree includes, the default console mux, and the default
459
+ * clock plan. Absent on board-resolved chips (their board already exists).
460
+ */
461
+ readonly customBoard?: ZephyrCustomBoardData;
462
+ }
463
+
464
+ /**
465
+ * Everything the custom-board generator needs from the silicon to emit a
466
+ * minimal, buildable out-of-tree board for a chip with no board package.
467
+ */
468
+ export interface ZephyrCustomBoardData {
469
+ /** Zephyr SoC name(s) for board.yml + the Kconfig SOC_* selection. */
470
+ readonly socs: readonly string[];
471
+ /** Devicetree includes for the generated board DTS root (SoC + pinctrl). */
472
+ readonly dtsIncludes: readonly string[];
473
+ /** The default console the generated board enables. */
474
+ readonly console: {
475
+ /** Controller nodelabel, e.g. 'usart1'. */
476
+ readonly nodeLabel: string;
477
+ /** TX pinctrl token from the SoC's pinctrl dtsi, e.g. 'usart1_tx_pa9'. */
478
+ readonly tx: string;
479
+ /** RX pinctrl token, e.g. 'usart1_rx_pa10'. */
480
+ readonly rx: string;
481
+ /** Baud rate (the DT `current-speed`). */
482
+ readonly speed: number;
483
+ };
484
+ /**
485
+ * Default clock plan — the numbers the generated DTS writes into the SoC's
486
+ * clock nodes (HSE crystal frequency, PLL dividers, bus prescalers). A
487
+ * board package overrides with its own crystal/plan; a custom board uses
488
+ * this silicon default.
489
+ */
490
+ readonly clocks: {
491
+ /** HSE crystal frequency in MHz. */
492
+ readonly hseMHz: number;
493
+ /** PLL divider/multiplier plan. */
494
+ readonly pll: {
495
+ readonly divM: number;
496
+ readonly mulN: number;
497
+ readonly divP: number;
498
+ readonly divQ: number;
499
+ };
500
+ /** System clock frequency in MHz (the &rcc clock-frequency). */
501
+ readonly sysMHz: number;
502
+ readonly ahbPrescaler: number;
503
+ readonly apb1Prescaler: number;
504
+ readonly apb2Prescaler: number;
505
+ };
506
+ /**
507
+ * Silicon USB node to alias as `usb.controller` in the generated DTS
508
+ * (e.g. 'usbotg_fs' aliased as 'zephyr_udc0'). Omit when usb is absent.
509
+ */
510
+ readonly usbNode?: string;
511
+ /**
512
+ * Pinctrl tokens muxing the USB node's pins (e.g.
513
+ * 'usb_otg_fs_dm_pa11'/'usb_otg_fs_dp_pa12'). The st,stm32-otgfs binding
514
+ * requires pinctrl-0 on an enabled node, so the generated board pre-enables
515
+ * the USB node with exactly these (the blackpill shape). Omit when the
516
+ * SoC's USB needs no board-side muxing.
517
+ */
518
+ readonly usbPinctrl?: readonly string[];
519
+ /**
520
+ * ADC node the generated board must pre-enable with the SoC driver's
521
+ * required properties — e.g. the STM32 F4 binding rejects an enabled adc
522
+ * node without `st,adc-clock-source`/`st,adc-prescaler` (upstream boards
523
+ * set them in their DTS; a custom board has none, so the generator emits
524
+ * them from this data). The baseline pinctrl satisfies the binding's
525
+ * pinctrl-0 requirement; the usage-driven overlay rewrites it to the
526
+ * channels the program actually reads. Omit on SoCs whose ADC needs no
527
+ * board-side enabling.
528
+ */
529
+ readonly adcNode?: {
530
+ readonly nodeLabel: string;
531
+ /** The binding's clock-source property value (e.g. 'SYNC'). */
532
+ readonly clockSource: string;
533
+ /** The binding's prescaler property value (e.g. 2). */
534
+ readonly prescaler: number;
535
+ /** Baseline pinctrl token (e.g. 'adc1_in1_pa1'). */
536
+ readonly pinctrl: string;
537
+ };
538
+ }
539
+
540
+ /**
541
+ * A named way to attach a probe to a board — what the user picks, and what
542
+ * flashing/debugging lower to.
543
+ */
544
+ export interface ZephyrProbeMethod {
545
+ /** User-facing id, stable per board (`stlink`, `dfu`, `jlink`, `uf2`, …). */
546
+ readonly id: string;
547
+ /** The west runner this method drives (flash and debug). */
548
+ readonly runner: string;
549
+ /** Args always passed with this method (before any user runnerArgs). */
550
+ readonly args?: readonly string[];
551
+ /** One-line human description for the wizard, doctor, and error messages. */
552
+ readonly description?: string;
553
+ /** Whether this method can debug (default true — SWD/JTAG probes can,
554
+ * bootloaders cannot and set this false explicitly). */
555
+ readonly debug?: boolean;
556
+ /** cortex-debug: the wire protocol (default 'swd'; esp_usb_jtag is 'jtag'). */
557
+ readonly debugInterface?: 'swd' | 'jtag';
558
+ /** cortex-debug servertype=jlink: the J-Link device name (e.g. 'STM32F411CE'). */
559
+ readonly debugDevice?: string;
560
+ /** Raw OpenOCD cfg lines for the debug server config (e.g. 'reset_config
561
+ * none') — the cfg-file form of the quirks `args` carry for west. */
562
+ readonly debugCfg?: readonly string[];
563
+ /** OpenOCD cfg `source [find …]` lines for the debug server (interface +
564
+ * target configs). Omitted entries fall back to the framework default. */
565
+ readonly debugCfgSource?: readonly string[];
242
566
  }
243
567
 
@@ -83,7 +83,7 @@ export const ZEPHYR_DISPLAY_PROFILES: Record<string, ZephyrDisplayProfile> = {
83
83
  // ST7796S SPI TFT, 320x480 RGB565 mounted landscape (effective 480x320).
84
84
  // Same DT nodelabel convention as the ILI9341 — the board's devicetree
85
85
  // carries the `display0` node bound to the ST7796 driver; the overlay
86
- // enables it via status="okay". Effective dims match the Arduino
86
+ // enables it via status="okay". Effective dims match the display
87
87
  // st7796-spi profile (480x320 landscape, rotation 1).
88
88
  driver: 'st7796-zephyr',
89
89
  dtLabel: 'display0',
package/src/doctor.ts CHANGED
@@ -1,77 +1,110 @@
1
- // ---------------------------------------------------------------------------
2
- // @typecad/framework-zephyr — Zephyr environment doctor
3
- //
4
- // `cuttlefish doctor` (Zephyr framework) — verify west (the Zephyr build tool)
5
- // is installed + responsive, the Zephyr RTOS is inside the framework's declared
6
- // compat range, and the configured board target exists in the checkout. Exits 0
7
- // if the environment is OK, non-zero otherwise. Mirrors framework-arduino's
8
- // doctor shape (dispatched via the framework's `doctor` export) and reuses
9
- // checkZephyrEnv so the detection logic can be shared with the build/test gates.
10
- // ---------------------------------------------------------------------------
11
-
12
- import * as ui from '@typecad/cuttlefish/utils/ui';
13
- import { loadCuttlefishConfig } from '@typecad/cuttlefish/config-loader';
14
- import { checkZephyrEnv } from './toolchain/env-check.js';
15
-
16
- /**
17
- * Verify west is installed + responsive, the Zephyr RTOS is inside the supported
18
- * range, and the configured board target exists in the checkout. Sets
19
- * process.exitCode = 1 on failure. Thin presenter over checkZephyrEnv.
20
- */
21
- export function runDoctor(): void {
22
- ui.printHeader();
23
- ui.printStep('Checking Zephyr environment...');
24
-
25
- const config = loadCuttlefishConfig(process.cwd());
26
- const buildTarget = config?.buildTarget;
27
-
28
- const result = checkZephyrEnv(buildTarget);
29
- const c = result.check;
30
-
31
- // west (the Zephyr build tool) — the analog of arduino-cli presence.
32
- if (c.westFound) {
33
- const ver = c.westVersion ?? 'found';
34
- const src = c.westSource ? ` (${c.westSource})` : '';
35
- ui.printInfo(`west ............. ${ver} ✓${src}`);
36
- } else {
37
- ui.printError('west ............. NOT FOUND');
38
- }
39
-
40
- // Zephyr RTOS version + declared compat range.
41
- ui.printInfo(`ZEPHYR_BASE ...... ${c.zephyrBase ?? '(not set)'}`);
42
- ui.printInfo(`Zephyr version .. ${c.zephyrVersion ?? 'unknown (could not read ZEPHYR_BASE/VERSION)'}`);
43
- ui.printInfo(`Supported range . ${c.compatRange ?? '(none declared)'}`);
44
-
45
- if (c.compatStatus === 'out-of-range') {
46
- ui.printError(`Zephyr ${c.zephyrVersion} is OUTSIDE the supported range (${c.compatRange}).`);
47
- } else if (c.compatStatus === 'undetectable') {
48
- ui.printWarning('Could not detect the Zephyr version (is ZEPHYR_BASE set?) compat check skipped.');
49
- } else {
50
- ui.printInfo('Zephyr compat ... OK');
51
- }
52
-
53
- // Board target the analog of the Arduino core presence check.
54
- if (buildTarget) {
55
- const resolved = c.resolvedBoardTarget ?? buildTarget;
56
- const arrow = resolved === buildTarget ? '' : ` → ${resolved}`;
57
- if (c.boardTargetSupported === false) {
58
- ui.printError(`Board target .... ${buildTarget}${arrow} NOT found in this Zephyr checkout`);
59
- ui.printInfo(' → check the board id, or run: west boards');
60
- } else if (c.boardTargetSupported === undefined) {
61
- ui.printInfo(`Board target .... ${buildTarget}${arrow}`);
62
- ui.printInfo('(could not verify board presence — no ZEPHYR_BASE boards/ tree found)');
63
- } else {
64
- ui.printInfo(`Board target .... ${buildTarget}${arrow}`);
65
- }
66
- } else {
67
- ui.printInfo('(no buildTarget in cuttlefish.config.ts skipping board check)');
68
- }
69
-
70
- // Exit code — mirrors framework-arduino's doctor.
71
- if (result.ok) {
72
- ui.printSuccess('Environment OK');
73
- return; // exitCode stays unset => 0
74
- }
75
- for (const line of result.messages) ui.printInfo(line);
76
- process.exitCode = 1;
77
- }
1
+ // ---------------------------------------------------------------------------
2
+ // @typecad/framework-zephyr — Zephyr environment doctor
3
+ //
4
+ // `cuttlefish doctor` (Zephyr framework) — verify west (the Zephyr build tool)
5
+ // is installed + responsive, the Zephyr RTOS is inside the framework's declared
6
+ // compat range, and the configured board target exists in the checkout. Exits 0
7
+ // if the environment is OK, non-zero otherwise. Follows the same contract
8
+ // doctor shape (dispatched via the framework's `doctor` export) and reuses
9
+ // checkZephyrEnv so the detection logic can be shared with the build/test gates.
10
+ // ---------------------------------------------------------------------------
11
+
12
+ import { existsSync, readFileSync } from 'node:fs';
13
+ import { join } from 'node:path';
14
+ import * as ui from '@typecad/cuttlefish/utils/ui';
15
+ import { loadCuttlefishConfig } from '@typecad/cuttlefish/config-loader';
16
+ import { checkZephyrEnv } from './toolchain/env-check.js';
17
+ import { PINNED_ZEPHYR_MANIFEST_REV, PINNED_ZEPHYR_SDK_VERSION, sdkFingerprint } from '@typecad/cuttlefish/board-catalog';
18
+ import { resolveChipFromBoard } from './chips/resolve.js';
19
+
20
+ /**
21
+ * Verify west is installed + responsive, the Zephyr RTOS is inside the supported
22
+ * range, and the configured board target exists in the checkout. Sets
23
+ * process.exitCode = 1 on failure. Thin presenter over checkZephyrEnv.
24
+ */
25
+ export function runDoctor(): void {
26
+ ui.printHeader();
27
+ ui.printStep('Checking Zephyr environment...');
28
+
29
+ const config = loadCuttlefishConfig(process.cwd());
30
+ const buildTarget = config?.buildTarget;
31
+
32
+ const result = checkZephyrEnv(buildTarget);
33
+ const c = result.check;
34
+
35
+ // west (the Zephyr build tool) presence.
36
+ if (c.westFound) {
37
+ const ver = c.westVersion ?? 'found';
38
+ const src = c.westSource ? ` (${c.westSource})` : '';
39
+ ui.printInfo(`west ............. ${ver} ✓${src}`);
40
+ } else {
41
+ ui.printError('west ............. NOT FOUND');
42
+ }
43
+
44
+ // Zephyr RTOS version + declared compat range.
45
+ ui.printInfo(`ZEPHYR_BASE ...... ${c.zephyrBase ?? '(not set)'}`);
46
+ ui.printInfo(`Zephyr version .. ${c.zephyrVersion ?? 'unknown (could not read ZEPHYR_BASE/VERSION)'}`);
47
+ ui.printInfo(`Workspace pin ... ${PINNED_ZEPHYR_MANIFEST_REV} (SDK ${PINNED_ZEPHYR_SDK_VERSION})`);
48
+ const fp = c.zephyrBase ? sdkFingerprint(c.zephyrBase) : undefined;
49
+ ui.printInfo(`SDK fingerprint . ${fp ?? '(no tree — run ' + 'npx --package @typecad/framework-zephyr zephyr-installer)'}`);
50
+ ui.printInfo(`Supported range . ${c.compatRange ?? '(none declared)'}`);
51
+
52
+ if (c.compatStatus === 'out-of-range') {
53
+ ui.printError(`Zephyr ${c.zephyrVersion} is OUTSIDE the supported range (${c.compatRange}).`);
54
+ } else if (c.compatStatus === 'undetectable') {
55
+ ui.printWarning('Could not detect the Zephyr version (is ZEPHYR_BASE set?) — compat check skipped.');
56
+ } else {
57
+ ui.printInfo('Zephyr compat ... OK');
58
+ }
59
+
60
+ // Board target availability.
61
+ if (buildTarget) {
62
+ const resolved = c.resolvedBoardTarget ?? buildTarget;
63
+ const arrow = resolved === buildTarget ? '' : ` → ${resolved}`;
64
+ if (c.boardTargetSupported === false) {
65
+ ui.printError(`Board target .... ${buildTarget}${arrow} NOT found in this Zephyr checkout`);
66
+ ui.printInfo(' check the board id, or run: west boards');
67
+ } else if (c.boardTargetSupported === undefined) {
68
+ ui.printInfo(`Board target .... ${buildTarget}${arrow}`);
69
+ ui.printInfo('(could not verify board presence — no ZEPHYR_BASE boards/ tree found)');
70
+ } else {
71
+ ui.printInfo(`Board target .... ${buildTarget}${arrow}`);
72
+ }
73
+ } else {
74
+ ui.printInfo('(no buildTarget in cuttlefish.config.ts — skipping board check)');
75
+ }
76
+
77
+ // Probe methods — from the board package's table, via the board constants
78
+ // the transpile persists (candidates cover the standard out-dir layouts).
79
+ // The debug line lists the debug-capable subset (bootloaders can't debug).
80
+ if (buildTarget) {
81
+ const bcPath = [
82
+ join(process.cwd(), 'out', 'src', 'board-constants.json'),
83
+ join(process.cwd(), 'out', 'board-constants.json'),
84
+ join(process.cwd(), 'src', 'out', 'src', 'board-constants.json'),
85
+ join(process.cwd(), 'src', 'out', 'board-constants.json'),
86
+ ].find((p) => existsSync(p));
87
+ if (bcPath) {
88
+ try {
89
+ const raw = JSON.parse(readFileSync(bcPath, 'utf8')) as Record<string, string | number | boolean>;
90
+ const chip = resolveChipFromBoard(new Map(Object.entries(raw)));
91
+ const methods = chip?.probeMethods ?? [];
92
+ if (methods.length > 0) {
93
+ ui.printInfo(`Probe methods .... ${methods.map((m) => m.id).join(', ')} (zephyr.probe / --probe)`);
94
+ const debuggable = methods.filter((m) => m.debug !== false).map((m) => m.id);
95
+ ui.printInfo(`Debug methods .... ${debuggable.join(', ') || '(none — an external probe is required)'}`);
96
+ }
97
+ } catch { /* best-effort listing */ }
98
+ } else {
99
+ ui.printInfo('Probe methods .... (build once to list them)');
100
+ }
101
+ }
102
+
103
+ // Exit code — 0 ok, non-zero otherwise.
104
+ if (result.ok) {
105
+ ui.printSuccess('Environment OK');
106
+ return; // exitCode stays unset => 0
107
+ }
108
+ for (const line of result.messages) ui.printInfo(line);
109
+ process.exitCode = 1;
110
+ }