1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-18 07:52:14 +01:00

Upload over debug port

This commit is contained in:
Cristian Maglie 2012-09-07 15:59:44 +02:00
parent 9b027224a0
commit ca74c94ae5
4 changed files with 98 additions and 70 deletions

View File

@ -63,11 +63,14 @@ public class BasicUploader extends Uploader {
// this wait a moment for the bootloader to enumerate. On Windows, also must // this wait a moment for the bootloader to enumerate. On Windows, also must
// deal with the fact that the COM port number changes from bootloader to // deal with the fact that the COM port number changes from bootloader to
// sketch. // sketch.
String use1200bpsTouch = prefs.get("upload.use_1200bps_touch"); String t = prefs.get("upload.use_1200bps_touch");
boolean doTouch = use1200bpsTouch != null && use1200bpsTouch.equals("true"); boolean doTouch = t != null && t.equals("true");
t = prefs.get("upload.wait_for_upload_port");
boolean waitForUploadPort = (t != null) && t.equals("true");
if (doTouch) { if (doTouch) {
String uploadPort = prefs.get("serial.port"); String uploadPort = prefs.get("serial.port");
String newUploadPort = null;
try { try {
// Toggle 1200 bps on selected serial port to force board reset. // Toggle 1200 bps on selected serial port to force board reset.
List<String> before = Serial.list(); List<String> before = Serial.list();
@ -77,64 +80,19 @@ public class BasicUploader extends Uploader {
.println(_("Forcing reset using 1200bps open/close on port ") + .println(_("Forcing reset using 1200bps open/close on port ") +
uploadPort); uploadPort);
Serial.touchPort(uploadPort, 1200); Serial.touchPort(uploadPort, 1200);
}
if (waitForUploadPort) {
// Scanning for available ports seems to open the port or // Scanning for available ports seems to open the port or
// otherwise assert DTR, which would cancel the WDT reset if // otherwise assert DTR, which would cancel the WDT reset if
// it happened within 250 ms. So we wait until the reset should // it happened within 250 ms. So we wait until the reset should
// have already occured before we start scanning. // have already occured before we start scanning.
if (!Base.isMacOS()) if (!Base.isMacOS())
Thread.sleep(300); Thread.sleep(300);
}
// Wait for a port to appear on the list
int elapsed = 0;
while (elapsed < 10000) {
List<String> now = Serial.list();
List<String> diff = new ArrayList<String>(now);
diff.removeAll(before);
if (verbose || Preferences.getBoolean("upload.verbose")) {
System.out.print("PORTS {");
for (String p : before)
System.out.print(p + ", ");
System.out.print("} / {");
for (String p : now)
System.out.print(p + ", ");
System.out.print("} => {");
for (String p : diff)
System.out.print(p + ", ");
System.out.println("}");
}
if (diff.size() > 0) {
newUploadPort = diff.get(0);
if (verbose || Preferences.getBoolean("upload.verbose"))
System.out.println("Found upload port: " +
newUploadPort);
break;
}
// Keep track of port that disappears uploadPort = waitForUploadPort(uploadPort, before);
before = now; } else {
Thread.sleep(250); Thread.sleep(2500);
elapsed += 250;
// On Windows, it can take a long time for the port to disappear and
// come back, so use a longer time out before assuming that the
// selected
// port is the bootloader (not the sketch).
if (((!Base.isWindows() && elapsed >= 500) || elapsed >= 5000) &&
now.contains(uploadPort)) {
if (verbose || Preferences.getBoolean("upload.verbose"))
System.out
.println("Uploading using selected port: " + uploadPort);
newUploadPort = uploadPort;
break;
} }
}
if (newUploadPort == null)
// Something happened while detecting port
throw new RunnerException(
_("Couldnt find a Leonardo on the selected port. Check that you have the correct port selected. If it is correct, try pressing the board's reset button after initiating the upload."));
uploadPort = newUploadPort;
} catch (SerialException e) { } catch (SerialException e) {
throw new RunnerException(e.getMessage()); throw new RunnerException(e.getMessage());
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -173,7 +131,7 @@ public class BasicUploader extends Uploader {
// sketch port never comes back). Doing this saves users from accidentally // sketch port never comes back). Doing this saves users from accidentally
// opening Serial Monitor on the soon-to-be-orphaned bootloader port. // opening Serial Monitor on the soon-to-be-orphaned bootloader port.
try { try {
if (uploadResult && doTouch) { if (uploadResult && waitForUploadPort) {
Thread.sleep(500); Thread.sleep(500);
long timeout = System.currentTimeMillis() + 2000; long timeout = System.currentTimeMillis() + 2000;
while (timeout > System.currentTimeMillis()) { while (timeout > System.currentTimeMillis()) {
@ -188,6 +146,56 @@ public class BasicUploader extends Uploader {
return uploadResult; return uploadResult;
} }
private String waitForUploadPort(String uploadPort, List<String> before)
throws InterruptedException, RunnerException {
// Wait for a port to appear on the list
int elapsed = 0;
while (elapsed < 10000) {
List<String> now = Serial.list();
List<String> diff = new ArrayList<String>(now);
diff.removeAll(before);
if (verbose || Preferences.getBoolean("upload.verbose")) {
System.out.print("PORTS {");
for (String p : before)
System.out.print(p + ", ");
System.out.print("} / {");
for (String p : now)
System.out.print(p + ", ");
System.out.print("} => {");
for (String p : diff)
System.out.print(p + ", ");
System.out.println("}");
}
if (diff.size() > 0) {
String newPort = diff.get(0);
if (verbose || Preferences.getBoolean("upload.verbose"))
System.out.println("Found upload port: " + newPort);
return newPort;
}
// Keep track of port that disappears
before = now;
Thread.sleep(250);
elapsed += 250;
// On Windows, it can take a long time for the port to disappear and
// come back, so use a longer time out before assuming that the
// selected
// port is the bootloader (not the sketch).
if (((!Base.isWindows() && elapsed >= 500) || elapsed >= 5000) &&
now.contains(uploadPort)) {
if (verbose || Preferences.getBoolean("upload.verbose"))
System.out.println("Uploading using selected port: " +
uploadPort);
return uploadPort;
}
}
// Something happened while detecting port
throw new RunnerException(
_("Couldnt find a Leonardo on the selected port. Check that you have the correct port selected. If it is correct, try pressing the board's reset button after initiating the upload."));
}
public boolean uploadUsingProgrammer(String buildPath, String className) public boolean uploadUsingProgrammer(String buildPath, String className)
throws RunnerException { throws RunnerException {

View File

@ -162,6 +162,7 @@ leonardo.upload.maximum_size=28672
leonardo.upload.speed=57600 leonardo.upload.speed=57600
leonardo.upload.disable_flushing=true leonardo.upload.disable_flushing=true
leonardo.upload.use_1200bps_touch=true leonardo.upload.use_1200bps_touch=true
leonardo.upload.wait_for_upload_port=true
leonardo.bootloader.tool=avrdude leonardo.bootloader.tool=avrdude
leonardo.bootloader.low_fuses=0xff leonardo.bootloader.low_fuses=0xff

View File

@ -1,16 +1,35 @@
arduino_due_x_r2.name=Arduino Due Dev. Ed. arduino_due_x.name=Arduino Due Dev. Ed.
arduino_due_x_r2.upload.tool=bossac arduino_due_x.upload.tool=bossac
arduino_due_x_r2.upload.protocol=sam-ba arduino_due_x.upload.protocol=sam-ba
arduino_due_x_r2.upload.maximum_size=524288 arduino_due_x.upload.maximum_size=524288
arduino_due_x_r2.upload.use_1200bps_touch=true arduino_due_x.upload.use_1200bps_touch=true
arduino_due_x_r2.build.mcu=cortex-m3 arduino_due_x.upload.wait_for_upload_port=true
arduino_due_x_r2.build.f_cpu=84000000L arduino_due_x.upload.native_usb=true
arduino_due_x_r2.build.core=arduino arduino_due_x.build.mcu=cortex-m3
arduino_due_x_r2.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON arduino_due_x.build.f_cpu=84000000L
arduino_due_x_r2.build.ldscript=linker_scripts/gcc/flash.ld arduino_due_x.build.core=arduino
arduino_due_x_r2.build.variant=arduino_due_x arduino_due_x.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON
arduino_due_x_r2.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a arduino_due_x.build.ldscript=linker_scripts/gcc/flash.ld
arduino_due_x_r2.build.vid=0x2341 arduino_due_x.build.variant=arduino_due_x
arduino_due_x_r2.build.pid=0x003e arduino_due_x.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a
arduino_due_x.build.vid=0x2341
arduino_due_x.build.pid=0x003e
arduino_due_x_dbg.name=Arduino Due Dev. Ed. (Debug port)
arduino_due_x_dbg.upload.tool=bossac
arduino_due_x_dbg.upload.protocol=sam-ba
arduino_due_x_dbg.upload.maximum_size=524288
arduino_due_x_dbg.upload.use_1200bps_touch=true
arduino_due_x_dbg.upload.wait_for_upload_port=false
arduino_due_x_dbg.upload.native_usb=false
arduino_due_x_dbg.build.mcu=cortex-m3
arduino_due_x_dbg.build.f_cpu=84000000L
arduino_due_x_dbg.build.core=arduino
arduino_due_x_dbg.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON
arduino_due_x_dbg.build.ldscript=linker_scripts/gcc/flash.ld
arduino_due_x_dbg.build.variant=arduino_due_x
arduino_due_x_dbg.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a
arduino_due_x_dbg.build.vid=0x2341
arduino_due_x_dbg.build.pid=0x003e

View File

@ -62,7 +62,7 @@ tools.bossac.path={runtime.ide.path}/hardware/tools
tools.bossac.upload.params.verbose=-i -d tools.bossac.upload.params.verbose=-i -d
tools.bossac.upload.params.quiet= tools.bossac.upload.params.quiet=
tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -e -w -v -b "{build.path}/{build.project_name}.bin" -R tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U {upload.native_usb} -e -w -v -b "{build.path}/{build.project_name}.bin" -R
# specialized tool for adk2 to twiddle the erase line before running bossac # specialized tool for adk2 to twiddle the erase line before running bossac
tools.adk2install.cmd=adk2install tools.adk2install.cmd=adk2install