Skip to content

Commit 7590504

Browse files
authored
Feature/add devkits support (#1557)
* Add usb location env var * Add version validation for openOCD * Add active debugging session validation * Add translations * Update documentation * feat: add validation for esp_detect_config.py existence Adds a check to verify that esp_detect_config.py exists before attempting to run it. This prevents potential errors when the script is missing and provides clearer error messages to users * Change notification to output channel * Remove min openocd version validation - Validation is hard to maintain and unnecessary if we validate based on existing "esp_detect_config.py" script * Fix output display tags
1 parent 4e088b7 commit 7590504

File tree

9 files changed

+296
-17
lines changed

9 files changed

+296
-17
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ These icons will be used in the steps below showing common ESP-IDF use cases:
9797

9898
10. Make sure to configure your drivers as mentioned in ESP-IDF [Configure JTAG Interface](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/jtag-debugging/configure-ft2232h-jtag.html) documentation.
9999

100-
11. Before debugging your device, select the device OpenOCD board configuration files by pressing <kbd>F1</kbd> and typing **ESP-IDF: Select OpenOCD Board Configuration**. You can test the connection by clicking status bar icon ![openocd](./media/readme/openocd.png) or pressing <kbd>F1</kbd> and typing **ESP-IDF: OpenOCD Manager**. The output is shown in the menu `View` -> `Output` and choose `ESP-IDF` from the dropdown list.
100+
11. Before debugging your device, if you are using a connected ESP-IDF development board, the OpenOCD configuration will be automatically selected based on your connected board, including the USB location if available (requires OpenOCD version v0.12.0-esp32-20240821 or higher). Otherwise, you can manually select the device OpenOCD board configuration files by pressing <kbd>F1</kbd> and typing **ESP-IDF: Select OpenOCD Board Configuration**. You can test the connection by clicking status bar icon ![openocd](./media/readme/openocd.png) or pressing <kbd>F1</kbd> and typing **ESP-IDF: OpenOCD Manager**. The output is shown in the menu `View` -> `Output` and choose `ESP-IDF` from the dropdown list.
101101

102102
> **NOTE:** You can start or stop the OpenOCD in Visual Studio Code using the **ESP-IDF: OpenOCD Manager** command or by clicking the `OpenOCD Server (Running | Stopped)` button in the status bar.
103103
@@ -159,7 +159,7 @@ Press <kbd>F1</kbd> or click menu `View` -> `Command Palette...` to show Visual
159159
</tr>
160160
<tr>
161161
<td>Pick a Workspace Folder</td>
162-
<td>When using a Visual Studio Code workspace with multiple folders, this command allows you to choose which workspace folder to apply this extensions commands to.
162+
<td>When using a Visual Studio Code workspace with multiple folders, this command allows you to choose which workspace folder to apply this extension's commands to.
163163
More information in <a href="https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/additionalfeatures/multiple-projects.html">working with multiple projects</a>.</td>
164164
<td></td>
165165
<td></td>
@@ -203,7 +203,7 @@ Press <kbd>F1</kbd> or click menu `View` -> `Command Palette...` to show Visual
203203
</tr>
204204
<tr>
205205
<td>Flash Your Project</td>
206-
<td>Write binary data to the ESPs flash chip from your current ESP-IDF project. This command will use either UART, DFU or JTAG based on <strong>idf.flashType</strong>.</td>
206+
<td>Write binary data to the ESP's flash chip from your current ESP-IDF project. This command will use either UART, DFU or JTAG based on <strong>idf.flashType</strong>.</td>
207207
<td><kbd>⌘</kbd> <kbd>I</kbd> <kbd>F</kbd></td>
208208
<td><kbd>Ctrl</kbd> <kbd>E</kbd> <kbd>F</kbd></td>
209209
</tr>
@@ -272,25 +272,25 @@ Press <kbd>F1</kbd> or click menu `View` -> `Command Palette...` to show Visual
272272
</tr>
273273
<tr>
274274
<td>Flash Your Project</td>
275-
<td>Write binary data to the ESPs flash chip from your current ESP-IDF project. This command will use either UART, DFU or JTAG based on <strong>idf.flashType</strong></td>
275+
<td>Write binary data to the ESP's flash chip from your current ESP-IDF project. This command will use either UART, DFU or JTAG based on <strong>idf.flashType</strong></td>
276276
<td><kbd>⌘</kbd> <kbd>I</kbd> <kbd>F</kbd></td>
277277
<td><kbd>Ctrl</kbd> <kbd>E</kbd> <kbd>F</kbd></td>
278278
</tr>
279279
<tr>
280280
<td>Flash (DFU) Your Project</td>
281-
<td>Write binary data to the ESPs flash chip from your current ESP-IDF project using DFU. Only for ESP32-S2 and ESP32-S3. </td>
281+
<td>Write binary data to the ESP's flash chip from your current ESP-IDF project using DFU. Only for ESP32-S2 and ESP32-S3. </td>
282282
<td></td>
283283
<td></td>
284284
</tr>
285285
<tr>
286286
<td>Flash (UART) Your Project</td>
287-
<td>Write binary data to the ESPs flash chip from your current ESP-IDF project using esptool.py.</td>
287+
<td>Write binary data to the ESP's flash chip from your current ESP-IDF project using esptool.py.</td>
288288
<td></td>
289289
<td></td>
290290
</tr>
291291
<tr>
292292
<td>Flash (with JTAG)</td>
293-
<td>Write binary data to the ESPs flash chip from your current ESP-IDF project using OpenOCD JTAG.</td>
293+
<td>Write binary data to the ESP's flash chip from your current ESP-IDF project using OpenOCD JTAG.</td>
294294
<td></td>
295295
<td></td>
296296
</tr>

docs_espressif/en/configureproject.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Configure Your Project
77

88
Select an Espressif target (esp32, esp32s2, etc.) by going to ``View`` > ``Command Palette`` and entering ``ESP-IDF: Set Espressif Device Target`` command.
99

10-
Go to ``View`` > ``Command Palette`` and enter ``ESP-IDF: Select OpenOCD Board Configuration`` to choose the openOCD configuration files for the extension openOCD server.
10+
If you are using a connected ESP-IDF development board, the OpenOCD configuration will be automatically selected based on your connected board. Otherwise, you can manually select the OpenOCD configuration by going to ``View`` > ``Command Palette`` and entering ``ESP-IDF: Select OpenOCD Board Configuration``.
1111

1212
.. note::
1313

l10n/bundle.l10n.es.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,7 @@
233233
"Type 'SWITCH' to confirm switching to Release Mode": "Escriba 'SWITCH' para confirmar el cambio al Modo Release",
234234
"Please type 'SWITCH' exactly to confirm": "Por favor escriba 'SWITCH' exactamente para confirmar",
235235
"Switching to Release Mode cancelled by user": "Cambio al Modo Release cancelado por el usuario",
236-
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "Usuario confirmó el cambio al Modo Release. Procediendo con el cifrado de flash."
236+
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "Usuario confirmó el cambio al Modo Release. Procediendo con el cifrado de flash.",
237+
"Connected ESP-IDF devkit detection is skipped while debugging. You can still select a target manually.": "La detección de devkit ESP-IDF conectados se omite durante la depuración. Aún puede seleccionar un objetivo manualmente.",
238+
"Connected ESP-IDF devkit detection is not available for your {openOCDVersion} OpenOCD version. Required version is {minRequiredVersion} or higher. You can still select a target manually.": "La detección de devkit ESP-IDF conectados no está disponible para su versión de OpenOCD {openOCDVersion}. Se requiere la versión {minRequiredVersion} o superior. Aún puede seleccionar un objetivo manualmente."
237239
}

