天嵌 ARM开发社区

 找回密码
 注册
查看: 1821|回复: 1

关于一个定时器裸机程序的问题

[复制链接]
wosuopu 发表于 2012-1-27 18:00:43 | 显示全部楼层 |阅读模式
我按照手册写了个TQ2440的定时程序,结果用JTag在gdb中调试时好像没有问题,但是通过usb下载到开发板上运行时好像就不行了。代码如下:Makefile文件内容如下:

  1. CFLAGS         := -Wall -Wstrict-prototypes -g -fomit-frame-pointer -ffreestanding
  2. all : crt0.S  time.c
  3.         arm-elf-gcc $(CFLAGS) -c -o crt0.o crt0.S
  4.         arm-elf-gcc $(CFLAGS) -c -o time.o time.c
  5.         arm-elf-ld -Ttext 0 crt0.o time.o -o time_elf
  6.         arm-elf-objcopy -O binary -S time_elf time.bin
  7.         arm-elf-objdump -D -m arm  time_elf > time.dis
  8. clean:
  9.         rm -f   time.dis time.bin time_elf *.o
复制代码
crt0.s文件内容如下:

  1. @*********************************************
  2. @ File:crt0.S
  3. @ 功能:通过它转入C程序
  4. @*********************************************
  5. .text
  6. .global _start
  7. _start:
  8.             ldr     r0, =0x53000000     @ WATCHDOG寄存器地址
  9.             mov     r1, #0x0
  10.             str   r1, [r0]              @ 写入0,禁止WATCHDOG,否则CPU会不断重启

  11.             ldr     sp, =1024*4         @ 设置堆栈,注意:不能大于4k, 因为现在可用的内存只有4K
  12.                                         @ nand flash中的代码在复位后会移到内部ram中,此ram只有4K
  13.             bl      main                @ 调用C程序中的main函数
  14. halt_loop:
  15.             b       halt_loop
复制代码
time.c文件内容如下:
  1. #define        GPBCON                (*(volatile unsigned long *)0x56000010)
  2. #define        GPBDAT                (*(volatile unsigned long *)0x56000014)
  3. #define TCFG0 (*(volatile unsigned int *)0x51000000)
  4. #define TCFG1 (*(volatile unsigned int *)0x51000004)
  5. #define TCON (*(volatile unsigned int *)0x51000008)
  6. #define TCNTB0 (*(volatile unsigned int *)0x5100000C)
  7. #define TCMPB0 (*(volatile unsigned int *)0x51000010)
  8. #define TCNTO0 (*(volatile unsigned int *)0x51000014)

  9. int main(void)
  10. {
  11.         //led init 全灭
  12.         unsigned int led = 0x1e0;
  13.         GPBCON = (1<<(5*2)) |(1<<(6*2)) |(1<<(7*2)) |(1<<(8*2));
  14.         GPBDAT = led;

  15.         //time init
  16.         TCFG0 = 99;
  17.         TCFG1 = 0x03;
  18.         TCNTB0 = 31250;
  19.         TCON |= 2;
  20.         TCON = 0x09;
  21.         while(1)
  22.         {
  23.                 while(TCNTO0 >= (31250>>1));
  24.                 while(TCNTO0 < (31250>>1));
  25.                 led = ~led;
  26.                 GPBDAT = led;
  27.         }
  28.         return 0;
  29. }
复制代码
实现的功能是定时让led灯闪烁,在使用JTag调试时没有问题,但是下载到开发板上运行时好像就不行了。
之前用纯汇编语言写过的程序也没有问题,现在用C来写就这样了。
raominping 发表于 2012-3-5 13:16:25 | 显示全部楼层
怎么没有延时啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-5-25 23:22 , Processed in 1.031250 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表