LoginSignup
2
2

More than 5 years have passed since last update.

Mac で Arduino Leonardo / SparkFun Pro Micro で 焼ける環境を用意する

Last updated at Posted at 2017-10-14

Overview

Pro MicroのようなAtmelのAVRマイコンは、 avrdude でhexを焼くのですが、
そのための準備や周辺情報について。

avrdude

Install編

$ brew update
$ brew install avrdude --with-usb
/usr/local/Homebrew/Library/Homebrew/brew.rb:12:in `<main>': Homebrew must be run under Ruby 2.3! (RuntimeError)

が出たら、

$ brew update

してから、再度、 brew install avrdude --with-usbでいけました。

AVRマイコンは、UARTでの焼き込みは保証されていない。SPIがbottomとして用意されている。

SPIでの焼き込みには、AVR ISPと言うものを使うが、買わなくても、ArduinoをISPとして利用するためのFWがあるので、それで代用。

Arduino UNO の Arduino ISP化

  1. Arduino UNO を USB で Mac に接続
  2. Arduino IDE の起動 (1.6.8で確認)
  3. ツール→マイコンボード→Arduino UNOを選択
  4. ツール→シリアルポートで、UNOのポートを選択
  5. ファイル→スケッチの例→ArduinoISP→ArduinoISPでISPのスケッチを呼び出し
  6. スケッチ→マイコンボードに書き込むで、UNOをISP化する。

Arduido ISP化された UNO と Pro Microの接続

Arduino UNO Pro Micro
5V VCC
GND GND
D10 RST
D11 16
D12 14
D13 15

Arduino ISP+avrdudeでのhexファイルの焼き込み

$ avrdude -p atmega32u4 -c avrisp -P /dev/tty.wchusbserial1410 -D -U flash:w:atmega32u4.hex:i

Arduino Leonardoに最初から焼き込まれているbootloaderでは、Arduino IDEから直接焼ける

Arduino Leonardoの互換品が、SparkFunからはPro Microとして発売されているが、
bootloaderが同じものではないので、SparkFun Pro Microでは、以下の手順で、
Ardiuno IDEから使えるようにするための追加のステップが必要。

arduinoで、sparkfunのarduino IDE の「追加のボードマネージャ」でSparkFunのボードを追加し、加えて、Board Manager Add-onを追加する必要がある。

https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/installing-mac--linux
を参考に、Arduinoとして、Pro Microを使える環境にしましょう。

世の中のPro Micro互換品の中には、Leonardoと互換のboot loaderを焼いているものもあるようなので、注意。。。

#その場合は、ボードマネージャでの設定は、Arduino Leonardoを選択すること。

なお、Pro Microは、3.3Vと5Vの両方が使えるようになっているが、16MHzで動かす場合には、5Vにする、つまり、ジャンパーをショートさせないといけない。忘れると誤動作してboot loaderを壊すこともあるようなので注意しよう。

Trouble shooting

Arduino IDEのようにavrdudeでhexをRESET操作せずに焼き込みたい

が、参考になるかもしれません。

avrdudeでの焼き込み

avrdudeで焼き込みに失敗するが、Windowsなどに接続すると、 Arduino Leonardoと表示されるデバイスがいる場合は、単にresetの問題が考えられます。

USBで接続をし、resetとGNDをショートした直後に以下のようなコマンドを実行して焼ければ、bingoです。

$ avrdude -p atmega32u4 -c avr109 -v -v -v -v -P /dev/tty.usbmodem1411 -U flash:w:atmega32u4.hex:i -D -b 57600 -F -C ../../../../Documents/Arduino/hardware/sparkfun/avr/avrdude.conf
$ avrdude -p atmega32u4 -c avr109 -v -v -v -v -P /dev/tty.usbmodem1411 -U flash:w:atmega32u4.hex:i -D -b 57600 -F -C ../../../../Documents/Arduino/hardware/sparkfun/avr/avrdude.conf

avrdude: Version 6.3, compiled on Mar 15 2016 at 21:26:45
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "../../../../Documents/Arduino/hardware/sparkfun/avr/avrdude.conf"
         User configuration file is "/Users/harold/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/tty.usbmodem1411
         Using Programmer              : avr109
         Overriding Baud Rate          : 57600
         AVR Part                      : ATmega32U4
         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        65    20     4    0 no       1024    4      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : butterfly
         Description     : Atmel AppNote AVR109 Boot Loader

Connecting to programmer: .avrdude: Send: . [1b] 
avrdude: Send: S [53] 
avrdude: Recv: C [43] 

avrdude: Recv: A [41] T [54] E [45] R [52] I [49] N [4e] 
avrdude: Send: V [56] 
avrdude: Recv: 1 [31] 0 [30] 
avrdude: Send: v [76] 
avrdude: Recv: ? [3f] 
avrdude: Send: p [70] 
avrdude: Recv: S [53] 
Found programmer: Id = "CATERIN"; type = S
    Software Version = 1.0; No Hardware Version given.
avrdude: Send: a [61] 
avrdude: Recv: Y [59] 
Programmer supports auto addr increment.
avrdude: Send: b [62] 
avrdude: Recv: Y [59] 
avrdude: Recv: . [00] 
avrdude: Recv: . [80] 
Programmer supports buffered memory access with buffersize=128 bytes.
avrdude: Send: t [74] 

Programmer supports the following devices:
avrdude: Recv: D [44] 
    Device code: 0x44
avrdude: Recv: . [00] 

avrdude: Send: T [54] D [44] 
avrdude: Recv: . [0d] 
avrdude: devcode selected: 0x44
avrdude: Send: P [50] 
avrdude: Recv: . [0d] 
avrdude: AVR device initialized and ready to accept instructions

Reading |                                                    | 0% 0.00savrdude: Send: s [73] 
avrdude: Recv: . [87] . [95] . [1e] 
Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: Send: F [46] 
avrdude: Recv: . [ff] 
avrdude: safemode read 1, lfuse value: ff
avrdude: Send: F [46] 
avrdude: Recv: . [ff] 
avrdude: safemode read 2, lfuse value: ff
avrdude: Send: F [46] 
avrdude: Recv: . [ff] 
avrdude: safemode read 3, lfuse value: ff
avrdude: safemode: lfuse reads as FF
avrdude: Send: N [4e] 
avrdude: Recv: . [d8] 
avrdude: safemode read 1, hfuse value: d8
avrdude: Send: N [4e] 
avrdude: Recv: . [d8] 
avrdude: safemode read 2, hfuse value: d8
avrdude: Send: N [4e] 
avrdude: Recv: . [d8] 
avrdude: safemode read 3, hfuse value: d8
avrdude: safemode: hfuse reads as D8
avrdude: Send: Q [51] 
avrdude: Recv: . [cb] 
avrdude: safemode read 1, efuse value: cb
avrdude: Send: Q [51] 
avrdude: Recv: . [cb] 
avrdude: safemode read 2, efuse value: cb
avrdude: Send: Q [51] 
avrdude: Recv: . [cb] 
avrdude: safemode read 3, efuse value: cb
avrdude: safemode: efuse reads as CB
avrdude: reading input file "atmega32u4.hex"
avrdude: writing flash (4376 bytes):

Writing |                                                    | 0% 0.00savrdude: Send: A [41] . [00] . [00] 
avrdude: Recv: . [0d] 
avrdude: Send: B [42] . [00] . [80] F [46] . [15] . [c1] . [00] . ..snip..
avrdude: Recv: . [0d] 
Writing | ################################################## | 100% 0.35s

avrdude: 4376 bytes of flash written
avrdude: verifying flash memory against atmega32u4.hex:
avrdude: load data flash data from input file atmega32u4.hex:
avrdude: input file atmega32u4.hex contains 4376 bytes
avrdude: reading on-chip flash data:

Reading |                                                    | 0% 0.00savrdude: Send: A [41] . [00] . [00] 
avrdude: Recv: . [0d] 
avrdude: Send: g [67] . [00] . [80] F [46] 
avrdude: Recv: . [15] . [c1] . [00] . [00] . [2e] . [c1] . [00] . ..snip..
Reading | ################################################## | 100% 0.04s

avrdude: avr_read(): skipping page 35: no interesting data
..snip..
avrdude: avr_read(): skipping page 255: no interesting data
avrdude: verifying ...
avrdude: 4376 bytes of flash verified

avrdude: Send: F [46] 
avrdude: Recv: . [ff] 
avrdude: safemode read 1, lfuse value: ff
avrdude: Send: F [46] 
avrdude: Recv: . [ff] 
avrdude: safemode read 2, lfuse value: ff
avrdude: Send: F [46] 
avrdude: Recv: . [ff] 
avrdude: safemode read 3, lfuse value: ff
avrdude: safemode: lfuse reads as FF
avrdude: Send: N [4e] 
avrdude: Recv: . [d8] 
avrdude: safemode read 1, hfuse value: d8
avrdude: Send: N [4e] 
avrdude: Recv: . [d8] 
avrdude: safemode read 2, hfuse value: d8
avrdude: Send: N [4e] 
avrdude: Recv: . [d8] 
avrdude: safemode read 3, hfuse value: d8
avrdude: safemode: hfuse reads as D8
avrdude: Send: Q [51] 
avrdude: Recv: . [cb] 
avrdude: safemode read 1, efuse value: cb
avrdude: Send: Q [51] 
avrdude: Recv: . [cb] 
avrdude: safemode read 2, efuse value: cb
avrdude: Send: Q [51] 
avrdude: Recv: . [cb] 
avrdude: safemode read 3, efuse value: cb
avrdude: safemode: efuse reads as CB
avrdude: safemode: Fuses OK (E:CB, H:D8, L:FF)
avrdude: Send: L [4c] 
avrdude: Recv: . [0d] 
avrdude: Send: E [45] 
avrdude: Recv: . [0d] 

avrdude done.  Thank you.

Arduino IDEで焼き込みができるようにする復活の仕方

FWを焼くと、 LeonardoのArduino IDE経由で焼き込みをするための、USB serial portである /dev/tty.usbmodem1411 が消えてしまうことがあります。

しかし、上のとおり、RESETをした直後は、Boot loaderに内蔵の焼き込み用の/dev/tty.usbmodem1411 が 数秒見えるので、その間に焼きこむと、復活できます。

  1. Arduino IDEを起動する
  2. スケッチ例で、Blinkなどを選択する
  3. ツール→マイコンボードボード→Arduino Leonardoを確認
void setup() {
}

// the loop function runs over and over again forever
void loop() {
  delay(1000);              // wait for a second
}

上のように、何もなければよいだけですが。

  1. USB端子を接続する
  2. RESETを行う (RST pinとGNDを接続して離す)
  3. Arduino IDEをすぐに立ち上げる
  4. ツール→シリアルポートに、/dev/tty.usbmodem1411などがあれば選択する。
  5. コマンド+Uなどでスケッチを焼き込む
  6. マイコンボードに書き込んでいます、、、の文字が出たら、すぐさま、再度、RESETを行う

で、焼けるはずです。

焼けなかったり、リセット直後に、ls /dev/tty.として何もいなければ、boot loaderが破損している可能性があります。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2