l10n/bundle.l10n.pt.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,7 @@
233233
"Type 'SWITCH' to confirm switching to Release Mode": "Digite 'SWITCH' para confirmar a mudança para o Modo de Release",
234234
"Please type 'SWITCH' exactly to confirm": "Por favor, digite 'SWITCH' exatamente para confirmar",
235235
"Switching to Release Mode cancelled by user": "Mudança para o Modo de Release cancelada pelo usuário",
236-
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "Usuário confirmou a mudança para o Modo de Release. Prosseguindo com a criptografia flash."
236+
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "Usuário confirmou a mudança para o Modo de Release. Prosseguindo com a criptografia flash.",
237+
"Connected ESP-IDF devkit detection is skipped while debugging. You can still select a target manually.": "A detecção de devkit ESP-IDF conectados é ignorada durante a depuração. Você ainda pode selecionar um alvo manualmente.",
238+
"Connected ESP-IDF devkit detection is not available for your {openOCDVersion} OpenOCD version. Required version is {minRequiredVersion} or higher. You can still select a target manually.": "A detecção de devkit ESP-IDF conectados não está disponível para sua versão do OpenOCD {openOCDVersion}. É necessária a versão {minRequiredVersion} ou superior. Você ainda pode selecionar um alvo manualmente."
237239
}

