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