Added .5MHz recovery clock to the AVRISP programmer project when in ISP programming...
authorDean Camera <dean@fourwalledcubicle.com>
Wed, 10 Feb 2010 04:02:10 +0000 (04:02 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Wed, 10 Feb 2010 04:02:10 +0000 (04:02 +0000)
Fixed AVRISP project not extending the command delay after each successful page/word/byte program.

LUFA/ManPages/ChangeLog.txt
Projects/AVRISP-MKII/AVRISP.txt
Projects/AVRISP-MKII/Lib/ISP/ISPProtocol.c
Projects/AVRISP-MKII/Lib/ISP/ISPTarget.c
Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c

index 1b5ede6..1041865 100644 (file)
@@ -25,6 +25,7 @@
   *    do not adversely affect the code operation (currently only the LEDs driver)\r
   *  - Added keyboard modifier masks (HID_KEYBOARD_MODIFER_*) and LED report masks (KEYBOARD_LED_*) to the HID class driver and\r
   *    Keyboard demos\r
+  *  - Added .5MHz recovery clock to the AVRISP programmer project when in ISP programming mode to correct mis-set fuses\r
   *\r
   *  <b>Changed:</b>\r
   *  - Slowed down software USART carried PDI programming in the AVRISP project to prevent transmission errors\r
@@ -58,6 +59,7 @@
   *  - Fixed SerialStream driver blocking while waiting for characters to be received instead of returning EOF\r
   *  - Fixed SerialStream driver not setting stdin to the created serial stream\r
   *  - Fixed USB_GetHIDReportSize() returning the number of bits in the specified report instead of bytes\r
+  *  - Fixed AVRISP project not extending the command delay after each successful page/word/byte program\r
   *\r
   *  \section Sec_ChangeLog091223 Version 091223\r
   *\r
index 7688f7e..cff8d7d 100644 (file)
  *   </tr>\r
  *  </table>\r
  *\r
+ *  In addition, the AVR's XCK pin will generate a .5MHz clock when SPI programming is used, to act as an external\r
+ *  device clock if the fuses have been mis-set. To use the recovery clock, connect XCK to the target AVR's XTAL1\r
+ *  pin, and set the ISP programming speed to 125KHz or below.\r
+ *\r
  *  <b><sup>1</sup></b> <i>Optional, see \ref SSec_Options section - for USB AVRs with ADC modules only</i> \n\r
  *  <b><sup>2</sup></b> <i>See AUX line related tokens in the \ref SSec_Options section</i>\r
  *\r
index 33ccbf9..e0eb441 100644 (file)
@@ -62,7 +62,14 @@ void ISPProtocol_EnterISPMode(void)
        uint8_t ResponseStatus = STATUS_CMD_FAILED;\r
        \r
        CurrentAddress = 0;\r
+       \r
+       /* Set up the synchronous USART to generate the recovery clock on XCK pin */\r
+       UBRR1  = (F_CPU / 500000UL);\r
+       UCSR1B = (1 << TXEN1);\r
+       UCSR1C = (1 << UMSEL10) | (1 << UPM11) | (1 << USBS1) | (1 << UCSZ11) | (1 << UCSZ10) | (1 << UCPOL1);\r
+       DDRD  |= (1 << 5);\r
 \r
+       /* Perform execution delay, initialize SPI bus */\r
        ISPProtocol_DelayMS(Enter_ISP_Params.ExecutionDelayMS); \r
        SPI_Init(ISPTarget_GetSPIPrescalerMask() | SPI_SCK_LEAD_RISING | SPI_SAMPLE_LEADING | SPI_MODE_MASTER);\r
 \r
@@ -118,6 +125,12 @@ void ISPProtocol_LeaveISPMode(void)
        SPI_ShutDown();\r
        ISPProtocol_DelayMS(Leave_ISP_Params.PostDelayMS);\r
 \r
+       /* Turn off the synchronous USART to terminate the recovery clock on XCK pin */\r
+       UBRR1  = (F_CPU / 500000UL);\r
+       UCSR1B = (1 << TXEN1);\r
+       UCSR1C = (1 << UMSEL10) | (1 << UPM11) | (1 << USBS1) | (1 << UCSZ11) | (1 << UCSZ10) | (1 << UCPOL1);\r
+       DDRD  &= ~(1 << 5);\r
+\r
        Endpoint_Write_Byte(CMD_LEAVE_PROGMODE_ISP);\r
        Endpoint_Write_Byte(STATUS_CMD_OK);\r
        Endpoint_ClearIN();\r
index c9822d0..267e518 100644 (file)
@@ -139,6 +139,9 @@ uint8_t ISPTarget_WaitForProgComplete(const uint8_t ProgrammingMode, const uint1
                        ProgrammingStatus = ISPTarget_WaitWhileTargetBusy();\r
                        break;\r
        }\r
+       \r
+       if (ProgrammingStatus == STATUS_CMD_OK)\r
+         TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
 \r
        return ProgrammingStatus;\r
 }\r
