Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/espIdf/hints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class ErrorHintProvider
let openOcdHintsPath: string | null = null;
try {
const openOCDManager = OpenOCDManager.init();
const openOCDVersion = await openOCDManager.version();
const openOCDVersion = await openOCDManager.version(true);
if (toolsPath && openOCDVersion) {
openOcdHintsPath = await getOpenOcdHintsYmlPath(
toolsPath,
Expand Down
2 changes: 1 addition & 1 deletion src/espIdf/hints/openocdhint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class OpenOCDErrorMonitor {
try {
// Check OpenOCD version first
const openOCDManager = OpenOCDManager.init();
const version = await openOCDManager.version();
const version = await openOCDManager.version(true);

if (!version) {
Logger.info(
Expand Down
3 changes: 2 additions & 1 deletion src/espIdf/openOcd/openOcdManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class OpenOCDManager extends EventEmitter {
this.configureServerWithDefaultParam();
}

public async version(): Promise<string> {
public async version(silent: boolean = false): Promise<string> {
const modifiedEnv = await appendIdfAndToolsToPath(this.workspace);
const openOcdPath = await isBinInPath("openocd", modifiedEnv, [
"openocd-esp32",
Expand All @@ -70,6 +70,7 @@ export class OpenOCDManager extends EventEmitter {
const resp = await sspawn(openOcdPath, ["--version"], {
cwd: this.workspace.fsPath,
env: modifiedEnv,
silent,
});
const versionString = resp.toString();
const match = versionString.match(/v\d+\.\d+\.\d+\-\S*/gi);
Expand Down
12 changes: 6 additions & 6 deletions src/espIdf/setTarget/DevkitsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class DevkitsCommand {
this.workspaceRoot = workspaceRoot;
}

public async runDevkitsScript(): Promise<string> {
public async runDevkitsScript(openOCDVersion: string): Promise<string> {
try {
const workspaceFolder = vscode.workspace.getWorkspaceFolder(
this.workspaceRoot
Expand All @@ -47,8 +47,6 @@ export class DevkitsCommand {
"idf.toolsPath",
this.workspaceRoot
) as string;
const openOCDManager = OpenOCDManager.init();
const openOCDVersion = await openOCDManager.version();

if (!toolsPath || !openOCDVersion) {
throw new Error("Could not get toolsPath or OpenOCD version");
Expand Down Expand Up @@ -88,6 +86,10 @@ export class DevkitsCommand {
const pythonBinPath = await getVirtualEnvPythonPath(this.workspaceRoot);
const modifiedEnv = await appendIdfAndToolsToPath(this.workspaceRoot);

// Remove OPENOCD_USB_ADAPTER_LOCATION from environment during device detection
// to allow scanning all available devices, not just the one at the configured location
delete modifiedEnv.OPENOCD_USB_ADAPTER_LOCATION;

OutputChannel.init();
OutputChannel.appendLine(
"Running ESP Detect Config...",
Expand Down Expand Up @@ -140,14 +142,12 @@ export class DevkitsCommand {
}
}

public async getScriptPath(): Promise<string | null> {
public async getScriptPath(openOCDVersion: string): Promise<string | null> {
try {
const toolsPath = idfConf.readParameter(
"idf.toolsPath",
this.workspaceRoot
) as string;
const openOCDManager = OpenOCDManager.init();
const openOCDVersion = await openOCDManager.version();

if (!toolsPath || !openOCDVersion) {
return null;
Expand Down
39 changes: 29 additions & 10 deletions src/espIdf/setTarget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import { Logger } from "../../logger/logger";
import { OutputChannel } from "../../logger/outputChannel";
import { selectOpenOcdConfigFiles } from "../openOcd/boardConfiguration";
import { OpenOCDManager } from "../openOcd/openOcdManager";
import { getTargetsFromEspIdf, IdfTarget } from "./getTargets";
import { setTargetInIDF } from "./setTargetInIdf";
import { updateCurrentProfileIdfTarget } from "../../project-conf";
Expand Down Expand Up @@ -95,11 +96,13 @@ export async function setIdfTarget(

if (!isDebugging) {
try {
const openOCDManager = OpenOCDManager.init();
const openOCDVersion = await openOCDManager.version();
const devkitsCmd = new DevkitsCommand(workspaceFolder.uri);
const scriptPath = await devkitsCmd.getScriptPath();
const scriptPath = await devkitsCmd.getScriptPath(openOCDVersion);

if (scriptPath) {
const devkitsOutput = await devkitsCmd.runDevkitsScript();
const devkitsOutput = await devkitsCmd.runDevkitsScript(openOCDVersion);
if (devkitsOutput) {
const parsed = JSON.parse(devkitsOutput);
if (parsed && Array.isArray(parsed.boards)) {
Expand Down Expand Up @@ -160,6 +163,13 @@ export async function setIdfTarget(
if (!selectedTarget) {
return;
}
// Create a plain object copy to avoid proxy issues when modifying/deleting properties
const customExtraVarsRead = readParameter(
"idf.customExtraVars",
workspaceFolder
) as { [key: string]: string };
const customExtraVars = { ...customExtraVarsRead };

if (selectedTarget.isConnected && selectedTarget.boardInfo) {
// Directly set OpenOCD configs for connected board
const configFiles = selectedTarget.boardInfo.config_files || [];
Expand All @@ -171,10 +181,6 @@ export async function setIdfTarget(
);
// Store USB location if available
if (selectedTarget.boardInfo.location) {
const customExtraVars = readParameter(
"idf.customExtraVars",
workspaceFolder
) as { [key: string]: string };
const location = selectedTarget.boardInfo.location.replace(
"usb://",
""
Expand All @@ -186,19 +192,32 @@ export async function setIdfTarget(
configurationTarget,
workspaceFolder.uri
);
} else {
// Clear OPENOCD_USB_ADAPTER_LOCATION if no location is available
delete customExtraVars["OPENOCD_USB_ADAPTER_LOCATION"];
await writeParameter(
"idf.customExtraVars",
customExtraVars,
configurationTarget,
workspaceFolder.uri
);
}
} else {
// Clear OPENOCD_USB_ADAPTER_LOCATION when switching to non-connected target
delete customExtraVars["OPENOCD_USB_ADAPTER_LOCATION"];
await writeParameter(
"idf.customExtraVars",
customExtraVars,
configurationTarget,
workspaceFolder.uri
);
await selectOpenOcdConfigFiles(
workspaceFolder.uri,
selectedTarget.idfTarget.target
);
}

await setTargetInIDF(workspaceFolder, selectedTarget.idfTarget);
const customExtraVars = readParameter(
"idf.customExtraVars",
workspaceFolder
) as { [key: string]: string };
customExtraVars["IDF_TARGET"] = selectedTarget.idfTarget.target;
await writeParameter(
"idf.customExtraVars",
Expand Down
Loading