Skip to content

Commit

Permalink
feat(stlink): add SWO support
Browse files Browse the repository at this point in the history
  • Loading branch information
ssimek committed Jan 12, 2025
1 parent 722e4c5 commit 41ada8b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
6 changes: 0 additions & 6 deletions src/frontend/configprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,6 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
return 'The ST-Link GDB Server does not have support for the rtos option.';
}

if (config.swoConfig.enabled && config.swoConfig.source === 'probe') {
vscode.window.showWarningMessage('SWO support is not available from the probe when using the ST-Link GDB server. Disabling SWO.');
config.swoConfig = { enabled: false, ports: [], cpuFrequency: 0, swoFrequency: 0 };
config.graphConfig = [];
}

return null;
}

Expand Down
53 changes: 49 additions & 4 deletions src/stlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,34 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
return commands;
}

public swoAndRTTCommands(): string[] {
return [];
public swoAndRTTCommands(): string[]{
const commands = [];
if (this.args.swoConfig.enabled) {
const swocommands = this.SWOConfigurationCommands();
commands.push(...swocommands);
}
return commands;
}

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

const commands = [
'EnableITMAccess',
`BaseSWOSetup ${ratio}`,
'SetITMId 1',
'ITMDWTTransferEnable',
'DisableITMPorts 0xFFFFFFFF',
`EnableITMPorts ${portMask}`,
'EnableDWTSync',
this.args.swoConfig.profile ? 'EnablePCSample' : 'DisablePCSample',
'ITMSyncEnable',
'ITMGlobalEnable'
];

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

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

if (this.args.swoConfig.enabled)
{
const swoport = this.ports['swoPort'];
serverargs.push('--swo-port', swoport.toString());

const { cpuFrequency, swoFrequency } = this.args.swoConfig;

serverargs.push('--cpu-clock', cpuFrequency.toString());
serverargs.push('--swo-clock-div', Math.floor(cpuFrequency / swoFrequency).toString());
}

if (this.args.serialNumber) {
serverargs.push('--serial-number', this.args.serialNumber);
}
Expand All @@ -196,8 +233,16 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
}

public serverLaunchStarted(): void {}
public serverLaunchCompleted(): void {}

public serverLaunchCompleted(): void {
if (this.args.swoConfig.enabled) {
this.emit('event', new SWOConfigureEvent({
type: 'socket',
args: this.args,
port: this.ports['swoPort'].toString()
}));
}
}

public debuggerLaunchStarted(): void {}
public debuggerLaunchCompleted(): void {}
}

0 comments on commit 41ada8b

Please sign in to comment.