天天看點

ok6410第一個裸闆程式led

開發環境:

系統:ubuntu 10.04.4

單闆:ok6410

編譯器:arm-linux-gcc-4.3.2

搭建開發環境詳見ubuntu 10.04.4開發環境配置。

目标:實作ok6410單闆上4個led燈閃爍

第一個程式很簡單,用彙編實作。硬體如下:

NLED1——>GPM0

NLED2——>GPM1

NLED3——>GPM2

NLED4——>GPM3

根據s3c6410手冊編寫代碼,包括2個檔案start.S和Makefile.

檔案start.S:

.globl _start

_start:



/* 硬體相關的設定 */

    /* Peri port setup */

    ldr r0, =0x70000000

    orr r0, r0, #0x13

    mcr p15,0,r0,c15,c2,4       @ 256M(0x70000000-0x7fffffff)

    

/* 關看門狗 */

/* 往WTCON(0x7E004000)寫0 */

	

	ldr r0, =0x7E004000

	mov r1, #0

	str r1, [r0]

/* 設定GPMCON讓GPM0/1/2/3作為輸出引腳 */

	ldr r1, =0x7F008820

	ldr r0, =0x1111

	str r0, [r1]



/* 設定GPMDAT讓GPM3輸出0 */

	ldr r1, =0x7F008824

	mov r0, #0



loop:	mov	r0,#0x0
	str	r0,[r1]
	bl	delay
	mov	r0,#0x0f
	str	r0,[r1]
	bl	delay
	b	loop

delay:
	mov	r4,#0x400
del1:	mov	r5,#0x1000
del2:	sub	r5,r5,#1
	cmp	r5,#1
	bne	del2
	sub	r4,r4,#1
	cmp	r4,#1
	bne	del1
	mov	pc,lr
	
halt:	b	halt
           

檔案Makefile:

1_led.bin: start.o
	arm-linux-ld -Ttext 0 -o 1_led.elf start.o
	arm-linux-objcopy -O binary 1_led.elf 1_led.bin
	arm-linux-objdump -D 1_led.elf > 1_led.dis

start.o : start.S
	arm-linux-gcc -o start.o start.S -c

clean:
	rm *.o 1_led.elf 1_led.bin 1_led.dis
           

編譯:

[email protected]:~$ cd Si/OK6410/1_led/

[email protected]:~/Si/OK6410/1_led$ ls

Makefile  start.S

[email protected]:~/Si/OK6410/1_led$ make

arm-linux-gcc -o start.o start.S -c

arm-linux-ld -Ttext 0 -o 1_led.elf start.o

arm-linux-objcopy -O binary 1_led.elf 1_led.bin

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

[email protected]:~/Si/OK6410/1_led$ cp 1_led.bin /home/change/work/tftpboot/

下面會用到tftp,tftp配置詳見ubuntu 10.04.4開發環境配置。

燒寫、測試:

考慮到大多數電腦沒有并口也沒有仿真器,直接用闆子自帶的u-boot測試程式,把程式放到記憶體運作。後期會寫操作nand的自我更新程式,那時再下載下傳程式就友善了。

U-Boot 2012.04.01 (Jan 11 2013 - 14:47:24) for SMDK6410


CPU:     [email protected]
         Fclk = 532MHz, Hclk = 133MHz, Pclk = 66MHz (ASYNC Mode) 
Board:   SMDK6410
DRAM:  128 MiB
WARNING: Caches not enabled
Flash: 0 KB
NAND:  select s3c_nand_oob_mlc_64
id_data[0] = 0xec id_data[1] = 0xd5 id_data[2] = 0x94 id_data[3] = 0x29 id_data[4] = 0x34 id_data[5] = 0x41 id_data[6] = 0xec id_data[7] = 0xd5 NAND_ECC_NONE selected by board driver. This is not recommended !!
2048 MiB
realpage value:255
page value:255
ret value:0
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0 

##### 100ask Bootloader for OpenJTAG #####
[n] Download u-boot to Nand Flash
[k] Download Linux kernel uImage
[j] Download root_jffs2 image
[y] Download root_yaffs image
[d] Download to SDRAM & Run
[z] Download zImage into RAM
[g] get file, and write to nand flash 0 block
[f] Format the Nand Flash
[s] Set the boot parameters
[b] Boot the system
[r] Reboot u-boot
[q] Quit from menu
Enter your selection: q
SMDK6410 # printenv
baudrate=115200
bootargs=console=ttySAC0,115200 root=/dev/mtdblock3
bootcmd=nand read 0x50000000 0x60000 0x200000;bootm 0x50000000
bootdelay=5
ethact=dm9000
ethaddr=00:0c:29:4d:e4:f4
ipaddr=172.16.1.111
netmask=255.255.255.0
serverip=172.16.1.114
stderr=serial
stdin=serial
stdout=serial

Environment size: 313/524284 bytes
SMDK6410 # set ipaddr 172.16.1.133
SMDK6410 # set gatewayip 172.16.1.1
SMDK6410 # set serverip 172.16.1.135
SMDK6410 # ping 172.16.1.135
dm9000 i/o: 0x18000000, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 00:0c:29:4d:e4:f4
operating at 100M full duplex mode
Using dm9000 device
host 172.16.1.135 is alive
SMDK6410 # save
Saving Environment to NAND...
Env_nand.c...
env_nand.c saveenv start1
env_nand.c saveenv start2
 res = 1472200204 len = 524284
Erasing Nand...
Erasing at 0x80000 -- 100% complete.
Writing to Nand... done
           
SMDK6410 # tftp 0x52000000 1_led.bin
dm9000 i/o: 0x18000000, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 00:0c:29:4d:e4:f4
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 172.16.1.135; our IP address is 172.16.1.133
Filename '1_led.bin'.
Load address: 0x52000000
Loading: #
done
Bytes transferred = 128 (80 hex)
SMDK6410 # go 0x52000000
## Starting application at 0x52000000 ...

u-boot下執行完上述指令。ok6410單闆上4個LED即開始閃爍。上面的u-boot是我仿照韋老師的jz2440移植的,需要源碼的留郵箱。
           

繼續閱讀