From a6909bdb49d99253b4e684365e72e5dce31a49a7 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 27 Feb 2015 10:47:43 +1100 Subject: [PATCH] Fix auto-reset on Leonardo-derived boards from Linux hosts Also renamed the touchPort() function, as it's now unambiguously single-purpose. The 1200bps reset from Linux hosts wasn't working with these newer JSSC-based versions. Adding a step which explicitly sets DTR low (via a TIOCMSET ioctl clearing DTR) fixes this. I'm fairly sure the reason why this worked on older Arduino with librxtx and not with jssc is that librxtx appears to keep HUPCL in the termio flags, but jssc appears to remove it. If HUPCL ("hangup on close") is set, it causes DTR to be explicitly pulled low on close. --- .../src/cc/arduino/packages/uploaders/SerialUploader.java | 2 +- arduino-core/src/processing/app/Serial.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java b/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java index 81c084054eb..86524f773c6 100644 --- a/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java +++ b/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java @@ -116,7 +116,7 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String if (verbose) System.out.println( I18n.format(_("Forcing reset using 1200bps open/close on port {0}"), uploadPort)); - Serial.touchPort(uploadPort, 1200); + Serial.touchForCDCReset(uploadPort); } Thread.sleep(400); if (waitForUploadPort) { diff --git a/arduino-core/src/processing/app/Serial.java b/arduino-core/src/processing/app/Serial.java index 672db063d69..53d0601ae7b 100644 --- a/arduino-core/src/processing/app/Serial.java +++ b/arduino-core/src/processing/app/Serial.java @@ -80,11 +80,12 @@ public Serial(String iname) throws SerialException { new Float(PreferencesData.get("serial.stopbits")).floatValue()); } - public static boolean touchPort(String iname, int irate) throws SerialException { + public static boolean touchForCDCReset(String iname) throws SerialException { SerialPort serialPort = new SerialPort(iname); try { serialPort.openPort(); - serialPort.setParams(irate, 8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); + serialPort.setParams(1200, 8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); + serialPort.setDTR(false); serialPort.closePort(); return true; } catch (SerialPortException e) {