diff --git a/src/espIdf/openOcd/openOcdManager.ts b/src/espIdf/openOcd/openOcdManager.ts index bc92900e7..d28c686e1 100644 --- a/src/espIdf/openOcd/openOcdManager.ts +++ b/src/espIdf/openOcd/openOcdManager.ts @@ -182,18 +182,13 @@ export class OpenOCDManager extends EventEmitter { ); } - const openOcdArgs = []; + const openOcdArgs: string[] = []; const openOcdDebugLevel = idfConf.readParameter( "idf.openOcdDebugLevel", this.workspace ) as string; openOcdArgs.push(`-d${openOcdDebugLevel}`); - openOcdConfigFilesList.forEach((configFile) => { - openOcdArgs.push("-f"); - openOcdArgs.push(configFile); - }); - const addLaunchArgs = idfConf.readParameter( "idf.openOcdLaunchArgs", this.workspace @@ -205,6 +200,16 @@ export class OpenOCDManager extends EventEmitter { }); } + openOcdConfigFilesList.forEach((configFile) => { + const isFileAlreadyInArgs = openOcdArgs.some((arg) => + arg.includes(configFile) + ); + if (!isFileAlreadyInArgs) { + openOcdArgs.push("-f"); + openOcdArgs.push(configFile); + } + }); + this.server = spawn("openocd", openOcdArgs, { cwd: this.workspace.fsPath, env: modifiedEnv, @@ -250,7 +255,8 @@ export class OpenOCDManager extends EventEmitter { if (!signal && code && code !== 0) { Logger.error( `OpenOCD Exit with non-zero error code ${code}`, - new Error("Spawn exit with non-zero" + code), "OpenOCDManager close" + new Error("Spawn exit with non-zero" + code), + "OpenOCDManager close" ); OutputChannel.appendLine( `OpenOCD Exit with non-zero error code ${code}`,