-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_swo_viewer.py
75 lines (70 loc) · 2.64 KB
/
add_swo_viewer.py
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
from swo_parser import swo_parser_main
import subprocess
from os import path, __file__
import time
import sys
Import("env")
def swo_viewer_task(*args, **kwargs):
print("Entrypoint")
board = env.BoardConfig()
platform = env.PioPlatform()
debug = board.manifest.get("debug", {})
openocd_path = path.join(platform.get_package_dir("tool-openocd"), "bin", "openocd")
upload_protocol = env.subst("$UPLOAD_PROTOCOL")
# connect_to_openocd_tcl()
server_args = ["-s", path.join(platform.get_package_dir("tool-openocd"), "scripts")]
if debug.get("openocd_board"):
server_args.extend(["-f", "board/%s.cfg" % debug.get("openocd_board")])
else:
assert debug.get("openocd_target"), (
"Missed target configuration for %s" % board.id
)
server_args.extend(
[
"-f",
"interface/%s.cfg" % upload_protocol,
"-c",
"transport select %s"
% ("hla_swd" if upload_protocol == "stlink" else "swd"),
"-f",
"target/%s.cfg" % debug.get("openocd_target"),
]
)
# per https://openocd.org/doc-release/pdf/openocd.pdf
# TRACECLKIN_freq: this should be specified to match target's current TRACECLKIN frequency (usually the same as HCLK).
# trace_freq: trace port frequency. Can be omitted in internal mode to let the adapter driver select the maximum supported rate automatically.
swo_trace_clkin_freq = str(
env.GetProjectOption("swo_trace_clkin_freq", env.subst("$BOARD_F_CPU")[:-1])
)
swo_trace_freq = str(env.GetProjectOption("swo_trace_freq", "115200"))
server_args.extend(
[
"-c",
"init; tpiu config internal - uart false %s %s; itm ports on"
% (swo_trace_clkin_freq, swo_trace_freq),
# "-c", "reset run"
# SWO parser.py was extended to make target run
]
)
server_args.insert(0, openocd_path)
print(
"Starting OpenOCD with SWO Trace clock-in frequency %s, SWO trace frequency %s. Invocation:"
% (swo_trace_clkin_freq, swo_trace_freq)
)
print(server_args)
# start client process in parallel
subprocess.Popen(
[env.subst("$PYTHONEXE"), path.join(env.subst("$PROJECT_DIR"), "swo_parser.py")]
)
# start openocd process parallel but wait in-line
openocd_process = subprocess.Popen(server_args)
openocd_process.communicate()
print("Exited from TCL client")
env.AddCustomTarget(
"swo_viewer",
None,
swo_viewer_task,
title="SWO Viewer",
description="Starts viewing the SWO output",
always_build=True,
)