Go Down

Topic: Leonardo "Blink" contains USB code? (Read 1 time) previous topic - next topic


Hi all,
Does the basic "Blink" sketch for the Leonardo include some USB device code?

Have just been experimenting with an ATmega32U4 board from Adafruit.  The bootloader is different from the Leonardo's, but I thought I'd give it a try with the Arduino IDE anyway.  I uploaded the blink sketch, which runs ok, but it had an unexpected side effect: it blue-screened the Windows 7 PC to which it was connected.  This is repeatable, and happens as soon as the bootloader times out and the sketch starts to run.

I guess the sketch contains some USB code, and Windows doesn't like a USB device changing character without the usual disconnect / reconnect sequence.  Can anybody confirm that is the case?  And what is the USB code doing?  I presume it's pretending to be a serial device so as to talk to the IDE terminal, but how does it link into the sketch?



That relevant code is in HardwareSerial.h and CDC.cpp. Every sketch compiled for the Leonardo will include that code because the Serial object is always instantiated. The USB serial device is initialised there. This should be the normal behaviour and for the PC it's the same as if the Arduino is disconnected and connected again.

Your Windows PC showing a blue screen because of that is really bad, even unexpected behaviour of a USB device should never crash the kernel.


It is easy to flash the Leonardo bootloader to the adafruit Atmega32U4 Breakout Board. You only need a programmer for ICSP. Done it some minutes ago, heres is the pin assignment:
Mein verwaister Arduino-Blog: http://www.sth77.de/ - letzter Eintrag: Diamex-ISP in der irgendwann mal aktuellen Arduino-IDE 1.6.4


There is a known problem with the Adafruit bootloader and driver (early versions and modifications at least) causing bluescreens.  The early Adafruit stuff was based on a now-obsolete Leonardo bootloader.  Best bet is to do like sth77 suggests and burn the Leonardo bootloader from Arduino 1.0.1 or later.


That's what I've done now, but I'm curious: what was the bug?


A bluescreen is caused by a bad driver ( or kernel ).

No matter what an usb device does, a driver must not produce a bluescreen.

Practically, you may need to learn how to avoid it.
If a different bootloader on the Leonardo avoids it, that's a workaround, at most.

Go Up