Fixed issues with EEPROM and FLASH ISP programming in the AVRISP project.
authorDean Camera <dean@fourwalledcubicle.com>
Mon, 1 Feb 2010 03:42:10 +0000 (03:42 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Mon, 1 Feb 2010 03:42:10 +0000 (03:42 +0000)
LUFA/ManPages/ChangeLog.txt
Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c
Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c

index b9436d6..8215bbe 100644 (file)
@@ -49,6 +49,7 @@
   *    ranges are specified (thanks to Thomas Bleeker)\r
   *  - Fixed CDC and RNDIS host demos and class drivers - bidirectional endpoints should use two seperate pipes, not one half-duplex pipe\r
   *  - Fixed Pipe_IsEndpointBound() not taking the endpoint's direction into account\r
   *    ranges are specified (thanks to Thomas Bleeker)\r
   *  - Fixed CDC and RNDIS host demos and class drivers - bidirectional endpoints should use two seperate pipes, not one half-duplex pipe\r
   *  - Fixed Pipe_IsEndpointBound() not taking the endpoint's direction into account\r
+  *  - Fixed EEPROM and FLASH ISP programming in the AVRISP project\r
   *\r
   *  \section Sec_ChangeLog091223 Version 091223\r
   *\r
   *\r
   *  \section Sec_ChangeLog091223 Version 091223\r
   *\r
index 59a77e5..33ccbf9 100644 (file)
@@ -198,14 +198,15 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command)
                        \r
                        /* AVR FLASH addressing requires us to modify the write command based on if we are writing a high\r
                         * or low byte at the current word address */\r
                        \r
                        /* AVR FLASH addressing requires us to modify the write command based on if we are writing a high\r
                         * or low byte at the current word address */\r
-                       Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_HIGH_BYTE_MASK;\r
+                       if (V2Command == CMD_PROGRAM_FLASH_ISP)\r
+                         Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_HIGH_BYTE_MASK;\r
 \r
                        /* Check to see the write completion method, to see if we have a valid polling address */\r
                        if (!(PollAddress) && (ByteToWrite != PollValue))\r
                        {\r
                                if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
                                  Write_Memory_Params.ProgrammingCommands[2] |= READ_WRITE_HIGH_BYTE_MASK;\r
 \r
                        /* Check to see the write completion method, to see if we have a valid polling address */\r
                        if (!(PollAddress) && (ByteToWrite != PollValue))\r
                        {\r
                                if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
                                  Write_Memory_Params.ProgrammingCommands[2] |= READ_WRITE_HIGH_BYTE_MASK;\r
-                                 \r
+\r
                                PollAddress = (CurrentAddress & 0xFFFF);                                \r
                        }               \r
 \r
                                PollAddress = (CurrentAddress & 0xFFFF);                                \r
                        }               \r
 \r
@@ -239,17 +240,17 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command)
                {\r
                        bool    IsOddByte   = (CurrentByte & 0x01);\r
                        uint8_t ByteToWrite = *(NextWriteByte++);\r
                {\r
                        bool    IsOddByte   = (CurrentByte & 0x01);\r
                        uint8_t ByteToWrite = *(NextWriteByte++);\r
-               \r
-                       if (IsOddByte && (V2Command == CMD_READ_FLASH_ISP))\r
-                         Write_Memory_Params.ProgrammingCommands[0] |=  READ_WRITE_HIGH_BYTE_MASK;\r
-                       else\r
-                         Write_Memory_Params.ProgrammingCommands[0] &= ~READ_WRITE_HIGH_BYTE_MASK;                     \r
                          \r
                        SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
                        SPI_SendByte(CurrentAddress >> 8);\r
                        SPI_SendByte(CurrentAddress & 0xFF);\r
                        SPI_SendByte(ByteToWrite);\r
                        \r
                          \r
                        SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
                        SPI_SendByte(CurrentAddress >> 8);\r
                        SPI_SendByte(CurrentAddress & 0xFF);\r
                        SPI_SendByte(ByteToWrite);\r
                        \r
+                       /* AVR FLASH addressing requires us to modify the write command based on if we are writing a high\r
+                        * or low byte at the current word address */\r
+                       if (V2Command == CMD_PROGRAM_FLASH_ISP)\r
+                         Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_HIGH_BYTE_MASK;\r
+\r
                        if (ByteToWrite != PollValue)\r
                        {\r
                                if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
                        if (ByteToWrite != PollValue)\r
                        {\r
                                if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
index 19b0aa0..c9822d0 100644 (file)
@@ -128,7 +128,7 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1
                                SPI_SendByte(PollAddress >> 8);\r
                                SPI_SendByte(PollAddress & 0xFF);\r
                        }\r
                                SPI_SendByte(PollAddress >> 8);\r
                                SPI_SendByte(PollAddress & 0xFF);\r
                        }\r
-                       while ((SPI_TransferByte(0x00) != PollValue) && TimeoutMSRemaining);\r
+                       while ((SPI_TransferByte(0x00) == PollValue) && TimeoutMSRemaining);\r
 \r
                        if (!(TimeoutMSRemaining))\r
                         ProgrammingStatus = STATUS_CMD_TOUT;\r
 \r
                        if (!(TimeoutMSRemaining))\r
                         ProgrammingStatus = STATUS_CMD_TOUT;\r