One, now the serial port can only print strings, do not realize the format of the output function, so the value of the variable can not print out. "Progressive printing" is not going to work, it's too painful to join printf right away. Second, the Code root@ubuntu:~/myboot# tree. ├──main.c├──makefile├──nand.c├──nand.h├──sdram.c├──start. S├──UART.C├──UART.H├──U-BOOT.LDS└──VSPRINTF.C 0 directories, Files 2.1 uart.c add uart_printf implementation
Click (here) to collapse or open the #include
#define GPHCON (* (volatile unsigned int *) 0x56000070)
#define GPHUP (* (volatile unsigned int *) 0x56000078)
#define ULCON0 (* (volatile unsigned int *) 0x50000000)
#define UCON0 (* (volatile unsigned int *) 0x50000004)
#define UFCON0 (* (volatile unsigned int *) 0x50000008)
#define UMCON0 (* (volatile unsigned int *) 0x5000000c)
#define UTRSTAT0 (* (volatile unsigned int *) 0x50000010)
#define UERSTAT0 (* (volatile unsigned int *) 0x50000014)
#define UFSTAT0 (* (volatile unsigned int *) 0x50000018)
#define UMSTAT0 (* (volatile unsigned int *) 0x5000001c)
#define UTXH0 (* (volatile unsigned char *) 0x50000020)//Type: char* #define URXH0 (* (volatile unsigned char *) 0x50000024 )
#define UBRDIV0 (* (volatile unsigned int *) 0x50000028)
#define Baud_rate 115200
void Uart_init (void) {
Gphcon = 0x000000a0;
Gphup = 0x000007ff;
ULCON0 = (0x03); 8N1
UCON0 = (0x01<<2) | (0x01);
UFCON0 = 0;
UMCON0 = 0;
UBRDIV0 = (int) ((50*1000*1000)/(BAUD_RATE*16))-1;
}
unsigned char uart_getc (void)
{
while (!) ( UTRSTAT0 & 0x01))
;
Return (URXH0 & 0xff);
}
void Uart_putc (char c)
{
while (!) ( UTRSTAT0&0X02))
;
UTXH0 = C;
if (' n ' = = c)
UART_PUTC (' \ R ');
}
void Uart_puts (char *s)
{
while (*s)
{
UART_PUTC (*s++);
}
}
/*uart_printf*/void uart_printf (char *fmt, ...)
{
Va_list ap;
Char buf[256];
Va_start (AP, FMT);
vsprintf (BUF, FMT, AP);
Uart_puts (BUF);
Va_end (AP);
2.2 VSPRINTF.C from linux_0.11 copy come over, slightly modify
Click (here) to collapse or open #include <stdarg.h>
/* We use the "so" we can do without the CType library * *
#define IS_DIGIT (c) ((c) >= ' 0 ' && (c) <= ' 9 ')
int strlen (const char *s)
{
const char *SC;
for (sc=s; *sc!= '; ++sc ')
;
return (SC-S);
}
static int skip_atoi (const char **s)
{
int i=0;
while (Is_digit (**s))
i = i*10 + * ((*s) + +)-' 0 ';
return i;
}
#define ZEROPAD 1/* pad with zero */
#define SIGN 2/* unsigned/signed long *
#define PLUS 4/* Show plus * *
#define SPACE 8/* space if plus * *
#define LEFT/* Left justified * *
#define SPECIAL/* 0x *
#define SMALL/* use ' abcdef ' instead ' abcdef ' *
#if 0
#define DO_DIV (n,base) ({\
int __res; \
__asm__ ("Divl%4": "=a" (n), "=d" (__res): "0" (N), "1" (0), "R" (base)); \
__res; })
#endif
#define DO_DIV (n,base) ({\
int __res; \
__res = ((unsigned long) n)% (unsigned) base; \
n = ((unsigned long) n)/(unsigned) base; \
__res; \
})
Static char * Number (char * str, int num, int base, int size, int precision
, int type)
{
Char c,sign,tmp[36];
const char *digits= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i;
if (type&small) digits= "0123456789abcdefghijklmnopqrstuvwxyz";
if (type&left) type &= ~zeropad;
if (base<2 | | base>36)
return 0;
c = (type & zeropad)? ' 0 ': ';
if (type&sign && num<0) {
sign= '-';
num =-num;
} else
sign=