2010年11月22日 星期一

Debug Message UART

前一篇 Hello World! UART 已經成功的透過UART將訊息輸出至 PC/NB端 putty or hyper terminal.
不過若要拿來當作一些訊息輸出來說還很不方便.
相信大家熟悉的字串輸出應該是printf / printfs這樣的使用方式.




所以這次加了兩個檔案 debug.c ,debug.h
在 uarttest.c 中做了以下紅字部分的修改.


#define RELEASE_MODE DEBUG_ALL_LOG
#include "LPC11xx.h"
#include "uart.h"
#include "debug.h"

extern volatile uint32_t UARTCount;
extern volatile uint8_t UARTBuffer[BUFSIZE];


int main (void) {
/* Basic chip initialization is taken care of in SystemInit() called
* from the startup code. SystemInit() and chip settings are defined
* in the CMSIS system_.c file.
*/
int test1=0;
/* NVIC is installed inside UARTInit file. */
UARTInit(115200);
printfs("*************************\n");
printfs("UART debug message v1.0\n");
printfs("Build date: \a");
printfs(__DATE__"\n");
printfs("Build time: \a");
printfs(__TIME__"\n");
printfs("*************************\n");

while (test1<10) { /* Loop forever */ printf("test = %d, \a",test1); printf("test = %x, \a",test1); printfs("test end .\n"); test1++; } while(1); }


來看看輸出的結果吧.
(圖1)

最一開始列印出版本訊息,包含的版本,build日期,時間.
build的日期與時間是build的時候代入的系統日期時間,這個訊息的自動產生有助於我們判別flash update是否有成功,這是一個非常實用的小技巧.




接著看看printf 怎麼使用?

printf("test = %d, \a",test1);


" ":內為顯示字串; %d: 表示10進位方式表示; \a:字串接續不顯示; test1:欲顯示於%d位置的變數,.



printf("test = %x, \a",test1);


" ":內為顯示字串; %x: 表示16進位方式表示; \a:字串接續符號,不顯示; test1:欲顯示於%x位置的變數




接著看看printfs 怎麼使用?
printfs("test end .\n");


" ":內為顯示字串; \n:換行符號,不顯示


顯示結果參考(圖1)


參考範例請至此下載  Download


9 則留言:

  1. 想請教板主,附的範例程式,經過Build之後出現下列錯誤,不知道哪個環節出錯?
    arm-none-eabi-gcc -D__USE_CMSIS=CMSISv1p30_LPC11xx -DDEBUG -D__CODE_RED -D__REDLIB__ -I"C:\Documents and Settings\??跚My Documents\lpcxpresso_3.6.3_317\workspace\CMSISv1p30_LPC11xx\inc" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -mcpu=cortex-m0 -mthumb -MMD -MP -MF"src/cr_startup_lpc11.d" -MT"src/cr_startup_lpc11.d" -o"src/cr_startup_lpc11.o" "../src/cr_startup_lpc11.c"

    ../src/cr_startup_lpc11.c:34:28: error: system_LPC11xx.h: No such file or directory
    ../src/cr_startup_lpc11.c: In function 'Reset_Handler':
    ../src/cr_startup_lpc11.c:205: warning: implicit declaration of function 'SystemInit'

    回覆刪除
  2. 松鼠你好,我這邊使用LPCXpresso v3.6.2 build之後都正常. 不知道你的版本是多少?以及能否提供 Project Explore 讓我看看.
    就你提供的訊息看來感覺是匯入錯誤,少了某些檔案.
    ~MCU diy~

    回覆刪除
  3. 版主你好,版本使用LPCXpresso v3.6.3,我找舊版看是否能解決.
    http://www.storepic.org/image-22E7_4DFF1386.jpg

    回覆刪除
  4. 從圖片來看. system_lpc11xx.h 找不到.
    請問一下你的workspace 目錄路徑,有中文嗎? 我看到其中出現一個亂碼.

    回覆刪除
  5. C:\Documents and Settings\XXX\My Documents\lpcxpresso_3.6\workspace

    XXX處可能你設定了中文使用者名稱.導致LPCXpresso看不到. 試試看改變workspace看看在重建project.
    ~MCU diy~

    回覆刪除
  6. 版主你好,如您所言,正是使用到中文路徑,導致無法build,非常感謝

    回覆刪除
  7. to 松鼠,這很常遇到(像是KEIL也可能會有繁簡中問題).
    所以都已經養成習慣這些專案都只放在英文路徑下..
    很高興你的問題解決了.

    ~MCU diy~

    回覆刪除
  8. 板主你好:想請您抽空幫我看一下程式,之前使用內建選單導入debug_printf.c,每次執行起始位置都在HardFault_Handler這中斷,目前改用您的debug.c,只要使用第二次UARTSend()就會進到IntDefaultHandler這中斷,不知道哪邊設定錯誤,再請您解惑.使用者:松鼠 密碼:空白
    http://ghouse.dyndns-work.com:7000/

    回覆刪除
  9. 作者已經移除這則留言。

    回覆刪除

Related Posts Plugin for WordPress, Blogger...