l10n/bundle.l10n.ru.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,7 @@
233233
"Type 'SWITCH' to confirm switching to Release Mode": "Введите 'SWITCH' для подтверждения переключения в Режим Релиза",
234234
"Please type 'SWITCH' exactly to confirm": "Пожалуйста, введите точно 'SWITCH' для подтверждения",
235235
"Switching to Release Mode cancelled by user": "Переключение в Режим Релиза отменено пользователем",
236-
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "Пользователь подтвердил переключение в Режим Релиза. Продолжаем шифрование флеш-памяти."
236+
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "Пользователь подтвердил переключение в Режим Релиза. Продолжаем шифрование флеш-памяти.",
237+
"Connected ESP-IDF devkit detection is skipped while debugging. You can still select a target manually.": "Обнаружение подключенных ESP-IDF devkit пропускается во время отладки. Вы все еще можете выбрать цель вручную.",
238+
"Connected ESP-IDF devkit detection is not available for your {openOCDVersion} OpenOCD version. Required version is {minRequiredVersion} or higher. You can still select a target manually.": "Обнаружение подключенных ESP-IDF devkit недоступно для вашей версии OpenOCD {openOCDVersion}. Требуется версия {minRequiredVersion} или выше. Вы все еще можете выбрать цель вручную."
237239
}

