Pages: [1]   Go Down
Author Topic: Leonardo "Blink" contains USB code?  (Read 780 times)
0 Members and 1 Guest are viewing this topic.
Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

thanks,
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Germany
Offline Offline
Edison Member
*
Karma: 48
Posts: 2337
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:


* 32U4Pin.png (22.05 KB, 265x335 - viewed 18 times.)
Logged

Mein Arduino-Blog: http://www.sth77.de/ - letzte Einträge: Teensy 3.0 - Teensyduino unter Window 7 - Teensyduino unter Windows 8

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
blink. blink. blink. blink. blink.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3071
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: