Skip to content

Commit 41ada8b

Browse files
committed
feat(stlink): add SWO support
1 parent 722e4c5 commit 41ada8b

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

src/frontend/configprovider.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -589,12 +589,6 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
589589
return 'The ST-Link GDB Server does not have support for the rtos option.';
590590
}
591591

592-
if (config.swoConfig.enabled && config.swoConfig.source === 'probe') {
593-
vscode.window.showWarningMessage('SWO support is not available from the probe when using the ST-Link GDB server. Disabling SWO.');
594-
config.swoConfig = { enabled: false, ports: [], cpuFrequency: 0, swoFrequency: 0 };
595-
config.graphConfig = [];
596-
}
597-
598592
return null;
599593
}
600594

src/stlink.ts

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,34 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
134134
return commands;
135135
}
136136

137-
public swoAndRTTCommands(): string[] {
138-
return [];
137+
public swoAndRTTCommands(): string[]{
138+
const commands = [];
139+
if (this.args.swoConfig.enabled) {
140+
const swocommands = this.SWOConfigurationCommands();
141+
commands.push(...swocommands);
142+
}
143+
return commands;
144+
}
145+
146+
private SWOConfigurationCommands(): string[] {
147+
const { decoders, swoFrequency, cpuFrequency } = this.args.swoConfig;
148+
const portMask = '0x' + calculatePortMask(decoders).toString(16);
149+
const ratio = Math.floor(cpuFrequency / swoFrequency) - 1;
150+
151+
const commands = [
152+
'EnableITMAccess',
153+
`BaseSWOSetup ${ratio}`,
154+
'SetITMId 1',
155+
'ITMDWTTransferEnable',
156+
'DisableITMPorts 0xFFFFFFFF',
157+
`EnableITMPorts ${portMask}`,
158+
'EnableDWTSync',
159+
this.args.swoConfig.profile ? 'EnablePCSample' : 'DisablePCSample',
160+
'ITMSyncEnable',
161+
'ITMGlobalEnable'
162+
];
163+
164+
return commands.map((c) => `interpreter-exec console "${c}"`);
139165
}
140166

141167
public serverExecutable(): string {
@@ -176,6 +202,17 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
176202
serverargs.push('--swd');
177203
}
178204

205+
if (this.args.swoConfig.enabled)
206+
{
207+
const swoport = this.ports['swoPort'];
208+
serverargs.push('--swo-port', swoport.toString());
209+
210+
const { cpuFrequency, swoFrequency } = this.args.swoConfig;
211+
212+
serverargs.push('--cpu-clock', cpuFrequency.toString());
213+
serverargs.push('--swo-clock-div', Math.floor(cpuFrequency / swoFrequency).toString());
214+
}
215+
179216
if (this.args.serialNumber) {
180217
serverargs.push('--serial-number', this.args.serialNumber);
181218
}
@@ -196,8 +233,16 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
196233
}
197234

198235
public serverLaunchStarted(): void {}
199-
public serverLaunchCompleted(): void {}
200-
236+
public serverLaunchCompleted(): void {
237+
if (this.args.swoConfig.enabled) {
238+
this.emit('event', new SWOConfigureEvent({
239+
type: 'socket',
240+
args: this.args,
241+
port: this.ports['swoPort'].toString()
242+
}));
243+
}
244+
}
245+
201246
public debuggerLaunchStarted(): void {}
202247
public debuggerLaunchCompleted(): void {}
203248
}

0 commit comments

Comments
 (0)