Fixed AVRISP programmer demo -- can now connect to a target and read/write Sig/Lock/Fuse/OSCCAL bytes successfully.
Changed SPI_Init() to allow for the clock polarity and data sample modes to be set. Changed Dataflash_Init() to no longer call SPI_Init() automatically.
This commit is contained in:
parent
1e8df8951a
commit
f229502d9a
9 changed files with 58 additions and 63 deletions
|
@ -150,10 +150,8 @@ void V2Protocol_ProcessCommand(void)
|
|||
break;
|
||||
}
|
||||
|
||||
printf("COMMAND 0x%02x\r\n", V2Command);
|
||||
|
||||
Endpoint_WaitUntilReady();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT);
|
||||
Endpoint_WaitUntilReady();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT);
|
||||
}
|
||||
|
||||
static void V2Protocol_Command_Unknown(uint8_t V2Command)
|
||||
|
@ -167,7 +165,6 @@ static void V2Protocol_Command_Unknown(uint8_t V2Command)
|
|||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
Endpoint_Write_Byte(V2Command);
|
||||
Endpoint_Write_Byte(STATUS_CMD_UNKNOWN);
|
||||
|
@ -178,7 +175,6 @@ static void V2Protocol_Command_SignOn(void)
|
|||
{
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
Endpoint_Write_Byte(CMD_SIGN_ON);
|
||||
Endpoint_Write_Byte(STATUS_CMD_OK);
|
||||
|
@ -189,31 +185,28 @@ static void V2Protocol_Command_SignOn(void)
|
|||
|
||||
static void V2Protocol_Command_GetSetParam(uint8_t V2Command)
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t ParamID;
|
||||
uint8_t ParamValue;
|
||||
} Get_Set_Param_Params;
|
||||
uint8_t ParamID = Endpoint_Read_Byte();
|
||||
uint8_t ParamValue;
|
||||
|
||||
Endpoint_Read_Stream_LE(&Get_Set_Param_Params, sizeof(Get_Set_Param_Params));
|
||||
if (V2Command == CMD_SET_PARAMETER)
|
||||
ParamValue = Endpoint_Read_Byte();
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
uint8_t ParamPrivs = V2Params_GetParameterPrivellages(Get_Set_Param_Params.ParamID);
|
||||
|
||||
Endpoint_Write_Byte(V2Command);
|
||||
|
||||
uint8_t ParamPrivs = V2Params_GetParameterPrivellages(ParamID);
|
||||
|
||||
if ((V2Command == CMD_SET_PARAMETER) && (ParamPrivs & PARAM_PRIV_WRITE))
|
||||
{
|
||||
Endpoint_Write_Byte(STATUS_CMD_OK);
|
||||
V2Params_SetParameterValue(Get_Set_Param_Params.ParamID, Get_Set_Param_Params.ParamValue);
|
||||
V2Params_SetParameterValue(ParamID, ParamValue);
|
||||
}
|
||||
else if ((V2Command == CMD_GET_PARAMETER) && (ParamPrivs & PARAM_PRIV_READ))
|
||||
{
|
||||
Endpoint_Write_Byte(STATUS_CMD_OK);
|
||||
Endpoint_Write_Byte(V2Params_GetParameterValue(Get_Set_Param_Params.ParamID));
|
||||
Endpoint_Write_Byte(V2Params_GetParameterValue(ParamID));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -229,7 +222,6 @@ static void V2Protocol_Command_LoadAddress(void)
|
|||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
// TODO: Check for extended address
|
||||
|
||||
|
@ -256,40 +248,28 @@ static void V2Protocol_Command_EnterISPMode(void)
|
|||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
uint8_t SCKDuration = V2Params_GetParameterValue(PARAM_SCK_DURATION);
|
||||
uint8_t ResponseStatus = STATUS_CMD_FAILED;
|
||||
|
||||
Enter_ISP_Params.TimeoutMS -= Enter_ISP_Params.ExecutionDelayMS +
|
||||
Enter_ISP_Params.PinStabDelayMS;
|
||||
|
||||
CurrentAddress = 0;
|
||||
|
||||
if (SCKDuration >= sizeof(SPIMaskFromSCKDuration))
|
||||
SCKDuration = (sizeof(SPIMaskFromSCKDuration) - 1);
|
||||
|
||||
V2Protocol_DelayMS(Enter_ISP_Params.ExecutionDelayMS);
|
||||
SPI_Init(SPIMaskFromSCKDuration[SCKDuration], true);
|
||||
SPI_Init(V2Protocol_GetSPIPrescalerMask() | SPI_SCK_LEAD_RISING | SPI_SAMPLE_LEADING | SPI_MODE_MASTER);
|
||||
V2Protocol_ChangeTargetResetLine(true);
|
||||
V2Protocol_DelayMS(Enter_ISP_Params.PinStabDelayMS);
|
||||
|
||||
while (Enter_ISP_Params.SynchLoops-- && (ResponseStatus == STATUS_CMD_FAILED))
|
||||
{
|
||||
uint8_t ResponseBytes[4];
|
||||
|
||||
|
||||
for (uint8_t RByte = 0; RByte < sizeof(ResponseBytes); RByte++)
|
||||
{
|
||||
ResponseBytes[RByte] = SPI_TransferByte(Enter_ISP_Params.EnterProgBytes[RByte]);
|
||||
V2Protocol_DelayMS(Enter_ISP_Params.ByteDelay);
|
||||
|
||||
if (Enter_ISP_Params.TimeoutMS >= Enter_ISP_Params.ByteDelay)
|
||||
Enter_ISP_Params.TimeoutMS -= Enter_ISP_Params.ByteDelay;
|
||||
else
|
||||
ResponseStatus = STATUS_CMD_TOUT;
|
||||
ResponseBytes[RByte] = SPI_TransferByte(Enter_ISP_Params.EnterProgBytes[RByte]);
|
||||
}
|
||||
|
||||
if (ResponseBytes[Enter_ISP_Params.PollIndex] == Enter_ISP_Params.PollValue)
|
||||
/* Check if polling disabled, or if the polled value matches the expected value */
|
||||
if (!Enter_ISP_Params.PollIndex || (ResponseBytes[Enter_ISP_Params.PollIndex - 1] == Enter_ISP_Params.PollValue))
|
||||
ResponseStatus = STATUS_CMD_OK;
|
||||
}
|
||||
|
||||
|
@ -310,7 +290,6 @@ static void V2Protocol_Command_LeaveISPMode(void)
|
|||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
V2Protocol_DelayMS(Leave_ISP_Params.PreDelayMS);
|
||||
V2Protocol_ChangeTargetResetLine(false);
|
||||
|
@ -335,7 +314,6 @@ static void V2Protocol_Command_ChipErase(void)
|
|||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
uint8_t ResponseStatus = STATUS_CMD_OK;
|
||||
|
||||
|
@ -364,7 +342,6 @@ static void V2Protocol_Command_ReadFuseLockSigOSCCAL(uint8_t V2Command)
|
|||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
uint8_t ResponseBytes[4];
|
||||
|
||||
|
@ -389,7 +366,6 @@ static void V2Protocol_Command_WriteFuseLock(uint8_t V2Command)
|
|||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
for (uint8_t SByte = 0; SByte < sizeof(Write_FuseLockSig_Params.WriteCommandBytes); SByte++)
|
||||
SPI_SendByte(Write_FuseLockSig_Params.WriteCommandBytes[SByte]);
|
||||
|
@ -416,7 +392,6 @@ static void V2Protocol_Command_SPIMulti(void)
|
|||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
Endpoint_Write_Byte(CMD_SPI_MULTI);
|
||||
Endpoint_Write_Byte(STATUS_CMD_OK);
|
||||
|
|
|
@ -51,7 +51,7 @@ static ParameterItem_t ParameterTable[] =
|
|||
.ParamPrivellages = PARAM_PRIV_READ },
|
||||
|
||||
{ .ParamID = PARAM_HW_VER,
|
||||
.ParamValue = 0x01,
|
||||
.ParamValue = 0x00,
|
||||
.ParamPrivellages = PARAM_PRIV_READ },
|
||||
|
||||
{ .ParamID = PARAM_SW_MAJOR,
|
||||
|
@ -59,7 +59,7 @@ static ParameterItem_t ParameterTable[] =
|
|||
.ParamPrivellages = PARAM_PRIV_READ },
|
||||
|
||||
{ .ParamID = PARAM_SW_MINOR,
|
||||
.ParamValue = 0x00,
|
||||
.ParamValue = 0x0C,
|
||||
.ParamPrivellages = PARAM_PRIV_READ },
|
||||
|
||||
{ .ParamID = PARAM_VTARGET,
|
||||
|
@ -67,7 +67,7 @@ static ParameterItem_t ParameterTable[] =
|
|||
.ParamPrivellages = PARAM_PRIV_READ },
|
||||
|
||||
{ .ParamID = PARAM_SCK_DURATION,
|
||||
.ParamValue = 0,
|
||||
.ParamValue = 0xFF,
|
||||
.ParamPrivellages = PARAM_PRIV_READ | PARAM_PRIV_WRITE },
|
||||
|
||||
{ .ParamID = PARAM_RESET_POLARITY,
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
|
||||
|
||||
# MCU name
|
||||
MCU = at90usb1287
|
||||
MCU = at90usb647
|
||||
|
||||
|
||||
# Target board (see library "Board Types" documentation, USER or blank for projects not requiring
|
||||
|
@ -194,9 +194,9 @@ CSTANDARD = -std=gnu99
|
|||
|
||||
# Place -D or -U options here for C sources
|
||||
CDEFS = -DF_CPU=$(F_CPU)UL -DF_CLOCK=$(F_CLOCK)UL -DBOARD=BOARD_$(BOARD) $(LUFA_OPTS)
|
||||
CDEFS += -DRESET_LINE_PORT=PORTA
|
||||
CDEFS += -DRESET_LINE_DDR=DDRA
|
||||
CDEFS += -DRESET_LINE_MASK="(1 << 0)"
|
||||
CDEFS += -DRESET_LINE_PORT=PORTB
|
||||
CDEFS += -DRESET_LINE_DDR=DDRB
|
||||
CDEFS += -DRESET_LINE_MASK="(1 << 4)"
|
||||
|
||||
|
||||
# Place -D or -U options here for ASM sources
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue