Skip to content

Commit c789cfe

Browse files
committed
use system_nrf5x.c built-in support for ETM with ENABLE_ETM
1 parent 19c99d3 commit c789cfe

File tree

4 files changed

+341
-29
lines changed

4 files changed

+341
-29
lines changed

hw/bsp/nrf/boards/pca10056/ozone/nrf52840.jdebug

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@ void AfterTargetReset (void) {
134134
**********************************************************************
135135
*/
136136
void BeforeTargetConnect (void) {
137-
//
138-
// Trace pin init is done by J-Link script file as J-Link script files are IDE independent
139-
//
140-
Project.SetJLinkScript("./Nordic_nRF52840_TraceExample.pex");
141137
}
142138

143139
/*********************************************************************
Lines changed: 335 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
/*********************************************************************
2+
* (c) SEGGER Microcontroller GmbH *
3+
* The Embedded Experts *
4+
* www.segger.com *
5+
**********************************************************************
6+
7+
File :
8+
Created : 30 Jun 2021 13:37
9+
Ozone Version : V3.24a
10+
*/
11+
12+
/*********************************************************************
13+
*
14+
* OnProjectLoad
15+
*
16+
* Function description
17+
* Project load routine. Required.
18+
*
19+
**********************************************************************
20+
*/
21+
void OnProjectLoad (void) {
22+
// Dialog-generated settings
23+
Project.AddSvdFile ("$(InstallDir)/Config/CPU/Cortex-M33F.svd");
24+
Project.AddSvdFile ("./nrf5340_application.svd");
25+
Project.SetDevice ("nRF5340_xxAA_APP");
26+
Project.SetHostIF ("USB", "");
27+
Project.SetTargetIF ("SWD");
28+
Project.SetTIFSpeed ("16 MHz");
29+
30+
Project.SetTraceSource ("Trace Pins");
31+
Project.SetTracePortWidth (4);
32+
33+
// User settings
34+
File.Open ("../../../../../../examples/device/cdc_msc/cmake-build-pca10095/cdc_msc.elf");
35+
}
36+
37+
/*********************************************************************
38+
*
39+
* OnStartupComplete
40+
*
41+
* Function description
42+
* Called when program execution has reached/passed
43+
* the startup completion point. Optional.
44+
*
45+
**********************************************************************
46+
*/
47+
//void OnStartupComplete (void) {
48+
//}
49+
50+
/*********************************************************************
51+
*
52+
* TargetReset
53+
*
54+
* Function description
55+
* Replaces the default target device reset routine. Optional.
56+
*
57+
* Notes
58+
* This example demonstrates the usage when
59+
* debugging an application in RAM on a Cortex-M target device.
60+
*
61+
**********************************************************************
62+
*/
63+
//void TargetReset (void) {
64+
//
65+
// unsigned int SP;
66+
// unsigned int PC;
67+
// unsigned int VectorTableAddr;
68+
//
69+
// VectorTableAddr = Elf.GetBaseAddr();
70+
// //
71+
// // Set up initial stack pointer
72+
// //
73+
// if (VectorTableAddr != 0xFFFFFFFF) {
74+
// SP = Target.ReadU32(VectorTableAddr);
75+
// Target.SetReg("SP", SP);
76+
// }
77+
// //
78+
// // Set up entry point PC
79+
// //
80+
// PC = Elf.GetEntryPointPC();
81+
//
82+
// if (PC != 0xFFFFFFFF) {
83+
// Target.SetReg("PC", PC);
84+
// } else if (VectorTableAddr != 0xFFFFFFFF) {
85+
// PC = Target.ReadU32(VectorTableAddr + 4);
86+
// Target.SetReg("PC", PC);
87+
// } else {
88+
// Util.Error("Project file error: failed to set entry point PC", 1);
89+
// }
90+
//}
91+
92+
/*********************************************************************
93+
*
94+
* BeforeTargetReset
95+
*
96+
* Function description
97+
* Event handler routine. Optional.
98+
*
99+
**********************************************************************
100+
*/
101+
//void BeforeTargetReset (void) {
102+
//}
103+
104+
/*********************************************************************
105+
*
106+
* AfterTargetReset
107+
*
108+
* Function description
109+
* Event handler routine. Optional.
110+
* The default implementation initializes SP and PC to reset values.
111+
**
112+
**********************************************************************
113+
*/
114+
void AfterTargetReset (void) {
115+
_SetupTarget();
116+
}
117+
118+
/*********************************************************************
119+
*
120+
* DebugStart
121+
*
122+
* Function description
123+
* Replaces the default debug session startup routine. Optional.
124+
*
125+
**********************************************************************
126+
*/
127+
//void DebugStart (void) {
128+
//}
129+
130+
/*********************************************************************
131+
*
132+
* TargetConnect
133+
*
134+
* Function description
135+
* Replaces the default target IF connection routine. Optional.
136+
*
137+
**********************************************************************
138+
*/
139+
//void TargetConnect (void) {
140+
//}
141+
142+
/*********************************************************************
143+
*
144+
* BeforeTargetConnect
145+
*
146+
* Function description
147+
* Event handler routine. Optional.
148+
*
149+
**********************************************************************
150+
*/
151+
void BeforeTargetConnect (void) {
152+
}
153+
154+
/*********************************************************************
155+
*
156+
* AfterTargetConnect
157+
*
158+
* Function description
159+
* Event handler routine. Optional.
160+
*
161+
**********************************************************************
162+
*/
163+
//void AfterTargetConnect (void) {
164+
//}
165+
166+
/*********************************************************************
167+
*
168+
* TargetDownload
169+
*
170+
* Function description
171+
* Replaces the default program download routine. Optional.
172+
*
173+
**********************************************************************
174+
*/
175+
//void TargetDownload (void) {
176+
//}
177+
178+
/*********************************************************************
179+
*
180+
* BeforeTargetDownload
181+
*
182+
* Function description
183+
* Event handler routine. Optional.
184+
*
185+
**********************************************************************
186+
*/
187+
//void BeforeTargetDownload (void) {
188+
//}
189+
190+
/*********************************************************************
191+
*
192+
* AfterTargetDownload
193+
*
194+
* Function description
195+
* Event handler routine. Optional.
196+
* The default implementation initializes SP and PC to reset values.
197+
*
198+
**********************************************************************
199+
*/
200+
void AfterTargetDownload (void) {
201+
_SetupTarget();
202+
}
203+
204+
/*********************************************************************
205+
*
206+
* BeforeTargetDisconnect
207+
*
208+
* Function description
209+
* Event handler routine. Optional.
210+
*
211+
**********************************************************************
212+
*/
213+
//void BeforeTargetDisconnect (void) {
214+
//}
215+
216+
/*********************************************************************
217+
*
218+
* AfterTargetDisconnect
219+
*
220+
* Function description
221+
* Event handler routine. Optional.
222+
*
223+
**********************************************************************
224+
*/
225+
//void AfterTargetDisconnect (void) {
226+
//}
227+
228+
/*********************************************************************
229+
*
230+
* AfterTargetHalt
231+
*
232+
* Function description
233+
* Event handler routine. Optional.
234+
*
235+
**********************************************************************
236+
*/
237+
//void AfterTargetHalt (void) {
238+
//}
239+
240+
/*********************************************************************
241+
*
242+
* BeforeTargetResume
243+
*
244+
* Function description
245+
* Event handler routine. Optional.
246+
*
247+
**********************************************************************
248+
*/
249+
//void BeforeTargetResume (void) {
250+
//}
251+
252+
/*********************************************************************
253+
*
254+
* OnSnapshotLoad
255+
*
256+
* Function description
257+
* Called upon loading a snapshot. Optional.
258+
*
259+
* Additional information
260+
* This function is used to restore the target state in cases
261+
* where values cannot simply be written to the target.
262+
* Typical use: GPIO clock needs to be enabled, before
263+
* GPIO is configured.
264+
*
265+
**********************************************************************
266+
*/
267+
//void OnSnapshotLoad (void) {
268+
//}
269+
270+
/*********************************************************************
271+
*
272+
* OnSnapshotSave
273+
*
274+
* Function description
275+
* Called upon saving a snapshot. Optional.
276+
*
277+
* Additional information
278+
* This function is usually used to save values of the target
279+
* state which can either not be trivially read,
280+
* or need to be restored in a specific way or order.
281+
* Typically use: Memory Mapped Registers,
282+
* such as PLL and GPIO configuration.
283+
*
284+
**********************************************************************
285+
*/
286+
//void OnSnapshotSave (void) {
287+
//}
288+
289+
/*********************************************************************
290+
*
291+
* OnError
292+
*
293+
* Function description
294+
* Called when an error occurred. Optional.
295+
*
296+
**********************************************************************
297+
*/
298+
//void OnError (void) {
299+
//}
300+
301+
/*********************************************************************
302+
*
303+
* _SetupTarget
304+
*
305+
* Function description
306+
* Setup the target.
307+
* Called by AfterTargetReset() and AfterTargetDownload().
308+
*
309+
* Auto-generated function. May be overridden by Ozone.
310+
*
311+
**********************************************************************
312+
*/
313+
void _SetupTarget(void) {
314+
unsigned int SP;
315+
unsigned int PC;
316+
unsigned int VectorTableAddr;
317+
318+
VectorTableAddr = Elf.GetBaseAddr();
319+
//
320+
// Set up initial stack pointer
321+
//
322+
SP = Target.ReadU32(VectorTableAddr);
323+
if (SP != 0xFFFFFFFF) {
324+
Target.SetReg("SP", SP);
325+
}
326+
//
327+
// Set up entry point PC
328+
//
329+
PC = Elf.GetEntryPointPC();
330+
if (PC != 0xFFFFFFFF) {
331+
Target.SetReg("PC", PC);
332+
} else {
333+
Util.Error("Project script error: failed to set up entry point PC", 1);
334+
}
335+
}

hw/bsp/nrf/family.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,8 @@ TU_ATTR_UNUSED static void power_event_handler(nrfx_power_usb_evt_t event)
9393
tusb_hal_nrf_power_event((uint32_t) event);
9494
}
9595

96-
#ifdef TRACE_ETM
97-
void trace_etm_init(void) {
98-
#ifdef NRF52840_XXAA
99-
// Trace clk: P0.7, Trace D0..D3: P1.0, P0.11, P0.12, P1.09
100-
// Setting drive strength to H0H1
101-
uint32_t const pin_cnf = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) |
102-
(GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos);
103-
NRF_P0->PIN_CNF[ 7] = pin_cnf; // CLK
104-
NRF_P1->PIN_CNF[ 0] = pin_cnf; // D0
105-
NRF_P0->PIN_CNF[11] = pin_cnf; // D1
106-
NRF_P0->PIN_CNF[12] = pin_cnf; // D2
107-
NRF_P1->PIN_CNF[ 9] = pin_cnf; // D3
108-
109-
// trace clock = 16 Mhz, Trace mux = parallel
110-
NRF_CLOCK->TRACECONFIG = (CLOCK_TRACECONFIG_TRACEPORTSPEED_32MHz << CLOCK_TRACECONFIG_TRACEPORTSPEED_Pos) |
111-
(CLOCK_TRACECONFIG_TRACEMUX_Parallel << CLOCK_TRACECONFIG_TRACEMUX_Pos);
112-
#endif
113-
}
114-
#else
115-
116-
#define trace_etm_init()
117-
#endif
118-
11996
void board_init(void)
12097
{
121-
trace_etm_init();
122-
12398
// stop LF clock just in case we jump from application without reset
12499
NRF_CLOCK->TASKS_LFCLKSTOP = 1UL;
125100

hw/bsp/nrf/family.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ function(add_board_target BOARD_TARGET)
4646
target_compile_definitions(${BOARD_TARGET} PUBLIC
4747
CONFIG_GPIO_AS_PINRESET
4848
)
49+
50+
if (TRACE_ETM STREQUAL "1")
51+
# ENABLE_TRACE will cause system_nrf5x.c to set up ETM trace
52+
target_compile_definitions(${BOARD_TARGET} PUBLIC ENABLE_TRACE)
53+
endif ()
54+
4955
target_include_directories(${BOARD_TARGET} PUBLIC
5056
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
5157
${NRFX_DIR}

0 commit comments

Comments
 (0)