http://www.obdev.at/products/vusb/usbasploader.html にあるUSBASPLoaderをATmega1284Pに移植してみましたが、うまく動作しない(USBとしてPCが認識してくれません)為、オリジナルに立ち返りATmega168Pでやってみました。
結果は、やはりUSBとして認識されません。色々やって分かったことをまとめてみました。
1.reset swが必要。
boot pinをショート(PORTD7=GND)にした状態でresetを押すことでUSBとして認識されます。
2.ユーザプログラムの書き込みは avrdude-5.11.1を使います。
DOSプロンプトで
I:\avrdude-5.11.1-bin>avrdude -c usbasp -P usb -p m168 -U flash:w:m168_led_blink.hex
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e9406
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: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "m168_led_blink.hex"
avrdude: input file m168_led_blink.hex auto detected as Intel Hex
avrdude: writing flash (218 bytes):
Writing | ################################################## | 100% 0.03s
avrdude: 218 bytes of flash written
avrdude: verifying flash memory against m168_led_blink.hex:
avrdude: load data flash data from input file m168_led_blink.hex:
avrdude: input file m168_led_blink.hex auto detected as Intel Hex
avrdude: input file m168_led_blink.hex contains 218 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.02s
avrdude: verifying ...
avrdude: 218 bytes of flash verified
avrdude: safemode: Fuses OK
avrdude done. Thank you.
3.書き込みが終わると直ぐにLEDが点滅を始めます。つまり、boot modeから抜け出ている事になります。
再びbootに入るには boot pinをショートしてresetを押しますとLEDの点滅停止してboot modeになります。
後は項目2.0を再び行えばユーザプログラムを書き込めます。
Flash 読み出し:
I:\avrdude-5.11.1-bin>avrdude -c usbasp -P usb -p m168 -U flash:r:-:i > dump.hex
:200000000C9434000C9451000C9451000C9451000C9451000C9451000C9451000C94510075
:200020000C9451000C9451000C9451000C9451000C9451000C9451000C9451000C94510038
:200040000C9451000C9451000C9451000C9451000C9451000C9451000C9451000C94510018
:200060000C9451000C94510011241FBECFEFD4E0DEBFCDBF11E0A0E0B1E0EAEDF0E002C086
:2000800005900D92A030B107D9F711E0A0E0B1E001C01D92A030B107E1F70E9453000C946D
:2000A0006B000C94000015B882E084B9299A8FEF99E6A8E181509040A040E1F700C0000067
:2000C00029988FEF99E6A8E181509040A040E1F700C00000EBCFF894FFCFFFFFFFFFFFFFB2
:2000E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF20
:20010000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
:20012000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDF
略
:2037C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF09
:2037E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9
:203800005CC000008FC0000073C0000071C000006FC000006DC000006BC0000069C0000029
:2038200067C0000065C0000063C0000061C000005FC000005DC000005BC0000059C0000088
:2038400057C0000055C0000053C0000051C000004FC000004DC000004BC0000049C00000E8
:2038600047C0000045C0000009021200010100803209040000000000000012011001FF003B
略
:2037E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9
ここからboot section
:203800005CC000008FC0000073C0000071C000006FC000006DC000006BC0000069C0000029
:2038200067C0000065C0000063C0000061C000005FC000005DC000005BC0000059C0000088
:2038400057C0000055C0000053C0000051C000004FC000004DC000004BC0000049C00000E8
:2038600047C0000045C0000009021200010100803209040000000000000012011001FF003B
:203880000008C016DC050201010200010E035500530042006100730070001C037700770016
:2038A00077002E00660069007300630068006C002E00640065000403090411241FBECFEF0F
略
:203F40001C3041F08FEF8093010104C08FEF809301011EE11093000184E199B1947131F47E
:203F60008150D9F71092240110921E0180910601882321F0CA9411F4DA9411F04F9B1CCE9E
:203F8000E5DDF999FECF92BD81BDF89A992780B50895262FF999FECF1FBA92BD81BD20BD58
:183FA0000FB6F894FA9AF99A0FBE01960895F894FFCF5AFF1E94060025
:00000001FF
Fuse 読み出し:
I:\avrdude-5.11.1-bin>avrdude -c usbasp -P usb -p m168 -U fuse:r:-:h
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9406
"fuse" memory type not defined for part "ATMEGA168"
avrdude: safemode: Fuses OK
avrdude done. Thank you.
ATmega168Pのfuse設定は下記のようになっています。
Fl=0xDF, Fh=0xD6, Ex=0xF8(0x00), Lock=0xFF
Lock bitはbootを保護するためには0xEFに設定するべきでしょう。