久久ER99热精品一区二区-久久精品99国产精品日本-久久精品免费一区二区三区-久久综合九色综合欧美狠狠

新聞中心

EEPW首頁 > 嵌入式系統 > 設計應用 > S3C2440在MDK4.22下使用printf向串口打印調試

S3C2440在MDK4.22下使用printf向串口打印調試

作者: 時間:2016-11-19 來源:網絡 收藏
背景知識:

串口的基本知識已經在上一篇講過了。這里重點講解如何在MDK4.22下使用printf函數,這樣的話就可以很方便的打印調試信息,追蹤。

本文引用地址:http://cqxgywz.com/article/201611/318140.htm

這個知識來源于MDK自帶的幫助手冊。有現成的代碼提供。

實現方式有2種,使用標準C庫下裁剪合適的函數,使用微庫C下裁剪合適的函數。

微庫下的情況,在魔術棒那里要勾選上使用微庫。然后需要定義如下結構和改寫如下函數--FILE stdout fputc ferror。

標準庫的情況,也是需要關注FILE stdout fputc ferror。注意網上很多文章說,在標準庫下,需要關掉半主機模式,我嘗試過,關掉后,需要定義_sys_exit函數,可以達到效果,但是如果不關掉半主機模式,和微庫一樣也只定義該定義的,也可以達到效果。不知道,是不是MDK版本升級后,已經統一了兩種模式。

具體代碼:

uart.c

#include "S3C2440.h"#include "uart.h"void init_uart0(void){rULCON0 = 0x03;  rUCON0 = (0x05);//15---12   	11-10		9		8		7				6						5		 4			3-2				1-0//not pclk/n	pclk		Tpulse	Rpulse	timeout disable	rx error int disable   loop dis  break dis	int or poll		int or pollrUFCON0 = 0x00;	  			rUMCON0 = 0x0; 				rUBRDIV0 = UART_BRDIV;}struct __FILE  {  int handle;  /* Whatever you require here. If the only file you are using is */  /* standard output using printf() for debugging, no file handling */  /* is required. */  };  /* FILE is typedef’ d in stdio.h. */  FILE __stdout;  int fputc(int ch, FILE *f) { WrUTXH0_L(ch); /* Loop until the end of transmission */ while(!(rUTRSTAT0 & TXD0READY)) ;return ch; } int ferror(FILE *f) {/* Your implementation of ferror */return EOF;}

main.c

#include "S3C2440.h"#include "uart.h"#include int main(void){	init_uart0();printf("hello worldrn");}

最終可以在UART0上打印hello world,這樣以后程序就可以拿來復用了!


評論


技術專區

關閉