Skip to content

Commit 6f96742

Browse files
committed
Merge pull request #2279 from cmaglie/fix-leo-upload-osx10.9.4
Fix for upload problems on Arduino Leonardo (and derivatives) on OSX 10.9
2 parents 82e04ba + aa776b3 commit 6f96742

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

app/src/cc/arduino/packages/uploaders/SerialUploader.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,13 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
8686
System.out.println(_("Forcing reset using 1200bps open/close on port ") + uploadPort);
8787
Serial.touchPort(uploadPort, 1200);
8888
}
89+
Thread.sleep(400);
8990
if (waitForUploadPort) {
9091
// Scanning for available ports seems to open the port or
9192
// otherwise assert DTR, which would cancel the WDT reset if
9293
// it happened within 250 ms. So we wait until the reset should
9394
// have already occured before we start scanning.
94-
Thread.sleep(300);
9595
uploadPort = waitForUploadPort(uploadPort, before);
96-
} else {
97-
Thread.sleep(400);
9896
}
9997
} catch (SerialException e) {
10098
throw new RunnerException(e);

hardware/arduino/avr/cores/arduino/CDC.cpp

+21-17
Original file line numberDiff line numberDiff line change
@@ -80,35 +80,39 @@ bool WEAK CDC_Setup(Setup& setup)
8080
if (CDC_SET_LINE_CODING == r)
8181
{
8282
USB_RecvControl((void*)&_usbLineInfo,7);
83-
return true;
8483
}
8584

8685
if (CDC_SET_CONTROL_LINE_STATE == r)
8786
{
8887
_usbLineInfo.lineState = setup.wValueL;
88+
}
8989

90+
if (CDC_SET_LINE_CODING == r || CDC_SET_CONTROL_LINE_STATE == r)
91+
{
9092
// auto-reset into the bootloader is triggered when the port, already
9193
// open at 1200 bps, is closed. this is the signal to start the watchdog
9294
// with a relatively long period so it can finish housekeeping tasks
9395
// like servicing endpoints before the sketch ends
94-
if (1200 == _usbLineInfo.dwDTERate) {
95-
// We check DTR state to determine if host port is open (bit 0 of lineState).
96-
if ((_usbLineInfo.lineState & 0x01) == 0) {
97-
*(uint16_t *)0x0800 = 0x7777;
98-
wdt_enable(WDTO_120MS);
99-
} else {
100-
// Most OSs do some intermediate steps when configuring ports and DTR can
101-
// twiggle more than once before stabilizing.
102-
// To avoid spurious resets we set the watchdog to 250ms and eventually
103-
// cancel if DTR goes back high.
104-
105-
wdt_disable();
106-
wdt_reset();
107-
*(uint16_t *)0x0800 = 0x0;
108-
}
96+
97+
// We check DTR state to determine if host port is open (bit 0 of lineState).
98+
if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0)
99+
{
100+
*(uint16_t *)0x0800 = 0x7777;
101+
wdt_enable(WDTO_120MS);
102+
}
103+
else
104+
{
105+
// Most OSs do some intermediate steps when configuring ports and DTR can
106+
// twiggle more than once before stabilizing.
107+
// To avoid spurious resets we set the watchdog to 250ms and eventually
108+
// cancel if DTR goes back high.
109+
110+
wdt_disable();
111+
wdt_reset();
112+
*(uint16_t *)0x0800 = 0x0;
109113
}
110-
return true;
111114
}
115+
return true;
112116
}
113117
return false;
114118
}

0 commit comments

Comments
 (0)