l10n/bundle.l10n.zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,7 @@
233233
"Type 'SWITCH' to confirm switching to Release Mode": "输入 'SWITCH' 确认切换到发布模式",
234234
"Please type 'SWITCH' exactly to confirm": "请准确输入 'SWITCH' 以确认",
235235
"Switching to Release Mode cancelled by user": "用户取消了切换到发布模式",
236-
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "用户确认切换到发布模式。继续进行闪存加密。"
236+
"User confirmed switching to Release Mode. Proceeding with flash encryption.": "用户确认切换到发布模式。继续进行闪存加密。",
237+
"Connected ESP-IDF devkit detection is skipped while debugging. You can still select a target manually.": "调试时跳过已连接的 ESP-IDF 开发板检测。您仍可以手动选择目标。",
238+
"Connected ESP-IDF devkit detection is not available for your {openOCDVersion} OpenOCD version. Required version is {minRequiredVersion} or higher. You can still select a target manually.": "您的 OpenOCD 版本 {openOCDVersion} 不支持已连接的 ESP-IDF 开发板检测功能。需要 {minRequiredVersion} 或更高版本。您仍可以手动选择目标。"
237239
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* Project: ESP-IDF VSCode Extension
3+
* File Created: Friday, 8th January 2021 5:34:24 pm
4+
* Copyright 2021 Espressif Systems (Shanghai) CO LTD
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import * as vscode from "vscode";
20+
import * as fs from "fs"
21+
import { join } from "path";
22+
import * as idfConf from "../../idfConfiguration";
23+
import { Logger } from "../../logger/logger";
24+
import { getVirtualEnvPythonPath } from "../../pythonManager";
25+
import { OpenOCDManager } from "../openOcd/openOcdManager";
26+
import { appendIdfAndToolsToPath, execChildProcess } from "../../utils";
27+
import { OutputChannel } from "../../logger/outputChannel";
28+
import { getOpenOcdScripts } from "../openOcd/boardConfiguration";
29+
30+
export class DevkitsCommand {
31+
private workspaceRoot: vscode.Uri;
32+
33+
constructor(workspaceRoot: vscode.Uri) {
34+
this.workspaceRoot = workspaceRoot;
35+
}
36+
37+
public async runDevkitsScript(): Promise<string> {
38+
try {
39+
const workspaceFolder = vscode.workspace.getWorkspaceFolder(
40+
this.workspaceRoot
41+
);
42+
if (!workspaceFolder) {
43+
throw new Error("No workspace folder found");
44+
}
45+
46+
const toolsPath = idfConf.readParameter(
47+
"idf.toolsPath",
48+
this.workspaceRoot
49+
) as string;
50+
const openOCDManager = OpenOCDManager.init();
51+
const openOCDVersion = await openOCDManager.version();
52+
53+
if (!toolsPath || !openOCDVersion) {
54+
throw new Error("Could not get toolsPath or OpenOCD version");
55+
}
56+
57+
const scriptPath = join(
58+
toolsPath,
59+
"tools",
60+
"openocd-esp32",
61+
openOCDVersion,
62+
"openocd-esp32",
63+
"share",
64+
"openocd",
65+
"espressif",
66+
"tools",
67+
"esp_detect_config.py"
68+
);
69+
70+
const openOcdScriptsPath = await getOpenOcdScripts(this.workspaceRoot);
71+
if (!openOcdScriptsPath) {
72+
throw new Error("Could not get OpenOCD scripts path");
73+
}
74+
75+
const espConfigPath = join(openOcdScriptsPath, "esp-config.json");
76+
77+
const notificationMode = idfConf.readParameter(
78+
"idf.notificationMode",
79+
this.workspaceRoot
80+
) as string;
81+
82+
const ProgressLocation =
83+
notificationMode === idfConf.NotificationMode.All ||
84+
notificationMode === idfConf.NotificationMode.Notifications
85+
? vscode.ProgressLocation.Notification
86+
: vscode.ProgressLocation.Window;
87+
88+
const pythonBinPath = await getVirtualEnvPythonPath(this.workspaceRoot);
89+
const modifiedEnv = await appendIdfAndToolsToPath(this.workspaceRoot);
90+
91+
OutputChannel.init();
92+
OutputChannel.appendLine(
93+
"Running ESP Detect Config...",
94+
"ESP Detect Config"
95+
);
96+
OutputChannel.show();
97+
98+
return await vscode.window.withProgress(
99+
{
100+
cancellable: true,
101+
location: ProgressLocation,
102+
title: "ESP-IDF: Running ESP Detect Config",
103+
},
104+
async (
105+
progress: vscode.Progress<{ message: string; increment: number }>,
106+
cancelToken: vscode.CancellationToken
107+
) => {
108+
try {
109+
const result = await execChildProcess(
110+
pythonBinPath,
111+
[scriptPath, "--esp-config", espConfigPath],
112+
this.workspaceRoot.fsPath,
113+
OutputChannel.init(),
114+
{ env: modifiedEnv },
115+
cancelToken
116+
);
117+
118+
OutputChannel.appendLine(result, "ESP Detect Config");
119+
OutputChannel.show();
120+
vscode.window.showInformationMessage("ESP Detect Config completed");
121+
return result;
122+
} catch (error) {
123+
const msg = error.message
124+
? error.message
125+
: "Error running ESP Detect Config";
126+
Logger.errorNotify(msg, error, "DevkitsCommand");
127+
OutputChannel.appendLine(msg, "ESP Detect Config");
128+
OutputChannel.show();
129+
throw error;
130+
}
131+
}
132+
);
133+
} catch (error) {
134+
const msg = error.message
135+
? error.message
136+
: "Error running ESP Detect Config";
137+
Logger.errorNotify(msg, error, "DevkitsCommand");
138+
OutputChannel.appendLine(msg, "ESP Detect Config");
139+
OutputChannel.show();
140+
}
141+
}
142+
143+
public async getScriptPath(): Promise<string | null> {
144+
try {
145+
const toolsPath = idfConf.readParameter(
146+
"idf.toolsPath",
147+
this.workspaceRoot
148+
) as string;
149+
const openOCDManager = OpenOCDManager.init();
150+
const openOCDVersion = await openOCDManager.version();
151+
152+
if (!toolsPath || !openOCDVersion) {
153+
return null;
154+
}
155+
156+
const scriptPath = join(
157+
toolsPath,
158+
"tools",
159+
"openocd-esp32",
160+
openOCDVersion,
161+
"openocd-esp32",
162+
"share",
163+
"openocd",
164+
"espressif",
165+
"tools",
166+
"esp_detect_config.py"
167+
);
168+
169+
return fs.existsSync(scriptPath) ? scriptPath : null;
170+
} catch (error) {
171+
return null;
172+
}
173+
}
174+
}

0 commit comments

Comments
 (0)