Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VSC-1575] Remove port validation for Jtag; Fix timing bug #1413

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
18 changes: 18 additions & 0 deletions src/espIdf/openOcd/tcl/tclClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ export class TCLClient extends EventEmitter {
});
}

// Verify if OpenOCD is ready to receive commands
public async verifyOpenOCDReady(): Promise<boolean> {
return new Promise<boolean>((resolve) => {
const timeout = setTimeout(() => {
this.removeAllListeners("response");
resolve(false);
}, 5000);

this.once("response", (data) => {
clearTimeout(timeout);
this.removeAllListeners("response");
resolve(true);
});

this.sendCommand("echo ready");
});
}

public sendCommandWithCapture(command: string) {
setTimeout(() => {
return this.sendCommand(`capture "${command}"`);
Expand Down
23 changes: 19 additions & 4 deletions src/espIdf/unitTest/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,18 @@ export async function buildFlashTestApp(
unitTestAppDirPath: Uri,
cancelToken: CancellationToken
) {
let flashType = readParameter("idf.flashType", unitTestAppDirPath) as ESP.FlashType;
let flashType = readParameter(
"idf.flashType",
unitTestAppDirPath
) as ESP.FlashType;
if (!flashType) {
flashType = ESP.FlashType.UART;
}
let canContinue = await buildCommand(unitTestAppDirPath, cancelToken, flashType);
let canContinue = await buildCommand(
unitTestAppDirPath,
cancelToken,
flashType
);
if (!canContinue) {
return;
}
Expand All @@ -169,8 +176,16 @@ export async function buildFlashTestApp(
return;
}
const flashBaudRate = readParameter("idf.flashBaudRate", unitTestAppDirPath);
const idfPathDir = readParameter("idf.espIdfPath", unitTestAppDirPath) as string;
const canFlash = await verifyCanFlash(flashBaudRate, port, unitTestAppDirPath);
const idfPathDir = readParameter(
"idf.espIdfPath",
unitTestAppDirPath
) as string;
const canFlash = await verifyCanFlash(
flashBaudRate,
port,
flashType,
unitTestAppDirPath
);
if (!canFlash) {
return;
}
Expand Down
7 changes: 6 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4214,7 +4214,12 @@ async function startFlashing(
if (IDFMonitor.terminal) {
IDFMonitor.terminal.sendText(ESP.CTRL_RBRACKET);
}
const canFlash = await verifyCanFlash(flashBaudRate, port, workspaceRoot);
const canFlash = await verifyCanFlash(
flashBaudRate,
port,
flashType,
workspaceRoot
);
if (!canFlash) {
return;
}
Expand Down
25 changes: 14 additions & 11 deletions src/flash/flashCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { OutputChannel } from "../logger/outputChannel";
export async function verifyCanFlash(
flashBaudRate: string,
port: string,
flashType: ESP.FlashType,
workspace: vscode.Uri
) {
let continueFlag = true;
Expand Down Expand Up @@ -69,20 +70,22 @@ export async function verifyCanFlash(
OutputChannel.appendLineAndShow(errStr, "Flash");
return Logger.warnNotify(errStr);
}
if (!port) {
try {
await vscode.commands.executeCommand("espIdf.selectPort");
} catch (error) {
const errStr = "Unable to execute the command: espIdf.selectPort";
if(flashType !== "JTAG") {
if (!port) {
try {
await vscode.commands.executeCommand("espIdf.selectPort");
} catch (error) {
const errStr = "Unable to execute the command: espIdf.selectPort";
OutputChannel.show();
OutputChannel.appendLineAndShow(errStr, "Flash");
Logger.error(errStr, error, "verifyCanFlash selectPort");
}
const errStr = "Select a port before flashing";
OutputChannel.show();
OutputChannel.appendLineAndShow(errStr, "Flash");
Logger.error(errStr, error, "verifyCanFlash selectPort");
return Logger.errorNotify(errStr, new Error("NOT_SELECTED_PORT"),
"flashCmd verifyCanFlash select port");
}
const errStr = "Select a port before flashing";
OutputChannel.show();
OutputChannel.appendLineAndShow(errStr, "Flash");
return Logger.errorNotify(errStr, new Error("NOT_SELECTED_PORT"),
"flashCmd verifyCanFlash select port");
}
if (!flashBaudRate) {
const errStr = "Select a baud rate before flashing";
Expand Down
30 changes: 20 additions & 10 deletions src/flash/jtagCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* Project: ESP-IDF VSCode Extension
* File Created: Thursday, 6th May 2021 2:29:08 pm
* Copyright 2021 Espressif Systems (Shanghai) CO LTD
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -35,19 +35,30 @@ export async function jtagFlashCommand(workspace: Uri) {
OutputChannel.appendLineAndShow(errStr, "Flash");
return Logger.warnNotify(errStr);
}
FlashTask.isFlashing = true;
const host = readParameter("openocd.tcl.host", workspace);
const port = readParameter("openocd.tcl.port", workspace);
const client = new TCLClient({ host, port });

// Add verification step before flashing
let isReady = false;
for (let attempt = 0; attempt < 3; attempt++) {
isReady = await client.verifyOpenOCDReady();
if (isReady) break;
await new Promise((resolve) => setTimeout(resolve, 1000));
}
if (!isReady) {
const errStr = "OpenOCD is not ready to accept commands. Please try again.";
OutputChannel.appendLineAndShow(errStr, "JTAG Flash");
return Logger.warnNotify(errStr);
}

FlashTask.isFlashing = true;
const jtag = new JTAGFlash(client);
const forceUNIXPathSeparator = readParameter(
"openocd.jtag.command.force_unix_path_separator",
workspace
);
let buildPath = readParameter(
"idf.buildPath",
workspace
) as string;
let buildPath = readParameter("idf.buildPath", workspace) as string;
const customTask = new CustomTask(workspace);
if (forceUNIXPathSeparator === true) {
buildPath = buildPath.replace(/\\/g, "/");
Expand All @@ -70,8 +81,7 @@ export async function jtagFlashCommand(workspace: Uri) {
} catch (msg) {
OpenOCDManager.init().showOutputChannel(true);
OutputChannel.appendLine(msg, "Flash");
Logger.errorNotify(msg, new Error("JTAG_FLASH_FAILED"),
"jtagFlashCommand");
Logger.errorNotify(msg, new Error("JTAG_FLASH_FAILED"), "jtagFlashCommand");
continueFlag = false;
}
FlashTask.isFlashing = false;
Expand Down