@typecad/framework-zephyr 1.0.0-alpha.13 → 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 (191) hide show
  1. package/README.md +22 -35
  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/controllers.d.ts +28 -8
  10. package/dist/chips/controllers.js +49 -12
  11. package/dist/chips/esp32s3.js +49 -0
  12. package/dist/chips/index.d.ts +6 -12
  13. package/dist/chips/index.js +18 -34
  14. package/dist/chips/resolve.d.ts +16 -2
  15. package/dist/chips/resolve.js +298 -15
  16. package/dist/chips/soc/.d.ts +2 -0
  17. package/dist/chips/soc/.js +129 -0
  18. package/dist/chips/soc/esp32.d.ts +2 -0
  19. package/dist/chips/soc/esp32.js +120 -0
  20. package/dist/chips/soc/esp32c3.d.ts +2 -0
  21. package/dist/chips/soc/esp32c3.js +90 -0
  22. package/dist/chips/soc/esp32c6.d.ts +2 -0
  23. package/dist/chips/soc/esp32c6.js +109 -0
  24. package/dist/chips/soc/esp32s3.d.ts +2 -0
  25. package/dist/chips/soc/esp32s3.js +189 -0
  26. package/dist/chips/soc/index.d.ts +2 -0
  27. package/dist/chips/soc/index.js +23 -0
  28. package/dist/chips/soc/nrf52840.d.ts +2 -0
  29. package/dist/chips/soc/nrf52840.js +130 -0
  30. package/dist/chips/soc/rp2040.d.ts +2 -0
  31. package/dist/chips/soc/rp2040.js +141 -0
  32. package/dist/chips/soc/rp2350a.d.ts +2 -0
  33. package/dist/chips/soc/rp2350a.js +145 -0
  34. package/dist/chips/soc/samd21g18a.d.ts +2 -0
  35. package/dist/chips/soc/samd21g18a.js +143 -0
  36. package/dist/chips/soc/stm32f411xe.d.ts +2 -0
  37. package/dist/chips/soc/stm32f411xe.js +251 -0
  38. package/dist/chips/types.d.ts +382 -12
  39. package/dist/chips/xiao-ble.js +33 -0
  40. package/dist/display/profiles.js +1 -1
  41. package/dist/doctor.js +38 -4
  42. package/dist/dt-config/custom-board.d.ts +23 -0
  43. package/dist/dt-config/custom-board.js +227 -0
  44. package/dist/dt-config/kconfig.d.ts +83 -1
  45. package/dist/dt-config/kconfig.js +116 -27
  46. package/dist/dt-config/overlay.js +623 -18
  47. package/dist/framework.manifest.d.ts +20 -30
  48. package/dist/framework.manifest.js +124 -178
  49. package/dist/index.d.ts +4 -1
  50. package/dist/index.js +8 -2
  51. package/dist/lowering/adc.d.ts +26 -5
  52. package/dist/lowering/adc.js +137 -31
  53. package/dist/lowering/ble.js +31 -28
  54. package/dist/lowering/dac.js +9 -9
  55. package/dist/lowering/fs.js +18 -10
  56. package/dist/lowering/gpio.d.ts +2 -0
  57. package/dist/lowering/gpio.js +90 -10
  58. package/dist/lowering/http.js +39 -14
  59. package/dist/lowering/hwtimer.d.ts +4 -0
  60. package/dist/lowering/hwtimer.js +35 -10
  61. package/dist/lowering/i2c.js +46 -54
  62. package/dist/lowering/index.d.ts +5 -5
  63. package/dist/lowering/index.js +15 -16
  64. package/dist/lowering/interrupts.d.ts +22 -5
  65. package/dist/lowering/interrupts.js +104 -22
  66. package/dist/lowering/mqtt.js +12 -6
  67. package/dist/lowering/power.js +0 -4
  68. package/dist/lowering/preferences.js +49 -77
  69. package/dist/lowering/pulse.js +5 -36
  70. package/dist/lowering/pwm.d.ts +32 -3
  71. package/dist/lowering/pwm.js +105 -17
  72. package/dist/lowering/random.js +3 -3
  73. package/dist/lowering/sensor.d.ts +37 -0
  74. package/dist/lowering/sensor.js +119 -0
  75. package/dist/lowering/spi.d.ts +12 -0
  76. package/dist/lowering/spi.js +65 -40
  77. package/dist/lowering/thread.d.ts +14 -0
  78. package/dist/lowering/thread.js +55 -0
  79. package/dist/lowering/timing.js +20 -46
  80. package/dist/lowering/tone.js +18 -5
  81. package/dist/lowering/uart.d.ts +13 -0
  82. package/dist/lowering/uart.js +72 -51
  83. package/dist/lowering/usb.d.ts +34 -0
  84. package/dist/lowering/usb.js +206 -0
  85. package/dist/lowering/wdt.d.ts +1 -1
  86. package/dist/lowering/wdt.js +17 -7
  87. package/dist/lowering/wifi.d.ts +3 -2
  88. package/dist/lowering/wifi.js +120 -111
  89. package/dist/sdk/board-catalog-sync.d.ts +16 -0
  90. package/dist/sdk/board-catalog-sync.js +41 -0
  91. package/dist/sdk/board-data.generated.d.ts +2 -0
  92. package/dist/sdk/board-data.generated.js +4 -0
  93. package/dist/sdk/catalog-walker.d.ts +90 -0
  94. package/dist/sdk/catalog-walker.js +682 -0
  95. package/dist/sdk/dts-reader.d.ts +83 -0
  96. package/dist/sdk/dts-reader.js +596 -0
  97. package/dist/strategy.d.ts +136 -17
  98. package/dist/strategy.js +881 -212
  99. package/dist/toolchain/bossac-touch.d.ts +18 -0
  100. package/dist/toolchain/bossac-touch.js +88 -0
  101. package/dist/toolchain/compat.d.ts +2 -2
  102. package/dist/toolchain/compat.js +8 -3
  103. package/dist/toolchain/debug-config.d.ts +21 -26
  104. package/dist/toolchain/debug-config.js +212 -72
  105. package/dist/toolchain/env-check.d.ts +4 -4
  106. package/dist/toolchain/env-check.js +5 -5
  107. package/dist/toolchain/index.d.ts +66 -1
  108. package/dist/toolchain/index.js +713 -58
  109. package/dist/toolchain/scaffold.d.ts +9 -0
  110. package/dist/toolchain/scaffold.js +84 -7
  111. package/dist/toolchain/west-discover.d.ts +8 -1
  112. package/dist/toolchain/west-discover.js +19 -6
  113. package/dist/toolchain/west-spawn.js +17 -5
  114. package/installer/CHANGELOG.md +473 -0
  115. package/installer/README.md +328 -0
  116. package/installer/environment.yml +46 -0
  117. package/installer/etc/conda/activate.d/zephyr.bat +7 -0
  118. package/installer/etc/conda/activate.d/zephyr.ps1 +12 -0
  119. package/installer/etc/conda/activate.d/zephyr.sh +20 -0
  120. package/installer/etc/conda/deactivate.d/zephyr.bat +6 -0
  121. package/installer/etc/conda/deactivate.d/zephyr.ps1 +6 -0
  122. package/installer/etc/conda/deactivate.d/zephyr.sh +4 -0
  123. package/installer/install.mjs +580 -0
  124. package/installer/install.ps1 +619 -0
  125. package/installer/install.sh +310 -0
  126. package/installer/lib/detect-platform.sh +62 -0
  127. package/installer/lib/fetch-sdk.sh +304 -0
  128. package/installer/lib/init-workspace.sh +153 -0
  129. package/installer/lib/write-activation.sh +76 -0
  130. package/installer/patches/tfm-c-include-separators.patch +19 -0
  131. package/installer/patches/zephyr-tfm-nordic-zephyr-include.patch +24 -0
  132. package/installer/templates/project/.typecad/activate-zephyr.ps1 +31 -0
  133. package/installer/templates/project/.typecad/activate-zephyr.sh +31 -0
  134. package/installer/templates/project/.vscode/settings.json +30 -0
  135. package/installer/templates/project/README.md +58 -0
  136. package/installer/versions.env +110 -0
  137. package/package.json +16 -16
  138. package/src/as-built.ts +206 -0
  139. package/src/boardgen.ts +1428 -0
  140. package/src/chips/controllers.ts +61 -12
  141. package/src/chips/index.ts +35 -54
  142. package/src/chips/resolve.ts +316 -14
  143. package/src/chips/types.ts +388 -13
  144. package/src/display/profiles.ts +1 -1
  145. package/src/doctor.ts +110 -77
  146. package/src/dt-config/custom-board.ts +325 -0
  147. package/src/dt-config/kconfig.ts +177 -19
  148. package/src/dt-config/overlay.ts +1058 -450
  149. package/src/framework.manifest.ts +125 -178
  150. package/src/index.ts +57 -41
  151. package/src/lowering/adc.ts +222 -102
  152. package/src/lowering/ble.ts +32 -28
  153. package/src/lowering/dac.ts +82 -82
  154. package/src/lowering/fs.ts +18 -10
  155. package/src/lowering/gpio.ts +242 -152
  156. package/src/lowering/http.ts +512 -488
  157. package/src/lowering/hwtimer.ts +139 -101
  158. package/src/lowering/i2c.ts +116 -126
  159. package/src/lowering/index.ts +91 -93
  160. package/src/lowering/interrupts.ts +113 -21
  161. package/src/lowering/mqtt.ts +12 -6
  162. package/src/lowering/preferences.ts +327 -354
  163. package/src/lowering/pwm.ts +167 -74
  164. package/src/lowering/random.ts +3 -3
  165. package/src/lowering/sensor.ts +155 -0
  166. package/src/lowering/spi.ts +164 -124
  167. package/src/lowering/thread.ts +63 -0
  168. package/src/lowering/timing.ts +46 -72
  169. package/src/lowering/uart.ts +73 -51
  170. package/src/lowering/usb.ts +221 -0
  171. package/src/lowering/wdt.ts +95 -84
  172. package/src/lowering/wifi.ts +120 -111
  173. package/src/sdk/board-catalog-sync.ts +62 -0
  174. package/src/strategy.ts +888 -229
  175. package/src/toolchain/bossac-touch.ts +112 -0
  176. package/src/toolchain/compat.ts +8 -3
  177. package/src/toolchain/debug-config.ts +666 -522
  178. package/src/toolchain/env-check.ts +9 -9
  179. package/src/toolchain/index.ts +765 -44
  180. package/src/toolchain/scaffold.ts +81 -7
  181. package/src/toolchain/west-discover.ts +334 -316
  182. package/src/toolchain/west-spawn.ts +17 -5
  183. package/src/async/timer-polyfill.ts +0 -107
  184. package/src/chips/esp32.ts +0 -74
  185. package/src/chips/esp32s3.ts +0 -57
  186. package/src/chips/xiao-ble.ts +0 -70
  187. package/src/lowering/power.ts +0 -70
  188. package/src/lowering/pulse.ts +0 -93
  189. package/src/lowering/tone.ts +0 -60
  190. package/src/lowering/worker-backing.ts +0 -94
  191. package/src/lowering/worker.ts +0 -17
