Hatena::ブログ(Diary)

toshi_hirasawaの日記

2011-02-04

秋月AE-ATMega(ATmega328P)に、avrdudeを使って arduino bootloader 書き込み

16:34

4っつのステップ

step1) unlocking the bootloader section of the chip

step2) setting the the fuses on the chip

step3) uploading the bootloader code to the chip

step4) locking the bootloader section of the chip.

の順番でやっていきます。


後半戦の参考資料はここがいい感じ

http://zampoh.cocolog-nifty.com/blog/2009/03/arduino---atmeg.html


ブートローダーの本体はarduinoIDE revision22をDLするとその中にはいってます

DLしたあと、ここらへんで見つけられる。

[hirasawa@deb505-64-32 atmega]$ pwd
/home/hirasawa/Desktop/avr-dude/arduino-0022/hardware/arduino/bootloaders/atmega
[hirasawa@deb505-64-32 atmega]$ ls -l | grep ATmegaBOOT_168_atmega328.hex 
-rw-r--r-- 1 hirasawa hirasawa  5533 2010-12-25 07:12 ATmegaBOOT_168_atmega328.hex
[hirasawa@deb505-64-32 atmega]$ 

このhexファイルを avrdude バイナリが置いてあるところにコピーするとよし

たとえば、わたしの場合は /home/hirasawa/Desktop/avr-dude/avrdude-5.10

step1 and 2) erase したあと、fuseの書き込み

deb505-64-32:/home/hirasawa/Desktop/avr-dude/avrdude-5.10# ./avrdude  -C avrdude.conf -c diecimila  -p m328p -t -B 4800
avrdude: BitBang OK 
avrdude: pin assign miso 3 sck 5 mosi 6 reset 7
avrdude: drain OK 

 ft245r:  bitclk 4800 -> ft baud 2400
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude> 

avrdude> erase
>>> erase 
avrdude: erasing chip
 ft245r:  bitclk 4800 -> ft baud 2400
avrdude> w efuse 0 0x05
>>> w efuse 0 0x05 

avrdude> w hfuse 0 0xda
>>> w hfuse 0 0xda 

avrdude> w lfuse 0 0xff
>>> w lfuse 0 0xff 

avrdude> d efuse
>>> d efuse 
0000  05                                                |.               |

avrdude> d hfuse
>>> d hfuse 
0000  da                                                |.               |

avrdude> d lfuse
>>> d lfuse 
0000  ff                                                |.               |

avrdude> 


step3) さて、bootloader書き込みぃ

deb505-64-32:/home/hirasawa/Desktop/avr-dude/avrdude-5.10# ./avrdude -C avrdude.conf -c diecimila  -p m328p -U flash:w:ATmegaBOOT_168_atmega328.hex 
avrdude: BitBang OK 
avrdude: pin assign miso 3 sck 5 mosi 6 reset 7
avrdude: drain OK 

 ft245r:  bitclk 230400 -> ft baud 115200
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
 ft245r:  bitclk 230400 -> ft baud 115200
avrdude: reading input file "ATmegaBOOT_168_atmega328.hex"
avrdude: input file ATmegaBOOT_168_atmega328.hex auto detected as Intel Hex
avrdude: writing flash (32670 bytes):

Writing | ################################################## | 100% 21.28s



avrdude: 32670 bytes of flash written
avrdude: verifying flash memory against ATmegaBOOT_168_atmega328.hex:
avrdude: load data flash data from input file ATmegaBOOT_168_atmega328.hex:
avrdude: input file ATmegaBOOT_168_atmega328.hex auto detected as Intel Hex
avrdude: input file ATmegaBOOT_168_atmega328.hex contains 32670 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 10.72s



avrdude: verifying ...
avrdude: 32670 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

deb505-64-32:/home/hirasawa/Desktop/avr-dude/avrdude-5.10# 

step4) 最後にロックをかけておしまい、っと


deb505-64-32:/home/hirasawa/Desktop/avr-dude/avrdude-5.10# ./avrdude  -C avrdude.conf -c diecimila  -p m328p -t -B 4800
avrdude: BitBang OK 
avrdude: pin assign miso 3 sck 5 mosi 6 reset 7
avrdude: drain OK 

 ft245r:  bitclk 4800 -> ft baud 2400
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude> w lock 0 0x0f
>>> w lock 0 0x0f 

avrdude> d efuse
>>> d efuse 
0000  05                                                |.               |

avrdude> d hfuse
>>> d hfuse 
0000  da                                                |.               |

avrdude> d lfuse
>>> d lfuse 
0000  ff                                                |.               |

avrdude> d lock
>>> d lock 
0000  0f                                                |.               |

avrdude> quit
>>> quit 

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

deb505-64-32:/home/hirasawa/Desktop/avr-dude/avrdude-5.10# 


最後にjumperの配置とコマンドのヒストリーでほんとにおしまいまとめ


 W
 B
 G
 R

 W  -
 B G
 R  -

  WBGRの意味の分からん場合は、前の記事をみること

 529  ./avrdude  -C avrdude.conf -c diecimila  -p m328p -t -B 4800
  530  lsmod | grep usb
  531  rmmod ftdi_sio usbserial
  532  ./avrdude  -C avrdude.conf -c diecimila  -p m328p -t -B 4800 kokode erase,w bit

  erase
    w efuse 0 0x05
    w hfuse 0 0xda
    w lfuse 0 0xff
    d efuse とかで中身の確認
    quit

  533  ./avrdude -C avrdude.conf -c diecimila  -p m328p -U flash:w:ATmegaBOOT_168_atmega328.hex                                 kokode bootloadup
  534  ./avrdude  -C avrdude.conf -c diecimila  -p m328p -t -B 4800  kokode lock bit

  w lock 0 0x0f
    dコマンドで確認


hirographica(旧charinko)hirographica(旧charinko) 2011/09/24 03:30 328pのconfググってたらヒットしたw

トラックバック - http://d.hatena.ne.jp/toshi_hirasawa/20110204/1296804870