FLASH/EEPROM reading and writing currently broken and unfinished, respectively.
* the project and is responsible for the initial application hardware configuration.\r
*/\r
\r
+// TODO: Add reversed target connector checks\r
+// TODO: Add in software SPI for lower programming speeds below 125KHz\r
+// TODO: Add in VTARGET detection\r
+\r
#include "AVRISP.h"\r
\r
/** Main program entry point. This routine contains the overall program flow, including initial\r
SetupHardware();\r
\r
V2Params_LoadEEPROMParamValues();\r
-\r
- printf("AVRISP-MKII Clone\r\n");\r
\r
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
\r
clock_prescale_set(clock_div_1);\r
\r
/* Hardware Initialization */\r
- SerialStream_Init(9600, false);\r
LEDs_Init();\r
USB_Init();\r
}\r
\r
#include <LUFA/Version.h>\r
#include <LUFA/Drivers/Board/LEDs.h>\r
- #include <LUFA/Drivers/Peripheral/SerialStream.h>\r
#include <LUFA/Drivers/Peripheral/SPI.h>\r
#include <LUFA/Drivers/USB/USB.h>
* \section SSec_Description Project Description: \r
*\r
* Firmware for an AVRStudio compatible AVRISP-MKII clone programmer. This project will enable the USB AVR series of\r
- * microcontrollers to act as a clone of the official Atmel AVRISP-MKII programmer, usable within AVRStudio.\r
+ * microcontrollers to act as a clone of the official Atmel AVRISP-MKII programmer, usable within AVRStudio. In its\r
+ * most basic form, it allows for the programming of 5V AVRs from within AVRStudio with no special hardware other than\r
+ * the USB AVR and the parts needed for the USB interface. If the user desires, more advanced circuits incorporating\r
+ * level conversion can be made to allow for the programming of 3.3V AVR designs.\r
*\r
* This device spoofs Atmel's official AVRISP-MKII device PID so that it remains compatible with Atmel's AVRISP-MKII\r
* drivers. When promted, direct your OS to install Atmel's AVRISP-MKII drivers provided with AVRStudio.\r
*\r
+ * Note that this design currently has several limitations:\r
+ * - Minimum target clock speed of 500KHz due to hardware SPI used\r
+ * - No VTARGET detection and notification\r
+ * - No reversed/shorted target connector detection and notification\r
+ *\r
* \section SSec_Options Project Options\r
*\r
* The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value.\r
Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params));\r
Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);\r
\r
- for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)\r
+ if (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_WRITES_MASK)\r
{\r
- // TODO - Read in programming data, write to device\r
+ for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)\r
+ {\r
+ if ((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01))\r
+ Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_ODD_BYTE_MASK;\r
+ \r
+ SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
+ SPI_SendByte(CurrentAddress >> 8);\r
+ SPI_SendByte(CurrentAddress & 0xFF);\r
+ SPI_SendByte(Endpoint_Read_Byte());\r
+ \r
+ // TODO - Correct Polling\r
+\r
+ if (((V2Command == CMD_PROGRAM_FLASH_ISP) && (CurrentByte & 0x01)) || (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
+ CurrentAddress++;\r
+ }\r
+ \r
+ /* If the current page must be committed, send the PROGRAM PAGE command to the target */\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(0x00);\r
+ }\r
+ }\r
+ else\r
+ { \r
+ // TODO - Read in programming data, write to device \r
}\r
\r
Endpoint_ClearOUT();\r
\r
Endpoint_Write_Byte(V2Command);\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
-\r
+ \r
for (uint16_t CurrentByte = 0; CurrentByte < Read_Memory_Params.BytesToRead; CurrentByte++)\r
{\r
if ((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01))\r
Endpoint_WaitUntilReady();\r
}\r
\r
- CurrentAddress++;\r
+ if (((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01)) || (V2Command == CMD_READ_EEPROM_ISP))\r
+ CurrentAddress++;\r
}\r
\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
\r
Endpoint_Write_Byte(V2Command);\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
- Endpoint_Write_Byte(ResponseBytes[Read_FuseLockSigOSCCAL_Params.RetByte]);\r
+ Endpoint_Write_Byte(ResponseBytes[Read_FuseLockSigOSCCAL_Params.RetByte - 1]);\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
Endpoint_ClearIN();\r
}\r
#include "V2ProtocolTarget.h"\r
/* Macros: */
- #define PROGRAMMER_ID "AVRISP_MK2"\r
+ #define PROGRAMMER_ID "AVRISP_MK2"\r
\r
- #define READ_WRITE_ODD_BYTE_MASK (1 << 3)\r
- #define TARGET_MODE_PAGE_MASK (1 << 0)\r
+ #define READ_WRITE_ODD_BYTE_MASK (1 << 3)\r
+ #define PROG_MODE_PAGED_WRITES_MASK (1 << 0)\r
+ #define PROG_MODE_COMMIT_PAGE_MASK (1 << 7)\r
/* Function Prototypes: */\r
void V2Protocol_ProcessCommand(void);\r
#include "V2ProtocolParams.h"\r
\r
/* Non-Volatile Parameter Values for EEPROM storage */\r
-uint8_t EEMEM EEPROM_Rest_Polarity;\r
+uint8_t EEMEM EEPROM_Rest_Polarity = 0x00;\r
\r
/* Volatile Parameter Values for RAM storage */\r
static ParameterItem_t ParameterTable[] = \r
.ParamPrivellages = PARAM_PRIV_READ },\r
\r
{ .ParamID = PARAM_SCK_DURATION,\r
- .ParamValue = 0xFF,\r
+ .ParamValue = 0x06,\r
.ParamPrivellages = PARAM_PRIV_READ | PARAM_PRIV_WRITE },\r
\r
{ .ParamID = PARAM_RESET_POLARITY,\r
- .ParamValue = 0x01,\r
+ .ParamValue = 0x00,\r
.ParamPrivellages = PARAM_PRIV_WRITE },\r
\r
{ .ParamID = PARAM_STATUS_TGT_CONN,\r
\r
/* The target RESET line polarity is a non-volatile parameter, save to EEPROM when changed */\r
if (ParamID == PARAM_RESET_POLARITY)\r
- eeprom_write_byte(&EEPROM_Rest_Polarity, Value);\r
+ eeprom_write_byte(&EEPROM_Rest_Polarity, Value); \r
}\r
}\r
else\r
{\r
- RESET_LINE_PORT &= ~RESET_LINE_MASK; \r
+ RESET_LINE_PORT &= ~RESET_LINE_MASK;\r
RESET_LINE_DDR &= ~RESET_LINE_MASK;\r
}\r
}\r
\r
do\r
{\r
- V2Protocol_DelayMS(1);\r
- \r
SPI_SendByte(0xF0);\r
SPI_SendByte(0x00);\r
\r
SPI_SendByte(0x00);\r
ResponseByte = SPI_ReceiveByte();\r
+\r
+ V2Protocol_DelayMS(1);\r
}\r
while ((ResponseByte & 0x01) && (TimeoutMS--));\r
\r
Lib/V2Protocol.c \\r
Lib/V2ProtocolParams.c \\r
Lib/V2ProtocolTarget.c \\r
- $(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c \\r
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \\r
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c \\r
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c \\r