GD-Link V2 Adapter User Guide
29
manuals of each series of MCUs.
Table 3-4. Trace mode enable
DBG_CTL |= DBG_CTL_TRACE_IOEN;
In the code, the serial printf output is redirected to the ITM output, and the added code is
shown in Table 3-5. Printf retarget.
Table 3-5. Printf retarget
#define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
#define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n)))
#define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))
#define DEMCR (*((volatile unsigned long *)(0xE000EDFC)))
#define TRCENA 0x01000000
int fputc(int ch, FILE *f)
{
if (DEMCR & TRCENA)
{
while (ITM_Port32(0) == 0) {};
ITM_Port8(0) = ch;
}
return(ch);
}
Enter the debugging interface, select "View" -> "Serial Windows" -> "Debug(printf)Viewer",
open the serial port printing interface, run the code at full speed, and the printed information
will be displayed in the Debug(printf)Viewer window. The Debug(printf)Viewer window in is
shown in Figure 3-31. Debug (printf) viewer window in KEIL.