Commit 5687ac73 authored by Dean Camera's avatar Dean Camera
Browse files

Fix TPI mode chip erase code not properly erasing the target memory space.

parent 8d494808
......@@ -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()))
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment