Fix to V2 Protocol for Fuse/Sig/Lock byte read -- off by one error on the array when writing back the response from the device.
FLASH/EEPROM reading and writing currently broken and unfinished, respectively.
This commit is contained in:
parent
dbb5f249bd
commit
bff4dbe189
8 changed files with 57 additions and 21 deletions
|
|
@ -264,9 +264,36 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
|
|||
Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params));
|
||||
Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);
|
||||
|
||||
for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)
|
||||
if (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_WRITES_MASK)
|
||||
{
|
||||
// TODO - Read in programming data, write to device
|
||||
for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)
|
||||
{
|
||||
if ((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01))
|
||||
Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_ODD_BYTE_MASK;
|
||||
|
||||
SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);
|
||||
SPI_SendByte(CurrentAddress >> 8);
|
||||
SPI_SendByte(CurrentAddress & 0xFF);
|
||||
SPI_SendByte(Endpoint_Read_Byte());
|
||||
|
||||
// TODO - Correct Polling
|
||||
|
||||
if (((V2Command == CMD_PROGRAM_FLASH_ISP) && (CurrentByte & 0x01)) || (V2Command == CMD_PROGRAM_EEPROM_ISP))
|
||||
CurrentAddress++;
|
||||
}
|
||||
|
||||
/* If the current page must be committed, send the PROGRAM PAGE command to the target */
|
||||
if (Write_Memory_Params.ProgrammingMode & PROG_MODE_COMMIT_PAGE_MASK)
|
||||
{
|
||||
SPI_SendByte(Write_Memory_Params.ProgrammingCommands[1]);
|
||||
SPI_SendByte(CurrentAddress >> 8);
|
||||
SPI_SendByte(CurrentAddress & 0xFF);
|
||||
SPI_SendByte(0x00);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO - Read in programming data, write to device
|
||||
}
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
|
|
@ -294,7 +321,7 @@ static void V2Protocol_Command_ReadMemory(uint8_t V2Command)
|
|||
|
||||
Endpoint_Write_Byte(V2Command);
|
||||
Endpoint_Write_Byte(STATUS_CMD_OK);
|
||||
|
||||
|
||||
for (uint16_t CurrentByte = 0; CurrentByte < Read_Memory_Params.BytesToRead; CurrentByte++)
|
||||
{
|
||||
if ((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01))
|
||||
|
|
@ -312,7 +339,8 @@ static void V2Protocol_Command_ReadMemory(uint8_t V2Command)
|
|||
Endpoint_WaitUntilReady();
|
||||
}
|
||||
|
||||
CurrentAddress++;
|
||||
if (((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01)) || (V2Command == CMD_READ_EEPROM_ISP))
|
||||
CurrentAddress++;
|
||||
}
|
||||
|
||||
Endpoint_Write_Byte(STATUS_CMD_OK);
|
||||
|
|
@ -377,7 +405,7 @@ static void V2Protocol_Command_ReadFuseLockSigOSCCAL(uint8_t V2Command)
|
|||
|
||||
Endpoint_Write_Byte(V2Command);
|
||||
Endpoint_Write_Byte(STATUS_CMD_OK);
|
||||
Endpoint_Write_Byte(ResponseBytes[Read_FuseLockSigOSCCAL_Params.RetByte]);
|
||||
Endpoint_Write_Byte(ResponseBytes[Read_FuseLockSigOSCCAL_Params.RetByte - 1]);
|
||||
Endpoint_Write_Byte(STATUS_CMD_OK);
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,10 +45,11 @@
|
|||
#include "V2ProtocolTarget.h"
|
||||
|
||||
/* Macros: */
|
||||
#define PROGRAMMER_ID "AVRISP_MK2"
|
||||
#define PROGRAMMER_ID "AVRISP_MK2"
|
||||
|
||||
#define READ_WRITE_ODD_BYTE_MASK (1 << 3)
|
||||
#define TARGET_MODE_PAGE_MASK (1 << 0)
|
||||
#define READ_WRITE_ODD_BYTE_MASK (1 << 3)
|
||||
#define PROG_MODE_PAGED_WRITES_MASK (1 << 0)
|
||||
#define PROG_MODE_COMMIT_PAGE_MASK (1 << 7)
|
||||
|
||||
/* Function Prototypes: */
|
||||
void V2Protocol_ProcessCommand(void);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
#include "V2ProtocolParams.h"
|
||||
|
||||
/* Non-Volatile Parameter Values for EEPROM storage */
|
||||
uint8_t EEMEM EEPROM_Rest_Polarity;
|
||||
uint8_t EEMEM EEPROM_Rest_Polarity = 0x00;
|
||||
|
||||
/* Volatile Parameter Values for RAM storage */
|
||||
static ParameterItem_t ParameterTable[] =
|
||||
|
|
@ -67,11 +67,11 @@ static ParameterItem_t ParameterTable[] =
|
|||
.ParamPrivellages = PARAM_PRIV_READ },
|
||||
|
||||
{ .ParamID = PARAM_SCK_DURATION,
|
||||
.ParamValue = 0xFF,
|
||||
.ParamValue = 0x06,
|
||||
.ParamPrivellages = PARAM_PRIV_READ | PARAM_PRIV_WRITE },
|
||||
|
||||
{ .ParamID = PARAM_RESET_POLARITY,
|
||||
.ParamValue = 0x01,
|
||||
.ParamValue = 0x00,
|
||||
.ParamPrivellages = PARAM_PRIV_WRITE },
|
||||
|
||||
{ .ParamID = PARAM_STATUS_TGT_CONN,
|
||||
|
|
@ -133,5 +133,5 @@ void V2Params_SetParameterValue(uint8_t ParamID, uint8_t Value)
|
|||
|
||||
/* The target RESET line polarity is a non-volatile parameter, save to EEPROM when changed */
|
||||
if (ParamID == PARAM_RESET_POLARITY)
|
||||
eeprom_write_byte(&EEPROM_Rest_Polarity, Value);
|
||||
eeprom_write_byte(&EEPROM_Rest_Polarity, Value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ void V2Protocol_ChangeTargetResetLine(bool ResetTarget)
|
|||
}
|
||||
else
|
||||
{
|
||||
RESET_LINE_PORT &= ~RESET_LINE_MASK;
|
||||
RESET_LINE_PORT &= ~RESET_LINE_MASK;
|
||||
RESET_LINE_DDR &= ~RESET_LINE_MASK;
|
||||
}
|
||||
}
|
||||
|
|
@ -89,13 +89,13 @@ uint8_t V2Protocol_WaitWhileTargetBusy(void)
|
|||
|
||||
do
|
||||
{
|
||||
V2Protocol_DelayMS(1);
|
||||
|
||||
SPI_SendByte(0xF0);
|
||||
SPI_SendByte(0x00);
|
||||
|
||||
SPI_SendByte(0x00);
|
||||
ResponseByte = SPI_ReceiveByte();
|
||||
|
||||
V2Protocol_DelayMS(1);
|
||||
}
|
||||
while ((ResponseByte & 0x01) && (TimeoutMS--));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue