diff --git a/app/src/processing/app/Serial.java b/app/src/processing/app/Serial.java index 14c0933c0..e084e12b2 100755 --- a/app/src/processing/app/Serial.java +++ b/app/src/processing/app/Serial.java @@ -105,9 +105,10 @@ public class Serial implements SerialPortEventListener { SerialPort port; boolean result = false; try { - Enumeration portList = CommPortIdentifier.getPortIdentifiers(); + @SuppressWarnings("unchecked") + Enumeration 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 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()); diff --git a/app/src/processing/app/debug/BasicUploader.java b/app/src/processing/app/debug/BasicUploader.java index 202e17932..1fc87d43a 100644 --- a/app/src/processing/app/debug/BasicUploader.java +++ b/app/src/processing/app/debug/BasicUploader.java @@ -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 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( _("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) { throw new RunnerException(e.getMessage()); } catch (InterruptedException e) { diff --git a/build/linux/dist/tools/bossac b/build/linux/dist/tools/bossac index ed31143e2..4fafe9dfa 100755 Binary files a/build/linux/dist/tools/bossac and b/build/linux/dist/tools/bossac differ diff --git a/hardware/arduino/sam/boards.txt b/hardware/arduino/sam/boards.txt index ca415eaf6..370e0f5f5 100644 --- a/hardware/arduino/sam/boards.txt +++ b/hardware/arduino/sam/boards.txt @@ -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 diff --git a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp index 134e9f901..64271b1f8 100644 --- a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp @@ -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) {