Skip to content

Commit c3d57ee

Browse files
committed
boards: nordic: nrf54h20dk: Add ETM support
Added configuration of coresight peripherals to the cpuapp JLinkScript so the funnels, replicators etc are correctly configured. Signed-off-by: Karsten Koenig <[email protected]>
1 parent 7eb9668 commit c3d57ee

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed

boards/nordic/nrf54h20dk/support/nrf54h20_cpuapp.JLinkScript

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,174 @@
11
__constant U32 _CPUCONF_ADDR = 0x52011000;
22
__constant U32 _CPUCONF_CPUWAIT_OFFSET = 0x50C;
33

4+
// ATBFUNNEL
5+
__constant U32 _ATBFUNNEL211_ADDR = 0xBF04D000;
6+
__constant U32 _ATBFUNNEL212_ADDR = 0xBF04E000;
7+
__constant U32 _ATBFUNNEL_CTRLREG_OFFSET = 0x0;
8+
__constant U32 _HOLDTIME_4 = 0x300;
9+
__constant U32 _ENS0 = 0x1;
10+
__constant U32 _ENS1 = 0x2;
11+
__constant U32 _ENS2 = 0x4;
12+
13+
// ATBREPLICATOR
14+
__constant U32 _ATBREPLICATOR212_ADDR = 0xBF04A000;
15+
__constant U32 _ATBREPLICATOR213_ADDR = 0xBF04B000;
16+
__constant U32 _ATBREPLICATOR_IDFILTER0_OFFSET = 0x0;
17+
__constant U32 _ATBREPLICATOR_IDFILTER1_OFFSET = 0x4;
18+
__constant U32 _ID_NONE = 0xFFFFFFFF;
19+
__constant U32 _ID1x = 0xFFFFFFFD;
20+
21+
// TSGEN
22+
__constant U32 _TSGEN_ADDR = 0xBF041000;
23+
__constant U32 _TSGEN_CNTCR_OFFSET = 0x0;
24+
__constant U32 _TSGEN_CNTFID0_OFFSET = 0x20;
25+
// Clock rate = TDD Freq. / 8
26+
__constant U32 _TS_CLOCKRATE = 40000000;
27+
28+
// CTI
29+
__constant U32 _CTI210_ADDR = 0xBF046000;
30+
__constant U32 _CTICONTROL_OFFSET = 0x0;
31+
__constant U32 _CTIOUTEN_OFFSET = 0xA0;
32+
__constant U32 _CTIGATE_OFFSET = 0x140;
33+
__constant U32 _TPIU_FLUSH_TRIG = 0x2;
34+
35+
// GPR
36+
__constant U32 _GPR_ADDR = 0xbf050000;
37+
__constant U32 _CPWRUPREQ_OFFSET = 0x0;
38+
__constant U32 _PWR_TPIU_GPIO_PATH = 0x101;
39+
40+
// TPIU
41+
__constant U32 _TPIU_ADDR = 0xBF043000;
42+
__constant U32 _CURRENTPORTSIZE_OFFSET = 0x4;
43+
__constant U32 _FFCR_OFFSET = 0x304;
44+
__constant U32 _FSCR_OFFSET = 0x308;
45+
__constant U32 _ENFCONT = 0x02;
46+
__constant U32 _FONFLIN = 0x10;
47+
__constant U32 _ENFTC = 0x1;
48+
__constant U32 _TPIU_SYNC_FRAME_COUNT = 0x8;
49+
__constant U32 _CURRENTPORTSIZE_4 = 0x8;
50+
51+
// TDDCONF
52+
__constant U32 _TDDCONF_ADDR = 0xBF001000;
53+
__constant U32 _TRACEPORTSPEED_OFFSET = 0x408;
54+
__constant U32 _SPEED80MHZ = 0x0;
55+
56+
// SPU
57+
__constant U32 _SPU131_ADDR = 0x5F920000;
58+
__constant U32 _FEATURE_GPIO_P7_OFFSET = 0xb80;
59+
__constant U32 _ATTR_SECDOM_SECURE = 0x10010;
60+
61+
// CoreSight general
62+
__constant U32 _CORESIGHT_CLAIMSET_OFFSET = 0xFA0;
63+
__constant U32 _CORESIGHT_CLAIMCLR_OFFSET = 0xFA4;
64+
__constant U32 _CORESIGHT_LAR_OFFSET = 0xFB0;
65+
__constant U32 _CORESIGHT_UNLOCK_KEY = 0xC5ACCE55;
66+
67+
// Settings
68+
__constant U32 _DEBUGGER_CLAIM_MASK = 0x2;
69+
70+
// Used to check if we have already set up tracing
71+
int _needCoresightSetup = 1;
72+
73+
// Unlock a CoreSight peripheral
74+
void _CSUnlock(U32 addr)
75+
{
76+
JLINK_MEM_WriteU32(addr + _CORESIGHT_LAR_OFFSET, _CORESIGHT_UNLOCK_KEY);
77+
}
78+
79+
// Lock a CoreSight peripheral
80+
void _CSLock(U32 addr)
81+
{
82+
JLINK_MEM_WriteU32(addr + _CORESIGHT_LAR_OFFSET, 0);
83+
}
84+
85+
// Set claim bits in the CoreSight peripheral to indicate to the firmware that it
86+
// has been configured by the host debugger
87+
void _CSClaim(U32 addr)
88+
{
89+
JLINK_MEM_WriteU32(addr + _CORESIGHT_CLAIMSET_OFFSET, _DEBUGGER_CLAIM_MASK);
90+
}
91+
92+
// Set up CoreSight and other necessary configuration so to enable ETM -> TPIU tracing.
93+
int _SetupSecdomTrace(void)
94+
{
95+
// Set up ATB funnels/replicators to route ApplicationDomain ETM to TPIU
96+
_CSUnlock(_ATBFUNNEL212_ADDR);
97+
JLINK_MEM_WriteU32(_ATBFUNNEL212_ADDR + _ATBFUNNEL_CTRLREG_OFFSET, _HOLDTIME_4 | _ENS0);
98+
_CSClaim(_ATBFUNNEL212_ADDR);
99+
_CSLock(_ATBFUNNEL212_ADDR);
100+
101+
_CSUnlock(_ATBREPLICATOR212_ADDR);
102+
JLINK_MEM_WriteU32(_ATBREPLICATOR212_ADDR + _ATBREPLICATOR_IDFILTER0_OFFSET, _ID_NONE);
103+
JLINK_MEM_WriteU32(_ATBREPLICATOR212_ADDR + _ATBREPLICATOR_IDFILTER1_OFFSET, _ID1x);
104+
_CSLock(_ATBREPLICATOR212_ADDR);
105+
_CSClaim(_ATBREPLICATOR212_ADDR);
106+
_CSLock(_ATBREPLICATOR212_ADDR);
107+
108+
_CSUnlock(_ATBFUNNEL211_ADDR);
109+
JLINK_MEM_WriteU32(_ATBFUNNEL211_ADDR + _ATBFUNNEL_CTRLREG_OFFSET, _HOLDTIME_4 | _ENS0);
110+
_CSClaim(_ATBFUNNEL211_ADDR);
111+
_CSLock(_ATBFUNNEL211_ADDR);
112+
113+
_CSUnlock(_ATBREPLICATOR213_ADDR);
114+
JLINK_MEM_WriteU32(_ATBREPLICATOR213_ADDR + _ATBREPLICATOR_IDFILTER0_OFFSET, _ID1x);
115+
JLINK_MEM_WriteU32(_ATBREPLICATOR213_ADDR + _ATBREPLICATOR_IDFILTER1_OFFSET, _ID_NONE);
116+
_CSClaim(_ATBREPLICATOR213_ADDR);
117+
_CSLock(_ATBREPLICATOR213_ADDR);
118+
119+
// Configure timestamp generator for the correct clock rate
120+
JLINK_MEM_WriteU32(_TSGEN_ADDR + _TSGEN_CNTFID0_OFFSET, _TS_CLOCKRATE);
121+
JLINK_MEM_WriteU32(_TSGEN_ADDR + _TSGEN_CNTCR_OFFSET, 1);
122+
_CSClaim(_TSGEN_ADDR);
123+
124+
// Configure CTI1 for TPIU formatter flushing
125+
_CSUnlock(_CTI210_ADDR);
126+
JLINK_MEM_WriteU32(_CTI210_ADDR + _CTIOUTEN_OFFSET, _TPIU_FLUSH_TRIG);
127+
JLINK_MEM_WriteU32(_CTI210_ADDR + _CTIGATE_OFFSET, _TPIU_FLUSH_TRIG);
128+
JLINK_MEM_WriteU32(_CTI210_ADDR + _CTICONTROL_OFFSET, 1);
129+
_CSClaim(_CTI210_ADDR);
130+
_CSLock(_CTI210_ADDR);
131+
132+
// Configure GPR to power on the necessary domains to trace to pins
133+
_CSUnlock(_GPR_ADDR);
134+
JLINK_MEM_WriteU32(_GPR_ADDR, _PWR_TPIU_GPIO_PATH);
135+
_CSClaim(_GPR_ADDR);
136+
_CSLock(_GPR_ADDR);
137+
138+
// Configure TPIU for port size 4, continuous formatting
139+
_CSUnlock(_TPIU_ADDR);
140+
JLINK_MEM_WriteU32(_TPIU_ADDR + _CURRENTPORTSIZE_OFFSET, _CURRENTPORTSIZE_4);
141+
JLINK_MEM_WriteU32(_TPIU_ADDR + _FFCR_OFFSET, _ENFCONT | _FONFLIN | _ENFTC);
142+
JLINK_MEM_WriteU32(_TPIU_ADDR + _FSCR_OFFSET, _TPIU_SYNC_FRAME_COUNT);
143+
_CSClaim(_TPIU_ADDR);
144+
_CSLock(_TPIU_ADDR);
145+
146+
return 0;
147+
}
148+
149+
int ConfigTargetSettings(void)
150+
{
151+
JLINK_ExecCommand("CORESIGHT_AddAP = Index=0 Type=AHB-AP");
152+
CORESIGHT_IndexAHBAPToUse = 0;
153+
154+
// Adjust trace sample delay to compensate for timing when using 320MHz
155+
JLINK_ExecCommand("TraceSampleAdjust TD = 1000");
156+
157+
return 0;
158+
}
159+
160+
int OnTraceStart(void)
161+
{
162+
// Set up CoreSight if not already configured
163+
if (_needCoresightSetup) {
164+
_SetupSecdomTrace();
165+
_needCoresightSetup = 0;
166+
}
167+
168+
return 0;
169+
}
170+
171+
4172
int SetupTarget(void)
5173
{
6174
JLINK_TARGET_Halt();

0 commit comments

Comments
 (0)