@@ -1,6 +1,15 @@
1
1
  /** Write a file only if the content differs from the existing file.
2
2
  * Returns true when the file was written (content changed or file was new). */
3
3
  export declare function writeIfChanged(filePath: string, content: string): boolean;
4
+ /**
5
+ * Append cuttlefish library packages' devicetree overlay fragments to the
6
+ * generated overlay. Library entries come from the transpiler's libraries.json
7
+ * sidecar (next to the emitted sources) and are already gated on the
8
+ * library's include token appearing in the emitted sources — no re-detection.
9
+ * Fragments merge after the framework overlay so library nodes (e.g.
10
+ * @typecad/zephyr-esp32s3-rgb's WS2812 node on I2S0) layer over it.
11
+ */
12
+ export declare function appendLibraryOverlayFragments(overlay: string, projectRoot: string): string;
4
13
  /**
5
14
  * Emit the Zephyr application skeleton around the generated src/main.cpp.
6
15
  *
@@ -9,6 +9,9 @@
9
9
  import { writeFileSync, existsSync, mkdirSync, readFileSync, readdirSync } from 'node:fs';
10
10
  import { join } from 'node:path';
11
11
  import { resolveKconfigFragments } from '../dt-config/kconfig.js';
12
+ import { scanSensorParts } from './index.js';
13
+ import { readCuttlefishLibrarySidecar } from '@typecad/cuttlefish/library-packages';
14
+ import { SENSOR_PART_INFO } from '@typecad/hal';
12
15
  /** Write a file only if the content differs from the existing file.
13
16
  * Returns true when the file was written (content changed or file was new). */
