免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1739 | 回复: 0
打印 上一主题 下一主题

ubuntu 下面的AVR开发环境建立 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-22 16:50 |只看该作者 |倒序浏览

                一个星期六星期天耗进去了,主要是走了弯路,找到窍门的话建立环境只需要10来分钟而已,不知道的话确实白白的耗时间,而且是在折磨。
(1)安装 binutils , gcc-avr , avr-libc
sudo apt-get install binutils-avr
sudo apt-get install gcc-avr
sudo apt-get install avr-libc
恩,因为是3个不同的项目组成的,其中binutils 包含了一些例如 as ld size 之类的工具,gcc就不用说了,是c编译器,avr-libc 就是为AVR开发的C库,编译链要建立的最低标准是这3个包。
因为这里是在apt包管理系统下面的,软件一般不会是最新的,但是也不旧,最关键是 apt比较容易管理安装软件,应该首选用这个。要折腾的自己下载源码包编译安装吧,XD
不需要设置环境变量的哦,安装好之后直接可以用了,很是方便。测试一下是否成功:
etual@Hikari:~$ avr-gcc
avr-gcc: no input files
提示没有待编译的源代码,这基本说明交叉编译器没有问题了。找个小程序编译一下。makefile我是直接用在window下面的WinAVR自动生成的Makefile,有个小问题是 sizebefore 和 sizeafter 有点问题,自己修改一下把,或者干脆屏蔽掉不用就OK.
下面折腾编程器,下载软件首选 avrdude , WinAVR已经打包进去的了,只是估计没有几个人用而已,呵呵.
安装包(5.2版本以后都支持usbasp了,这个安装的是5.5版本)
sudo apt-get install avrdude
下面是关键的一步,好吧,就是因为这个东西,耗了我2天了,就是因为这个小东西!!!!!
首先确定avrdude包安装在什么地方:
etual@Hikari:~$ dpkg -L avrdude | grep bin
/usr/bin
/usr/bin/avrdude
默认都是这里,也就是说执行的程序就放在 /usr/bin/avrdude ,我们要去作的就是改 avrdude,添加管理员权限,进入该目录查看一下 avrdude属性
etual@Hikari:/usr/bin$ ls avrdude -l
-rwxr-xr-x 1 root root 213316 2008-05-11 17:48 avrdude
可以看到,默认安装的程序只是普通执行权限(看不懂的可以去找找linux关于文件权限的知识),我们需要添加超级权限,免得出现莫名其妙的问题.
加管理权限
etual@Hikari:/usr/bin$ sudo chmod +s avrdude
在list一下看看属性
etual@Hikari:/usr/bin$ ls avrdude -l
-rwsr-sr-x 1 root root 213316 2008-05-11 17:48 avrdude
可以看到这里已经是s属性而不是普通的x属性了。
这有什么差别呢?如果没有改之前
etual@Hikari:~$avrdude 执行的是 x 属性
修改了之后
etual@Hikari:~$avrdude 执行的是 s 管理属性
其实就是跟平时的sudo命令一个作用
etual@Hikari:~$sudo avrdude 跟之前的 s 属性权限是一样的。
如果你不改这里的华,就每次运行的时候加 sudo 得到管理权限咯,或者干脆用root登录
不过一般不这么去做。
一般建议是去改了,因为一般配套的GUI是不会跟你考虑权限问题的,它只会简单的调用。
好了,基本完工,如果适应普通的并口下载线的话,已经可以正常工作了。
测试一下擦出功能,我的芯片是 mega8,并口下载线是马老师版本,也就是 stk200 :
etual@Hikari:~$avrdude -p m8 -c stk200 -e
如果看到下面的信息代表没有问题了。
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9307
avrdude: erasing chip
avrdude: safemode: Fuses OK
avrdude done.  Thank you.
如果使用流行的 usbasp 下载器的话,现在还不行,因为没有 libusb 库
http://libusb.wiki.sourceforge.net/下载了,并安装好
下载
libusb-0.1 (LEGACY)
                                       
0.1.12
这个版本,至于为啥,我还没有详细看....
# tar -vxf libusb-0.1.12.tar.gz
# cd libusb-0.1.12
# ./configure
# make
# make install
编译安装之后,好吧,其实编译前解决依赖关系才是让人最绝望的过程,good luck ....
下面就可以用 uabasp 了
例如我下载一个已经编译好的 leds.hex 的 LED闪烁程序
etual@Hikari:~/work/avr/leds$ avrdude -p m8 -c usbasp -U flash:w:leds.hex
如果显示下面这样的显示的话表示基本没有问题了.
etual@Hikari:~/work/avr/leds$ avrdude -p m8 -c usbasp -U flash:w:leds.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e9307
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "leds.hex"
avrdude: input file leds.hex auto detected as Intel Hex
avrdude: writing flash (206 bytes):
Writing | ################################################## | 100% 0.08s
avrdude: 206 bytes of flash written
avrdude: verifying flash memory against leds.hex:
avrdude: load data flash data from input file leds.hex:
avrdude: input file leds.hex auto detected as Intel Hex
avrdude: input file leds.hex contains 206 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.06s
avrdude: verifying ...
avrdude: 206 bytes of flash verified
avrdude: safemode: Fuses OK
avrdude done.  Thank you.
到这为止,基本的开发环境已经建立了,剩下就是慢慢折腾吧,哈哈.在这个过程中发觉了一堆好网站,特别是那个libusb的项目,很有学习的价值.
http://www.obdev.at/products/avrusb/index.html
http://www.linux-usb.org/
http://libusb.wiki.sourceforge.net/
http://www.fischl.de


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/52089/showart_1871796.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP