Skip to content

Fix for upload problems on Arduino Leonardo (and derivatives) on OSX 10.9 #2279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/src/cc/arduino/packages/uploaders/SerialUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
System.out.println(_("Forcing reset using 1200bps open/close on port ") + uploadPort);
Serial.touchPort(uploadPort, 1200);
}
Thread.sleep(400);
if (waitForUploadPort) {
// Scanning for available ports seems to open the port or
// otherwise assert DTR, which would cancel the WDT reset if
// it happened within 250 ms. So we wait until the reset should
// have already occured before we start scanning.
Thread.sleep(300);
uploadPort = waitForUploadPort(uploadPort, before);
} else {
Thread.sleep(400);
}
} catch (SerialException e) {
throw new RunnerException(e);
Expand Down
38 changes: 21 additions & 17 deletions hardware/arduino/avr/cores/arduino/CDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,35 +80,39 @@ bool WEAK CDC_Setup(Setup& setup)
if (CDC_SET_LINE_CODING == r)
{
USB_RecvControl((void*)&_usbLineInfo,7);
return true;
}

if (CDC_SET_CONTROL_LINE_STATE == r)
{
_usbLineInfo.lineState = setup.wValueL;
}

if (CDC_SET_LINE_CODING == r || CDC_SET_CONTROL_LINE_STATE == r)
{
// auto-reset into the bootloader is triggered when the port, already
// open at 1200 bps, is closed. this is the signal to start the watchdog
// with a relatively long period so it can finish housekeeping tasks
// like servicing endpoints before the sketch ends
if (1200 == _usbLineInfo.dwDTERate) {
// We check DTR state to determine if host port is open (bit 0 of lineState).
if ((_usbLineInfo.lineState & 0x01) == 0) {
*(uint16_t *)0x0800 = 0x7777;
wdt_enable(WDTO_120MS);
} else {
// Most OSs do some intermediate steps when configuring ports and DTR can
// twiggle more than once before stabilizing.
// To avoid spurious resets we set the watchdog to 250ms and eventually
// cancel if DTR goes back high.

wdt_disable();
wdt_reset();
*(uint16_t *)0x0800 = 0x0;
}

// We check DTR state to determine if host port is open (bit 0 of lineState).
if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0)
{
*(uint16_t *)0x0800 = 0x7777;
wdt_enable(WDTO_120MS);
}
else
{
// Most OSs do some intermediate steps when configuring ports and DTR can
// twiggle more than once before stabilizing.
// To avoid spurious resets we set the watchdog to 250ms and eventually
// cancel if DTR goes back high.

wdt_disable();
wdt_reset();
*(uint16_t *)0x0800 = 0x0;
}
return true;
}
return true;
}
return false;
}
Expand Down