刚开始学习arm开发的时候看的是《S3c2410完全开发流程》,是非常不错的开发入门教程,表达一下对作者的崇高够意,但美中不足的是书中有些寄存器只是针对于2410的,而现在我手中的板子是2440的。虽然道理是相通的,但是如果能有2440的就更好了,谁让咱是新手呢?(什么是新手?新手就是板子必须是一样的,例子完全是一样的才能学习)
一、环境搭建:
1.1 windows XP:
DNW : 下载编写好的u-boot
SecureCRT: 显示串口打印消息
vmware +
ubuntu 10.10
硬件: tq2440 + 电源
双母头串口线 + usb转串口
usb下载线
虚拟机中,直接解压EABI-4.3.3_EmbedSky_20091210.tar.bz2到/目录下,不用设置环境变量。在Makefile中把编译工具链的路径写死就行了。
二、汇编写的点亮LED
2.1 start.S
-
.text
-
.global _start
-
_start:
-
ldr r0, =0x56000010
-
ldr r1, =0x00015400
-
str r1, [r0]
-
-
ldr r0, =0x56000014
-
mov r1, #0
-
str r1, [r0]
-
-
loop:
-
b loop
2.2 Makefile
-
CROSS_COMPILE = /opt/EmbedSky/crosstools_3.4.5_softfloat/gcc-3.4.5-glibc-2.3.6/arm-linux/bin/ arm-linux-
-
-
AS = $(CROSS_COMPILE)as
-
LD = $(CROSS_COMPILE)ld
-
CC = $(CROSS_COMPILE)gcc
-
CPP = $(CC) -E
-
AR = $(CROSS_COMPILE)ar
-
NM = $(CROSS_COMPILE)nm
-
STRIP = $(CROSS_COMPILE)strip
-
OBJCOPY = $(CROSS_COMPILE)objcopy
-
OBJDUMP = $(CROSS_COMPILE)objdump RANLIB = $(CROSS_COMPILE)RANLIB
-
-
led_on:start.S
-
$(CC) -g -c -o led_on.o start.S
-
$(LD) -Ttext 0x0000000 -g led_on.o -o led_on_tmp.o
-
$(OBJCOPY) -O binary -S led_on_tmp.o led_on
-
clean:
-
rm -f led_on
-
rm -f led_on.o
-
rm -f led_on_tmp.o
三、c语言写的点亮LED
3.1 start.S
-
.text
-
.global _start
-
_start:
-
ldr sp, =1024*4
-
bl main
-
-
loop:
-
b loop
3.2 main.c
-
#define GPBCON (*(volatile unsigned int *) 0x56000000)
-
#define GPBDAT (*(volatile unsigned int *) 0x56000004)
-
-
void main()
-
{
-
GPBCON = 0x15400;
-
GPBDAT = 0x0;
-
return ;
-
}
3.3 Makefile
-
CROSS_COMPILE = /opt/EmbedSky/crosstools_3.4.5_softfloat/gcc-3.4.5-glibc-2.3.6/arm-linux/bin/ arm-linux-
-
LD = $(CROSS_COMPILE)ld
-
CC = $(CROSS_COMPILE)gcc
-
OBJCOPY = $(CROSS_COMPILE)objcopy
-
-
led_on:start.S
-
$(CC) -g -c -o led_on.o start.S
-
$(CC) -g -c -o main.o main.c
-
$(LD) -Ttext 0x0000000 start.o main.o -o led_on_tmp.o
-
$(OBJCOPY) -O binary -S led_on_tmp.o led_on
-
clean:
-
rm -f led_on
-
rm -f led_on.o
-
rm -f led_on_tmp.o
四、
c语言写的流水灯
4.1 start.S
-
.text
-
.global _start
-
_start:
-
ldr r0, =0x53000000
-
mov r1, #0x0
-
str r1, [r0]
-
-
ldr sp, =1024*4
-
bl main
-
-
loop:
-
b loop
4.2 main.c
-
#define GPBCON (*(volatile unsigned int *) 0x56000010)
-
#define GPBDAT (*(volatile unsigned int *) 0x56000014)
-
-
static inline void delay (unsigned long loops)
-
{
-
__asm__ volatile ("1:\n"
-
"subs %0, %1, #1\n"
-
"bne 1b":"=r" (loops):"0" (loops));
-
}
-
-
void main()
-
{
-
int i = 1;
-
GPBCON = 0x15400;
-
while(1)
-
{
-
GPBDAT = 0x7FF&(~i<<5);
-
i *= 2;
-
if(16==i)
-
i = 1;
-
delay(400000);
-
}
-
return ;
-
}
要注意的是,s3c2440默认情况下是开启了watchdog,所以当运行这个程序时突然灯亮的顺序不对了,要考虑关闭watchdog。
delay(400000); 很接近1s,400000这个数值是凑出来的,具体这个延时是怎么算的,还不太清楚,但是肯定和51“一个机器周期=12个时钟周期”的计算方法不一样。
阅读(3399) | 评论(0) | 转发(1) |