硬件平台:友善之臂mini2440
u-boot:2010.03
交叉工具链:arm-linux-gcc 4.3.2
led1 led2 led3 led4
GPB5 GPB6 GPB7 GPB8
code:main.c
#include "led.h"
int main(void)
{
int count = 0;
show("hello.world!\n");
led_x_init(LED1);
led_x_init(LED2);
led_x_init(LED4);
led_x_init(LED3);
while(1)
{
led_x_on(LED1);
led_x_off(LED2);
led_x_on(LED3);
led_x_off(LED4);
delay();
led_x_off(LED1);
led_x_on(LED2);
led_x_off(LED3);
led_x_on(LED4);
delay();
if (count++ > 5)
break;
}
show("hello.linux!\n");
return 0;
}
led.h:
#ifndef __LED_H__
#define __LED_H__
#include "mini2440addr.h"
#include "delay.h"
#define LED1 0x5
#define LED2 0x6
#define LED3 0x7
#define LED4 0x8
#define GPB_OUT 0x1
#define GPB_IN 0x0
#define led_x_init(n) {rGPBCON &= ~(0x11<<((n)*2));rGPBCON |= (GPB_OUT<<((n)*2));}
#define led_x_on(n) (rGPBDAT &= ~(1<<(n)))
#define led_x_off(n) (rGPBDAT |= 1<<(n))
void (*show)(char*,...) = 0x33f91708;
#endif /*__LED_H__*/
Makefile:
led.bin:main.o delay.o
arm-linux-ld -Ttext 0x30000000 main.o delay.o -o led.elf
arm-linux-objcopy -O binary led.elf led.bin
arm-linux-objdump -d led.elf > led.dls
delay.o: delay.c
arm-linux-gcc -c delay.c -o delay.o
main.o: main.c
arm-linux-gcc -c main.c -o main.o
clean:
rm led.bin led.o led.elf led.dls
调试过程中发现一个问题:led3和led4的初始化放在led1和led2之前的话,led3和led4的初始化会失败,原因还在查找中,找到后补上日志!