|
我按照手册写了个TQ2440的定时程序,结果用JTag在gdb中调试时好像没有问题,但是通过usb下载到开发板上运行时好像就不行了。代码如下:Makefile文件内容如下:
- CFLAGS := -Wall -Wstrict-prototypes -g -fomit-frame-pointer -ffreestanding
- all : crt0.S time.c
- arm-elf-gcc $(CFLAGS) -c -o crt0.o crt0.S
- arm-elf-gcc $(CFLAGS) -c -o time.o time.c
- arm-elf-ld -Ttext 0 crt0.o time.o -o time_elf
- arm-elf-objcopy -O binary -S time_elf time.bin
- arm-elf-objdump -D -m arm time_elf > time.dis
- clean:
- rm -f time.dis time.bin time_elf *.o
复制代码 crt0.s文件内容如下:
- @*********************************************
- @ File:crt0.S
- @ 功能:通过它转入C程序
- @*********************************************
- .text
- .global _start
- _start:
- ldr r0, =0x53000000 @ WATCHDOG寄存器地址
- mov r1, #0x0
- str r1, [r0] @ 写入0,禁止WATCHDOG,否则CPU会不断重启
- ldr sp, =1024*4 @ 设置堆栈,注意:不能大于4k, 因为现在可用的内存只有4K
- @ nand flash中的代码在复位后会移到内部ram中,此ram只有4K
- bl main @ 调用C程序中的main函数
- halt_loop:
- b halt_loop
复制代码 time.c文件内容如下:
- #define GPBCON (*(volatile unsigned long *)0x56000010)
- #define GPBDAT (*(volatile unsigned long *)0x56000014)
- #define TCFG0 (*(volatile unsigned int *)0x51000000)
- #define TCFG1 (*(volatile unsigned int *)0x51000004)
- #define TCON (*(volatile unsigned int *)0x51000008)
- #define TCNTB0 (*(volatile unsigned int *)0x5100000C)
- #define TCMPB0 (*(volatile unsigned int *)0x51000010)
- #define TCNTO0 (*(volatile unsigned int *)0x51000014)
- int main(void)
- {
- //led init 全灭
- unsigned int led = 0x1e0;
- GPBCON = (1<<(5*2)) |(1<<(6*2)) |(1<<(7*2)) |(1<<(8*2));
- GPBDAT = led;
- //time init
- TCFG0 = 99;
- TCFG1 = 0x03;
- TCNTB0 = 31250;
- TCON |= 2;
- TCON = 0x09;
- while(1)
- {
- while(TCNTO0 >= (31250>>1));
- while(TCNTO0 < (31250>>1));
- led = ~led;
- GPBDAT = led;
- }
- return 0;
- }
复制代码 实现的功能是定时让led灯闪烁,在使用JTag调试时没有问题,但是下载到开发板上运行时好像就不行了。
之前用纯汇编语言写过的程序也没有问题,现在用C来写就这样了。
|
|