-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathZG23_Traceconfig.JLinkScript
235 lines (203 loc) · 7.98 KB
/
ZG23_Traceconfig.JLinkScript
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*********************************************************************
* Z-Wave ZG23 Embedded Trace Module script *
* Initializes and enables the ETM module and drives out the default *
* pins. See the code for more details. *
**********************************************************************
-------------------------- END-OF-HEADER -----------------------------
File : ZG23_TraceConfig.JLinkScript
Purpose : Example script for the Z-Wave EFR32ZG23, EFR32FG23 (and ZGM230?)
Literature:
[1] J-Link User Guide - https://www.segger.com/downloads/jlink/UM08001
[2] JLinkScript syntax - https://wiki.segger.com/J-Link_script_files#Using_J-Link_script_files
*/
/*********************************************************************
*
* OnTraceStart()
*
* Function description
* If present, called right before trace is started.
* Used to initialize MCU specific trace related things like configuring the trace pins for alternate function.
*
* Return value
* >= 0: O.K.
* < 0: Error
*
* Notes
* (1) May use high-level API functions like JLINK_MEM_ etc.
* (2) Should not call JLINK_TARGET_Halt(). Can rely on target being halted when entering this function
*/
int OnTraceStart(void) {
U32 v;
U32 PortWidth; // this is passed in from Ozone based on the setup chosen
U32 CMU_BASE;
U32 CMU_TRACECLKCTRL;
U32 CMU_CLKEN0;
U32 CMU_TRACEPRESC_SHIFT;
U32 CMU_TRACEPRESC_MASK;
U32 CMU_CLKEN0GPIO_SHIFT;
U32 CMU_CLKEN0GPIO_MASK;
U32 GPIO_BASE;
U32 GPIO_DBGROUTEPEN;
U32 GPIO_TRACEROUTEPEN;
U32 GPIO_TRACEROUTEPEN_TRACE_MASK;
U32 GPIO_TRACEROUTEPEN_ETMTDATA3PEN;
U32 GPIO_TRACEROUTEPEN_ETMTDATA2PEN;
U32 GPIO_TRACEROUTEPEN_ETMTDATA1PEN;
U32 GPIO_TRACEROUTEPEN_ETMTDATA0PEN;
U32 GPIO_TRACEROUTEPEN_ETMTCLKPEN;
U32 GPIO_TRACEROUTEPEN_SWVPEN;
U32 GPIO_PORT_A;
U32 GPIO_MODE_PUSH_PULL;
U32 GPIO_Px_BASE;
U32 GPIO_Px_CTRL;
U32 GPIO_Px_MODEL;
U32 GPIO_Px_MODEH;
U32 GPIO_Px_DOUT;
U32 routepen;
U32 tracePortSize;
U32 etmPort;
U32 etmTCLKPin;
U32 etmTD0Pin;
U32 etmTD1Pin;
U32 etmTD2Pin;
U32 etmTD3Pin;
U32 _TRACE_presc;
JLINK_SYS_Report("Start: Initializing trace pins");
PortWidth = JLINK_TRACE_PortWidth; // Ozone Tools->Trace Settings to choose the number of data pins - 4 pins rarely stalls the CPU
JLINK_SYS_Report1("PortWidth: ", PortWidth);
/* CMU */
CMU_BASE = 0x50008000;
CMU_TRACECLKCTRL = CMU_BASE + 0x080;
CMU_CLKEN0 = CMU_BASE + 0x064;
CMU_TRACEPRESC_SHIFT = 4;
CMU_TRACEPRESC_MASK = 0x3<<CMU_TRACEPRESC_SHIFT;
CMU_CLKEN0GPIO_SHIFT = 26;
CMU_CLKEN0GPIO_MASK = 0x1<<CMU_CLKEN0GPIO_SHIFT;
/* GPIO */
GPIO_BASE = 0x5003C000; // NS: 0x5003C000
GPIO_DBGROUTEPEN = GPIO_BASE + 0x440;
GPIO_TRACEROUTEPEN = GPIO_BASE + 0x444;
GPIO_TRACEROUTEPEN_TRACE_MASK = 0x3F;
GPIO_TRACEROUTEPEN_ETMTDATA3PEN = 0x20;
GPIO_TRACEROUTEPEN_ETMTDATA2PEN = 0x10;
GPIO_TRACEROUTEPEN_ETMTDATA1PEN = 0x8;
GPIO_TRACEROUTEPEN_ETMTDATA0PEN = 0x4;
GPIO_TRACEROUTEPEN_ETMTCLKPEN = 0x2;
GPIO_TRACEROUTEPEN_SWVPEN = 0x1;
GPIO_PORT_A = 1;
GPIO_MODE_PUSH_PULL = 0x04;
//
// Init clocks
//
//JLINK_SYS_Report1("CMU_CLKEN0: ", JLINK_MEM_ReadU32(CMU_CLKEN0));
JLINK_MEM_WriteU32(CMU_CLKEN0, 1 << CMU_CLKEN0GPIO_SHIFT); // Enable clock for GPIO
JLINK_SYS_Report1("CMU_CLKEN0: ", JLINK_MEM_ReadU32(CMU_CLKEN0));
// Z-Wave operates the ZG23 at 39MHz so the ETM can be clocked at DIV1 (ETM max is 40)
_TRACE_presc = 0; /* 0: DIV1, 1: DIV2, 3: DIV4 */
//JLINK_SYS_Report1("CMU_TRACECLKCTRL: ", JLINK_MEM_ReadU32(CMU_TRACECLKCTRL));
JLINK_MEM_WriteU32(CMU_TRACECLKCTRL, _TRACE_presc << CMU_TRACEPRESC_SHIFT);
JLINK_SYS_Report1("CMU_TRACECLKCTRL: ", JLINK_MEM_ReadU32(CMU_TRACECLKCTRL));
JLINK_MEM_WriteU32(GPIO_DBGROUTEPEN, 0x3); // enable the 2 SWD pins
//
// Set GPIO ROUTE
//
routepen = GPIO_TRACEROUTEPEN_ETMTCLKPEN
| GPIO_TRACEROUTEPEN_ETMTDATA0PEN;
if (PortWidth > 1) {
routepen |= GPIO_TRACEROUTEPEN_ETMTDATA1PEN;
}
if (PortWidth > 2) {
routepen |= (GPIO_TRACEROUTEPEN_ETMTDATA2PEN
| GPIO_TRACEROUTEPEN_ETMTDATA3PEN);
}
etmPort = GPIO_PORT_A;
etmTCLKPin = 4;
etmTD0Pin = 3;
etmTD1Pin = 5;
etmTD2Pin = 6;
etmTD3Pin = 7;
// Calculating position of port registers
GPIO_Px_BASE = GPIO_BASE + ( etmPort * 48 );
GPIO_Px_CTRL = GPIO_Px_BASE + 0x00;
GPIO_Px_MODEL = GPIO_Px_BASE + 0x04;
GPIO_Px_MODEH = GPIO_Px_BASE + 0x0C;
GPIO_Px_DOUT = GPIO_Px_BASE + 0x10;
v = JLINK_MEM_ReadU32(GPIO_Px_CTRL);
v &= ~(0x70); // AND off the slew rate bits
v |= 0x40; // bits 6:4 are the slew rate
JLINK_MEM_WriteU32(GPIO_Px_CTRL, v); // set SLEW rate for the port - default is 0x40 - higher number is faster slew rate - 0x70 is fastest but may need several GNDs
JLINK_SYS_Report1("GPIO_Px_CTRL: ", JLINK_MEM_ReadU32(GPIO_Px_CTRL));
//
// TCLK init
//
v = JLINK_MEM_ReadU32(GPIO_Px_MODEL);
JLINK_SYS_Report1("R_GPIO_Px_MODEL: ", v);
v &= ~(0xF << (4 * etmTCLKPin)); // Mask Mode register
v |= (GPIO_MODE_PUSH_PULL << (4 * etmTCLKPin)); // Set push pull function mode
JLINK_SYS_Report1("W_GPIO_Px_MODEL: ", v);
JLINK_MEM_WriteU32(GPIO_Px_MODEL, v);
JLINK_SYS_Report1("GPIO_Px_MODEL: ", JLINK_MEM_ReadU32(GPIO_Px_MODEL));
//
// TD0 init
//
v = JLINK_MEM_ReadU32(GPIO_Px_MODEL);
v &= ~(0xF << (4 * etmTD0Pin)); // Mask Mode register
v |= (GPIO_MODE_PUSH_PULL << (4 * etmTD0Pin)); // Set push pull function mode
JLINK_MEM_WriteU32(GPIO_Px_MODEL, v);
if (PortWidth > 1) {
//
// TD1 init
//
v = JLINK_MEM_ReadU32(GPIO_Px_MODEL);
v &= ~(0xF << (4 * etmTD1Pin)); // Mask Mode register
v |= (GPIO_MODE_PUSH_PULL << (4 * etmTD1Pin)); // Set push pull function mode
JLINK_MEM_WriteU32(GPIO_Px_MODEL, v);
}
if (PortWidth > 2) {
//
// TD2 init
//
v = JLINK_MEM_ReadU32(GPIO_Px_MODEL);
v &= ~(0xF << (4 * etmTD2Pin)); // Mask Mode register
v |= (GPIO_MODE_PUSH_PULL << (4 * etmTD2Pin)); // Set push pull function mode
JLINK_MEM_WriteU32(GPIO_Px_MODEL, v);
//
// TD3 init
//
v = JLINK_MEM_ReadU32(GPIO_Px_MODEL);
v &= ~(0xF << (4 * etmTD3Pin)); // Mask Mode register
v |= (GPIO_MODE_PUSH_PULL << (4 * etmTD3Pin)); // Set push pull function mode
JLINK_MEM_WriteU32(GPIO_Px_MODEL, v);
}
//
// TRACEROUTE pin enable
//
v = JLINK_MEM_ReadU32(GPIO_TRACEROUTEPEN);
JLINK_SYS_Report1("R_GPIO_TRACEROUTEPEN: ", v);
v &= ~(GPIO_TRACEROUTEPEN_TRACE_MASK << 1); // Mask TRACEROUTEPEN register
v |= routepen; // Set TRACEROUTEPEN
JLINK_SYS_Report1("W_GPIO_TRACEROUTEPEN: ", v);
JLINK_MEM_WriteU32(GPIO_TRACEROUTEPEN, v);
JLINK_SYS_Report1("GPIO_TRACEROUTEPEN: ", JLINK_MEM_ReadU32(GPIO_TRACEROUTEPEN));
JLINK_SYS_Report("End: Initializing trace pins");
return 0;
}
/*********************************************************************
*
* ConfigTargetSettings()
*
* Function description
* Called before InitTarget(). Mainly used to set some global DLL variables to customize the normal connect procedure.
* For ARM CoreSight devices this may be specifying the base address of some CoreSight components (ETM, ...)
* that cannot be automatically detected by J-Link due to erroneous ROM tables etc.
* May also be used to specify the device name in case debugger does not pass it to the DLL.
*
* Notes
* (1) May not, under absolutely NO circumstances, call any API functions that perform target communication.
* (2) Should only set some global DLL variables
*/
int ConfigTargetSettings(void) {
JLINK_ExecCommand("CORESIGHT_SetTPIUBaseAddr = 0xE0040000 ForceUnlock = 1"); // TPIU address is missing in ROM table
JLINK_SYS_Report("Set TPIU Base Address");
return 0;
}