From 958b20a8ef51c9f6f104ce59d8f17ea476a7a20c Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Sat, 25 Dec 2010 17:49:30 +0000 Subject: [PATCH] Fixed possible programming problem in the AVRISP-MKII clone project when programming specific patterns into a target memory space that is only byte (not page) addressable. --- LUFA/ManPages/ChangeLog.txt | 2 ++ LUFA/ManPages/FutureChanges.txt | 5 +++- Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c | 28 ++++++++++++---------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt index 1bce5faba0..ef2ef96cff 100644 --- a/LUFA/ManPages/ChangeLog.txt +++ b/LUFA/ManPages/ChangeLog.txt @@ -38,6 +38,8 @@ * - Fixed broken HID_REQ_GetReport request handler in the Low Level GenericHID demo * - Fixed possible lost data in the XPLAINBridge, USBtoSerial and Benito projects when the host exceeds the packet * timeout period on received packets as set by USB_STREAM_TIMEOUT_MS (thanks to Justin Rajewski) + * - Fixed possible programming problem in the AVRISP-MKII clone project when programming specific patterns into a target + * memory space that is only byte (not page) addressable * * \section Sec_ChangeLog101122 Version 101122 * New: diff --git a/LUFA/ManPages/FutureChanges.txt b/LUFA/ManPages/FutureChanges.txt index bfa5a530fb..2197cb5d3b 100644 --- a/LUFA/ManPages/FutureChanges.txt +++ b/LUFA/ManPages/FutureChanges.txt @@ -20,7 +20,10 @@ * -# Re-add interrupt Pipe/Endpoint support * -# Add HID report macros to make HID report editing easier * -# Investigate dynamically created device descriptors - * -# Check if ALL the workaround reg save/restore code in the unordered EP config is required + * - Known Bugs + * -# Errors with AVRISP-MKII program with full EEPROM programming on the ATMEGA8 (and others?) + * -# No wakeup when plugged into hub, and hub plugged into host + * -# Incomplete TMC class demo errors * - Documentation/Support * -# Add detailed overviews of how each demo works * -# Add board overviews diff --git a/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c b/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c index 97e0fb305a..e7d3e675c1 100644 --- a/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c +++ b/Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c @@ -146,8 +146,6 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command) Endpoint_Read_Stream_LE(&Write_Memory_Params, (sizeof(Write_Memory_Params) - sizeof(Write_Memory_Params.ProgData)), NO_STREAM_CALLBACK); - - Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite); if (Write_Memory_Params.BytesToWrite > sizeof(Write_Memory_Params.ProgData)) @@ -206,7 +204,7 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command) if (!(PollAddress) && (ByteToWrite != PollValue)) { if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP)) - Write_Memory_Params.ProgrammingCommands[2] |= READ_WRITE_HIGH_BYTE_MASK; + Write_Memory_Params.ProgrammingCommands[2] |= READ_WRITE_HIGH_BYTE_MASK; PollAddress = (CurrentAddress & 0xFFFF); } @@ -224,15 +222,16 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command) ISPTarget_SendByte(StartAddress & 0xFF); ISPTarget_SendByte(0x00); - /* Check if polling is possible and enabled, if not switch to timed delay mode */ - if (!(PollAddress) && (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_VALUE_MASK)) + /* Check if polling is enabled and possible, if not switch to timed delay mode */ + if ((Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_VALUE_MASK) && !(PollAddress)) { - Write_Memory_Params.ProgrammingMode &= ~PROG_MODE_PAGED_VALUE_MASK; - Write_Memory_Params.ProgrammingMode |= PROG_MODE_PAGED_TIMEDELAY_MASK; + Write_Memory_Params.ProgrammingMode = (Write_Memory_Params.ProgrammingMode & ~PROG_MODE_PAGED_VALUE_MASK) | + PROG_MODE_PAGED_TIMEDELAY_MASK; } ProgrammingStatus = ISPTarget_WaitForProgComplete(Write_Memory_Params.ProgrammingMode, PollAddress, PollValue, - Write_Memory_Params.DelayMS, Write_Memory_Params.ProgrammingCommands[2]); + Write_Memory_Params.DelayMS, + Write_Memory_Params.ProgrammingCommands[2]); /* Check to see if the FLASH address has crossed the extended address boundary */ if ((V2Command == CMD_PROGRAM_FLASH_ISP) && !(CurrentAddress & 0xFFFF)) @@ -270,18 +269,21 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command) if (ByteToWrite != PollValue) { if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP)) - Write_Memory_Params.ProgrammingCommands[2] |= READ_WRITE_HIGH_BYTE_MASK; + Write_Memory_Params.ProgrammingCommands[2] |= READ_WRITE_HIGH_BYTE_MASK; + else + Write_Memory_Params.ProgrammingCommands[2] &= ~READ_WRITE_HIGH_BYTE_MASK; PollAddress = (CurrentAddress & 0xFFFF); } else if (!(Write_Memory_Params.ProgrammingMode & PROG_MODE_WORD_READYBUSY_MASK)) { - Write_Memory_Params.ProgrammingMode &= ~PROG_MODE_WORD_VALUE_MASK; - Write_Memory_Params.ProgrammingMode |= PROG_MODE_WORD_TIMEDELAY_MASK; + Write_Memory_Params.ProgrammingMode = (Write_Memory_Params.ProgrammingMode & ~PROG_MODE_WORD_VALUE_MASK) | + PROG_MODE_WORD_TIMEDELAY_MASK; } ProgrammingStatus = ISPTarget_WaitForProgComplete(Write_Memory_Params.ProgrammingMode, PollAddress, PollValue, - Write_Memory_Params.DelayMS, Write_Memory_Params.ProgrammingCommands[2]); + Write_Memory_Params.DelayMS, + Write_Memory_Params.ProgrammingCommands[2]); /* Restore previous programming mode mask in case the current word needed to change it */ Write_Memory_Params.ProgrammingMode = PreviousProgrammingMode; @@ -293,7 +295,7 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command) /* EEPROM just increments the address each byte, flash needs to increment on each word and * also check to ensure that a LOAD EXTENDED ADDRESS command is issued each time the extended * address boundary has been crossed */ - if ((CurrentByte & 0x01) || (V2Command == CMD_PROGRAM_EEPROM_ISP)) + if (IsOddByte || (V2Command == CMD_PROGRAM_EEPROM_ISP)) { CurrentAddress++;