@@ -134,8 +134,34 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
134
134
return commands ;
135
135
}
136
136
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 } "` ) ;
139
165
}
140
166
141
167
public serverExecutable ( ) : string {
@@ -176,6 +202,17 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
176
202
serverargs . push ( '--swd' ) ;
177
203
}
178
204
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
+
179
216
if ( this . args . serialNumber ) {
180
217
serverargs . push ( '--serial-number' , this . args . serialNumber ) ;
181
218
}
@@ -196,8 +233,16 @@ export class STLinkServerController extends EventEmitter implements GDBServerCon
196
233
}
197
234
198
235
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
+
201
246
public debuggerLaunchStarted ( ) : void { }
202
247
public debuggerLaunchCompleted ( ) : void { }
203
248
}
0 commit comments