sdram 裸机程序

 硬件平台 :JZ2440

 实现功能:将led闪烁代码从2440的2k sram中拷贝到sdram

 

 start.s      -->   上电初始化,拷贝代码

 sdram.c   -->   led代码

 

 start.s 源码:

.equ MENRI_BASE, 0x48000000
.equ SDRAM_BASE, 0x30000000

.text
.global _start
_start:
        bl close_watchdog
        bl sdram_set
        bl copy_sram_to_sdram
        ldr pc,=on_sdram
on_sdram:
        ldr sp,=0x34000000
        bl main
loop1:
       b loop1
        
close_watchdog:
        ldr r0,=0x53000000
        mov r1,#0x0        
        str r1,[r0]
        mov pc,lr

copy_sram_to_sdram:
        ldr r0,=SDRAM_BASE
        mov r1,#0x0
        mov r3,#4*1024
l:    
        ldr r4,[r1], #4
        str r4,[r0],#4    
        cmp r1, r3  
        bne l
         
         mov pc,lr 
         
sdram_set:
        mov r1,#MENRI_BASE
        adrl r2,mem_reg_set
        add r3,r1,#52
m:
        ldr r4,[r2],#4
        str r4,[r1],#4
        cmp r1,r3
        bne m
        
        mov pc,lr

.align 4
mem_reg_set:
.long  0x22011110
.long  0x00000700
.long  0x00000700
.long  0x00000700 
.long  0x00000700               
.long  0x00000700               
.long  0x00000700 
.long  0x00018005
.long  0x00018005
.long  0x008c07a3
.long  0x000000b1
.long  0x00000030
.long  0x00000030

 

sdram.c 源码:

#define GPFCON (*(unsigned long *)0x56000050) 
#define GPFDAT (*(unsigned long *)0x56000054)
#define LED1_ON   (1<<8)
#define LED2_ON   (1<<10)
#define LED3_ON   (1<<12)

void delay(unsigned long num)
{
    while(--num);
}

int main(void)
{
    GPFCON=LED1_ON|LED2_ON|LED3_ON;
    while(1)
    {
        GPFDAT=(1<<4);
        delay(100000);
        GPFDAT=(1<<5);
        delay(100000);
        GPFDAT=(1<<6);
        delay(100000);
    }
    
    return 0;
}

 

编译的Makefile:

sdram.bin:start.s sdram.c
    arm-linux-gcc -o start.o -c start.s
    arm-linux-gcc -o sdram.o -c sdram.c
    arm-linux-ld -Ttext 0x3000000 -o sdram_elf start.o sdram.o
    arm-linux-objcopy  -O binary -S sdram_elf sdram.bin
    arm-linux-objdump -D -m arm sdram_elf > sdram.dis
clean:
    rm *.o *.dis *.bin sdram_elf 

 

 

 

 

 

 

 

 

 

    

posted @ 2019-02-20 17:49  张不源  Views(243)  Comments(0Edit  收藏  举报