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_ ...@@ -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. /** 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] WriteAddress Start address to write to within the target's address space
* \param[in] WriteBuffer Buffer to source data from * \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 * \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 */ /* Wait until the NVM controller is no longer busy */
if (!(TINYNVM_WaitWhileNVMControllerBusy())) if (!(TINYNVM_WaitWhileNVMControllerBusy()))
...@@ -139,9 +138,12 @@ bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t Byte) ...@@ -139,9 +138,12 @@ bool TINYNVM_WriteMemory(const uint32_t WriteAddress, const uint8_t Byte)
/* Send the address of the location to write to */ /* Send the address of the location to write to */
TINYNVM_SendPointerAddress(WriteAddress); TINYNVM_SendPointerAddress(WriteAddress);
/* Write the byte of data to the target */ while (WriteLength--)
XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT); {
XPROGTarget_SendByte(Byte); /* Write the byte of data to the target */
XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI);
XPROGTarget_SendByte(*(WriteBuffer++));
}
return true; return true;
} }
......
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
void TINYNVM_SendPointerAddress(const uint16_t AbsoluteAddress); void TINYNVM_SendPointerAddress(const uint16_t AbsoluteAddress);
bool TINYNVM_WaitWhileNVMBusBusy(void); bool TINYNVM_WaitWhileNVMBusBusy(void);
bool TINYNVM_ReadMemory(const uint32_t ReadAddress, uint8_t* ReadBuffer, uint16_t ReadLength); 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); bool TINYNVM_EraseMemory(void);
#endif #endif
...@@ -134,6 +134,7 @@ static void XPROGProtocol_EnterXPROGMode(void) ...@@ -134,6 +134,7 @@ static void XPROGProtocol_EnterXPROGMode(void)
} }
else else
{ {
#if 0
/* Enable TPI programming mode with the attached target */ /* Enable TPI programming mode with the attached target */
XPROGTarget_EnableTargetTPI(); XPROGTarget_EnableTargetTPI();
...@@ -144,6 +145,8 @@ static void XPROGProtocol_EnterXPROGMode(void) ...@@ -144,6 +145,8 @@ static void XPROGProtocol_EnterXPROGMode(void)
/* Wait until the NVM bus becomes active */ /* Wait until the NVM bus becomes active */
NVMBusEnabled = TINYNVM_WaitWhileNVMBusBusy(); NVMBusEnabled = TINYNVM_WaitWhileNVMBusBusy();
#endif
NVMBusEnabled = true;
} }
Endpoint_Write_Byte(CMD_XPROG); Endpoint_Write_Byte(CMD_XPROG);
...@@ -313,9 +316,14 @@ static void XPROGProtocol_WriteMemory(void) ...@@ -313,9 +316,14 @@ static void XPROGProtocol_WriteMemory(void)
} }
else else
{ {
Serial_TxByte((uint8_t)WriteMemory_XPROG_Params.Length);
/* Send write command to the TPI device, indicate timeout if occurred */ /* Send write command to the TPI device, indicate timeout if occurred */
if (!(TINYNVM_WriteMemory(WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData[0]))) if (!(TINYNVM_WriteMemory(WriteMemory_XPROG_Params.Address, WriteMemory_XPROG_Params.ProgData,
ReturnStatus = XPRG_ERR_TIMEOUT; WriteMemory_XPROG_Params.Length)))
{
ReturnStatus = XPRG_ERR_TIMEOUT;
}
} }
Endpoint_Write_Byte(CMD_XPROG); Endpoint_Write_Byte(CMD_XPROG);
...@@ -355,6 +363,8 @@ static void XPROGProtocol_ReadMemory(void) ...@@ -355,6 +363,8 @@ static void XPROGProtocol_ReadMemory(void)
} }
else else
{ {
Serial_TxByte((uint8_t)ReadMemory_XPROG_Params.Length);
/* Read the TPI target's memory, indicate timeout if occurred */ /* Read the TPI target's memory, indicate timeout if occurred */
if (!(TINYNVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length))) if (!(TINYNVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length)))
ReturnStatus = XPRG_ERR_TIMEOUT; ReturnStatus = XPRG_ERR_TIMEOUT;
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <stdio.h> #include <stdio.h>
#include <LUFA/Drivers/USB/USB.h> #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Peripheral/SerialStream.h>
#include "../V2Protocol.h" #include "../V2Protocol.h"
#include "XPROGTarget.h" #include "XPROGTarget.h"
......
Supports Markdown
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