-
Notifications
You must be signed in to change notification settings - Fork 2
/
trace.go
98 lines (73 loc) · 2.56 KB
/
trace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2020 Sebastian Lehmann. All rights reserved.
// Use of this source code is governed by a GNU-style
// license that can be found in the LICENSE file.
package gostlink
import (
"errors"
)
type TraceConfigType int
const (
TraceConfigTypeDisabled TraceConfigType = 0 // tracing is disabled
TraceConfigTypeExternal = 1 // trace output is captured externally
TraceConfigTypeInternal = 2 // trace output is handled by OpenOCD adapter driver
)
type TpuiPinProtocolType int
const (
TpuiPinProtocolSync TpuiPinProtocolType = 0 // synchronous trace output
TpuiPinProtocolAsynManchester = 1 // asynchronous output with Manchester coding
TpuiPinProtocolAsyncUart = 2 // asynchronous output with NRZ coding
)
type itmTsPrescaler int
const (
itmTsPrescale1 itmTsPrescaler = 0 // no prescaling for the timestamp counter
itmTsPrescale4 = 1 // refclock divided by 4 for the timestamp counter
itmTsPrescale16 = 2 // refclock divided by 16 for the timestamp counter
itmTsPrescale64 = 3 // refclock divided by 64 for the timestamp counter
)
const tpuiAcprMaxSwoScaler = 0x1fff
func (h *StLink) usbTraceDisable() error {
if !h.version.flags.Get(flagHasTrace) {
return errors.New("st-link does not support trace")
}
ctx := h.initTransfer(transferIncoming)
ctx.cmdBuf.WriteByte(cmdDebug)
ctx.cmdBuf.WriteByte(debugApiV2StopTraceRx)
err := h.usbTransferErrCheck(ctx, 2)
if err == nil {
h.trace.enabled = false
return nil
} else {
return errors.New("could not disable trace")
}
}
func (h *StLink) usbTraceEnable() error {
if h.version.flags.Get(flagHasTrace) {
ctx := h.initTransfer(transferIncoming)
ctx.cmdBuf.WriteByte(cmdDebug)
ctx.cmdBuf.WriteByte(debugApiV2StartTraceRx)
ctx.cmdBuf.WriteUint16LE(traceSize)
ctx.cmdBuf.WriteUint32LE(h.trace.sourceHz)
err := h.usbTransferErrCheck(ctx, 2)
if err == nil {
h.trace.enabled = true
logger.Debugf("enabled trace recording at %d Hz", h.trace.sourceHz)
return nil
} else {
return errors.New("usb xfer error at enabling trace")
}
} else {
return errors.New("tracing not supported by st-link")
}
}
func (h *StLink) usbReadTrace(buffer []byte, size uint32) error {
if !h.version.flags.Get(flagHasTrace) {
return errors.New("trace is not supported by connected device")
}
bytesRead, err := usbRawRead(h.traceEndpoint, buffer)
if err != nil {
return err
} else {
logger.Debugf("Read [%d from %d] bytes from trace channel", bytesRead, size)
return nil
}
}