From 871d9bf1af06fe208ca16cb3b19722bec1300e63 Mon Sep 17 00:00:00 2001
From: Dean Camera <dean@fourwalledcubicle.com>
Date: Sun, 24 Jan 2010 13:38:20 +0000
Subject: [PATCH] Fixed DFU bootloader programming not discarding the correct
 number of filler bytes from the host when non-aligned programming ranges are
 specified (thanks to Thomas Bleeker).

---
 Bootloaders/DFU/BootloaderDFU.c                 | 4 ++--
 LUFA/ManPages/ChangeLog.txt                     | 2 ++
 Projects/TemperatureDataLogger/TempDataLogger.c | 4 ++++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c
index 553a5a2ef..157b78ffb 100644
--- a/Bootloaders/DFU/BootloaderDFU.c
+++ b/Bootloaders/DFU/BootloaderDFU.c
@@ -205,8 +205,8 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
 					/* Throw away the filler bytes before the start of the firmware */
 					DiscardFillerBytes(DFU_FILLER_BYTES_SIZE);
 
-					/* Throw away the page alignment filler bytes before the start of the firmware */
-					DiscardFillerBytes(StartAddr % SPM_PAGESIZE);
+					/* Throw away the packet alignment filler bytes before the start of the firmware */
+					DiscardFillerBytes(StartAddr % FIXED_CONTROL_ENDPOINT_SIZE);
 					
 					/* Calculate the number of bytes remaining to be written */
 					uint16_t BytesRemaining = ((EndAddr - StartAddr) + 1);
diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt
index 6a2126fb4..e5bdbb3d1 100644
--- a/LUFA/ManPages/ChangeLog.txt
+++ b/LUFA/ManPages/ChangeLog.txt
@@ -41,6 +41,8 @@
   *  - Fixed invalid USB controller PLL prescaler values for the ATMEGAxxU2 controllers
   *  - Fixed lack of support for the ATMEGA32U2 in the DFU and CDC class bootloaders
   *  - Fixed Benito project not resetting the target AVR automatically when programming has completed
+  *  - Fixed DFU bootloader programming not discarding the correct number of filler bytes from the host when non-aligned programming
+  *    ranges are specified (thanks to Thomas Bleeker)
   *
   *  \section Sec_ChangeLog091223 Version 091223
   *
diff --git a/Projects/TemperatureDataLogger/TempDataLogger.c b/Projects/TemperatureDataLogger/TempDataLogger.c
index 538a6a5e8..2f2e8daf7 100644
--- a/Projects/TemperatureDataLogger/TempDataLogger.c
+++ b/Projects/TemperatureDataLogger/TempDataLogger.c
@@ -96,6 +96,7 @@ FATFS DiskFATState;
 FIL TempLogFile;
 
 
+/** ISR to handle the 500ms ticks for sampling and data logging */
 ISR(TIMER1_COMPA_vect, ISR_BLOCK)
 {
 	uint8_t LEDMask = LEDs_GetLEDs();
@@ -157,6 +158,7 @@ int main(void)
 	}
 }
 
+/** Opens the log file on the Dataflash's FAT formatted partition according to the current date */
 void OpenLogFile(void)
 {
 	char LogFileName[12];
@@ -172,6 +174,7 @@ void OpenLogFile(void)
 	f_lseek(&TempLogFile, TempLogFile.fsize);
 }
 
+/** Closes the open data log file on the Dataflash's FAT formatted partition */
 void CloseLogFile(void)
 {
 	/* Sync any data waiting to be written, unmount the storage device */
@@ -301,6 +304,7 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI
 	DS1307_SetDate(ReportParams->Day,  ReportParams->Month,  ReportParams->Year);
 	DS1307_SetTime(ReportParams->Hour, ReportParams->Minute, ReportParams->Second);
 	
+	/* If the logging interval has changed from its current value, write it to EEPROM */
 	if (LoggingInterval500MS_SRAM != ReportParams->LogInterval500MS)
 	{
 		LoggingInterval500MS_SRAM = ReportParams->LogInterval500MS;
-- 
GitLab