arduino/Arduino — pull request #103 by PeterVH (2012-07-10 20:29:43+00:00)
Title: Leonardo: after burning a sketch, remove the magic baud rate to avoid future unwanted board resets

An example of such an unwanted board reset happens if you burn ArduinoISP into a leonardo and subsequently want to use the leonardo to burn a bootloader into another avr chip.

See also: http://arduino.cc/forum/index.php/topic,108270.msg838797.html#msg838797

This is what happens, withou this modification:
1. The ide resets the leonardo by "touching" the serial port: it sets DTR when the speed is 1200 baud.
It does not use avrdude to do this.
2. Avrdude downloads the sketch at the baudrate specified in boards.txt. When it is done, avrdude nicely sets the speed back to what it was before: 1200 baud.
Then you decide to burn a bootloader to your target:
3.The ide makes its first call to avrdude. Again, when avrdude is done, just before it closes the port it sets the speed back to what it was: 1200 baud. Closing the port toggles DTR and the leoardo reboots!
4. The ide makes its second call to avrdude, but the leonardo is not yet up and you get the 'not in sync' error.