Skip to content

Commit

Permalink
Changed how the resolveCubePath function works as `fs.readdirSync(<pa…
Browse files Browse the repository at this point in the history
…th>, { withFileTypes: true })` only works with node runtimes of v10.10+ - while the debugadapter is using a node v8 runtime.

Also fixed the launch.json for the debug server.
  • Loading branch information
Marus committed Jan 18, 2021
1 parent 3714742 commit ded617a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"type": "node",
"request": "launch",
"runtimeArgs": [ "--nolazy" ],
"program": "${workspaceRoot}/src/gdb.ts",
"program": "${workspaceRoot}/dist/debugadapter.js",
"stopOnEntry": false,
"args": [ "--server=4711" ],
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/dist/*js"
"${workspaceRoot}/dist/*.js"
],
"cwd": "${workspaceRoot}"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1619,5 +1619,5 @@
"compile": "webpack --mode development",
"test-compile": "tsc -p ./"
},
"version": "0.3.7"
"version": "0.3.8-pre2"
}
75 changes: 29 additions & 46 deletions src/stlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import { EventEmitter } from 'events';


// Path of the top-level STM32CubeIDE installation directory, os-dependant
const ST_DIR = os.platform() === 'win32' ? 'c:\\ST' : '/opt/st';
const ST_DIR = (
os.platform() === 'win32' ? 'c:\\ST' :
os.platform() === 'darwin' ? '/Applications/STM32CubeIDE.app/Contents/Eclipse' : '/opt/st'
);

const SERVER_EXECUTABLE_NAME = (
os.platform() === 'win32' ? 'ST-LINK_gdbserver.exe' : 'ST-LINK_gdbserver'
)

const STMCUBEIDE_REGEX = /^STM32CubeIDE_(.+)$/;
// Example: c:\ST\STM32CubeIDE_1.5.0\
Expand All @@ -28,10 +35,14 @@ function resolveCubePath(dirSegments, regex, suffix, executable = '')
let dir = path.join(...dirSegments);
let resolvedDir;
try {
for (let subDir of fs.readdirSync(dir, { withFileTypes: true }).sort()) {
if (!subDir.isDirectory())
for (let subDir of fs.readdirSync(dir).sort()) {
let fullPath = path.join(dir, subDir);
let stats = fs.statSync(fullPath)
if (!stats.isDirectory()) {
continue;
let match = subDir.name.match(regex);
}

let match = subDir.match(regex);
if (match) {
let fullPath = path.join(dir, match[0], suffix, executable);
if (fs.existsSync(fullPath)) {
Expand All @@ -53,12 +64,19 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon

private args: ConfigurationArguments;
private ports: { [name: string]: number };
private static readonly stmCubeIdeDir: string = resolveCubePath([ST_DIR], STMCUBEIDE_REGEX, 'STM32CubeIDE');


public static getSTMCubeIdeDir(): string {
if (os.platform() == 'darwin') {
return ST_DIR;
} else {
return resolveCubePath([ST_DIR], STMCUBEIDE_REGEX, 'STM32CubeIDE');
}
}

public static getArmToolchainPath(): string {
// Try to resolve gcc location
return resolveCubePath([this.stmCubeIdeDir, 'plugins'], GCC_REGEX, 'tools/bin');
return resolveCubePath([this.getSTMCubeIdeDir(), 'plugins'], GCC_REGEX, 'tools/bin');
}

constructor() {
Expand Down Expand Up @@ -110,41 +128,11 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
}

public swoCommands(): string[] {
const commands = [];
// if (this.args.swoConfig.enabled && this.args.swoConfig.source !== 'probe') {
// const swocommands = this.SWOConfigurationCommands();
// commands.push(...swocommands);
// }
return commands;
return [];
}

// private SWOConfigurationCommands(): string[] {
// const portMask = '0x' + calculatePortMask(this.args.swoConfig.decoders).toString(16);
// const swoFrequency = this.args.swoConfig.swoFrequency;
// const cpuFrequency = this.args.swoConfig.cpuFrequency;

// const ratio = Math.floor(cpuFrequency / swoFrequency) - 1;

// const commands: string[] = [
// 'EnableITMAccess',
// `BaseSWOSetup ${ratio}`,
// 'SetITMId 1',
// 'ITMDWTTransferEnable',
// 'DisableITMPorts 0xFFFFFFFF',
// `EnableITMPorts ${portMask}`,
// 'EnableDWTSync',
// 'ITMSyncEnable',
// 'ITMGlobalEnable'
// ];

// commands.push(this.args.swoConfig.profile ? 'EnablePCSample' : 'DisablePCSample');

// return commands.map((c) => `interpreter-exec console "${c}"`);
// }

public serverExecutable(): string {
if (this.args.serverpath) { return this.args.serverpath; }
else { return resolveCubePath([STLinkServerController.stmCubeIdeDir, 'plugins'], GDB_REGEX, 'tools/bin', os.platform() === 'win32' ? 'ST-LINK_gdbserver.exe' : 'ST-LINK_gdbserver') }
else { return resolveCubePath([STLinkServerController.getSTMCubeIdeDir(), 'plugins'], GDB_REGEX, 'tools/bin', SERVER_EXECUTABLE_NAME) }
}

public serverArguments(): string[] {
Expand All @@ -156,11 +144,13 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
if (this.args.stm32cubeprogrammer) {
serverargs.push('-cp', this.args.stm32cubeprogrammer);
} else {
let stm32cubeprogrammer = resolveCubePath([STLinkServerController.stmCubeIdeDir, 'plugins'], PROG_REGEX, 'tools/bin');
let stm32cubeprogrammer = resolveCubePath([STLinkServerController.getSTMCubeIdeDir(), 'plugins'], PROG_REGEX, 'tools/bin');
// Fallback to standalone programmer if no STMCube32IDE is installed:
if (!stm32cubeprogrammer) {
if (os.platform() === 'win32') {
stm32cubeprogrammer = process.env.ProgramFiles + '\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin';
} else if (os.platform() === 'darwin') {
stm32cubeprogrammer = '/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin';
} else {
stm32cubeprogrammer = '/usr/local/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin';
}
Expand Down Expand Up @@ -189,13 +179,6 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon

public serverLaunchStarted(): void {}
public serverLaunchCompleted(): void {
// if (this.args.swoConfig.enabled && this.args.swoConfig.source !== 'probe') {
// this.emit('event', new SWOConfigureEvent({
// type: 'serial',
// device: this.args.swoConfig.source,
// baudRate: this.args.swoConfig.swoFrequency
// }));
// }
}

public debuggerLaunchStarted(): void {}
Expand Down

0 comments on commit ded617a

Please sign in to comment.