查看: 2404|回复: 0

SIN210学习笔记__Eclipse配置ARM交叉编译器

[复制链接]
  • TA的每日心情
    慵懒
    2016-10-17 12:07
  • 签到天数: 306 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2015-2-27 10:40:09 | 显示全部楼层 |阅读模式
    分享到:
    作为IT行业的孩纸,Eclipse应该都不陌生,都用它写过程序,下面来以一个简单的Demo,来在Eclipse中配置ARM交叉编译环境,开发程序在sin210中运行。
       以下的Demo使用的就是Twinkle_LED的程序,具体可参看上个帖子。
      首先下载安装Eclipse,笔者使用的是Ubuntu 12.04 LTS   amd64。具体安装Eclipse和安装配置java,这个我是使用的apt-get安装的,这里就不详细介绍了。以下内容假设你已经安装好了Eclipse。
      打开Eclipse,新建一个C Project 如下图所示,然后点击Next  ,在下一步点击Finish。
      
    新建一个sin210.c  文件添加到sin210项目中,sin210.c中的代码如下:
    #include    #include    #include    #include    #include    #include    #define LED1         0   #define LED2         1   #define LED3         2   #define LED4         3       int main(int argc, char **argv)   {       unsigned int count = 0;       printf("\nThe LEDs start Twinkle\n");       int fdled = -1;       usleep(500*1000);       fdled = open("/dev/led",O_RDWR);       if(fdled<0)        {          printf("Error:Can't open /dev/leds\n");          return -1;        }       printf("\nThe LEDs start Twinkle\n");       while(1)       {         count++;         ioctl(fdled, count%2,      LED1);         ioctl(fdled, (count%4)/2,   LED2);         ioctl(fdled, (count%8)/4,  LED3);         ioctl(fdled, (count)/8, LED4);         usleep(500*1000);       }      return 0;   }  
    直达楼层 1# 发表于 2015-02-17  00:36:50 我想评分  回到列表 收藏此帖         作为IT行业的孩纸,Eclipse应该都不陌生,都用它写过程序,下面来以一个简单的Demo,来在Eclipse中配置ARM交叉编译环境,开发程序在sin210中运行。      以下的Demo使用的就是Twinkle_LED的程序,具体可参看这个帖子(SIN210学习笔记__Twinkle LED )。
       首先下载安装Eclipse,笔者使用的是Ubuntu 12.04 LTS   amd64。具体安装Eclipse和安装配置java,这个我是使用的apt-get安装的,这里就不详细介绍了。以下内容假设你已经安装好了Eclipse。  
       打开Eclipse,新建一个C Project 如下图所示,然后点击Next  ,在下一步点击Finish。
       
      新建一个sin210.c  文件添加到sin210项目中,sin210.c中的代码如下:
      view  plaincopy to clipboardprint?

    • #include
    • #include
    • #include
    • #include
    • #include
    • #include
    • #define LED1 0
    • #define LED2 1
    • #define LED3 2
    • #define LED4 3
    • int main(int argc, char **argv)
    • {
    • unsigned int count = 0;
    • printf("\nThe LEDs start Twinkle\n");
    • int fdled = -1;
    • usleep(500*1000);
    • fdled = open("/dev/led",O_RDWR);
    • if(fdled<0)
    • {
    • printf("Error:Can't open /dev/leds\n");
    • return -1;
    • }
    • printf("\nThe LEDs start Twinkle\n");
    • while(1)
    • {
    • count++;
    • ioctl(fdled, count%2, LED1);
    • ioctl(fdled, (count%4)/2, LED2);
    • ioctl(fdled, (count%8)/4, LED3);
    • ioctl(fdled, (count)/8, LED4);
    • usleep(500*1000);
    • }
    • return 0;
    • }
    #include  #include  #include  #include  #include  #include  #define LED1         0 #define LED2         1 #define LED3         2 #define LED4         3 int main(int argc, char **argv) {     unsigned int count = 0;     printf("\nThe LEDs start Twinkle\n");     int fdled = -1;     usleep(500*1000);     fdled = open("/dev/led",O_RDWR);     if(fdled<0)      {        printf("Error:Can't open /dev/leds\n");        return -1;      }     printf("\nThe LEDs start Twinkle\n");     while(1)     {       count++;       ioctl(fdled, count%2,      LED1);       ioctl(fdled, (count%4)/2,   LED2);       ioctl(fdled, (count%8)/4,  LED3);       ioctl(fdled, (count)/8, LED4);       usleep(500*1000);     }    return 0; }
    在sin210项目 点击右键  —> 属性 设置C/C++ Build  -> Manage Configurations...  添加 ARM   然后设置成Active。
    如下图所示:

    点击 Settings  设置Cross GCC Compiler  和 Cross GCC  Linker 两项的 Command 如下图所示,将  gcc 改为  arm-linux-gcc


    点击编译即可在项目的ARM文件夹下生成可执行文件 sin210
    (刚这个程序的代码,在eclipse编译产生的可执行文件大概是44K左右,而上篇帖子用Makefile,生成的可执行文件大概是5.6K左右。。。)
    发送到开发板上,然后执行即可看到效果,开发板上的4个LED以不同的频率闪烁。
    串口打印信息如下:   

    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-4-25 04:01 , Processed in 0.121813 second(s), 18 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.