14
17
  export function writeIfChanged(filePath, content) {
@@ -57,6 +60,31 @@ function readEmittedSources(srcDir) {
57
60
  }
58
61
  return out;
59
62
  }
63
+ /**
64
+ * Append cuttlefish library packages' devicetree overlay fragments to the
65
+ * generated overlay. Library entries come from the transpiler's libraries.json
66
+ * sidecar (next to the emitted sources) and are already gated on the
67
+ * library's include token appearing in the emitted sources — no re-detection.
68
+ * Fragments merge after the framework overlay so library nodes (e.g.
69
+ * @typecad/zephyr-esp32s3-rgb's WS2812 node on I2S0) layer over it.
70
+ */
71
+ export function appendLibraryOverlayFragments(overlay, projectRoot) {
72
+ let out = overlay;
73
+ for (const entry of readCuttlefishLibrarySidecar(join(projectRoot, 'src'))) {
74
+ if (!entry.overlay)
75
+ continue;
76
+ try {
77
+ const fragment = readFileSync(entry.overlay, 'utf8').trim();
78
+ if (fragment.length > 0) {
79
+ out += (out.endsWith('\n') ? '' : '\n') + '\n' + fragment + '\n';
80
+ }
81
+ }
82
+ catch {
83
+ // best-effort; a missing fragment surfaces as a DT error
84
+ }
85
+ }
86
+ return out;
87
+ }
60
88
  /**
61
89
  * Emit the Zephyr application skeleton around the generated src/main.cpp.
62
90
  *
@@ -97,17 +125,28 @@ export function scaffoldZephyrProject(projectRoot, debug = false, userKconfig, p
97
125
  usesDac: uses('dac_') || uses('__tc_dac'),
98
126
  usesFS: uses('__tc_fs'),
99
127
  usesHwtimer: uses('counter_') || uses('__tc_hw'),
100
- usesI2c: uses('i2c_'),
101
- usesSpi: uses('spi_'),
102
- usesUart: uses('uart_'),
128
+ // The __tc_<bus> alternative matches the shim's state block — a program
129
+ // that only calls begin() emits `(void)__tc_i2c1_dev;` (no driver API
130
+ // call yet), but the shim still declared DEVICE_DT_GET(DT_NODELABEL(...))
131
+ // so the overlay must enable the node or the device symbol is missing.
132
+ usesI2c: uses('i2c_') || uses('__tc_i2c'),
133
+ // DT-bound sensor parts: the __tc_sensor_* state references and the
134
+ // sensor_sample_fetch/sensor_channel_get calls both carry the token.
135
+ usesSensor: uses('sensor_') || uses('__tc_sensor'),
136
+ usesFloatFormat: /%[-0-9.]*[eEfFgG]/.test(src),
137
+ usesSpi: uses('spi_') || uses('__tc_spi'),
138
+ usesUart: uses('uart_') || uses('__tc_uart'),
139
+ // USB CDC serial: every usb.* lowering calls into the __tc_usb<N>_* shim
140
+ // (device + init helper emitted under usesUsb).
141
+ usesUsb: uses('__tc_usb'),
142
+ // STM32F4 DBGMCU keep-SWD-alive init present (emitted for stm32f4 socs).
143
+ usesStm32DebugSleep: uses('__tc_stm32_dbgmcu'),
103
144
  usesWdt: uses('wdt_'),
104
145
  usesBle: uses('bt_') || uses('bt_gatt') || uses('bt_le_'),
105
146
  usesDisplay: uses('display_write') || uses('display_init') || uses('display_fill_rect') || uses('__tc_display_dev') || uses('CuttlefishDisplayTarget'),
106
147
  usesTouch: uses('ft6336u') || uses('touch_'),
107
- // Power tokens: k_sleep + pm_state_force / PM_STATE_* (what power.ts emits).
108
- // The old `power_` token matched nothing the power HAL emits and collides
109
- // with tx_power_dbm — removed.
110
- usesPower: uses('pm_') || uses('k_sleep') || uses('PM_STATE_'),
148
+ // (The power HAL is removed; its former pm_/k_sleep token scan is gone —
149
+ // nothing here must match tx_power_dbm's `power` substring.)
111
150
  usesWifi: uses('wifi_') || uses('net_mgmt') || uses('conn_mgr'),
112
151
  // HTTP: the __tc_http_* shim + http_client_req + getaddrinfo. The '_'-anchored
113
152
  // 'http_' token matches __tc_http_* and http_client_req (the core HTTP lib
@@ -138,6 +177,12 @@ export function scaffoldZephyrProject(projectRoot, debug = false, userKconfig, p
138
177
  '# Auto-generated by @typecad/framework-zephyr from cuttlefish.config.ts.',
139
178
  'cmake_minimum_required(VERSION 3.20.0)',
140
179
  '',
180
+ '# The app is its own board root: MCU-only targets generate an out-of-tree',
181
+ '# custom board under boards/typecad/<name>/ that Zephyr must discover.',
182
+ '# Harmless when boards/ holds only .overlay files (BOARD_ROOT just needs',
183
+ '# the directory to exist).',
184
+ 'list(APPEND BOARD_ROOT ${CMAKE_CURRENT_SOURCE_DIR})',
185
+ '',
141
186
  'find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})',
142
187
  '',
143
188
  'project(zephyr_app)',
@@ -202,6 +247,38 @@ export function scaffoldZephyrProject(projectRoot, debug = false, userKconfig, p
202
247
  continue;
203
248
  prjConf.push(`${sym}=${val}`);
204
249
  }
250
+ // ── Cuttlefish library packages ─────────────────────────────────────────
251
+ // Libraries the program imports (recorded in the transpiler's libraries.json
252
+ // sidecar, next to the emitted sources) contribute their manifest's kconfig
253
+ // lines — e.g. @typecad/zephyr-esp32s3-rgb contributes CONFIG_LED_STRIP.
254
+ // Sidecar entries are already gated on the library's include token
255
+ // appearing in the emitted sources, so no re-detection here. User
256
+ // zephyr.kconfig overrides still win.
257
+ const libraryEntries = readCuttlefishLibrarySidecar(srcDir);
258
+ if (libraryEntries.length > 0) {
259
+ prjConf.push('', '# Library packages (cuttlefish.library.json contributions).');
260
+ for (const entry of libraryEntries) {
261
+ for (const line of entry.kconfig) {
262
+ const sym = line.split('=')[0];
263
+ if (userKconfig && sym !== undefined && userKconfig.hasOwnProperty(sym))
264
+ continue;
265
+ prjConf.push(line);
266
+ }
267
+ }
268
+ }
269
+ // Per-part Kconfig exceptions: catalog parts whose driver is NOT default-y
270
+ // on its DT node carry extra lines here (empty today — every in-tree sensor
271
+ // driver lights up from the node; the path exists so the first exception
272
+ // found by the generator has somewhere to go).
273
+ const sensorParts = scanSensorParts(src);
274
+ if (sensorParts.length > 0) {
275
+ const extra = [...new Set(sensorParts.flatMap((sp) => SENSOR_PART_INFO[sp.part]?.kconfig ?? []))];
276
+ if (extra.length > 0) {
277
+ prjConf.push('', '# Sensor part Kconfig (catalog exceptions).');
278
+ for (const line of extra)
279
+ prjConf.push(line);
280
+ }
281
+ }
205
282
  // Emit user-specified Kconfig from cuttlefish.config.ts zephyr.kconfig.
206
283
  // These override any matching auto-detected symbol (skipped above).
207
284
  if (userKconfig) {
@@ -9,8 +9,11 @@ export interface WestInstall {
9
9
  westExecutable?: string;
10
10
  /** Absolute path to a Python interpreter with west installed (mode 'module'). */
