环境:ubuntu12.04+atmega128A+JTAG ICE
网上已经有很多教程了,在前人走过的路上自然格外轻松,不过还是要稍微总结一下,毕竟还是有些不一样的。
(1)安装工具链
>sudo apt-get install binutils-avr avr-libc gcc-avr
(安装信息省略)
装完后用如下命令查看是否成功
zhy@hoply:~$ avr-gcc -v
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.5.3/lto-wrapper
Target: avr
Configured with: ../src/configure -v --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-libssp --build=i686-linux-gnu --host=i686-linux-gnu --target=avr
Thread model: single
gcc version 4.5.3 (GCC)
(2)安装下载工具
>sudo apt-get install avrdude avrdude-doc
装完后值得说一下了,很多网上买的下载器是只提供windows下的驱动,linux下怎么用完全没讲,这里提供一个思路,供参考。
avr-dude支持很多种编程器,具体支持哪些可以打开/usr/share/doc/avrdude-doc/avrdude-html/avrdude.html网页文件的第2.1节查看,avrdude的详细使用说明也就是这个。同样,我也网购了这样的一个编程器,只知道它是一个USB转串口而制成的一个JTAG ICE,工作波特率什么的完全不知道,怎么办?只能自己试了。
zhy@hoply:~$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubBus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
可以看到最后一个PL2303设备是我的AVR编程器
zhy@hoply:~$ ls /dev/ttyUSB*
/dev/ttyUSB0
设备名为ttyUSB0,因为仅有一个USB串口设备
zhy@hoply:~$ sudo avrdude -p m128 -c jtag1 -P /dev/ttyUSB0 -t
avrdude: jtagmkI_recv(): failed to send command to serial port
如此,把可能的设备试了个遍,不行。这才意识到可能是波特率设置问题,加上波特率参数再试
zhy@hoply:~$ sudo avrdude -p m128 -c jtag1 -b 9600 -P /dev/ttyUSB0 -t
avrdude: jtagmkI_recv(): failed to send command to serial port
就这样一次又一次,终于被我试出来了!
zhy@hoply:~$ sudo avrdude -p m128 -c jtag1 -b 19200 -P /dev/ttyUSB0 -t
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e9702
avrdude>
测试一下:
avrdude> part
>>> part
AVR Part : ATMEGA128
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PA0
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 4 12 64 0 no 4096 8 0 9000 9000 0xff 0xff
flash 33 6 128 0 yes 131072 256 512 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
calibration 0 0 0 0 no 4 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
avrdude> dump eeprom 0 16
>>> dump eeprom 0 16
0000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
avrdude> erase
>>> erase
avrdude: erasing chip
暂时没什么问题,后续再写个程序试试看。