From 5687ac7316335009160ccd7f56fce5e7746c5889 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Tue, 2 Feb 2010 04:33:58 +0000 Subject: [PATCH] Fix TPI mode chip erase code not properly erasing the target memory space. --- Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c | 13 ++++++++++--- Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h | 2 +- Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c | 2 +- Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c index e3e43dd503..ca5def27eb 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c @@ -188,18 +188,25 @@ bool TINYNVM_WriteMemory(const uint16_t WriteAddress, uint8_t* WriteBuffer, uint } /** Erases the target's memory space. + * + * \param[in] Address Address inside the memory space to erase * * \return Boolean true if the command sequence complete successfully */ -bool TINYNVM_EraseMemory(void) +bool TINYNVM_EraseMemory(const uint8_t EraseCommand, const uint16_t Address) { /* Wait until the NVM controller is no longer busy */ if (!(TINYNVM_WaitWhileNVMControllerBusy())) return false; - /* Set the NVM control register to the CHIP ERASE command to erase the target */ + /* Set the NVM control register to the target memory erase command */ TINYNVM_SendWriteNVMRegister(XPROG_Param_NVMCMDRegAddr); - XPROGTarget_SendByte(TINY_NVM_CMD_CHIPERASE); + XPROGTarget_SendByte(EraseCommand); + + /* Write to a location within the target address space to start the erase process */ + TINYNVM_SendPointerAddress(Address); + XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT); + XPROGTarget_SendByte(0x00); /* Wait until the NVM bus is ready again */ if (!(TINYNVM_WaitWhileNVMBusBusy())) diff --git a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h index c314ded46c..f8aa140684 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h +++ b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h @@ -65,7 +65,7 @@ bool TINYNVM_WaitWhileNVMBusBusy(void); bool TINYNVM_ReadMemory(const uint16_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadLength); bool TINYNVM_WriteMemory(const uint16_t WriteAddress, uint8_t* WriteBuffer, uint16_t WriteLength); - bool TINYNVM_EraseMemory(void); + bool TINYNVM_EraseMemory(const uint8_t EraseCommand, const uint16_t Address); #if defined(INCLUDE_FROM_TINYNVM_C) static void TINYNVM_SendReadNVMRegister(const uint8_t Address); diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c index defd7ffe00..38ccd11499 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c @@ -322,7 +322,7 @@ bool XMEGANVM_EraseMemory(const uint8_t EraseCommand, const uint32_t Address) { /* Other erase modes just need us to address a byte within the target memory space */ XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2)); - XMEGANVM_SendAddress(Address); + XMEGANVM_SendAddress(Address); XPROGTarget_SendByte(0x00); } diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c index 0057a675fb..e7b57da171 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c @@ -237,7 +237,7 @@ static void XPROGProtocol_Erase(void) else { /* Erase the target memory, indicate timeout if ocurred */ - if (!(TINYNVM_EraseMemory())) + if (!(TINYNVM_EraseMemory(TINY_NVM_CMD_CHIPERASE, Erase_XPROG_Params.Address))) ReturnStatus = XPRG_ERR_TIMEOUT; }