11
11
  pythonExecutable?: string;
12
- /** Absolute path to the Zephyr SDK root (for $ZEPHYR_BASE), if found. */
12
+ /** Absolute path to the Zephyr workspace (for $ZEPHYR_BASE), if found. */
13
13
  zephyrBase?: string;
14
+ /** Absolute path to the Zephyr SDK install dir (hosttools/openocd lives
15
+ * there), if found — used to put the SDK's openocd on the flash PATH. */
16
+ sdkInstallDir?: string;
14
17
  /** mode 'micromamba': path to the micromamba binary (for `micromamba run -n …`). */
15
18
  micromambaExe?: string;
16
19
  /** mode 'micromamba': the conda env name (default 'zephyr'). */
@@ -27,6 +30,10 @@ export declare function discoverFromPath(): WestInstall | null;
27
30
  /** The canonical Zephyr workspace layout puts the venv beside the SDK:
28
31
  * <workspace>/{.venv, zephyr}. So ${ZEPHYR_BASE}/../.venv is the venv. */
29
32
  export declare function discoverFromZephyrBase(): WestInstall | null;
33
+ /** The installer-written ZEPHYR_BASE of the micromamba env, fs-only (no
34
+ * spawn) — the cheap probe shared by board-catalog overlay discovery.
35
+ * Undefined when the installer env or its env-vars file is absent. */
36
+ export declare function micromambaZephyrBase(envName?: string): string | undefined;
30
37
  export declare function discoverFromMicromamba(envName?: string): WestInstall | null;
