Miyoo >> Assembly

LED


參考資料:
1. pdf
2. lichee
3. mangopi_r
4. allwinner

暫存器


綠色LED是接到PA1


輸出控制


main.s

  .global _start
   
  .equiv GPIO_BASE, 0x01c20800
  .equiv PA,        (0 * 0x24)
  .equiv PORT_CFG0, 0x00
  .equiv PORT_DATA, 0x10
    
  .arm
  .text
_start:
  .long 0xea000016
  .byte 'e', 'G', 'O', 'N', '.', 'B', 'T', '0'
  .long 0, __spl_size
  .byte 'S', 'P', 'L', 2
  .long 0, 0
  .long 0, 0, 0, 0, 0, 0, 0, 0
  .long 0, 0, 0, 0, 0, 0, 0, 0
    
_vector:
  b reset
  b .
  b .
  b .
  b .
  b .
  b .
  b .
    
reset:
  ldr r0, =GPIO_BASE
  ldr r1, =0x10
  str r1, [r0, #(PA + PORT_CFG0)]
  
0:
  ldr r1, =0x02
  str r1, [r0, #(PA + PORT_DATA)]
  ldr r2, =50000
1:
  subs r2, #1
  bne 1b
  ldr r1, =0x00
  str r1, [r0, #(PA + PORT_DATA)]
  ldr r2, =50000
2:
  subs r2, #1
  bne 2b
  b 0b
  .end

main.ld

OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)

MEMORY {
  ram : ORIGIN = 0x00000000, LENGTH = 32M
}

SECTIONS {
  .text :
  {
    PROVIDE(__spl_start = .);
    *(.text*)
    PROVIDE(__spl_end = .);
    *(.init.text)
    *(.exit.text)
    *(.glue*)
    *(.note.gnu.build-id)
  } > ram
  PROVIDE(__spl_size = __spl_end - __spl_start);

  .rodata ALIGN(8) :
  {
    PROVIDE(__rodata_start = .);
    *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*)))
    PROVIDE(__rodata_end = .);
  } > ram

  .data ALIGN(8) :
  {
    PROVIDE(__data_start = .);  
    *(.data*)
    . = ALIGN(8);
      PROVIDE(__data_end = .);
    PROVIDE(__image_end = .);
  } > ram

  .bss ALIGN(8) (NOLOAD) :
  {
    PROVIDE(__bss_start = .);
    *(.bss*)
    *(.sbss*)
    *(COMMON)
    . = ALIGN(8);
    PROVIDE(__bss_end = .);
  } > ram

  .stab 0 : { *(.stab) }
  .stabstr 0 : { *(.stabstr) }
  .stab.excl 0 : { *(.stab.excl) }
  .stab.exclstr 0 : { *(.stab.exclstr) }
  .stab.index 0 : { *(.stab.index) }
  .stab.indexstr 0 : { *(.stab.indexstr) }
  .comment 0 : { *(.comment) }
  .debug_abbrev 0 : { *(.debug_abbrev) }
  .debug_info 0 : { *(.debug_info) }
  .debug_line 0 : { *(.debug_line) }
  .debug_pubnames 0 : { *(.debug_pubnames) }
  .debug_aranges 0 : { *(.debug_aranges) }
}

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
	gcc mksunxi.c -o mksunxi
	./mksunxi main.bin

flash:
	sunxi-fel -p spiflash-write 0 main.bin

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

進入燒錄模式後,然後插入USB至電腦,可以找到如下裝置

$ lsusb
  Bus 002 Device 081: ID 1f3a:efe8 Onda (unverified) V972 tablet in flashing mode

編譯、燒錄

$ 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
  gcc mksunxi.c -o mksunxi
  ./mksunxi main.bin
  The bootloader head has been fixed, spl size is 512 bytes.

$ make flash
  sunxi-fel -p spiflash-write 0 main.bin
  100% [================================================]     1 kB,   55.9 kB/s

接著重新上電即可


返回上一頁