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.
pull/1469/head
Dean Camera 16 years ago
parent dbb5f249bd
commit bff4dbe189

@ -34,6 +34,10 @@
* the project and is responsible for the initial application hardware configuration. * the project and is responsible for the initial application hardware configuration.
*/ */
// TODO: Add reversed target connector checks
// TODO: Add in software SPI for lower programming speeds below 125KHz
// TODO: Add in VTARGET detection
#include "AVRISP.h" #include "AVRISP.h"
/** Main program entry point. This routine contains the overall program flow, including initial /** Main program entry point. This routine contains the overall program flow, including initial
@ -45,8 +49,6 @@ int main(void)
V2Params_LoadEEPROMParamValues(); V2Params_LoadEEPROMParamValues();
printf("AVRISP-MKII Clone\r\n");
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
for (;;) for (;;)
@ -68,7 +70,6 @@ void SetupHardware(void)
clock_prescale_set(clock_div_1); clock_prescale_set(clock_div_1);
/* Hardware Initialization */ /* Hardware Initialization */
SerialStream_Init(9600, false);
LEDs_Init(); LEDs_Init();
USB_Init(); USB_Init();
} }

@ -46,7 +46,6 @@
#include <LUFA/Version.h> #include <LUFA/Version.h>
#include <LUFA/Drivers/Board/LEDs.h> #include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Peripheral/SerialStream.h>
#include <LUFA/Drivers/Peripheral/SPI.h> #include <LUFA/Drivers/Peripheral/SPI.h>
#include <LUFA/Drivers/USB/USB.h> #include <LUFA/Drivers/USB/USB.h>

@ -50,11 +50,19 @@
* \section SSec_Description Project Description: * \section SSec_Description Project Description:
* *
* Firmware for an AVRStudio compatible AVRISP-MKII clone programmer. This project will enable the USB AVR series of * Firmware for an AVRStudio compatible AVRISP-MKII clone programmer. This project will enable the USB AVR series of
* microcontrollers to act as a clone of the official Atmel AVRISP-MKII programmer, usable within AVRStudio. * microcontrollers to act as a clone of the official Atmel AVRISP-MKII programmer, usable within AVRStudio. In its
* most basic form, it allows for the programming of 5V AVRs from within AVRStudio with no special hardware other than
* the USB AVR and the parts needed for the USB interface. If the user desires, more advanced circuits incorporating
* level conversion can be made to allow for the programming of 3.3V AVR designs.
* *
* This device spoofs Atmel's official AVRISP-MKII device PID so that it remains compatible with Atmel's AVRISP-MKII * This device spoofs Atmel's official AVRISP-MKII device PID so that it remains compatible with Atmel's AVRISP-MKII
* drivers. When promted, direct your OS to install Atmel's AVRISP-MKII drivers provided with AVRStudio. * drivers. When promted, direct your OS to install Atmel's AVRISP-MKII drivers provided with AVRStudio.
* *
* Note that this design currently has several limitations:
* - Minimum target clock speed of 500KHz due to hardware SPI used
* - No VTARGET detection and notification
* - No reversed/shorted target connector detection and notification
*
* \section SSec_Options Project Options * \section SSec_Options Project Options
* *
* The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value.

@ -264,7 +264,34 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params)); Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params));
Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite); 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)
{
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 // TODO - Read in programming data, write to device
} }
@ -312,7 +339,8 @@ static void V2Protocol_Command_ReadMemory(uint8_t V2Command)
Endpoint_WaitUntilReady(); Endpoint_WaitUntilReady();
} }
CurrentAddress++; if (((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01)) || (V2Command == CMD_READ_EEPROM_ISP))
CurrentAddress++;
} }
Endpoint_Write_Byte(STATUS_CMD_OK); 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(V2Command);
Endpoint_Write_Byte(STATUS_CMD_OK); 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_Write_Byte(STATUS_CMD_OK);
Endpoint_ClearIN(); Endpoint_ClearIN();
} }

@ -45,10 +45,11 @@
#include "V2ProtocolTarget.h" #include "V2ProtocolTarget.h"
/* Macros: */ /* Macros: */
#define PROGRAMMER_ID "AVRISP_MK2" #define PROGRAMMER_ID "AVRISP_MK2"
#define READ_WRITE_ODD_BYTE_MASK (1 << 3) #define READ_WRITE_ODD_BYTE_MASK (1 << 3)
#define TARGET_MODE_PAGE_MASK (1 << 0) #define PROG_MODE_PAGED_WRITES_MASK (1 << 0)
#define PROG_MODE_COMMIT_PAGE_MASK (1 << 7)
/* Function Prototypes: */ /* Function Prototypes: */
void V2Protocol_ProcessCommand(void); void V2Protocol_ProcessCommand(void);

@ -37,7 +37,7 @@
#include "V2ProtocolParams.h" #include "V2ProtocolParams.h"
/* Non-Volatile Parameter Values for EEPROM storage */ /* 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 */ /* Volatile Parameter Values for RAM storage */
static ParameterItem_t ParameterTable[] = static ParameterItem_t ParameterTable[] =
@ -67,11 +67,11 @@ static ParameterItem_t ParameterTable[] =
.ParamPrivellages = PARAM_PRIV_READ }, .ParamPrivellages = PARAM_PRIV_READ },
{ .ParamID = PARAM_SCK_DURATION, { .ParamID = PARAM_SCK_DURATION,
.ParamValue = 0xFF, .ParamValue = 0x06,
.ParamPrivellages = PARAM_PRIV_READ | PARAM_PRIV_WRITE }, .ParamPrivellages = PARAM_PRIV_READ | PARAM_PRIV_WRITE },
{ .ParamID = PARAM_RESET_POLARITY, { .ParamID = PARAM_RESET_POLARITY,
.ParamValue = 0x01, .ParamValue = 0x00,
.ParamPrivellages = PARAM_PRIV_WRITE }, .ParamPrivellages = PARAM_PRIV_WRITE },
{ .ParamID = PARAM_STATUS_TGT_CONN, { .ParamID = PARAM_STATUS_TGT_CONN,

@ -89,13 +89,13 @@ uint8_t V2Protocol_WaitWhileTargetBusy(void)
do do
{ {
V2Protocol_DelayMS(1);
SPI_SendByte(0xF0); SPI_SendByte(0xF0);
SPI_SendByte(0x00); SPI_SendByte(0x00);
SPI_SendByte(0x00); SPI_SendByte(0x00);
ResponseByte = SPI_ReceiveByte(); ResponseByte = SPI_ReceiveByte();
V2Protocol_DelayMS(1);
} }
while ((ResponseByte & 0x01) && (TimeoutMS--)); while ((ResponseByte & 0x01) && (TimeoutMS--));

@ -138,7 +138,6 @@ SRC = $(TARGET).c \
Lib/V2Protocol.c \ Lib/V2Protocol.c \
Lib/V2ProtocolParams.c \ Lib/V2ProtocolParams.c \
Lib/V2ProtocolTarget.c \ Lib/V2ProtocolTarget.c \
$(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \

Loading…
Cancel
Save