31
38
  /** Candidate Zephyr workspace directories. Each may contain both `.venv/`
32
39
  * and `zephyr/` (the SDK). Exported for test injection. */
@@ -42,13 +42,14 @@ function pythonRunsWest(exe) {
42
42
  return false;
43
43
  }
44
44
  }
45
- /** True if `cmd` runs `west --version` successfully. */
45
+ /** True if `cmd` runs `west --version` successfully. `cmd` comes from
46
+ * `where`/`which` output — a venv launcher (west.exe) or script path, spawned
47
+ * without a shell like every other command in this module. */
46
48
  function westOnPath(cmd) {
47
49
  try {
48
50
  const r = spawnSync(cmd, ['--version'], {
49
51
  encoding: 'utf8',
50
52
  timeout: 15_000,
51
- shell: IS_WIN,
52
53
  windowsHide: true,
53
54
  });
54
55
  return r.status === 0;
@@ -67,12 +68,11 @@ export function isZephyrBase(dir) {
67
68
  }
68
69
  // ── Strategy 1: `west` on PATH ──────────────────────────────────────────────
69
70
  export function discoverFromPath() {
70
- // shell only on Windows (where.exe resolution through cmd) an args array
71
- // with shell: true triggers Node's DEP0190 deprecation warning on Linux/
72
- // macOS, where `which` is a plain executable that needs no shell.
71
+ // No shell: `where`/`which` are plain executables Node resolves from PATH
72
+ // (where.exe is a real PE, not a cmd builtin), and an args array with a
73
+ // truthy shell triggers Node's DEP0190 deprecation warning.
73
74
  const which = spawnSync(IS_WIN ? 'where' : 'which', ['west'], {
74
75
  encoding: 'utf8',
75
- shell: IS_WIN,
76
76
  windowsHide: true,
77
77
  });
78
78
  if (which.status !== 0)
@@ -160,6 +160,17 @@ function readMicromambaEnvVar(envDir, varName) {
160
160
  }
161
161
  return undefined;
162
162
  }
163
+ /** The installer-written ZEPHYR_BASE of the micromamba env, fs-only (no
164
+ * spawn) — the cheap probe shared by board-catalog overlay discovery.
165
+ * Undefined when the installer env or its env-vars file is absent. */
166
+ export function micromambaZephyrBase(envName = process.env.TYPECAD_ZEPHYR_ENV || 'zephyr') {
167
+ const mm = findMicromamba();
168
+ if (!mm)
169
+ return undefined;
170
+ const envDir = join(mm.rootPrefix, 'envs', envName);
171
+ const zb = readMicromambaEnvVar(envDir, 'TYPECAD_ZEPHYR_BASE');
172
+ return zb && isZephyrBase(zb) ? zb : undefined;
173
+ }
163
174
  export function discoverFromMicromamba(envName = process.env.TYPECAD_ZEPHYR_ENV || 'zephyr') {
164
175
  const mm = findMicromamba();
165
176
  if (!mm)
@@ -172,12 +183,14 @@ export function discoverFromMicromamba(envName = process.env.TYPECAD_ZEPHYR_ENV
172
183
  // anything else in the cuttlefish process) can detect the Zephyr version
173
184
  // WITHOUT activation — micromamba run sets it only inside the west subprocess.
174
185
  const zb = readMicromambaEnvVar(envDir, 'TYPECAD_ZEPHYR_BASE');
186
+ const sdk = readMicromambaEnvVar(envDir, 'TYPECAD_ZEPHYR_SDK_INSTALL_DIR');
175
187
  return {
176
188
  mode: 'micromamba',
177
189
  micromambaExe: mm.exe,
178
190
  envName,
179
191
  mambaRootPrefix: mm.rootPrefix,
180
192
  zephyrBase: zb && isZephyrBase(zb) ? zb : undefined,
193
+ sdkInstallDir: sdk && existsSync(sdk) ? sdk : undefined,
181
194
  source: 'micromamba',
182
195
  };
183
196
  }
@@ -14,7 +14,8 @@
14
14
  // (find_package(Zephyr) needs it). west's prj.conf/CMakeLists are found via
15
15
  // the project dir regardless.
16
16
  // ---------------------------------------------------------------------------
17
- import { dirname } from 'node:path';
17
+ import { dirname, join } from 'node:path';
18
+ import { existsSync } from 'node:fs';
18
19
  import { discoverWest } from './west-discover.js';
19
20
  /**
20
21
  * The Scripts/ (Windows) or bin/ (POSIX) directory of the venv the discovered
@@ -41,8 +42,19 @@ export function buildEnv(install) {
41
42
  if (install.zephyrBase && !env.ZEPHYR_BASE) {
42
43
  env.ZEPHYR_BASE = install.zephyrBase;
43
44
  }
44
- const bin = venvBinDir(install);
45
- if (bin) {
45
+ // SWD flashing (`zephyr.runner: 'openocd'`): west's openocd runner resolves
46
+ // a bare `openocd` from PATH. The Zephyr SDK ships it under
47
+ // hosttools/openocd/bin (the SDK's own setup.cmd puts that dir on PATH for
48
+ // activated terminals) — do the same for spawned west processes so ST-Link
49
+ // flashing works without activation. $ZEPHYR_SDK_INSTALL_DIR (set by an
50
+ // activated env) wins over the discovered install dir.
51
+ const sdkRoot = env.ZEPHYR_SDK_INSTALL_DIR || install.sdkInstallDir;
52
+ const openocdBin = sdkRoot ? join(sdkRoot, 'hosttools', 'openocd', 'bin') : undefined;
53
+ const prepend = [
54
+ openocdBin !== undefined && existsSync(openocdBin) ? openocdBin : undefined,
55
+ venvBinDir(install),
56
+ ].filter((d) => d !== undefined);
57
+ if (prepend.length > 0) {
46
58
  const sep = process.platform === 'win32' ? ';' : ':';
47
59
  // On Windows the PATH environment variable may be cased as `Path` (the
48
60
  // registry-native form, the only one populated when node is launched from
@@ -50,9 +62,9 @@ export function buildEnv(install) {
50
62
  // casing can leave the other stale/empty, which under PowerShell would drop
51
63
  // the user's real PATH (cmake, ninja, …) — breaking `west` configure. Read
52
64
  // whichever casing is populated and write that same casing back, preserving
53
- // the full existing value with the venv dir prepended.
65
+ // the full existing value with the discovered dirs prepended.
54
66
  const existing = env.Path ?? env.PATH ?? '';
55
- const updated = bin + sep + existing;
67
+ const updated = prepend.join(sep) + sep + existing;
56
68
  if (env.Path !== undefined || (env.PATH === undefined && process.platform === 'win32')) {
57
69
  env.Path = updated;
58
70
  }