开发环境:
系统:Ubuntu 10.04.4
单板:micro2440
编译器:arm-linux-gcc-4.3.2
搭建开发环境详见Ubuntu 10.04.4开发环境配置。http://www.linuxidc.com/Linux/2013-04/83609.htm
目标:实现micro2440单板上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
linuxidc@linuxidc:~$ cd /home/linuxidc/Si/micro2440/1_led/
linuxidc@linuxidc:~/Si/micro2440/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
linuxidc@linuxidc:~/Si/micro2440/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 2012.04.01 (Oct 25 2012 - 22:47:25)
CPUID: 32440001
FCLK: 400 MHz
HCLK: 100 MHz
PCLK: 50 MHz
DRAM: 64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND: 256 MiB
In: serial
Out: serial
Err: serial
Net: dm9000
Warning: dm9000 MAC addresses don't match:
Address in SROM is ff:ff:ff:ff:ff:ff
Address in environment is 00:0c:29:4d:e4:f4
Hit any key to stop autoboot: 0
SMDK2410 # printenv
baudrate=115200
bootargs=console=ttySAC0 root=/dev/mtdblock3
bootcmd=nand read 30000000 kernel;bootm 30000000
bootdelay=5
ethact=dm9000
ethaddr=00:0c:29:4d:e4:f4
gatewayip=172.16.1.1
ipaddr=172.16.1.133
mtddevname=u-boot
mtddevnum=0
mtdids=nand0=micro2440-0
mtdparts=mtdparts=micro2440-0:256k(u-boot),128k(params),2M(kernel),-(rootfs)
netmask=255.255.255.0
partition=nand0,0
serverip=172.16.1.135
stderr=serial
stdin=serial
stdout=serial
Environment size: 476/131068 bytes
SMDK2410 # tftp 0x30000000 1_led.bin
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:0c:29:4d:e4:f4
could not establish link
Using dm9000 device
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)
SMDK2410 # nand erase 0 0x40000
NAND erase: device 0 offset 0x0, size 0x40000
Erasing at 0x20000 -- 100% complete.
OK
SMDK2410 # nand write 0x30000000 0 0x40000
NAND write: device 0 offset 0x0, size 0x40000
262144 bytes written: OK
SMDK2410 #
注意printenv发现网卡参数不对,需要设置如下:
SMDK2410 # set ipaddr 172.16.1.133
SMDK2410 # set gatewayip 172.16.1.1
SMDK2410 # set serverip 172.16.1.135
SMDK2410 # save
接着单板断电,拨到NAND Flash启动,上电,4个LED灯就开始闪烁。