From 75da79ad7602d1a73e46155a5630f41d91f9bd83 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Thu, 8 Mar 2012 14:20:12 -0500 Subject: give Leonardo bootloader 250 ms to finish housekeeping before leaving self-programming mode Earlier approach had bootloader end as soon as it was told to. On Linux this caused problems with avrdude because the microcontroller never had a chance to send an acknowledgement. --- bootloaders/caterina/Caterina.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'bootloaders/caterina/Caterina.c') diff --git a/bootloaders/caterina/Caterina.c b/bootloaders/caterina/Caterina.c index c8e82a9..2b50636 100755 --- a/bootloaders/caterina/Caterina.c +++ b/bootloaders/caterina/Caterina.c @@ -62,6 +62,7 @@ uint16_t TxLEDPulse = 0; // time remaining for Tx LED pulse uint16_t RxLEDPulse = 0; // time remaining for Rx LED pulse /* Bootloader timeout timer */ +#define TIMEOUT_PERIOD 8000 uint16_t Timeout = 0; uint16_t bootKey = 0x7777; @@ -133,12 +134,14 @@ int main(void) /* Enable global interrupts so that the USB stack can function */ sei(); + Timeout = 0; + while (RunBootloader) { CDC_Task(); USB_USBTask(); /* Time out and start the sketch if one is present */ - if (Timeout > 8000) + if (Timeout > TIMEOUT_PERIOD) RunBootloader = false; LEDPulse(); @@ -475,7 +478,11 @@ void CDC_Task(void) if (Command == 'E') { - RunBootloader = false; + /* We nearly run out the bootloader timeout clock, + * leaving just a few hundred milliseconds so the + * bootloder has time to respond and service any + * subsequent requests */ + Timeout = TIMEOUT_PERIOD - 250; // Send confirmation byte back to the host WriteNextResponseByte('\r'); -- cgit v1.2.3-18-g5258