用的板子是友善之臂mini2440,自己学习韦东山的一期视频,在写uart裸板程序时发现怎么都无法实现功能
s3c2440.h
/* GPIO寄存器 */
#define GPBCON (*(volatile unsigned int*)0x56000010)
#define GPGCON (*(volatile unsigned int*)0x56000060)
#define GPHCON (*(volatile unsigned int*)0x56000070)
#define GPBDAT (*(volatile unsigned int*)0x56000014)
#define GPGDAT (*(volatile unsigned int*)0x56000064)
#define GPHUP (*(volatile unsigned int*)0x56000078)
/* UART寄存器 */
#define UCON0 (*(volatile unsigned int*)0x50000004)
#define UBRDIV0 (*(volatile unsigned int*)0x50000004)
#define ULCON0 (*(volatile unsigned int*)0x50000028)
#define UTRSTAT0 (*(volatile unsigned int*)0x50000010)
#define UTXH0 (*(volatile unsigned char*)0x50000020)
#define URXH0 (*(volatile unsigned char*)0x50000024)
#define UFCON0 (*(volatile unsigned int*)0x50000008)
#define UMCON0 (*(volatile unsigned int*)0x5000000C)
#define UCON1 (*(volatile unsigned int*)0x50004004)
#define UBRDIV1 (*(volatile unsigned int*)0x50004028)
#define ULCON1 (*(volatile unsigned int*)0x50004000)
#define UTRSTAT1 (*(volatile unsigned int*)0x50004010)
#define UTXH1 (*(volatile unsigned char*)0x50004020)
#define URXH1 (*(volatile unsigned char*)0x50004024)
#define UFCON1 (*(volatile unsigned int*)0x50004008)
#define UMCON1 (*(volatile unsigned int*)0x5000400C)
uart.h
#ifndef _UART_H
#define _UART_H
void uart0_init();
int putchar(int c);
int getchar(void);
int puts(const char *s);
#endif
uart.c
#include "s3c2440.h"
/* 设置引脚用于串口 */
void uart0_init()
{
GPHCON &= ~((3<<8)|(3<<10)); //清空GPH2,GPH3
GPHCON |= ((2<<8)|(2<<10)); //GPH4,GPH5用于TXD1,RXD1
GPHUP &= ~((1<<4)|(1<<5)); //使能内部上拉
UFCON0 = 0x00; //不使用FIFO
UMCON0 = 0x00; //不使用流控
ULCON0 = 0x00000003; //设置数据格式8n1:8位数据位,无校验位,1停止位
UCON0 = 0x00000005; //PCLK,中断/查询模式
UBRDIV0 = 26; //设置波特率 115200
}
int putchar(int c)
{
while(!(UTRSTAT0) & (1<<2))
UTXH0 = (unsigned char)c;
}
int getchar(void)
{
while(!(UTRSTAT0) & (1<<0))
return URXH0;
}
int puts(const char *s)
{
while(*s)
{
putchar(*s);
s++;
}
}
main.c
#include "s3c2440.h"
#include "uart.h"
int main(void)
{
unsigned char c;
uart0_init();
puts("hello,world!\n");
while(1)
{
c = getchar();
putchar(c);
}
return 0;
}
start.S
.text
.global _start
_start:
/*设置内存:sp 栈*/
ldr sp,=4096 /*nand启动*/
/* 关闭看门狗 */
ldr r0, =0x53000000
ldr r1, =0
str r1, [r0]
/* 设置CPU工作于异步模式 */
mrc p15,0,r0,c1,c0,0
orr r0,r0,#0xc0000000 //R1_nF:OR:R1_iA
mcr p15,0,r0,c1,c0,0
/* 设置MPLL,FCLK */
/* CLKDIVN(0x4c000014) = 0x5 */
ldr r0, =0x4c000014
ldr r1, =0x5 /* HCLK = FCLK/4 = 100 MHz , PCLK = HCLK/2 = 50MHz */
str r1, [r0]
/* 设置MPLLCON(0x4c000004) = (92<<12)|(1<<4)|(1<<0) FCLK = 400 MHz*/
ldr r0, =0x4c000004
ldr r1, =(92<<12)|(1<<4)|(1<<0)
str r1,[r0]
/*调用main*/
bl main
halt:
b halt
Makefile
all:
arm-linux-gcc -c -o uart.o uart.c
arm-linux-gcc -c -o main.o main.c
arm-linux-gcc -c -o start.o start.S
arm-linux-ld -Ttext 0 start.o uart.o main.o -o uart.elf
arm-linux-objcopy -O binary -S uart.elf uart.bin
arm-linux-objdump -D uart.elf > uart.dis
clean:
rm *.bin *.o *.elf *.dis
程序写完后扔到虚拟机里编译生成.bin文件,之后用友善之臂自己编写的下载工具进行烧写
之后选择nand启动,连接串口,并没有看到返回字符串hello,world!
特来请教