Skip to content
Snippets Groups Projects
Commit 6333d0c4 authored by Cristian Maglie's avatar Cristian Maglie Committed by Cristian Maglie
Browse files

Merge pull request #49 from arduino/1200bps-touch

Implemented Auto-Reset on 1200bps-touch (Native Port) to restart bootloader
parents ffdef056 b11b8e8b
No related branches found
No related tags found
No related merge requests found
......@@ -28,8 +28,8 @@ arduino_zero_native.pid.0=0x004d
arduino_zero_native.upload.tool=bossac
arduino_zero_native.upload.protocol=sam-ba
arduino_zero_native.upload.maximum_size=262144
arduino_zero_native.upload.use_1200bps_touch=false
arduino_zero_native.upload.wait_for_upload_port=false
arduino_zero_native.upload.use_1200bps_touch=true
arduino_zero_native.upload.wait_for_upload_port=true
arduino_zero_native.upload.native_usb=true
arduino_zero_native.build.mcu=cortex-m0plus
arduino_zero_native.build.f_cpu=48000000L
......
......@@ -23,12 +23,28 @@
extern "C" {
#endif
#define NVM_MEMORY ((volatile uint16_t *)0x000000)
#define APP_START 0x00002004
static inline bool nvmReady(void) {
return NVMCTRL->INTFLAG.reg & NVMCTRL_INTFLAG_READY;
}
__attribute__ ((long_call, section (".ramfunc")))
static void banzai() {
// Disable all interrupts
__disable_irq();
// Reset the device
// Erase application
while (!nvmReady())
;
NVMCTRL->STATUS.reg |= NVMCTRL_STATUS_MASK;
NVMCTRL->ADDR.reg = (uintptr_t)&NVM_MEMORY[APP_START / 4];
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMD_ER | NVMCTRL_CTRLA_CMDEX_KEY;
while (!nvmReady())
;
// Reset the device
NVIC_SystemReset() ;
while (true);
......
......@@ -119,21 +119,25 @@ bool WEAK CDC_Setup(Setup& setup)
if (CDC_SET_LINE_CODING == r)
{
USBD_RecvControl((void*)&_usbLineInfo,7);
return false;
}
if (CDC_SET_CONTROL_LINE_STATE == r)
{
_usbLineInfo.lineState = setup.wValueL;
}
if (CDC_SET_LINE_CODING == r || CDC_SET_CONTROL_LINE_STATE == r)
{
// auto-reset into the bootloader is triggered when the port, already
// open at 1200 bps, is closed.
if (1200 == _usbLineInfo.dwDTERate)
// open at 1200 bps, is closed. We check DTR state to determine if host
// port is open (bit 0 of lineState).
if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0)
{
initiateReset(250);
}
else
{
// We check DTR state to determine if host port is open (bit 0 of lineState).
if ((_usbLineInfo.lineState & 0x01) == 0)
initiateReset(250);
else
cancelReset();
cancelReset();
}
return false;
}
......
......@@ -58,10 +58,13 @@ void delay( uint32_t ms )
} while ( _ulTickCount - start <= ms ) ;
}
#include "Reset.h" // for tickReset()
void SysTick_Handler( void )
{
// Increment tick count each ms
_ulTickCount++ ;
tickReset();
}
#ifdef __cplusplus
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment