埋め込み学習-uboot-lesson 9.2-C点灯LED
前のスタックの初期化とBSSセグメントのクリアを行った後,Cを用いてプログラムの作成を行うことができ,ここではLEDを直接操作し,その効果を見ることができる.
新しいmainを作成します.c
そしてstart.Sではman関数にジャンプさせます.
コードは詳しく説明しません.
すべてのコードを貼り付けます.Makefile
start.S
菜鸟一枚、间违いがあれば、よろしくお愿いします...
新しいmainを作成します.c
/********************************************
*file name: main.c
*author : stone
*date : 2016.6.30
*function : LED
*********************************************/
#define GPMCON (*(volatile unsigned long *)0x7F008820)
#define GPMDAT (*(volatile unsigned long *)0x7F008824)
int gboot_main()
{
GPMCON = 0x1111;
GPMDAT = 0x00; //
return 0;
}
そしてstart.Sではman関数にジャンプさせます.
ldr pc,=gboot_main @ gboot_main
コードは詳しく説明しません.
すべてのコードを貼り付けます.Makefile
all: start.o mem.o main.o
arm-linux-ld -Tgboot.lds -o gboot.elf $^
arm-linux-objcopy -O binary gboot.elf gboot.bin
%.o : %.S
arm-linux-gcc -g -c $^
%.o : %.c
arm-linux-gcc -g -c $^
.PHONY: clean
clean:
rm *.o *.elf *.bin
start.S
@****************************
@file name: start.S
@author : stone
@date : 2016.6.30
@function :
@
@ SVC
@
@
@ MMU
@
@ LED
@
@
@
@
@ BSS
@ gboot_main
@****************************
.text
.global _start @ _start
_start:
b reset
ldr pc, _undefined_instruction
ldr pc, _software_interrupt
ldr pc, _prefetch_abort
ldr pc, _data_abort
ldr pc, _not_used
ldr pc, _irq
ldr pc, _fiq
_undefined_instruction: .word undefined_instruction
_software_interrupt: .word software_interrupt
_prefetch_abort: .word prefetch_abort
_data_abort: .word data_abort
_not_used: .word not_used
_irq: .word irq
_fiq: .word fiq
undefined_instruction: @
nop
software_interrupt: @
nop
prefetch_abort: @
nop
data_abort: @
nop
not_used: @
nop
irq: @
nop
fiq: @
nop
reset: @reset
bl set_svc @ SVC
bl set_peri_port @
bl disable_watchdog @
bl disable_interrupt @
bl disable_mmu @ mmu
bl init_clock @
bl mem_init @
bl copy_to_ram @
bl init_stack @
bl clean_bss @ bss
ldr pc,=gboot_main @ gboot_main
@bl light_led @ LED
set_svc:
mrs r0, cpsr @ cpsr
bic r0, r0, #0x1f @ 5 M[4:0]
orr r0, r0, #0xd3 @0b10011 16 0x13 irq fiq, 0b11010011 0xd3
msr cpsr, r0 @ cpsr
mov pc, lr @
set_peri_port:
ldr r0, =0x70000000 @
orr r0, r0, #0x13 @256MB
mcr p15,0,r0,c15,c2,4 @ cp15
mov pc, lr
#define pwTCON 0x7E004000 @WTCON
disable_watchdog:
ldr r0, =pwTCON @ R0
mov r1, #0x0 @ 0,
str r1,[r0]
mov pc,lr
disable_interrupt:
mvn r1,#0x0 @0x0 , r1
ldr r0,=0x71200014 @VIC0
str r1,[r0]
ldr r0,=0x71300014 @VIC1
str r1,[r0]
mov pc,lr
disable_mmu:
mcr p15,0,r0,c7,c7,0 @ ICACHE DCACHE
mrc p15,0,r0,c1,c0,0 @read control register
bic r0,r0,#0x00000007 @mmu dcache
mcr p15,0,r0,c1,c0,0 @write control register
mov pc,lr
#define CLK_DIV0 0x7e00f020
#define CLK_SRC 0x7e00f01c
#define OTHERS 0x7e00f900
#define MPLL_CON 0X7E00F010
#define APLL_CON 0X7E00F00c
#define PLL_VAL ((1<<31)|(266<<16)|(3<<8)|(1<<0))
#define DIV_VAL ((0X0<<0)|(0X1<<9)|(0X1<<8)|(0X3<<12))
init_clock:
ldr r0,=CLK_DIV0 @
ldr r1,=DIV_VAL
str r1,[r0]
ldr r0,=OTHERS @ 7 0 6 0( )
ldr r1,[r0]
bic r1,r1,#0xc0
str r1,[r0]
ldr r0,=APLL_CON @APLL 533Mhz
ldr r1,=PLL_VAL
str r1,[r0]
ldr r0,=MPLL_CON @MPLL 533Mhz
ldr r1,=PLL_VAL
str r1,[r0]
ldr r0, =CLK_SRC @ APLL MPLL
mov r1, #0x3 @APLL MPLL
str r1, [r0]
mov pc,lr
copy_to_ram:
ldr r0, =0x0c000000 @
ldr r1, =0x50008000 @
add r3, r0, #1024*4 @ 4KB
copy_loop:
ldr r2, [r0], #4 @ r0
str r2, [r1], #4 @ r1
cmp r0, r3 @ r0
bne copy_loop
mov pc, lr
init_stack:
ldr sp,=0x54000000 @50000000 + 64
mov pc,lr
clean_bss:
ldr r0,=bss_start
ldr r1,=bss_end
cmp r0,r1 @ r0 r1 , , ,
moveq pc,lr @ ,
clean_loop:
mov r2,#0
str r2,[r0],#4
cmp r0,r1
bne clean_loop
mov pc,lr
#define GPMCON 0x7F008820 @
#define GPMDAT 0x7F008824 @
light_led:
ldr r0,=GPMCON
ldr r1,=0x1111 @
str r1,[r0]
ldr r0,=GPMDAT
ldr r1,=0x00 @
str r1,[r0]
mov pc,lr
菜鸟一枚、间违いがあれば、よろしくお愿いします...