Skip to content

Commit 7e7921f

Browse files
committed
tests: subsys: swo: use jlink scipt for nrf54l
Needed custom jlink script to get output from SWO. Signed-off-by: Piotr Kosycarz <[email protected]>
1 parent 8c6ac72 commit 7e7921f

File tree

2 files changed

+87
-41
lines changed

2 files changed

+87
-41
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SWO configuration for nRF54L
2+
3+
// Secure address for TAD.TRACEPPORTSPEED
4+
__constant U32 _TAD_TRACEPORTSPEED = 0x50053518;
5+
6+
// The nRF54L chips have an additional divider for the SWO frequency, which
7+
// is configured in TAD.TRACEPORTSPEED. The J-Link needs to be aware of this.
8+
U32 SWO_GetSWOBaseClock(U32 CPUClock) {
9+
U32 divider;
10+
11+
divider = JLINK_MEM_ReadU32(_TAD_TRACEPORTSPEED);
12+
13+
if (divider == 0) {
14+
return CPUClock;
15+
}
16+
17+
if (divider == 1) {
18+
// Divide by 2
19+
return CPUClock >> 1;
20+
}
21+
22+
if (divider == 2) {
23+
// Divide by 4
24+
return CPUClock >> 2;
25+
}
26+
27+
if (divider == 3) {
28+
// Divide by 32
29+
return CPUClock >> 5;
30+
}
31+
32+
// We should never get here, the checks cover all valid divider values
33+
34+
return CPUClock;
35+
}

tests/subsys/swo/pytest/test_swo.py

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515

1616
logger = logging.getLogger(__name__)
1717

18+
1819
# Kill parent process and all child processes (if started)
1920
def _kill(proc):
2021
try:
2122
for child in psutil.Process(proc.pid).children(recursive=True):
2223
child.kill()
2324
proc.kill()
2425
except Exception as e:
25-
logger.exception(f'Could not kill JLinkSWOViewerCLExe - {e}')
26+
logger.exception(f"Could not kill JLinkSWOViewerCLExe - {e}")
2627

2728

2829
def test_swo_logging(dut: DeviceAdapter):
@@ -37,53 +38,64 @@ def test_swo_logging(dut: DeviceAdapter):
3738
COLLECT_TIMEOUT = 10.0
3839
EXPECTED = rf"log_swo: \d+: Hello from {PLATFORM}"
3940

41+
NRF54L_JLINK_SCRIPT = Path(__file__).parent.resolve() / "nrf54l_swo.script"
42+
4043
logger.debug(f"{dut.device_config=}")
4144

