uint8_t ProgrammingCommands[3];\r
uint8_t PollValue1;\r
uint8_t PollValue2;\r
+ uint8_t ProgData[256];\r
} Write_Memory_Params;\r
\r
- Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params));\r
+ uint8_t* NextWriteByte = Write_Memory_Params.ProgData;\r
+\r
+ Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params) - sizeof(Write_Memory_Params.ProgData));\r
Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);\r
- \r
+ Endpoint_Read_Stream_LE(&Write_Memory_Params.ProgData, Write_Memory_Params.BytesToWrite);\r
+\r
+ Endpoint_ClearOUT();\r
+ Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
+\r
uint8_t ProgrammingStatus = STATUS_CMD_OK; \r
uint16_t PollAddress = 0;\r
uint8_t PollValue = (V2Command == CMD_PROGRAM_FLASH_ISP) ? Write_Memory_Params.PollValue1 :\r
Write_Memory_Params.PollValue2;\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
- /* Check if the endpoint bank is currently empty */\r
- if (!(Endpoint_IsReadWriteAllowed()))\r
- {\r
- Endpoint_ClearOUT();\r
- Endpoint_WaitUntilReady();\r
- } \r
-\r
+ {\r
bool IsOddByte = (CurrentByte & 0x01);\r
- uint8_t ByteToWrite = Endpoint_Read_Byte();\r
+ uint8_t ByteToWrite = *(NextWriteByte++);\r
\r
if (IsOddByte && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
- Write_Memory_Params.ProgrammingCommands[0] |= READ_WRITE_HIGH_BYTE_MASK;\r
+ Write_Memory_Params.ProgrammingCommands[0] |= READ_WRITE_HIGH_BYTE_MASK;\r
else\r
Write_Memory_Params.ProgrammingCommands[0] &= ~READ_WRITE_HIGH_BYTE_MASK;\r
\r
if (!(PollAddress))\r
{\r
Write_Memory_Params.ProgrammingMode &= ~PROG_MODE_PAGED_VALUE_MASK;\r
- Write_Memory_Params.ProgrammingMode &= ~PROG_MODE_PAGED_TIMEDELAY_MASK; \r
+ Write_Memory_Params.ProgrammingMode |= PROG_MODE_PAGED_TIMEDELAY_MASK; \r
}\r
\r
ProgrammingStatus = V2Protocol_WaitForProgComplete(Write_Memory_Params.ProgrammingMode, PollAddress, PollValue,\r
/* Word/byte mode memory programming */\r
for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)\r
{\r
- /* Check if the endpoint bank is currently empty */\r
- if (!(Endpoint_IsReadWriteAllowed()))\r
- {\r
- Endpoint_ClearOUT();\r
- Endpoint_WaitUntilReady();\r
- } \r
-\r
bool IsOddByte = (CurrentByte & 0x01);\r
- uint8_t ByteToWrite = Endpoint_Read_Byte();\r
+ uint8_t ByteToWrite = *(NextWriteByte++);\r
\r
if (IsOddByte && (V2Command == CMD_READ_FLASH_ISP))\r
- Write_Memory_Params.ProgrammingCommands[0] |= READ_WRITE_HIGH_BYTE_MASK;\r
+ Write_Memory_Params.ProgrammingCommands[0] |= READ_WRITE_HIGH_BYTE_MASK;\r
else\r
Write_Memory_Params.ProgrammingCommands[0] &= ~READ_WRITE_HIGH_BYTE_MASK; \r
\r
break;\r
}\r
}\r
- \r
- Endpoint_ClearOUT();\r
- Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
\r
Endpoint_Write_Byte(V2Command);\r
Endpoint_Write_Byte(ProgrammingStatus);\r
bool IsOddByte = (CurrentByte & 0x01);\r
\r
if (IsOddByte && (V2Command == CMD_READ_FLASH_ISP))\r
- Read_Memory_Params.ReadMemoryCommand |= READ_WRITE_HIGH_BYTE_MASK;\r
+ Read_Memory_Params.ReadMemoryCommand |= READ_WRITE_HIGH_BYTE_MASK;\r
else\r
Read_Memory_Params.ReadMemoryCommand &= ~READ_WRITE_HIGH_BYTE_MASK;\r
\r
uint8_t TxData[255];\r
} SPI_Multi_Params;\r
\r
- Endpoint_Read_Stream_LE(&SPI_Multi_Params, sizeof(SPI_Multi_Params) -\r
- sizeof(SPI_Multi_Params.TxData));\r
+ Endpoint_Read_Stream_LE(&SPI_Multi_Params, sizeof(SPI_Multi_Params) - sizeof(SPI_Multi_Params.TxData));\r
Endpoint_Read_Stream_LE(&SPI_Multi_Params.TxData, SPI_Multi_Params.TxBytes);\r
\r
Endpoint_ClearOUT();\r