Skip to content

Commit 19c99d3

Browse files
committed
etm trace for nrf52840
1 parent 1b658ae commit 19c99d3

File tree

5 files changed

+278
-11
lines changed

5 files changed

+278
-11
lines changed

hw/bsp/lpc18/boards/mcb1800/board.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@
4343

4444
static inline void board_lpc18_pinmux(void) {
4545
const PINMUX_GRP_T pinmuxing[] = {
46+
// ETM Trace
47+
#ifdef TRACE_ETM
48+
{ 0xF, 4, SCU_MODE_FUNC2 | SCU_MODE_HIGHSPEEDSLEW_EN },
49+
{ 0xF, 5, SCU_MODE_FUNC3 | SCU_MODE_HIGHSPEEDSLEW_EN },
50+
{ 0xF, 6, SCU_MODE_FUNC3 | SCU_MODE_HIGHSPEEDSLEW_EN },
51+
{ 0xF, 7, SCU_MODE_FUNC3 | SCU_MODE_HIGHSPEEDSLEW_EN },
52+
{ 0xF, 8, SCU_MODE_FUNC3 | SCU_MODE_HIGHSPEEDSLEW_EN },
53+
#endif
54+
4655
// LEDs
4756
{ 0xD, 10, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC4) },
4857
{ 0xD, 11, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC4 | SCU_MODE_PULLDOWN) },
@@ -65,15 +74,6 @@ static inline void board_lpc18_pinmux(void) {
6574

6675
{ 0x9, 5, SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC2 }, // P9_5 USB1_VBUS_EN, USB1 VBus function
6776
{ 0x2, 5, SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2 }, // P2_5 USB1_VBUS, MUST CONFIGURE THIS SIGNAL FOR USB1 NORMAL OPERATION
68-
69-
// ETM Trace
70-
#ifdef TRACE_ETM
71-
{ 0xF, 4, SCU_MODE_FUNC2 | SCU_MODE_HIGHSPEEDSLEW_EN },
72-
{ 0xF, 5, SCU_MODE_FUNC3 | SCU_MODE_HIGHSPEEDSLEW_EN },
73-
{ 0xF, 6, SCU_MODE_FUNC3 | SCU_MODE_HIGHSPEEDSLEW_EN },
74-
{ 0xF, 7, SCU_MODE_FUNC3 | SCU_MODE_HIGHSPEEDSLEW_EN },
75-
{ 0xF, 8, SCU_MODE_FUNC3 | SCU_MODE_HIGHSPEEDSLEW_EN },
76-
#endif
7777
};
7878

7979
Chip_SCU_SetPinMuxing(pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T));

hw/bsp/nrf/boards/pca10056/board.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#define LED_STATE_ON 0
3737

3838
// Button
39-
#define BUTTON_PIN 11
39+
#define BUTTON_PIN 25 // button 4
4040
#define BUTTON_STATE_ACTIVE 0
4141

4242
// UART
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
2+
/*********************************************************************
3+
*
4+
* OnProjectLoad
5+
*
6+
* Function description
7+
* Project load routine. Required.
8+
*
9+
**********************************************************************
10+
*/
11+
void OnProjectLoad (void) {
12+
// Dialog-generated settings
13+
Project.AddSvdFile ("$(InstallDir)/Config/CPU/Cortex-M4F.svd");
14+
Project.AddSvdFile ("$(InstallDir)/Config/Peripherals/ARMv7M.svd");
15+
16+
Project.SetDevice ("nRF52840_xxAA");
17+
Project.SetHostIF ("USB", "");
18+
Project.SetTargetIF ("SWD");
19+
Project.SetTIFSpeed ("8 MHz");
20+
Project.SetTraceSource ("Trace Pins");
21+
Project.SetTracePortWidth (4);
22+
23+
// User settings
24+
File.Open ("../../../../../../examples/device/cdc_msc/cmake-build-pca10056/cdc_msc.elf");
25+
}
26+
27+
/*********************************************************************
28+
*
29+
* TargetReset
30+
*
31+
* Function description
32+
* Replaces the default target device reset routine. Optional.
33+
*
34+
* Notes
35+
* This example demonstrates the usage when
36+
* debugging a RAM program on a Cortex-M target device
37+
*
38+
**********************************************************************
39+
*/
40+
//void TargetReset (void) {
41+
//
42+
// unsigned int SP;
43+
// unsigned int PC;
44+
// unsigned int VectorTableAddr;
45+
//
46+
// Exec.Reset();
47+
//
48+
// VectorTableAddr = Elf.GetBaseAddr();
49+
//
50+
// if (VectorTableAddr != 0xFFFFFFFF) {
51+
//
52+
// Util.Log("Resetting Program.");
53+
//
54+
// SP = Target.ReadU32(VectorTableAddr);
55+
// Target.SetReg("SP", SP);
56+
//
57+
// PC = Target.ReadU32(VectorTableAddr + 4);
58+
// Target.SetReg("PC", PC);
59+
// }
60+
//}
61+
62+
/*********************************************************************
63+
*
64+
* BeforeTargetReset
65+
*
66+
* Function description
67+
* Event handler routine. Optional.
68+
*
69+
**********************************************************************
70+
*/
71+
//void BeforeTargetReset (void) {
72+
//}
73+
74+
/*********************************************************************
75+
*
76+
* AfterTargetReset
77+
*
78+
* Function description
79+
* Event handler routine.
80+
* - Sets the PC register to program reset value.
81+
* - Sets the SP register to program reset value on Cortex-M.
82+
*
83+
**********************************************************************
84+
*/
85+
void AfterTargetReset (void) {
86+
unsigned int SP;
87+
unsigned int PC;
88+
unsigned int VectorTableAddr;
89+
90+
VectorTableAddr = Elf.GetBaseAddr();
91+
92+
if (VectorTableAddr == 0xFFFFFFFF) {
93+
Util.Log("Project file error: failed to get program base");
94+
} else {
95+
SP = Target.ReadU32(VectorTableAddr);
96+
Target.SetReg("SP", SP);
97+
98+
PC = Target.ReadU32(VectorTableAddr + 4);
99+
Target.SetReg("PC", PC);
100+
}
101+
}
102+
103+
/*********************************************************************
104+
*
105+
* DebugStart
106+
*
107+
* Function description
108+
* Replaces the default debug session startup routine. Optional.
109+
*
110+
**********************************************************************
111+
*/
112+
//void DebugStart (void) {
113+
//}
114+
115+
/*********************************************************************
116+
*
117+
* TargetConnect
118+
*
119+
* Function description
120+
* Replaces the default target IF connection routine. Optional.
121+
*
122+
**********************************************************************
123+
*/
124+
//void TargetConnect (void) {
125+
//}
126+
127+
/*********************************************************************
128+
*
129+
* BeforeTargetConnect
130+
*
131+
* Function description
132+
* Event handler routine. Optional.
133+
*
134+
**********************************************************************
135+
*/
136+
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");
141+
}
142+
143+
/*********************************************************************
144+
*
145+
* AfterTargetConnect
146+
*
147+
* Function description
148+
* Event handler routine. Optional.
149+
*
150+
**********************************************************************
151+
*/
152+
//void AfterTargetConnect (void) {
153+
//}
154+
155+
/*********************************************************************
156+
*
157+
* TargetDownload
158+
*
159+
* Function description
160+
* Replaces the default program download routine. Optional.
161+
*
162+
**********************************************************************
163+
*/
164+
//void TargetDownload (void) {
165+
//}
166+
167+
/*********************************************************************
168+
*
169+
* BeforeTargetDownload
170+
*
171+
* Function description
172+
* Event handler routine. Optional.
173+
*
174+
**********************************************************************
175+
*/
176+
//void BeforeTargetDownload (void) {
177+
//}
178+
179+
/*********************************************************************
180+
*
181+
* AfterTargetDownload
182+
*
183+
* Function description
184+
* Event handler routine.
185+
* - Sets the PC register to program reset value.
186+
* - Sets the SP register to program reset value on Cortex-M.
187+
*
188+
**********************************************************************
189+
*/
190+
void AfterTargetDownload (void) {
191+
unsigned int SP;
192+
unsigned int PC;
193+
unsigned int VectorTableAddr;
194+
195+
VectorTableAddr = Elf.GetBaseAddr();
196+
197+
if (VectorTableAddr == 0xFFFFFFFF) {
198+
Util.Log("Project file error: failed to get program base");
199+
} else {
200+
SP = Target.ReadU32(VectorTableAddr);
201+
Target.SetReg("SP", SP);
202+
203+
PC = Target.ReadU32(VectorTableAddr + 4);
204+
Target.SetReg("PC", PC);
205+
}
206+
}
207+
208+
/*********************************************************************
209+
*
210+
* BeforeTargetDisconnect
211+
*
212+
* Function description
213+
* Event handler routine. Optional.
214+
*
215+
**********************************************************************
216+
*/
217+
//void BeforeTargetDisconnect (void) {
218+
//}
219+
220+
/*********************************************************************
221+
*
222+
* AfterTargetDisconnect
223+
*
224+
* Function description
225+
* Event handler routine. Optional.
226+
*
227+
**********************************************************************
228+
*/
229+
//void AfterTargetDisconnect (void) {
230+
//}
231+
232+
/*********************************************************************
233+
*
234+
* AfterTargetHalt
235+
*
236+
* Function description
237+
* Event handler routine. Optional.
238+
*
239+
**********************************************************************
240+
*/
241+
//void AfterTargetHalt (void) {
242+
//}

hw/bsp/nrf/family.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,33 @@ 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+
96119
void board_init(void)
97120
{
121+
trace_etm_init();
122+
98123
// stop LF clock just in case we jump from application without reset
99124
NRF_CLOCK->TASKS_LFCLKSTOP = 1UL;
100125

hw/bsp/stm32h7/family.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void trace_etm_init(void) {
7777
DBGMCU->CR |= DBGMCU_CR_DBG_TRACECKEN | DBGMCU_CR_DBG_CKD1EN | DBGMCU_CR_DBG_CKD3EN;
7878
}
7979
#else
80-
#define etm_trace_init()
80+
#define trace_etm_init()
8181
#endif
8282

8383
void board_init(void)

0 commit comments

Comments
 (0)