;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; CPT2 data over STM for DRA829/J7ES
; 03 Jun 19 - Richard Woodruff - Create.
; 24 Jan 20 - Richard Woodruff - Explicit connections needed for current SW.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 IF COMBIPROBE()||UTRACE()
    SYStem.CONFIG.CONNECTOR MIPI34 ; because of converter LA-3782

; Step #1 Connect to a core (CM3/CR5x/A72/C7/C6/ICSS)
; Step #2 Clocks for IPs to trace need to be enabled
; Step #3 Configure below for desired probes
;      - There are 7 aggregators which host probe groups.
;           -- Each has a TraceID
;      - Each probe can emit (latency, throughput, or Transaction) data
;           -- The STM2 MasterID is the probe number in the aggregator (M8 packet)
;           -- The Function determines the function (C8 packet)

; A72 (1x2)  : DRA829 (core.assign 1 2)
; CR5 (3x2)  : DRA829-CR5-MCU DRA829-CR5-MAIN0 DRA829-CR5-MAIN1 (core.assign 1 2)
; CM3 (1x1)  : DRA829-CM3
; PRU (2x3x2): DRA829-ICSS0 DRA829-ICSS0-RTU DRA829-ICSS0-TX (core.assign 1 2)
; C66 (2x1)  : DRA829-C66X (core.assign 1 2)
; C7x (1x1)  : DRA829-C71X

System.CPU DRA829
core.assign 1. 2.
system.attach
break

&GTCSPEED="200MHz"  ; 250MHz Default, SDK now sets down to 200MHz

;     TraceID        Agg        TBR    Agg base   ; ProbeBase: AggBase+0x20000 + Prob#x0x1000
;STM2.TraceID 0x50 ; * SOC    : TBR2 - 0x9E100000
;STM2.TraceID 0x51 ; * MCU    : TBR3 - 0x9E020000         ..
;STM2.TraceID 0x52 ; * AC     : TBR3 - 0x9E140000         ..     
;STM2.TraceID 0x53 ; * HC     : TBR3 - 0x9E180000         ..
;STM2.TraceID 0x54 ; * MSMC_0 : TBR1 - 0x90140000         ..
;STM2.TraceID 0x55 ; * MSMC_1 : TBR1 - 0x90180000         ..
;STM2.TraceID 0x56 ; * C7     : TBR1 - 0x91440000         ..

&TBR="TBR1"

STM2Trace.METHOD.Onchip2
onchip2.TraceCONNECT.&TBR

ETM.OFF  ; for demo keep it simple and suppress processor trace
STM2.TraceID 0x50--0x56
STM2.TimeStampCLOCK &GTCSPEED
STM2.TimeStamps.ON

;**********************************************
; Run the following sequence to "switch" to
; a different aggregator after trace has been
; captured:
; 1) STM2.TraceID <new_id>
; 2) STM2T.flowprocess
; 3) CPTT.flowprocess
;**********************************************

; View STP trace stream
STM2T.L /track

Data.set eaxi:0x00A90000 %LE %Long 0x1       ; ensure GTC on for debug timestamps
CPTracerTrace.CLOCK &GTCSPEED

;****************************************************
; The following channels are available for the
; CPTracerTrace.List window:
; - probe:        Does not work without correct STP master packets
; - cycle:        Message type
; - address:      Address of transaction
; - trans.<xxx>:  Transaction specific fields
; - thru.<xxx>:   Throughput specific fields
; - lat.<xxx>:    Latency specific fields
;*****************************************************
CPTracerTrace.method.onchip2
CPTracerTrace.TraceCONNECT.&TBR
cptt.l LAT.matched Lat.tracked LAT.maxwait LAT.totalwait LAT.creditwait TIme.Back /track
IF VERSION.BUILD()>129059.
(
  name.user avglat lat.totalwait / lat.tracked
  cptt.l User.avglat
  cptt.DRAW.channel.User.avglat
)
CPTT

;**************************************************
; Setup SystemTrace
;**************************************************
STM2.state

; Open CPTracer control panel
CPT.state

cptracer.MSMC1.on
cptracer.MSMC1.EMIF0_I.OPeration.LATency
CPTracerTrace.OFF 

; open a dump window into DDR to generate transactions
data.dump eaxi:0x80000000

; ARM and disarm test to see cptt used indicator move.
; CPTracerTrace.arm

; Note: Apparent init issue. Sometimes when starting at Continuous decode is not clean.
tpiu.PortMode.Wrapped
tpiu.portmode.Continuous

enddo
