/*
LUFA Library
- Copyright (C) Dean Camera, 2017.
+ Copyright (C) Dean Camera, 2021.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+ Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
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();
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)
{
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)