4245
SWO_CONFIG = {
43-
'nrf52dk/nrf52832': {
44-
'device': 'nRF52832_xxAA',
45-
'cpufreq': 64000000,
46-
'swofreq': 1000000,
46+
"nrf52dk/nrf52832": {
47+
"device": "nRF52832_xxAA",
48+
"cpufreq": 64000000,
49+
"swofreq": 1000000,
50+
"args": "",
4751
},
48-
'nrf52840dk/nrf52840': {
49-
'device': 'nRF52840_xxAA',
50-
'cpufreq': 64000000,
51-
'swofreq': 1000000,
52+
"nrf52840dk/nrf52840": {
53+
"device": "nRF52840_xxAA",
54+
"cpufreq": 64000000,
55+
"swofreq": 1000000,
56+
"args": "",
5257
},
53-
'nrf5340dk/nrf5340/cpuapp': {
54-
'device': 'nRF5340_xxAA_APP',
55-
'cpufreq': 64000000,
56-
'swofreq': 1000000,
58+
"nrf5340dk/nrf5340/cpuapp": {
59+
"device": "nRF5340_xxAA_APP",
60+
"cpufreq": 64000000,
61+
"swofreq": 1000000,
62+
"args": "",
5763
},
58-
'nrf54l15dk/nrf54l05/cpuapp': {
59-
'device': 'nRF54L05_M33',
60-
'cpufreq': 128000000,
61-
'swofreq': 1000000,
64+
"nrf54l15dk/nrf54l05/cpuapp": {
65+
"device": "nRF54L05_M33",
66+
"cpufreq": 128000000,
67+
"swofreq": 1000000,
68+
"args": f"-jlinkscriptfile {NRF54L_JLINK_SCRIPT}",
6269
},
63-
'nrf54l15dk/nrf54l10/cpuapp': {
64-
'device': 'nRF54L10_M33',
65-
'cpufreq': 128000000,
66-
'swofreq': 1000000,
70+
"nrf54l15dk/nrf54l10/cpuapp": {
71+
"device": "nRF54L10_M33",
72+
"cpufreq": 128000000,
73+
"swofreq": 1000000,
74+
"args": f"-jlinkscriptfile {NRF54L_JLINK_SCRIPT}",
6775
},
68-
'nrf54l15dk/nrf54l15/cpuapp': {
69-
'device': 'nRF54L15_M33',
70-
'cpufreq': 128000000,
71-
'swofreq': 1000000,
76+
"nrf54l15dk/nrf54l15/cpuapp": {
77+
"device": "nRF54L15_M33",
78+
"cpufreq": 128000000,
79+
"swofreq": 1000000,
80+
"args": f"-jlinkscriptfile {NRF54L_JLINK_SCRIPT}",
7281
},
73-
'nrf54lm20dk/nrf54lm20a/cpuapp': {
74-
'device': 'NRF54LM20A_M33',
75-
'cpufreq': 128000000,
76-
'swofreq': 1000000,
82+
"nrf54lm20dk/nrf54lm20a/cpuapp": {
83+
"device": "NRF54LM20A_M33",
84+
"cpufreq": 128000000,
85+
"swofreq": 1000000,
86+
"args": f"-jlinkscriptfile {NRF54L_JLINK_SCRIPT}",
7787
},
78-
'nrf54lv10dk/nrf54lv10a/cpuapp': {
79-
'device': 'NRF54LV10A_M33',
80-
'cpufreq': 128000000,
81-
'swofreq': 1000000,
88+
"nrf54lv10dk/nrf54lv10a/cpuapp": {
89+
"device": "NRF54LV10A_M33",
90+
"cpufreq": 128000000,
91+
"swofreq": 1000000,
92+
"args": f"-jlinkscriptfile {NRF54L_JLINK_SCRIPT}",
8293
},
83-
'[email protected]/nrf54lv10a/cpuapp': {
84-
'device': 'NRF54LV10A_M33',
85-
'cpufreq': 128000000,
86-
'swofreq': 1000000,
94+
"[email protected]/nrf54lv10a/cpuapp": {
95+
"device": "NRF54LV10A_M33",
96+
"cpufreq": 128000000,
97+
"swofreq": 1000000,
98+
"args": f"-jlinkscriptfile {NRF54L_JLINK_SCRIPT}",
8799
},
88100
}
89101

@@ -103,13 +115,14 @@ def test_swo_logging(dut: DeviceAdapter):
103115
cmd += f" -cpufreq {SWO_CONFIG[PLATFORM]['cpufreq']}"
104116
cmd += f" -swofreq {SWO_CONFIG[PLATFORM]['swofreq']}"
105117
cmd += f" -itmmask 0xFFFF -outputfile {log_filename}"
118+
cmd += f" {SWO_CONFIG[PLATFORM]['args']}"
106119
try:
107120
logger.info(f"Executing:\n{cmd}")
108121
proc = subprocess.Popen(
109122
cmd,
110123
stdout=subprocess.PIPE,
111124
stderr=subprocess.STDOUT,
112-
encoding='UTF-8',
125+
encoding="UTF-8",
113126
shell=True,
114127
)
115128
except OSError as exc:
@@ -127,9 +140,7 @@ def test_swo_logging(dut: DeviceAdapter):
127140
log_file_content = log_file.read()
128141

129142
# if nothing in log_file, stop test
130-
assert(
131-
len(log_file_content) > 0
132-
), f"File {log_filename} is empty"
143+
assert len(log_file_content) > 0, f"File {log_filename} is empty"
133144

134145
# Check if log file contains expected string
135146
expected_str = re.search(EXPECTED, log_file_content)

0 commit comments

Comments
 (0)