8000 Support debugger for az3166 (#302) · Netoperz/vscode-arduino@469122d · GitHub
[go: up one dir, main page]

Skip to content

Commit 469122d

Browse files
authored
Support debugger for az3166 (microsoft#302)
* fix some debug issues: 1. findFile resolve multiple openocd.exe 2. openocd has two possible script folders : ../scripts and ../share/openocd/scripts 3. if output is undefined, the elf path is not right. * revert unexpected change * fix a issue when source file is change but elf is not compiled again. * fix errors on mac * fix tslint error
1 parent 906b7f4 commit 469122d

File tree

7 files changed

+41
-23
lines changed

7 files changed

+41
-23
lines changed

misc/openOCDMapping.json

Lines changed: 7 additions & 1 deletion
< 10000 td data-grid-cell-id="diff-2aac6f98cb7196f7f24710dbe1729c3c03eb7dcea443800829d8b3f4cf6ff842-10-14-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,11 @@
88
"board": "arduino:samd:mzero_bl",
99
"interface": "interface/cmsis-dap.cfg",
1010
"target": "target/at91samdXX.cfg"
11+
},
12+
{
13+
"board": "AZ3166:stm32f4:MXCHIP_AZ3166",
14+
"interface": "interface/stlink-v2-1.cfg",
15+
"target": "target/stm32f4x.cfg"
1116
}
12-
]
17+
]
18+

misc/usbmapping.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
"package": "arduino",
1515
"architecture": "samd",
1616
"id": "edison"
17+
}, {
18+
"vid": "03eb",
19+
"pid": "2111",
20+
"name": "Arduino M0 Pro (Programming USB Port)",
21+
"package": "arduino",
22+
"architecture": "samd",
23+
"id": "mzero_pro_bl_dbg"
1724
}, {
1825
"vid": "2a03",
1926
"pid": "804f",

src/common/sys/darwin.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@ export function validateArduinoPath(arduinoPath: string): boolean {
2626
}
2727

2828
export function findFile(fileName: string, cwd: string): string {
29-
let result;
29+
let pathString;
3030
try {
31-
result = childProcess.execSync("find ${cwd} -name ${fileName} -type f", { encoding: "utf8" });
32-
result = path.resolve(result).trim();
31+
pathString = childProcess.execSync(`find ${cwd} -name ${fileName} -type f`, { encoding: "utf8" }).split("\n");
3332

34-
if (fileExistsSync(result)) {
35-
result = path.normalize(result);
33+
if (pathString && pathString[0] && fileExistsSync(pathString[0].trim())) {
34+
pathString = path.normalize(pathString[0].trim());
35+
} else {
36+
pathString = null;
3637
}
3738
} catch (ex) {
3839
// Ignore the errors.
3940
}
40-
return result;
41+
return pathString;
4142
}

src/common/sys/linux.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ export function validateArduinoPath(arduinoPath: string): boolean {
2929
export function findFile(fileName: string, cwd: string): string {
3030
let pathString;
3131
try {
32-
pathString = childProcess.execSync("find ${cwd} -name ${fileName} -type f", { encoding: "utf8" });
33-
pathString = path.resolve(pathString).trim();
32+
pathString = childProcess.execSync(`find ${cwd} -name ${fileName} -type f`, { encoding: "utf8" }).split("\n");
3433

35-
if (fileExistsSync(pathString)) {
36-
pathString = path.normalize(pathString);
34+
if (pathString && pathString[0] && fileExistsSync(pathString[0].trim())) {
35+
pathString = path.normalize(pathString[0].trim());
36+
} else {
37+
pathString = null;
3738
}
3839
} catch (ex) {
3940
// Ignore the errors.

src/common/sys/win32.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ export function findFile(fileName: string, cwd: string): string {
3232
let result;
3333
try {
3434
let pathString;
35-
pathString = childProcess.execSync(`dir ${fileName} /S /B`, {encoding: "utf8", cwd});
36-
pathString = path.resolve(pathString).trim();
37-
38-
if (fileExistsSync(pathString)) {
39-
result = path.normalize(pathString);
35+
pathString = childProcess.execSync(`dir ${fileName} /S /B`, {encoding: "utf8", cwd}).split("\n");
36+
if (pathString && pathString[0] && fileExistsSync(pathString[0].trim())) {
37+
result = path.normalize(pathString[0].trim());
4038
}
4139
} catch (ex) {
4240
// Ignore the errors.

src/debug/configurator.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ export class DebugConfigurator {
7575
const dc = DeviceContext.getIntance();
7676

7777
if (!config.program || config.program === "${file}") {
78-
config.program = path.join(vscode.workspace.rootPath, dc.output || "output", `${path.basename(dc.sketch)}.elf`);
79-
if (!util.fileExistsSync(config.program)) {
80-
await this._arduinoApp.verify();
81-
}
78+
dc.output = dc.output || "output";
79+
config.program = path.join(vscode.workspace.rootPath, dc.output, `${path.basename(dc.sketch)}.elf`);
80+
// always compile elf to make sure debug the right elf
81+
await this._arduinoApp.verify();
8282

8383
config.program = config.program.replace(/\\/g, "/");
8484

@@ -110,6 +110,7 @@ export class DebugConfigurator {
110110
if (!util.fileExistsSync(config.debugServerPath)) {
111111
vscode.window.showErrorMessage("Cannot find the OpenOCD from the launch.json debugServerPath property." +
112112
"Please input the right path of OpenOCD");
113+
return;
113114
}
114115
this.resolveOpenOcdOptions(config);
115116
}
@@ -121,9 +122,13 @@ export class DebugConfigurator {
121122
const boardOpenOcdConfig = baordSettings.find((board) => board.board === this._boardManager.currentBoard.key);
122123
if (boardOpenOcdConfig) {
123124
const debugServerPath = config.debugServerPath;
124-
const scriptsFolder = path.join(path.dirname(debugServerPath), "../share/openocd/scripts/");
125+
let scriptsFolder = path.join(path.dirname(debugServerPath), "../scripts/");
126+
if (!util.directoryExistsSync(scriptsFolder)) {
127+
scriptsFolder = path.join(path.dirname(debugServerPath), "../share/openocd/scripts/");
128+
}
129+
125130
/* tslint:disable:max-line-length*/
126-
config.debugServerArgs = `-s ${scriptsFolder} -f ${path.join(scriptsFolder, boardOpenOcdConfig.interface)} -f ${path.join(scriptsFolder, boardOpenOcdConfig.target)}`;
131+
config.debugServerArgs = `-s ${scriptsFolder} -f ${boardOpenOcdConfig.interface} -f ${boardOpenOcdConfig.target}`;
127132
}
128133
}
129134
}

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export async function activate(context: vscode.ExtensionContext) {
158158
const arduinoConfigurator = new DebugConfigurator(context.extensionPath, arduinoApp, arduinoSettings, boardManager);
159159
// Arduino debugger
160160
context.subscriptions.push(registerCommand("arduino.debug.startSession", async (config) => {
161-
if (status.debug) {
161+
if (!status.debug) {
162162
status.debug = "debug";
163163
try {
164164
await arduinoConfigurator.run(config);

0 commit comments

Comments
 (0)
0