描述:
在某宝上买的s3c2440的板子,网上找的电子书学习了一段LED点灯的程序,然后就遇到了一个非常奇怪的问题,片外内存的初始化用C语言写,不能正常点灯,换成汇编就能正常点灯。请大神们帮忙看看到底怎么回事
Makefile:
sdram.bin: sdram.s GPIO_LED.c
arm-linux-gcc -c -o sdram.o sdram.s
arm-linux-gcc -c -o GPIO_LED.o GPIO_LED.c
arm-linux-ld -Ttext 0x30000000 sdram.o GPIO_LED.o -o sdram_elf
arm-linux-objcopy -O binary -S sdram_elf sdram.bin
arm-linux-objdump -D -m arm sdram_elf > sdram.dis
clean:
rm -f *.dis sdram.bin sdram_elf *.o *~
sdram.s
.text
.global _start
_start:
ldr sp, =4096
bl disable_watchdog //关看门狗
bl sdram_setup //初始化片外内存
bl nandcopy2sdram //将片内内存里的东西拷贝到片外内存
ldr pc, =sdram //跳转到片外内存
sdram:
ldr sp, =0x34000000
bl main
halt_loop:
b halt_loop
GPIO_LED.c //点亮开发板上的LED灯
#define GPFCON (*(volatile unsigned long *)0x56000050)
#define GPFDAT (*(volatile unsigned long *)0x56000054)
#define WDCON (*(unsigned long*)0x53000000)
#define SDRAMCON 0x48000000
#define GPF4_out (1<<(4*2))
#define GPF5_out (1<<(5*2))
#define GPF6_out (1<<(6*2))
void wait(volatile unsigned long dly)
{
for(; dly > 0; dly--);
}
int main(void)
{
unsigned long i = 0;
GPFCON = GPF4_out|GPF5_out|GPF6_out; // 将LED1,2,4对应的GPF4/5/6三个引脚设为输出
while(1){
wait(30000);
GPFDAT = (~(i<<4)); // 根据i的值,点亮LED1,2,4
if(++i == 8)
i = 0;
}
return 0;
}
void disable_watchdog()
{
WDCON = 0 ; //禁用watchdog
}
void sdram_setup()
{
unsigned long const sdramfig[] = {
0x22011110,
0x00000700,
0x00000700,
0x00000700,
0x00000700,
0x00000700,
0x00000700,
0x00018005,
0x00018005,
0x008c07a3,
0x000000b1,
0x00000030,
0x00000030,
};
int i = 0;
volatile unsigned long *p = (volatile unsigned long *) SDRAMCON;
for(;i<13;i++)
{
&n