1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-15 12:29:26 +01:00

Auto restart after upload (linux only for now). Auto reset/erase when uploading a new sketch.

This commit is contained in:
Cristian Maglie 2012-08-14 10:05:02 +02:00
parent e2c98640c9
commit df19935d31
5 changed files with 62 additions and 34 deletions

View File

@ -105,9 +105,10 @@ public class Serial implements SerialPortEventListener {
SerialPort port;
boolean result = false;
try {
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
@SuppressWarnings("unchecked")
Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
CommPortIdentifier portId = portList.nextElement();
if ((CommPortIdentifier.PORT_SERIAL == portId.getPortType()) && (portId.getName().equals(iname))) {
port = (SerialPort) portId.open("tap", 2000);
port.setSerialPortParams(irate, 8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
@ -148,10 +149,10 @@ public class Serial implements SerialPortEventListener {
try {
port = null;
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
@SuppressWarnings("unchecked")
Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId =
(CommPortIdentifier) portList.nextElement();
CommPortIdentifier portId = portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
//System.out.println("found " + portId.getName());

View File

@ -67,7 +67,7 @@ public class BasicUploader extends Uploader {
boolean doTouch = use1200bpsTouch != null && use1200bpsTouch.equals("true");
if (doTouch) {
String uploadPort = prefs.get("serial.port");
String caterinaUploadPort = null;
String newUploadPort = null;
try {
// Toggle 1200 bps on selected serial port to force board reset.
List<String> before = Serial.list();
@ -104,10 +104,10 @@ public class BasicUploader extends Uploader {
System.out.println("}");
}
if (diff.size() > 0) {
caterinaUploadPort = diff.get(0);
newUploadPort = diff.get(0);
if (verbose || Preferences.getBoolean("upload.verbose"))
System.out.println("Found Leonardo upload port: " +
caterinaUploadPort);
System.out.println("Found upload port: " +
newUploadPort);
break;
}
@ -125,16 +125,16 @@ public class BasicUploader extends Uploader {
if (verbose || Preferences.getBoolean("upload.verbose"))
System.out
.println("Uploading using selected port: " + uploadPort);
caterinaUploadPort = uploadPort;
newUploadPort = uploadPort;
break;
}
}
if (caterinaUploadPort == null)
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 = caterinaUploadPort;
uploadPort = newUploadPort;
} catch (SerialException e) {
throw new RunnerException(e.getMessage());
} catch (InterruptedException e) {

Binary file not shown.

View File

@ -30,6 +30,21 @@ 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_r2.name=Arduino DueX R2 Dev. Ed.
arduino_due_x_r2.upload.tool=bossac
arduino_due_x_r2.upload.protocol=sam-ba
arduino_due_x_r2.upload.maximum_size=524288
arduino_due_x_r2.upload.use_1200bps_touch=true
arduino_due_x_r2.build.mcu=cortex-m3
arduino_due_x_r2.build.f_cpu=84000000L
arduino_due_x_r2.build.core=arduino
arduino_due_x_r2.build.extra_flags=-D__SAM3X8E__ -mthumb -DUSB_PID={build.pid} -DUSB_VID={build.vid} -DUSBCON
arduino_due_x_r2.build.ldscript=linker_scripts/gcc/flash.ld
arduino_due_x_r2.build.variant=arduino_due_x
arduino_due_x_r2.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a
arduino_due_x_r2.build.vid=0x2341
arduino_due_x_r2.build.pid=0x003e
##############################################################
adk2.name=Google ADK2

View File

@ -73,6 +73,38 @@ int WEAK CDC_GetInterface(uint8_t* interfaceNum)
return USBD_SendControl(0,&_cdcInterface,sizeof(_cdcInterface));
}
__attribute__ ((long_call, section (".ramfunc")))
void banzai() {
// Disable all interrupts
__disable_irq();
// Set bootflag to run SAM-BA bootloader at restart
const int EEFC_FCMD_CGPB = 0x0C;
const int EEFC_KEY = 0x5A;
while (EFC0->EEFC_FSR & EEFC_FSR_FRDY == 0);
EFC0->EEFC_FCR =
EEFC_FCR_FCMD(EEFC_FCMD_CGPB) |
EEFC_FCR_FARG(1) |
EEFC_FCR_FKEY(EEFC_KEY);
while (EFC0->EEFC_FSR & EEFC_FSR_FRDY == 0);
// From here flash memory is no more available.
// Memory swap needs some time to stabilize
volatile uint32_t i;
for (i=0; i<1000000; i++);
// BANZAIIIIIII!!!
const int RSTC_KEY = 0xA5;
RSTC->RSTC_CR =
RSTC_CR_KEY(RSTC_KEY) |
RSTC_CR_PROCRST |
RSTC_CR_PERRST |
RSTC_CR_EXTRST;
while (true);
}
bool WEAK CDC_Setup(Setup& setup)
{
uint8_t r = setup.bRequest;
@ -99,31 +131,12 @@ bool WEAK CDC_Setup(Setup& setup)
{
_usbLineInfo.lineState = setup.wValueL;
// 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
// open at 1200 bps, is closed.
if (1200 == _usbLineInfo.dwDTERate)
{
// We check DTR state to determine if host port is open (bit 0 of lineState).
if ((_usbLineInfo.lineState & 0x01) == 0)
{
/* TODO, AVR Stuff
*(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.
/* TODO, AVR Stuff
wdt_disable();
wdt_reset();
*(uint16_t *)0x0800 = 0x0;
*/
}
banzai();
}
return true;
}
@ -131,7 +144,6 @@ bool WEAK CDC_Setup(Setup& setup)
return false;
}
int _serialPeek = -1;
void Serial_::begin(uint32_t baud_count)
{