您的位置:首页 > 其它

展讯平台如何调试之打LOG--串口log

2012-04-04 17:39 1111 查看
公司最近做一款数据卡,还是用的展讯的8800,板子还没回来,想先在8802上实验一下!但是在移植到8802上的时候板子一直都跑不起来。以前出现问题的时候第一反映就是去打LOG,查异常,但是这次貌似死得很早,根本就认不出diag!怎么办呢?

在这种情况下就用串口来打印吧,选择的理由是串口初始化简单,打印工具普遍!

在确定了不是FLASH的问题后,就要确定BOOT是不是跑过去了,汇编跑过去后进入main里面,在main.c里面的main函数里面把tf_main_nand.c里面的对串口初始化的代码考出来,

#define UART_BASE_CLK 26000000
LOCAL  void TF_UartInit(void)
{
unsigned long baud_rate;
baud_rate = UART_BASE_CLK/115200;   //for 48MHz clk src

*(volatile uint32 *)GR_GEN0 |= BIT_21;
#ifdef PLATFORM_SC8800G
//uart clk sel and div config
REG32(GR_CLK_DLY)  |=  (BIT_22 | BIT_23);
REG32(GR_CLK_GEN5) &= ~(BIT_5 | BIT_4 | BIT_3);
#endif
*(volatile uint32 *)0x84000010 = 0x00;
*(volatile uint32 *)0x84000018 = 0x1C;
*(volatile uint32 *)0x8400001C = 0x00;
*(volatile uint32 *)0x84000024 = (uint16)baud_rate; //115200
*(volatile uint32 *)0x84000028 = (baud_rate>>8);
}


好了,在main.c里面加入TF_UartInit();串口初始化了,串口初始化完毕以后怎么打串口log呢?当时也不知道,就全局搜索关于uarttrace之类的函数,结果在tf_main_nand.c里面有这么一个函数,TF_UartTrace,好吧,移植一下,让这个函数在main.c里面就能用

#include "stdarg.h"

#define   SIO_TX_EMPTY(s)    	    ((s) & 0xFF00)
#define   WAIT_FIFO_EMPTY        \
{                                      \
while( SIO_TX_EMPTY(*(volatile uint32*)(0x8400000c)));\
}

LOCAL void WriteCharToUART(char c)
{
while ((((*(volatile uint32*)0x8400000c) >> 8 )&0xFF) >= 32 ) {};

*(volatile uint32*)0x84000000 = c;
}

LOCAL void TF_SendMsgOut(char * buf, int size)
{
while (size --)
{
WriteCharToUART(*(buf++));
}

WriteCharToUART('\r');
WriteCharToUART('\n');
}

#define TRACE_LOG_MSG \
va_start(args, x_format);\
nBuf = vsprintf(format_str, x_format, args);\
/* was there an error? */\
/* Was the expanded string too long? */\
va_end(args);\
/* Send message to serial buffer! */ \
TF_SendMsgOut(format_str, nBuf + 1);

PUBLIC void cg_TF_UartTrace(
const char *x_format, ...)
{
char       format_str[256];
va_list    args;
int        nBuf;

WAIT_FIFO_EMPTY

memset (format_str,0,256);
TRACE_LOG_MSG		/*assert verified*/

WAIT_FIFO_EMPTY
}

LOCAL void delay()
{
uint32 i = 1000;
while(i--);
}

#define init_trace() cg_TF_UartTrace("%s,%d", __func__, __LINE__);\
delay()


OK,这样加了自己的一些宏,同时把这个打印函数所有要用的关联宏和函数拷贝出来,就好了。这样的话就只要在程序里面铺满 init_trace(),这样在XP下自带的串口输出工具就可以知道程序到底走在哪里了!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: