BCM2835 >> Assembly

LED


參考資料:
1. example
2. firmware
3. datasheet
4. rpi_software

LED連接到GPIO-29


暫存器


Alternate Function


GPIO SET


GPIO CLR


main.s

  .global _start
 
  .equiv GPFSEL2, 0x20200008
  .equiv GPSET0,  0x2020001c
  .equiv GPCLR0,  0x20200028

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

0:
  ldr r0, =GPSET0
  ldr r1, =(1 << 29)
  str r1, [r0]
  ldr r2, =0x100000
1:
  subs r2, #1
  bne 1b
  
  ldr r0, =GPCLR0
  ldr r1, =(1 << 29)
  str r1, [r0]
  ldr r2, =0x100000
1:
  subs r2, #1
  bne 1b
  b 0b
  .end

P.S. 實體位址是0x20000000,虛擬位址是0x7e000000

main.ld

MEMORY {
    ram : ORIGIN = 0x8000, LENGTH = 0x10000
}

SECTIONS {
    .text : { *(.text*) } > ram
    .bss : { *(.bss*) } > ram
}

Makefile

all:
	arm-none-eabi-as -mcpu=arm1176jzf-s -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 kernel.img

clean:
	rm -rf kernel.img main.o main.elf

編譯

$ make
  arm-none-eabi-as -mcpu=arm1176jzf-s -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 kernel.img

接著準備SDCard,並且格式化成FAT32,並且把bootcode.binstart.elf放到SDCard根目錄,這兩個檔案是必須存在的開機檔案,然後把剛剛編譯的kernel.img也放到SDCard根目錄,接著,插入SDCard到Raspberry Pi


返回上一頁