Skip to content

Commit 38eb846

Browse files
committed
Fix for #1114, remove global variables from ST
1 parent a872fa2 commit 38eb846

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

src/frontend/configprovider.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,22 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
6060
switch (os.platform()) {
6161
case 'darwin':
6262
Object.assign(config, config.osx);
63-
delete config.osx;
6463
break;
6564
case 'win32':
6665
Object.assign(config, config.windows);
67-
delete config.windows;
6866
break;
6967
case 'linux':
7068
Object.assign(config, config.linux);
71-
delete config.linux;
7269
break;
7370
default:
7471
console.log(`Unknown platform ${os.platform()}`);
7572
break;
7673
}
74+
// Delete all OS props instead just the current one. See Issue#1114
75+
delete config.osx;
76+
delete config.windows;
77+
delete config.linux;
78+
7779
this.sanitizeChainedConfigs(config);
7880
if (config.debugger_args && !config.debuggerArgs) {
7981
config.debuggerArgs = config.debugger_args;
@@ -192,9 +194,11 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
192194
this.setOsSpecficConfigSetting(config, 'toolchainPath', 'armToolchainPath');
193195

194196
if (!config.toolchainPath) {
195-
// Special case to auto-resolve GCC toolchain for STM32CubeIDE users
196197
if (!config.armToolchainPath && config.servertype === 'stlink') {
197-
config.armToolchainPath = STLinkServerController.getArmToolchainPath();
198+
// Special case to auto-resolve GCC toolchain for STM32CubeIDE users. Doesn't quite work
199+
// if you are using WSL or remote debug. It will be re-calcutate later anyways in the debug adapter
200+
const stController = new STLinkServerController();
201+
config.armToolchainPath = stController.getArmToolchainPath();
198202
config.toolchainPath = config.armToolchainPath;
199203
}
200204
}
@@ -467,11 +471,14 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
467471
propName = propName || dstName;
468472
const settings = vscode.workspace.getConfiguration('cortex-debug');
469473
const obj = settings[propName];
470-
if (obj) {
474+
if ((obj !== undefined) && (obj !== null)) {
471475
if (typeof obj === 'object') {
472476
const osName = os.platform();
473477
const osOverride = ((osName === 'win32') ? 'windows' : (osName === 'darwin') ? 'osx' : 'linux');
474-
config[dstName] = obj[osOverride] || '';
478+
const val = obj[osOverride];
479+
if (val !== undefined) {
480+
config[dstName] = obj[osOverride];
481+
}
475482
} else {
476483
config[dstName] = obj;
477484
}

src/stlink.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ function get_ST_DIR(): string {
4444
}
4545

4646
// Path of the top-level STM32CubeIDE installation directory, os-dependant
47+
/*
4748
const ST_DIR = get_ST_DIR();
4849
const ST_CLT_ISTALL_DIR = get_CLT_INSTALL_DIR();
50+
*/
4951
const SERVER_EXECUTABLE_NAME = os.platform() === 'win32' ? 'ST-LINK_gdbserver.exe' : 'ST-LINK_gdbserver';
5052

5153
const STMCUBEIDE_REGEX = /^STM32CubeIDE_(.+)$/i;
@@ -92,26 +94,27 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
9294
public readonly name: string = 'ST-LINK';
9395
// STLink uses 4 ports per core. Not sure what 3rd and 4th are for but reserve them anyways
9496
public readonly portsNeeded: string[] = ['gdbPort', 'swoPort', 'gap1', 'gap2'];
95-
97+
public readonly ST_DIR = get_ST_DIR();
98+
public readonly ST_CLT_ISTALL_DIR = get_CLT_INSTALL_DIR();
9699
private args: ConfigurationArguments;
97100
private ports: { [name: string]: number };
98101
private targetProcessor: number = 0;
99102

100-
public static getSTMCubeIdeDir(): string {
103+
public getSTMCubeIdeDir(): string {
101104
switch (os.platform()) {
102105
case 'darwin':
103-
return ST_DIR;
106+
return this.ST_DIR;
104107
case 'linux':
105-
return resolveCubePath([ST_DIR], STMCUBEIDE_REGEX, '');
108+
return resolveCubePath([this.ST_DIR], STMCUBEIDE_REGEX, '');
106109
default:
107-
return resolveCubePath([ST_DIR], STMCUBEIDE_REGEX, 'STM32CubeIDE');
110+
return resolveCubePath([this.ST_DIR], STMCUBEIDE_REGEX, 'STM32CubeIDE');
108111
}
109112
}
110113

111-
public static getArmToolchainPath(): string {
114+
public getArmToolchainPath(): string {
112115
// Try to resolve gcc location
113-
if (ST_CLT_ISTALL_DIR) {
114-
const p = path.join(ST_CLT_ISTALL_DIR, 'GNU-tools-for-STM32', 'bin');
116+
if (this.ST_CLT_ISTALL_DIR) {
117+
const p = path.join(this.ST_CLT_ISTALL_DIR, 'GNU-tools-for-STM32', 'bin');
115118
if (fs.existsSync(p)) {
116119
return p;
117120
}
@@ -202,14 +205,14 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
202205
if (this.args.serverpath) {
203206
return this.args.serverpath;
204207
} else {
205-
if (ST_CLT_ISTALL_DIR) {
206-
const p = path.join(ST_CLT_ISTALL_DIR, 'STLink-gdb-server', 'bin', SERVER_EXECUTABLE_NAME);
208+
if (this.ST_CLT_ISTALL_DIR) {
209+
const p = path.join(this.ST_CLT_ISTALL_DIR, 'STLink-gdb-server', 'bin', SERVER_EXECUTABLE_NAME);
207210
if (fs.existsSync(p)) {
208211
this.args.serverpath = p;
209212
return p;
210213
}
211214
}
212-
return resolveCubePath([STLinkServerController.getSTMCubeIdeDir(), 'plugins'], GDB_SERVER_REGEX, 'tools/bin', SERVER_EXECUTABLE_NAME);
215+
return resolveCubePath([this.getSTMCubeIdeDir(), 'plugins'], GDB_SERVER_REGEX, 'tools/bin', SERVER_EXECUTABLE_NAME);
213216
}
214217
}
215218

@@ -227,14 +230,14 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
227230
if (stm32cubeprogrammer) {
228231
serverargs.push('-cp', stm32cubeprogrammer);
229232
} else {
230-
if (ST_CLT_ISTALL_DIR) {
231-
const p = path.join(ST_CLT_ISTALL_DIR, 'STM32CubeProgrammer', 'bin');
233+
if (this.ST_CLT_ISTALL_DIR) {
234+
const p = path.join(this.ST_CLT_ISTALL_DIR, 'STM32CubeProgrammer', 'bin');
232235
if (fs.existsSync(p)) {
233236
stm32cubeprogrammer = p;
234237
}
235238
}
236239
if (!stm32cubeprogrammer) {
237-
stm32cubeprogrammer = resolveCubePath([STLinkServerController.getSTMCubeIdeDir(), 'plugins'], PROG_REGEX, 'tools/bin');
240+
stm32cubeprogrammer = resolveCubePath([this.getSTMCubeIdeDir(), 'plugins'], PROG_REGEX, 'tools/bin');
238241
// Fallback to standalone programmer if no STMCube32IDE is installed:
239242
if (!stm32cubeprogrammer) {
240243
if (os.platform() === 'win32') {

0 commit comments

Comments
 (0)