diff --git a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c index 4d879bd67b..41e6852ce0 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c @@ -119,14 +119,13 @@ bool TINYNVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_ /** Writes byte addressed memory to the target's memory spaces. * - * \param[in] WriteCommand Command to send to the device to write each memory byte * \param[in] WriteAddress Start address to write to within the target's address space * \param[in] WriteBuffer Buffer to source data from - * + * \param[in] WriteLength Total number of bytes to write to the device * * \return Boolean true if the command sequence complete successfully */ -bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t Byte) +bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t* WriteBuffer, uint16_t WriteLength) { /* Wait until the NVM controller is no longer busy */ if (!(TINYNVM_WaitWhileNVMControllerBusy())) @@ -139,9 +138,12 @@ bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t Byte) /* Send the address of the location to write to */ TINYNVM_SendPointerAddress(WriteAddress); - /* Write the byte of data to the target */ - XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT); - XPROGTarget_SendByte(Byte); + while (WriteLength--) + { + /* Write the byte of data to the target */ + XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI); + XPROGTarget_SendByte(*(WriteBuffer++)); + } return true; } diff --git a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h index 2d98c0d488..e7d8dad2db 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h +++ b/Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.h @@ -65,7 +65,7 @@ void TINYNVM_SendPointerAddress(const uint16_t AbsoluteAddress); bool TINYNVM_WaitWhileNVMBusBusy(void); bool TINYNVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadLength); - bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t Byte); + bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t* WriteBuffer, uint16_t WriteLength); bool TINYNVM_EraseMemory(void); #endif diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c index 39f82a0df7..5275cca8d7 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c @@ -134,6 +134,7 @@ static void XPROGProtocol_EnterXPROGMode(void) } else { + #if 0 /* Enable TPI programming mode with the attached target */ XPROGTarget_EnableTargetTPI(); @@ -144,6 +145,8 @@ static void XPROGProtocol_EnterXPROGMode(void) /* Wait until the NVM bus becomes active */ NVMBusEnabled = TINYNVM_WaitWhileNVMBusBusy(); + #endif + NVMBusEnabled = true; } Endpoint_Write_Byte(CMD_XPROG); @@ -313,9 +316,14 @@ static void XPROGProtocol_WriteMemory(void) } else { + Serial_TxByte((uint8_t)WriteMemory_XPROG_Params.Length); + /* Send write command to the TPI device, indicate timeout if occurred */ - if (!(TINYNVM_WriteMemory(WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData[0]))) - ReturnStatus = XPRG_ERR_TIMEOUT; + if (!(TINYNVM_WriteMemory(WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData, + WriteMemory_XPROG_Params.Length))) + { + ReturnStatus = XPRG_ERR_TIMEOUT; + } } Endpoint_Write_Byte(CMD_XPROG); @@ -355,6 +363,8 @@ static void XPROGProtocol_ReadMemory(void) } else { + Serial_TxByte((uint8_t)ReadMemory_XPROG_Params.Length); + /* Read the TPI target's memory, indicate timeout if occurred */ if (!(TINYNVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length))) ReturnStatus = XPRG_ERR_TIMEOUT; diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h index a95e5b8512..4bb600910f 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.h @@ -42,6 +42,7 @@ #include #include + #include #include "../V2Protocol.h" #include "XPROGTarget.h"