We have a device, and I would like to use the printf function to send messages to the IDE for debugging purposes. Setup:
ARM Cortex-M3 device
Interface ULINK2
uVision4 IDE
I followed the instructions available in this link to be able to see messages in the "Debug (printf)" window. First, I modified the "retarget.c" file to redirect the output to the ITM interface:
#include <stdio.h> #include <rt_misc.h> #pragma import(__use_no_semihosting_swi) // Para utilização do saida de debug através do ULINK2 #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 struct __FILE { int handle; /* Add whatever you need here */ }; FILE __stdout; // Escreve caractere na porta de Debug int sendchar (int ch) { if (DEMCR & TRCENA) { while (ITM_Port32(0) == 0); ITM_Port8(0) = ch; } return(ch); } int fputc(int ch, FILE *f) { return (sendchar(ch)); } int ferror(FILE *f) { /* Your implementation of ferror */ return EOF; } void _ttywrch(int ch) { sendchar(ch); } void _sys_exit(int return_code) { label: goto label; /* endless loop */ }
Then I set up IMT in uVision4 following the instructions: 
The project compiles fine. I download the application to the device and start a debugging session using uVision4. I try to use printf with a simple message in the main function right after the system initialization, but the debug viewer remains empty. I set breakpoints in the "sendchar" function, I see that all lines fall as expected.
Has anyone succeeded in using printf with ULINK2 and uVision4? Does anyone know why I don't see the output in the Debug Viewer window?
UPDATE
I tried using the existing ITM features, resulting in a simpler "retarget.c":
int fputc(int ch, FILE *f) { return (ITM_SendChar((uint32_t)ch)); }
However, there is no output in Debug Viewer. When I go to the printf function call, “Trace: Data Overflow” is displayed at the bottom of the IDE, and then “Trace: Communication Error”.
source share