X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/ad9225bdd34230e13333be5d4c29e4f96abc9b2b..f2740a66bafa876dfcf2cdfa4c6f3e17395e8bf8:/Bootloaders/HID/BootloaderHID.c?ds=inline diff --git a/Bootloaders/HID/BootloaderHID.c b/Bootloaders/HID/BootloaderHID.c index c21bf5692..a1f3e6718 100644 --- a/Bootloaders/HID/BootloaderHID.c +++ b/Bootloaders/HID/BootloaderHID.c @@ -84,6 +84,9 @@ int main(void) while (RunBootloader) USB_USBTask(); + /* Wait a short time to end all USB transactions and then disconnect */ + _delay_us(1000); + /* Disconnect from the host - USB interface will be reset later along with the AVR */ USB_Detach(); @@ -152,6 +155,10 @@ void EVENT_USB_Device_ControlRequest(void) uint16_t PageAddress = Endpoint_Read_16_LE(); #endif + /* Determine if the given page address is correctly aligned to the + start of a flash page. */ + bool PageAddressIsAligned = !(PageAddress & (SPM_PAGESIZE - 1)); + /* Check if the command is a program page command, or a start application command */ #if (FLASHEND > 0xFFFF) if ((uint16_t)(PageAddress >> 8) == COMMAND_STARTAPPLICATION) @@ -161,7 +168,7 @@ void EVENT_USB_Device_ControlRequest(void) { RunBootloader = false; } - else if (PageAddress < BOOT_START_ADDR) + else if ((PageAddress < BOOT_START_ADDR) && PageAddressIsAligned) { /* Erase the given FLASH page, ready to be programmed */ ATOMIC_BLOCK(ATOMIC_RESTORESTATE)