\r
static void V2Protocol_Command_LoadAddress(void)\r
{\r
- Endpoint_Read_Stream_LE(&CurrentAddress, sizeof(CurrentAddress));\r
+ Endpoint_Read_Stream_BE(&CurrentAddress, sizeof(CurrentAddress));\r
\r
Endpoint_ClearOUT();\r
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
\r
if (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_WRITES_MASK)\r
{\r
+ uint16_t StartAddress = (CurrentAddress & 0xFFFF);\r
+ \r
/* Paged mode memory programming */\r
for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)\r
{\r
bool IsOddByte = (CurrentByte & 0x01);\r
uint8_t ByteToWrite = Endpoint_Read_Byte();\r
\r
- if ((V2Command == CMD_READ_FLASH_ISP) && IsOddByte)\r
- Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_ODD_BYTE_MASK;\r
+ if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
+ Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_HIGH_BYTE_MASK;\r
\r
SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
SPI_SendByte(CurrentAddress >> 8);\r
\r
if (!(PollAddress) && (ByteToWrite != PollValue))\r
{\r
- if (V2Command == CMD_PROGRAM_FLASH_ISP)\r
- PollAddress = (((CurrentAddress & 0xFFFF) << 1) | IsOddByte);\r
- else\r
- PollAddress = (CurrentAddress & 0xFFFF); \r
+ if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
+ Write_Memory_Params.ProgrammingCommands[2] |= READ_WRITE_HIGH_BYTE_MASK;\r
+ \r
+ PollAddress = (CurrentAddress & 0xFFFF); \r
}\r
+ \r
+ /* Check if the endpoint bank is currently empty */\r
+ if (!(Endpoint_IsReadWriteAllowed()))\r
+ {\r
+ Endpoint_ClearOUT();\r
+ Endpoint_WaitUntilReady();\r
+ } \r
\r
if (IsOddByte || (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
CurrentAddress++;\r
if (Write_Memory_Params.ProgrammingMode & PROG_MODE_COMMIT_PAGE_MASK)\r
{\r
SPI_SendByte(Write_Memory_Params.ProgrammingCommands[1]);\r
- SPI_SendByte(CurrentAddress >> 8);\r
- SPI_SendByte(CurrentAddress & 0xFF);\r
+ SPI_SendByte(StartAddress >> 8);\r
+ SPI_SendByte(StartAddress & 0xFF);\r
SPI_SendByte(0x00);\r
\r
/* Check if polling is possible, if not switch to timed delay mode */\r
Write_Memory_Params.ProgrammingMode &= ~PROG_MODE_PAGED_VALUE_MASK;\r
Write_Memory_Params.ProgrammingMode &= ~PROG_MODE_PAGED_TIMEDELAY_MASK; \r
}\r
+\r
+ ProgrammingStatus = V2Protocol_WaitForProgComplete(Write_Memory_Params.ProgrammingMode, PollAddress, PollValue,\r
+ Write_Memory_Params.DelayMS, Write_Memory_Params.ProgrammingCommands[2]);\r
}\r
- \r
- ProgrammingStatus = V2Protocol_WaitForProgComplete(Write_Memory_Params.ProgrammingMode, PollAddress, PollValue,\r
- Write_Memory_Params.DelayMS, (V2Command == CMD_READ_FLASH_ISP),\r
- Write_Memory_Params.ProgrammingCommands[2]);\r
}\r
else\r
{\r
bool IsOddByte = (CurrentByte & 0x01);\r
uint8_t ByteToWrite = Endpoint_Read_Byte();\r
\r
- if ((V2Command == CMD_READ_FLASH_ISP) && IsOddByte)\r
- Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_ODD_BYTE_MASK;\r
+ if (IsOddByte && (V2Command == CMD_READ_FLASH_ISP))\r
+ Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_HIGH_BYTE_MASK;\r
\r
SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
SPI_SendByte(CurrentAddress >> 8);\r
\r
if (ByteToWrite != PollValue)\r
{\r
- if (V2Command == CMD_PROGRAM_FLASH_ISP)\r
- PollAddress = (((CurrentAddress & 0xFFFF) << 1) | IsOddByte);\r
- else\r
- PollAddress = (CurrentAddress & 0xFFFF);\r
+ if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
+ Write_Memory_Params.ProgrammingCommands[2] |= READ_WRITE_HIGH_BYTE_MASK;\r
+ \r
+ PollAddress = (CurrentAddress & 0xFFFF);\r
}\r
\r
+ /* Check if the endpoint bank is currently empty */\r
+ if (!(Endpoint_IsReadWriteAllowed()))\r
+ {\r
+ Endpoint_ClearOUT();\r
+ Endpoint_WaitUntilReady();\r
+ } \r
+\r
if (IsOddByte || (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
CurrentAddress++;\r
\r
ProgrammingStatus = V2Protocol_WaitForProgComplete(Write_Memory_Params.ProgrammingMode, PollAddress, PollValue,\r
- Write_Memory_Params.DelayMS, (V2Command == CMD_READ_FLASH_ISP),\r
- Write_Memory_Params.ProgrammingCommands[2]);\r
+ Write_Memory_Params.DelayMS, Write_Memory_Params.ProgrammingCommands[2]);\r
\r
if (ProgrammingStatus != STATUS_CMD_OK)\r
break;\r
for (uint16_t CurrentByte = 0; CurrentByte < Read_Memory_Params.BytesToRead; CurrentByte++)\r
{\r
if ((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01))\r
- Read_Memory_Params.ReadMemoryCommand ^= READ_WRITE_ODD_BYTE_MASK;\r
+ Read_Memory_Params.ReadMemoryCommand ^= READ_WRITE_HIGH_BYTE_MASK;\r
\r
SPI_SendByte(Read_Memory_Params.ReadMemoryCommand);\r
SPI_SendByte(CurrentAddress >> 8);\r