掌機 - GP2X Wiz - Assembly - LED



LED連接到GPIOC-16


GPIO架構


暫存器


main.s

    .global _start

    .equiv GPIOC_OUT,    0xc000a080
    .equiv GPIOC_OUTENB, 0xc000a084

    .arm
    .text
_start:
    b reset
    b .
    b .
    b .
    b .
    b .
    b .
    b .
   
reset:
    ldr r0, =GPIOC_OUTENB
    ldr r1, =(1 << 16)
    str r1, [r0]

    ldr r0, =GPIOC_OUT
0:
    eor r1, #(1 << 16)
    str r1, [r0]
    ldr r2, =1000000
1:
    subs r2, #1
    bne 1b
    b 0b
    .end

main.ld

MEMORY {
    RAM : ORIGIN = 0, LENGTH = 16K
}

SECTIONS {
    text : {
        *(.text*)
        FILL(0x00)
        . = 0x4000;
    } > RAM
}

upload.py

#!/usr/bin/python
import os
import sys
import serial
 
DEF_FILE = 'main.bin'
DEF_PORT = '/dev/ttyUSB0'
   
if os.geteuid() != 0:
    print 'run me as root'
    sys.exit()
  
if os.path.exists(DEF_FILE) == False:
    print 'failed to open {}'.format(DEF_FILE)
    sys.exit()
  
print 'uploading...'
ser = serial.Serial(DEF_PORT, 19200)
ser.flush()
f = open(DEF_FILE, 'rb')
ser.write(f.read())
f.close()
ser.close()
print 'upload complete'

Makefile

all:
	arm-none-eabi-as -mcpu=arm9 -o main.o main.s
	arm-none-eabi-ld -T main.ld -o main.elf main.o
	arm-none-eabi-objcopy -O binary main.elf main.bin

upload:
	sudo ./upload.py

clean:
	rm -rf main.bin main.elf main.o

上傳步驟如下:
1. 讓Wiz進入UART開機模式
2. 執行如下指令

$ make
    arm-none-eabi-as -mcpu=arm9 -o main.o main.s
    arm-none-eabi-ld -T main.ld -o main.elf main.o
    arm-none-eabi-objcopy -O binary main.elf main.bin

$ make upload
    sudo ./upload.py
    uploading...
    upload complete

完成