开发环境


1、硬件平台:FS2410(s3c2410)

2、主机:Ubuntu 12.04 LTS



LED原理图



LED的GPIO的配置


    • 配置GPFCON寄存器,设置GPF4-7为输出

    • 配置GPFDAT,设置LED灯亮与灭




主要步骤


    • 通过设置GPFCON将GPF4-7设置为输出

    • 设置GPFDAT,可以将led灯亮或灭,GPFDAT的相应位置1灯灭,置0灯亮



源代码

   NAND flash启动

    1. 关狗 

    2. 设置栈

    //start.S

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    .text
    .global _start
    _start:
    #define WATCHDOG 0x53000000
         ldr r0, =WATCHDOG    //关看门狗
         mov r1, #0
         str r1, [r0]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
         ldr sp, =1024*4    //设置堆栈
         bl main      //跳转进入main函数
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
    loop:
         b loop

    //led.c (s3c2410.h 网上找,其中包含option.h,我找了一段时间,所以上传附件了)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    #include "s3c2410.h"
    void  delay( long  long  max)     //延迟函数
    {
         int  i, j;
         for (i = 0; i < max; i++)
             for (j = 0; j < max; j ++);
    }
    int  main( void )
    {
         int  i;
         GPFCON = GPFCON & (~(0xff << 8)) | (0x55 << 8);     //设置GPF4-7为输出
         GPFDAT &= ~(0xf << 4);      //将4个LED灯开启
         while (1)
         {
             for (i = 0; i < 5; i++)
             {
                 GPFDAT = GPFDAT | (0xf << i);   //利用循环设置流水灯     
                 delay(500);
             }
             GPFDAT &= ~(0xf << 4);    //4个LED灯开启
         }
         return  0;
    }

    //Makefile

    1
    2
    3
    4
    5
    6
    7
    led.bin: start.S led.c                                               
         arm-linux-gcc -c start.S -o start.o
         arm-linux-gcc -c led.c -o led.o
         arm-linux-ld -Ttext 0x30008000 start.o led.o -o led
         arm-linux-objcopy -O binary -S led led.bin
       6 clean:
         rm  -f *.o led.bin




步骤


   ①首先make

   可以看见生成了led.bin文件

   ②下载到开发板

   由于我用的bootloader是出厂自带的,而这个bootloader里面没有tftp,所以这里用古老的zmodem协议,但是在下载过程中报告失败,囧……

   于是我换到windows下


   OK,大功告成,流水灯很顺利



小结


   好久没玩arm裸机了,这次只是在linux下测试下环境

   可以看见,linux下的编程并没有比windows下多多少东西,也就一个Makefile而已,但是对于过程而言,就清楚多了