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:
parent
e2c98640c9
commit
df19935d31
@ -105,9 +105,10 @@ public class Serial implements SerialPortEventListener {
|
|||||||
SerialPort port;
|
SerialPort port;
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
try {
|
try {
|
||||||
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
@SuppressWarnings("unchecked")
|
||||||
|
Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
|
||||||
while (portList.hasMoreElements()) {
|
while (portList.hasMoreElements()) {
|
||||||
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
|
CommPortIdentifier portId = portList.nextElement();
|
||||||
if ((CommPortIdentifier.PORT_SERIAL == portId.getPortType()) && (portId.getName().equals(iname))) {
|
if ((CommPortIdentifier.PORT_SERIAL == portId.getPortType()) && (portId.getName().equals(iname))) {
|
||||||
port = (SerialPort) portId.open("tap", 2000);
|
port = (SerialPort) portId.open("tap", 2000);
|
||||||
port.setSerialPortParams(irate, 8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
|
port.setSerialPortParams(irate, 8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
|
||||||
@ -148,10 +149,10 @@ public class Serial implements SerialPortEventListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
port = null;
|
port = null;
|
||||||
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
@SuppressWarnings("unchecked")
|
||||||
|
Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
|
||||||
while (portList.hasMoreElements()) {
|
while (portList.hasMoreElements()) {
|
||||||
CommPortIdentifier portId =
|
CommPortIdentifier portId = portList.nextElement();
|
||||||
(CommPortIdentifier) portList.nextElement();
|
|
||||||
|
|
||||||
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
|
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
|
||||||
//System.out.println("found " + portId.getName());
|
//System.out.println("found " + portId.getName());
|
||||||
|
@ -67,7 +67,7 @@ public class BasicUploader extends Uploader {
|
|||||||
boolean doTouch = use1200bpsTouch != null && use1200bpsTouch.equals("true");
|
boolean doTouch = use1200bpsTouch != null && use1200bpsTouch.equals("true");
|
||||||
if (doTouch) {
|
if (doTouch) {
|
||||||
String uploadPort = prefs.get("serial.port");
|
String uploadPort = prefs.get("serial.port");
|
||||||
String caterinaUploadPort = null;
|
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();
|
||||||
@ -104,10 +104,10 @@ public class BasicUploader extends Uploader {
|
|||||||
System.out.println("}");
|
System.out.println("}");
|
||||||
}
|
}
|
||||||
if (diff.size() > 0) {
|
if (diff.size() > 0) {
|
||||||
caterinaUploadPort = diff.get(0);
|
newUploadPort = diff.get(0);
|
||||||
if (verbose || Preferences.getBoolean("upload.verbose"))
|
if (verbose || Preferences.getBoolean("upload.verbose"))
|
||||||
System.out.println("Found Leonardo upload port: " +
|
System.out.println("Found upload port: " +
|
||||||
caterinaUploadPort);
|
newUploadPort);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,16 +125,16 @@ public class BasicUploader extends Uploader {
|
|||||||
if (verbose || Preferences.getBoolean("upload.verbose"))
|
if (verbose || Preferences.getBoolean("upload.verbose"))
|
||||||
System.out
|
System.out
|
||||||
.println("Uploading using selected port: " + uploadPort);
|
.println("Uploading using selected port: " + uploadPort);
|
||||||
caterinaUploadPort = uploadPort;
|
newUploadPort = uploadPort;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (caterinaUploadPort == null)
|
if (newUploadPort == null)
|
||||||
// Something happened while detecting port
|
// Something happened while detecting port
|
||||||
throw new RunnerException(
|
throw new RunnerException(
|
||||||
_("Couldn’t 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."));
|
_("Couldn’t 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) {
|
} catch (SerialException e) {
|
||||||
throw new RunnerException(e.getMessage());
|
throw new RunnerException(e.getMessage());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
BIN
build/linux/dist/tools/bossac
vendored
BIN
build/linux/dist/tools/bossac
vendored
Binary file not shown.
@ -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.vid=0x2341
|
||||||
arduino_due_x.build.pid=0x003e
|
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
|
adk2.name=Google ADK2
|
||||||
|
@ -73,6 +73,38 @@ int WEAK CDC_GetInterface(uint8_t* interfaceNum)
|
|||||||
return USBD_SendControl(0,&_cdcInterface,sizeof(_cdcInterface));
|
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)
|
bool WEAK CDC_Setup(Setup& setup)
|
||||||
{
|
{
|
||||||
uint8_t r = setup.bRequest;
|
uint8_t r = setup.bRequest;
|
||||||
@ -99,31 +131,12 @@ bool WEAK CDC_Setup(Setup& setup)
|
|||||||
{
|
{
|
||||||
_usbLineInfo.lineState = setup.wValueL;
|
_usbLineInfo.lineState = setup.wValueL;
|
||||||
// auto-reset into the bootloader is triggered when the port, already
|
// 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
|
// open at 1200 bps, is closed.
|
||||||
// with a relatively long period so it can finish housekeeping tasks
|
|
||||||
// like servicing endpoints before the sketch ends
|
|
||||||
if (1200 == _usbLineInfo.dwDTERate)
|
if (1200 == _usbLineInfo.dwDTERate)
|
||||||
{
|
{
|
||||||
// We check DTR state to determine if host port is open (bit 0 of lineState).
|
// We check DTR state to determine if host port is open (bit 0 of lineState).
|
||||||
if ((_usbLineInfo.lineState & 0x01) == 0)
|
if ((_usbLineInfo.lineState & 0x01) == 0)
|
||||||
{
|
banzai();
|
||||||
/* 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;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -131,7 +144,6 @@ bool WEAK CDC_Setup(Setup& setup)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int _serialPeek = -1;
|
int _serialPeek = -1;
|
||||||
void Serial_::begin(uint32_t baud_count)
|
void Serial_::begin(uint32_t baud_count)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user