這兩天遇到一個問題
新接的project沒辦法將printf的訊息丟到RVDS上的stdio console window
而廠商的UART與JTAG又是共用pin (hardware strapping)
所以用ICE debug時沒辦法用UART !!!
這實在是有點困擾
而廠商所提供的SDK又把系統的printf給從新導向到他們自己實作的函式中
但是他們又沒提供相對應的object file
本想跟廠商要object file
想想算了
乾脆自己來做一個
由於ICE是透過一個事先定義好的software interrupt (0x123456)來跟RVDS溝通
當interrupt產生時
如果R0 = 0x03
就是一個Output
那R1裡的參數就會被傳到RVDS並從stdio console window顯示出來
如果R1 = 0x07
那就是一個input
那R1裡的參數就會是user從stdio console window輸入的值
以下就是如果在RVDS上實作透過JTAG將訊息丟到stdio console window
#include <stdio.h> #include <stdarg.h> #include <string.h> /* software interrupt address for stdio between JTAG and RVDS */ #define SEMI_SWI 0x123456 #define REQ_WR 0x03 /* write operation operand in r1 */ #define REQ_RD 0x07 /* read operation operand in r1 */ #define WriteC(c) __WriteC(REQ_WR, c) #define ReadC(c) __ReadC(REQ_RD) /* * Pre-declaring functions for stdio input/output * */ __swi(SEMI_SWI) void __WriteC(unsigned op, char *c) ; __swi(SEMI_SWI) char __ReadC(unsigned op) ; /* * redirect function to output string on stdio console window on RVDS through JTAG * without using UART * */ void stdio_printf(const char *fmt, ...) { int i = 0 ; char buf[256] ; va_list args ; memset(buf, 0, sizeof(buf)) ; va_start(args, fmt) ; vsprintf(buf, fmt, args) ; while(buf[i]) { WriteC(&buf[i]) ; i++ ; } va_end(args) ; }
全站熱搜