From 28e9e122af24e63e84d5bcd2c619b76c490970fc Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Sat, 31 Dec 2011 12:19:08 -0500 Subject: reset the Leonardo board when leaving the bootloader, before starting the sketch Done so all IO and other registers are properly reinitialized when a new sketch is uploaded or when an existing sketch is started. Uses a watchdog timeout with a 15 ms period to accomplish the reset. Bootloader checks the reason for reset and only enumerates as bootloader and enters the programming loop if reset was NOT caused by WDT. --- bootloaders/diskloader/src/DiskLoader.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'bootloaders/diskloader/src/DiskLoader.cpp') diff --git a/bootloaders/diskloader/src/DiskLoader.cpp b/bootloaders/diskloader/src/DiskLoader.cpp index 6580618..09f59a7 100644 --- a/bootloaders/diskloader/src/DiskLoader.cpp +++ b/bootloaders/diskloader/src/DiskLoader.cpp @@ -56,7 +56,7 @@ void Program(u8 ep, u16 page, u8 count) boot_rww_enable (); } - +void StartSketch(); int USBGetChar(); #define getch USBGetChar @@ -111,10 +111,15 @@ int main(void) __attribute__ ((naked)); // STK500v1 main loop, very similar to optiboot in protocol and implementation int main() { + uint8_t MCUSR_state = MCUSR; // store the reason for the reset + MCUSR &= ~(1 << WDRF); // must clear the watchdog reset flag before disabling and reenabling WDT wdt_disable(); TXLED0; RXLED0; - LED0; + LED0; + if (MCUSR_state & (1<