Commit 4600fd0c authored by Dean Camera's avatar Dean Camera
Browse files

Fix TPI NVM Write handler -- AVRStudio sends out writes in page sized chunks,...

Fix TPI NVM Write handler -- AVRStudio sends out writes in page sized chunks, not byte sized chunks.
parent 7c8f4a71
......@@ -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;
}
......
......@@ -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
......@@ -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;
......
......@@ -42,6 +42,7 @@
#include <stdio.h>
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Peripheral/SerialStream.h>
#include "../V2Protocol.h"
#include "XPROGTarget.h"
......
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