We are hoping to gain some clarity on using the 4-bit trace port of the TWR-K65F180M. I'm going to include everything we've tried here as it may help someone else as well.
Initially, we were having issues even getting JTAG to work. We followed the guidelines to remove the shunt on J32, but this did not allow us to utilize JTAG. We updated the bootloader firmware per this forum post:
JTAG in TWR-K65F180M not functional on rev A0
Note: The forum response from Natish Harish contains the binary file you will want to use. I missed it the first few times.
After that, we were still unable to use JTAG. We then added 0 Ohm resistors for R54 - R58 (for the trace functionality) and R68, R69. This got us going with JTAG debugging. However, we are still having issues using the 4-bit trace mode.
We followed all of the configuration guidelines here:
ULINKpro User's Guide: Enable 4-Pin Trace (ETM)
As the above link was for the K70, we modified it to point to the addresses of the corresponding registers on the K65. Our resultant initialization file is:
/*-------------------------------------------------------------------
** Define the function to enable the trace port
**-----------------------------------------------------------------*/
FUNC void SetupTrace(void) {
_wDWORD(0x40048038,(_RDWORD(0x40048038) | 0x00002000)); // SIM_SCGC5 : Enable PORT E clock
_wDWORD(0x40048004,(_RDWORD(0x40048004) | 0x00001000)); // SIM_SOPT2 : Trace Clock Source is set as "Core/system clock"
_wDWORD(0x40048068,(_RDWORD(0x40048068) & 0xFFFFFFF0)); // SIM_CLKDIV4: Set TRACEDIV = b000 & TRACEFRAC = b0
// Note: Do not change the value of SIM_CLKDIV4[0..3] in your application!
_wDWORD(0x4004D000, 0x00000740); // PTE0: TraceClock, High drive strength
_wDWORD(0x4004D004, 0x00000740); // PTE1: TRACED3 , High drive strength
_wDWORD(0x4004D008, 0x00000740); // PTE2: TRACED2 , High drive strength
_wDWORD(0x4004D00C, 0x00000740); // PTE3: TRACED1 , High drive strength
_wDWORD(0x4004D010, 0x00000740); // PTE4: TRACED0 , High drive strength
}
/*-------------------------------------------------------------------
** Invoke the function at debugger startup
**-----------------------------------------------------------------*/
SetupTrace();
/*-------------------------------------------------------------------
** Execute upon software RESET
**-----------------------------------------------------------------*/
FUNC void OnResetExec(void) {
SetupTrace();
}
We have gotten some of the trace functionality to work but not with the 4-bit trace mode. We have tried changing our debugger clock speeds, and we have tried with matched/mis-matched core clock settings.
We have had success when using the ETB and slowing the debug clock down, but we do not see anything in the Event Viewer window. When we step through the code we can use ETB we are able to log several thousand (highest I saw was 7500 events), but if we just let it run we stop logging ETM after around 10 seconds. Using SWO - Manchester we can only see ITM data, and we see the events in the Event Viewer window. Similar to running the ETM port, we have to step through in order to log more than several thousand events.
We did have a few questions:
The Core Clock field needs to match the frequency of the actual clock on the MCU. Does it also need to match the Xtal field in the Target settings tab? The description makes it sound like the Xtal field should match the frequency of the external oscillator.
Do we need to install a 0 Ohm on R53?
In our initialization file, do we need to change the pin mulitplexing? The example did not do this, but it would seem to me that we ought to be assigning the multiplex assignment.
Are there any limitations for the 4-bit trace port that we are overlooking?
Any help would be greatly appreciated.
Thanks,
Adam
/*-------------------------------------------------------------------
** Define the function to enable the trace port
**-----------------------------------------------------------------*/
FUNC void SetupTrace(void) { _wDWORD(0x40048038,(_RDWORD(0x40048038) | 0x00002000)); // SIM_SCGC5 : Enable PORT E clock
_wDWORD(0x40048004,(_RDWORD(0x40048004) | 0x00001000)); // SIM_SOPT2 : Trace Clock Source is set as "Core/system clock"
_wDWORD(0x40048068,(_RDWORD(0x40048068) & 0xFFFFFFF0)); // SIM_CLKDIV4: Set TRACEDIV = b000 & TRACEFRAC = b0
// Note: Do not change the value of SIM_CLKDIV4[0..3] in your application!
_wDWORD(0x4004D000, 0x00000540); // PTE0 (ALT5): TraceClock, High drive strength, Passive Filter Disabled, Slew Rate Fast, No pull
_wDWORD(0x4004D004, 0x00000540); // PTE1 (ALT5): TRACED3 , High drive strength, Passive Filter Disabled, Slew Rate Fast, No pull
_wDWORD(0x4004D008, 0x00000540); // PTE2 (ALT5): TRACED2 , High drive strength, Passive Filter Disabled, Slew Rate Fast, No pull
_wDWORD(0x4004D00C, 0x00000540); // PTE3 (ALT5): TRACED1 , High drive strength, Passive Filter Disabled, Slew Rate Fast, No pull
_wDWORD(0x4004D010, 0x00000540); // PTE4 (ALT5): TRACED0 , High drive strength, Passive Filter Disabled, Slew Rate Fast, No pull
}/*-------------------------------------------------------------------
** Invoke the function at debugger startup
**-----------------------------------------------------------------*/
SetupTrace();/*-------------------------------------------------------------------
** Execute upon software RESET
**-----------------------------------------------------------------*/
FUNC void OnResetExec(void) {
SetupTrace();
}
- Unplug and replug the ULINKPro USB cable.
- The trace clock appears to continue run while the processor is stopped.
Also, we're not sure how to automatically tell the trace/debugger that we are going to change the clock speed. How can we run trace at anything beyond the default 20.971520 MHz that the processor comes up at?
Adam,
The Trace clock depends on two clock sources - MCGOUTCLK and Core/system in SIM_SOPT2[TRACECLKSEL]. The trace clock divider setup in SIM_CLKDIV4[TRACEFRAC,TRACEDIV]. The TRACE_CLKOUT pin will be at maximum half of the selected clock source. You can't achieve 120 (NORMAL)/180 (HSRUN) MHz on TRACE_CLKOUT, the best can be no more than 60 (120MHz Core) or 90 (180MHz Core) MHz with proper TRACEFRAC and TRACEDIV setup.
I will see if I can duplicate the symptom you described about changing clock speed while debugging.
Regards,
TsiChung
TsiChung,
Thank you for confirming the divide by two, and thank you for taking a look at this. Are you sure that we should be able to debug with a 180 MHz core clock? Page 121 (Table 6-1) of the K65P reference manual shows that the TRACEKLIN signal is limited to 120 MHz. Would we simply need to set a divider via SIM_CLKDIV4[TRACEFRAC, TRACEDIV]? Everything I've seen thus far suggests we don't want to do that.
We have also been in contact with ARM. We are starting to think there may be an issue with the ULINK Pro firmware. We are able to get trace functionality working until we hit a breakpoint or halt debugging. However, once we start debugging again the trace clock does not re-synchronize. I will keep updating as we find out more.
Thanks,
Adam
Adam,
I agreed that the trace clock should be 120MHz.
Regards,
TsiChung
We have modified our initialization file to correct the pin multiplex assignments. We were setting the alternates for PTE0 - 4 to ALT3, but they needed to be set to ALT5.
/*-------------------------------------------------------------------
** Define the function to enable the trace port
**-----------------------------------------------------------------*/
FUNC void SetupTrace(void) {
_wDWORD(0x40048038,(_RDWORD(0x40048038) | 0x00002000)); // SIM_SCGC5 : Enable PORT E clock
_wDWORD(0x40048004,(_RDWORD(0x40048004) | 0x00001000)); // SIM_SOPT2 : Trace Clock Source is set as "Core/system clock"
_wDWORD(0x40048068,(_RDWORD(0x40048068) & 0xFFFFFFF0)); // SIM_CLKDIV4: Set TRACEDIV = b000 & TRACEFRAC = b0
// Note: Do not change the value of SIM_CLKDIV4[0..3] in your application!
_wDWORD(0x4004D000, 0x00000540); // PTE0 (ALT5): TraceClock, High drive strength, Passive Filter Disabled, Slew Rate Fast, No pull
_wDWORD(0x4004D004, 0x00000540); // PTE1 (ALT5): TRACED3 , High drive strength, Passive Filter Disabled, Slew Rate Fast, No pull
_wDWORD(0x4004D008, 0x00000540); // PTE2 (ALT5): TRACED2 , High drive strength, Passive Filter Disabled, Slew Rate Fast, No pull
_wDWORD(0x4004D00C, 0x00000540); // PTE3 (ALT5): TRACED1 , High drive strength, Passive Filter Disabled, Slew Rate Fast, No pull
_wDWORD(0x4004D010, 0x00000540); // PTE4 (ALT5): TRACED0 , High drive strength, Passive Filter Disabled, Slew Rate Fast, No pull
}
/*-------------------------------------------------------------------
** Invoke the function at debugger startup
**-----------------------------------------------------------------*/
SetupTrace();
/*-------------------------------------------------------------------
** Execute upon software RESET
**-----------------------------------------------------------------*/
FUNC void OnResetExec(void) {
SetupTrace();
}
We have also come across this link that looks like it may help.
Hi,
I am also interested in the subject, I have asked someone for help already.
BR
XiangJun Rong