@@ -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