Fix TPI mode chip erase code not properly erasing the target memory space.
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 2 Feb 2010 04:33:58 +0000 (04:33 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 2 Feb 2010 04:33:58 +0000 (04:33 +0000)
Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h
Projects/AVRISP-MKII/Lib/XPROG/XMEGANVM.c
Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c

index e3e43dd..ca5def2 100644 (file)
@@ -189,17 +189,24 @@ bool TINYNVM_WriteMemory(const uint16_t WriteAddress, uint8_t* WriteBuffer, uint
 \r
 /** Erases the target's memory space.\r
  *\r
+ *  \param[in] Address  Address inside the memory space to erase\r
+ *\r
  *  \return Boolean true if the command sequence complete successfully\r
  */\r
-bool TINYNVM_EraseMemory(void)\r
+bool TINYNVM_EraseMemory(const uint8_t EraseCommand, const uint16_t Address)\r
 {\r
        /* Wait until the NVM controller is no longer busy */\r
        if (!(TINYNVM_WaitWhileNVMControllerBusy()))\r
          return false;\r
 \r
-       /* Set the NVM control register to the CHIP ERASE command to erase the target */\r
+       /* Set the NVM control register to the target memory erase command */\r
        TINYNVM_SendWriteNVMRegister(XPROG_Param_NVMCMDRegAddr);\r
-       XPROGTarget_SendByte(TINY_NVM_CMD_CHIPERASE);   \r
+       XPROGTarget_SendByte(EraseCommand);\r
+\r
+       /* Write to a location within the target address space to start the erase process */\r
+       TINYNVM_SendPointerAddress(Address);\r
+       XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT);\r
+       XPROGTarget_SendByte(0x00);\r
 \r
        /* Wait until the NVM bus is ready again */\r
        if (!(TINYNVM_WaitWhileNVMBusBusy()))\r
index c314ded..f8aa140 100644 (file)
@@ -65,7 +65,7 @@
                bool TINYNVM_WaitWhileNVMBusBusy(void);\r
                bool TINYNVM_ReadMemory(const uint16_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadLength);\r
                bool TINYNVM_WriteMemory(const uint16_t WriteAddress, uint8_t* WriteBuffer, uint16_t WriteLength);\r
-               bool TINYNVM_EraseMemory(void);\r
+               bool TINYNVM_EraseMemory(const uint8_t EraseCommand, const uint16_t Address);\r
 \r
                #if defined(INCLUDE_FROM_TINYNVM_C)\r
                        static void TINYNVM_SendReadNVMRegister(const uint8_t Address);\r
index defd7ff..38ccd11 100644 (file)
@@ -322,7 +322,7 @@ bool XMEGANVM_EraseMemory(const uint8_t EraseCommand, const uint32_t Address)
        {\r
                /* Other erase modes just need us to address a byte within the target memory space */\r
                XPROGTarget_SendByte(PDI_CMD_STS | (PDI_DATSIZE_4BYTES << 2));\r
-               XMEGANVM_SendAddress(Address);  \r
+               XMEGANVM_SendAddress(Address);\r
                XPROGTarget_SendByte(0x00);\r
        }\r
        \r
index 0057a67..e7b57da 100644 (file)
@@ -237,7 +237,7 @@ static void XPROGProtocol_Erase(void)
        else\r
        {\r
                /* Erase the target memory, indicate timeout if ocurred */\r
-               if (!(TINYNVM_EraseMemory()))\r
+               if (!(TINYNVM_EraseMemory(TINY_NVM_CMD_CHIPERASE, Erase_XPROG_Params.Address)))\r
                  ReturnStatus = XPRG_ERR_TIMEOUT;\r
        }\r
        \r