mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Upload over debug port (part 2)
This commit is contained in:
parent
ca74c94ae5
commit
d96264e60f
@ -91,7 +91,7 @@ public class BasicUploader extends Uploader {
|
|||||||
|
|
||||||
uploadPort = waitForUploadPort(uploadPort, before);
|
uploadPort = waitForUploadPort(uploadPort, before);
|
||||||
} else {
|
} else {
|
||||||
Thread.sleep(2500);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
} catch (SerialException e) {
|
} catch (SerialException e) {
|
||||||
throw new RunnerException(e.getMessage());
|
throw new RunnerException(e.getMessage());
|
||||||
@ -136,8 +136,13 @@ public class BasicUploader extends Uploader {
|
|||||||
long timeout = System.currentTimeMillis() + 2000;
|
long timeout = System.currentTimeMillis() + 2000;
|
||||||
while (timeout > System.currentTimeMillis()) {
|
while (timeout > System.currentTimeMillis()) {
|
||||||
List<String> portList = Serial.list();
|
List<String> portList = Serial.list();
|
||||||
if (portList.contains(Preferences.get("serial.port")))
|
String uploadPort = Preferences.get("serial.port");
|
||||||
|
if (portList.contains(Preferences.get("serial.port"))) {
|
||||||
|
// Remove the magic baud rate (1200bps) to avoid
|
||||||
|
// future unwanted board resets
|
||||||
|
Serial.touchPort(uploadPort, 9600);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
70
hardware/arduino/sam/cores/arduino/Reset.cpp
Normal file
70
hardware/arduino/sam/cores/arduino/Reset.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2012 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "Reset.h"
|
||||||
|
|
||||||
|
__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
|
||||||
|
for (uint32_t i=0; i<1000000; i++)
|
||||||
|
// force compiler to not optimize this
|
||||||
|
__asm__ __volatile__("");
|
||||||
|
|
||||||
|
// BANZAIIIIIII!!!
|
||||||
|
const int RSTC_KEY = 0xA5;
|
||||||
|
RSTC->RSTC_CR =
|
||||||
|
RSTC_CR_KEY(RSTC_KEY) |
|
||||||
|
RSTC_CR_PROCRST |
|
||||||
|
RSTC_CR_PERRST;
|
||||||
|
|
||||||
|
while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetClass::initiate(int _ticks) {
|
||||||
|
ticks = _ticks;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetClass::cancel() {
|
||||||
|
ticks = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetClass::tick() {
|
||||||
|
if (ticks == -1)
|
||||||
|
return;
|
||||||
|
ticks--;
|
||||||
|
if (ticks == 0)
|
||||||
|
banzai();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ResetClass::ticks = -1;
|
33
hardware/arduino/sam/cores/arduino/Reset.h
Normal file
33
hardware/arduino/sam/cores/arduino/Reset.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2012 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RESET_H
|
||||||
|
#define RESET_H
|
||||||
|
|
||||||
|
class ResetClass {
|
||||||
|
public:
|
||||||
|
static void initiate(int _ticks);
|
||||||
|
static void cancel();
|
||||||
|
static void tick();
|
||||||
|
private:
|
||||||
|
static int ticks;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern ResetClass Reset;
|
||||||
|
|
||||||
|
#endif
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "USBAPI.h"
|
#include "USBAPI.h"
|
||||||
|
#include "Reset.h"
|
||||||
|
|
||||||
#ifdef CDC_ENABLED
|
#ifdef CDC_ENABLED
|
||||||
|
|
||||||
@ -73,38 +74,6 @@ 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;
|
||||||
@ -136,7 +105,9 @@ bool WEAK CDC_Setup(Setup& setup)
|
|||||||
{
|
{
|
||||||
// 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();
|
Reset.initiate(240);
|
||||||
|
else
|
||||||
|
Reset.cancel();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "USBAPI.h"
|
#include "USBAPI.h"
|
||||||
|
#include "Reset.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
//#define TRACE_CORE(x) x
|
//#define TRACE_CORE(x) x
|
||||||
@ -368,6 +369,8 @@ static bool USBD_SendDescriptor(Setup& setup)
|
|||||||
// Endpoint 0 interrupt
|
// Endpoint 0 interrupt
|
||||||
static void USB_ISR(void)
|
static void USB_ISR(void)
|
||||||
{
|
{
|
||||||
|
Reset.tick();
|
||||||
|
|
||||||
// End of Reset
|
// End of Reset
|
||||||
if (Is_udd_reset())
|
if (Is_udd_reset())
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user