@@ -159,10 +162,7 @@ uint8_t ISPTarget_WaitWhileTargetBusy(void)
        }\r
        while ((SPI_ReceiveByte() & 0x01) && TimeoutMSRemaining);\r
 \r
-       if (!(TimeoutMSRemaining))\r
-         return STATUS_RDY_BSY_TOUT;\r
-       else\r
-         return STATUS_CMD_OK;\r
+       return ((TimeoutMSRemaining) ? STATUS_CMD_OK : STATUS_RDY_BSY_TOUT);\r
 }\r
 \r
 /** Sends a low-level LOAD EXTENDED ADDRESS command to the target, for addressing of memory beyond the\r
index 91ed775..0ab2975 100644 (file)
@@ -82,9 +82,12 @@ bool TINYNVM_WaitWhileNVMBusBusy(void)
                /* Send the SLDCS command to read the TPI STATUS register to see the NVM bus is active */\r
                XPROGTarget_SendByte(TPI_CMD_SLDCS | TPI_STATUS_REG);\r
                if (XPROGTarget_ReceiveByte() & TPI_STATUS_NVM)\r
-                 return true;\r
+               {\r
+                       TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+                       return true;\r
+               }\r
        }\r
-       \r
+\r
        return false;\r
 }\r
 \r
@@ -103,9 +106,12 @@ bool TINYNVM_WaitWhileNVMControllerBusy(void)
 \r
                /* Check to see if the BUSY flag is still set */\r
                if (!(XPROGTarget_ReceiveByte() & (1 << 7)))\r
-                 return true;\r
+               {\r
+                       TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+                       return true;\r
+               }\r
        }\r
-       \r
+\r
        return false;\r
 }\r
 \r
@@ -167,6 +173,10 @@ bool TINYNVM_WriteMemory(const uint16_t WriteAddress, uint8_t* WriteBuffer, uint
        \r
        while (WriteLength)\r
        {\r
+               /* Wait until the NVM controller is no longer busy */\r
+               if (!(TINYNVM_WaitWhileNVMControllerBusy()))\r
+                 return false;\r
+\r
                /* Write the low byte of data to the target */\r
                XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI);\r
                XPROGTarget_SendByte(*(WriteBuffer++));\r
@@ -175,10 +185,6 @@ bool TINYNVM_WriteMemory(const uint16_t WriteAddress, uint8_t* WriteBuffer, uint
                XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI);\r
                XPROGTarget_SendByte(*(WriteBuffer++));\r
 \r
-               /* Wait until the NVM controller is no longer busy */\r
-               if (!(TINYNVM_WaitWhileNVMControllerBusy()))\r
-                 return false;\r
-\r
                /* Need to decrement the write length twice, since we read out a whole word */\r
                WriteLength -= 2;\r
        }\r
index 38ccd11..fc98cfc 100644 (file)
@@ -77,7 +77,10 @@ bool XMEGANVM_WaitWhileNVMBusBusy(void)
                /* Send the LDCS command to read the PDI STATUS register to see the NVM bus is active */\r
                XPROGTarget_SendByte(PDI_CMD_LDCS | PDI_STATUS_REG);\r
                if (XPROGTarget_ReceiveByte() & PDI_STATUS_NVM)\r
-                 return true;\r
+               {\r
+                       TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+                       return true;\r
+               }\r
        }\r
        \r
        return false;\r
@@ -99,7 +102,10 @@ bool XMEGANVM_WaitWhileNVMControllerBusy(void)
                \r
                /* Check to see if the BUSY flag is still set */\r
                if (!(XPROGTarget_ReceiveByte() & (1 << 7)))\r
-                 return true;\r
+               {\r
+                       TimeoutMSRemaining = COMMAND_TIMEOUT_MS;\r
+                       return true;\r
+               }\r
        }\r
        \r
        return false;\r