显示调试过程中的printf IDE信息 [英] Show printf messages in IDE during debug
问题描述
我们有一个设备,我想使用printf函数将消息发送到IDE中进行调试。设置:
We have a device and I'd like to use printf function to send messages to the IDE for debugging purposes. The setup:
-
ARM Cortex-M3的设备
ARM Cortex-M3 device
ULINK2接口
uVision4 IDE
uVision4 IDE
我跟着此链接是能够看到的说明在调试(printf的)查看器的消息。
首先,我修改了retarget.c中的文件,将输出重定向到的 ITM 接口:
I've followed the instructions available in this link to be able to see the messages in the "Debug (printf) Viewer". 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 */
}
然后我配置了uVision4的IMT,以下的说明:
Then I configured the IMT in the uVision4, following the instructions:
该项目编译罚款。我的应用程序下载到设备上,并开始与uVision4我调试会话。我尝试在main函数用printf用一个简单的信息,系统初始化之后,但调试器保持为空。
我已经把断点诠释了sendchar功能,我可以看到,所有的线都命中,符合市场预期。
The project compiles fine. I download the application to the device and start I debug session with 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've put breakpoints int the "sendchar" function, I can see that all lines are hit, as expected.
有没有人用printf与ULINK2和uVision4成功了吗?有没有人有,为什么我看不到在调试器窗口的任何输出线索?
Has anyone succeeded using printf with ULINK2 and uVision4? Does anyone has a clue on why I can't see any output in the Debug Viewer window?
更新
我试图使用现有的ITM功能,导致一个简单的retarget.c中
I've tried to use the existing ITM functions, resulting in a simpler "retarget.c":
int fputc(int ch, FILE *f) {
return (ITM_SendChar((uint32_t)ch));
}
然而,没有输出显示在调试器。当我踏上过的printf funcion电话,跟踪:数据溢出显示在IDE的底部,其次是跟踪:通信错误。
Nevertheless, no output is shown in the Debug Viewer. When I step over the printf funcion call, "Trace: Data Overflow" is displayed in the bottom of the IDE, followed by "Trace: Communication Error".
推荐答案
的问题是在跟踪配置CoreClock字段。它不匹配器件的时钟。之后,我改变了它的设备时钟匹配,右输出被显示在浏览器的调试。
The problem was in the "CoreClock" field in the "Trace" configuration. It didn't match the device's clock. After I changed it to match the device clock, the right output was shown in the Debug Viewer.
一些有用的链接:
这篇关于显示调试过程中的printf IDE信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!