您的位置:首页 > 其它

TQ2440第一个裸板程序led

2013-04-22 22:48 267 查看
开发环境

系统:ubuntu 10.04.4

单板:tq2440

编译器:arm-linux-gcc-4.3.2

搭建开发环境详见ubuntu 10.04.4开发环境配置。

目标:实现tq2440单板上4个led灯闪烁

第一个程序很简单,用汇编实现。硬件如下:

nLED_1——>GPB5

nLED_2——>GPB6

nLED_3——>GPB7

nLED_4——>GPB8

根据s3c2440手册编写代码,包括2个文件1_led.s和Makefile.

一、编写源码

文件·1_led.s:

.text
.global _start
_start:
ldr	r0,=0x56000010
mov	r1,#0x00015400
str	r1,[r0]
ldr	r0,=0x56000014
loop:	mov	r1,#0x00000000
str	r1,[r0]
bl	delay
mov	r1,#0x00000ff0
str	r1,[r0]
bl	delay
b	loop

delay:
mov	r4,#100
del1:	mov	r5,#1000
del2:	sub	r5,r5,#1
nop
cmp	r5,#1
bne	del2
sub	r4,r4,#1
nop
cmp	r4,#1
bne	del1
mov	pc,lr


文件Makefile:

1_led.bin:1_led.s
arm-linux-gcc -g -c -o 1_led.o 1_led.s
arm-linux-ld -Ttext 0x00000000 -g 1_led.o -o 1_led_elf
arm-linux-objcopy -O binary -S 1_led_elf 1_led.bin
arm-linux-objdump -D 1_led_elf > 1_led.dis
clean:
rm -f 1_led.bin *.o 1_led_elf 1_led.dis


二、编译

change@change:~$ cd /home/change/Si/tq2440/1_led/

change@change:~/Si/tq2440/1_led$ make

arm-linux-gcc -g -c -o 1_led.o 1_led.s

arm-linux-ld -Ttext 0x00000000 -g 1_led.o -o 1_led_elf

arm-linux-objcopy -O binary -S 1_led_elf 1_led.bin

arm-linux-objdump -D 1_led_elf > 1_led.dis

change@change:~/Si/tq2440/1_led$ ls

1_led.bin 1_led.dis 1_led_elf 1_led.o 1_led.s Makefile

三、烧写、测试:

很多人电脑都没有并口或者openjtag编程器,这里介绍直接用u-boot烧写。前提是单板已有u-boot并且支持网卡。

我用NOR Flash里的u-boot烧写程序到NAND Flash,过程如下:

单板NOR Flash启动上电:

U-Boot 1.1.6 (Mar 24 2012 - 03:44:51)

DRAM:  64 MB
Flash:  2 MB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Hit any key to stop autoboot:  0
TQ2440 # printenv
bootargs=noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0
bootdelay=3
baudrate=115200
ethaddr=08:00:3e:26:0a:5b
ipaddr=192.168.1.111
serverip=192.168.1.110
netmask=255.255.255.0
bootcmd=nboot 0x30000000 0 0;bootm 0x30000000
tdin=serial
stdout=serial
stderr=serial

Environment size: 477/131068 bytes
TQ2440 # set ipaddr 172.16.1.133
TQ2440 # set gatewayip 172.16.1.1
TQ2440 # set serverip 172.16.1.135
TQ2440 # ping 172.16.1.135
dm9000 i/o: 0x20000000, id: 0x90000a46
MAC: 00:80:00:80:00:80
could not establish link
host 172.16.1.135 is alive
TQ2440 # tftp 0x30000000 1_led.bin
dm9000 i/o: 0x20000000, id: 0x90000a46
MAC: 00:80:00:80:00:80
could not establish link
TFTP from server 172.16.1.135; our IP address is 172.16.1.133
Filename '1_led.bin'.
Load address: 0x30000000
Loading: #
done
Bytes transferred = 96 (60 hex)
TQ2440 # nand erase 0 0x40000

NAND erase: device 0 offset 0x0, size 0x40000
Erasing at 0x20000 -- 100% complete.
OK
TQ2440 # nand write 0x30000000 0 0x40000

NAND write: device 0 offset 0x0, size 0x40000
262144 bytes written: OK
TQ2440 #


其中上面网卡参数设置根据自己的网关设定。

tq2440单板断电,拨到NAND Flash启动,上电4个LED灯即开始闪烁。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: