Fix to V2 Protocol for Fuse/Sig/Lock byte read -- off by one error on the array when...
authorDean Camera <dean@fourwalledcubicle.com>
Mon, 24 Aug 2009 09:37:54 +0000 (09:37 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Mon, 24 Aug 2009 09:37:54 +0000 (09:37 +0000)
FLASH/EEPROM reading and writing currently broken and unfinished, respectively.

Projects/Incomplete/AVRISP/AVRISP.c
Projects/Incomplete/AVRISP/AVRISP.h
Projects/Incomplete/AVRISP/AVRISP.txt
Projects/Incomplete/AVRISP/Lib/V2Protocol.c
Projects/Incomplete/AVRISP/Lib/V2Protocol.h
Projects/Incomplete/AVRISP/Lib/V2ProtocolParams.c
Projects/Incomplete/AVRISP/Lib/V2ProtocolTarget.c
Projects/Incomplete/AVRISP/makefile

index 7564f7c..f3634fd 100644 (file)
  *  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
@@ -44,8 +48,6 @@ int main(void)
        SetupHardware();\r
 \r
        V2Params_LoadEEPROMParamValues();\r
-\r
-       printf("AVRISP-MKII Clone\r\n");\r
        \r
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 \r
@@ -68,7 +70,6 @@ void SetupHardware(void)
        clock_prescale_set(clock_div_1);\r
 \r
        /* Hardware Initialization */\r
-       SerialStream_Init(9600, false);\r
        LEDs_Init();\r
        USB_Init();\r
 }\r
index 8a082f6..daae7f8 100644 (file)
@@ -46,7 +46,6 @@
 \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>
 
index 6ab346c..e26cfb1 100644 (file)
  *  \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
index 85e3a38..cffb91e 100644 (file)
@@ -264,9 +264,36 @@ static void V2Protocol_Command_ProgramMemory(uint8_t V2Command)
        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
@@ -294,7 +321,7 @@ static void V2Protocol_Command_ReadMemory(uint8_t V2Command)
        \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
@@ -312,7 +339,8 @@ static void V2Protocol_Command_ReadMemory(uint8_t V2Command)
                        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
@@ -377,7 +405,7 @@ static void V2Protocol_Command_ReadFuseLockSigOSCCAL(uint8_t V2Command)
                \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
index 30d4043..39406e4 100644 (file)
                #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
index 9e64672..74c8f20 100644 (file)
@@ -37,7 +37,7 @@
 #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
@@ -67,11 +67,11 @@ static ParameterItem_t ParameterTable[] =
                  .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
@@ -133,5 +133,5 @@ void V2Params_SetParameterValue(uint8_t ParamID, uint8_t Value)
 \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
index 15ac3e5..caa7010 100644 (file)
@@ -71,7 +71,7 @@ void V2Protocol_ChangeTargetResetLine(bool ResetTarget)
        }\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
@@ -89,13 +89,13 @@ uint8_t V2Protocol_WaitWhileTargetBusy(void)
        \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
index c4e13ac..72b1fd7 100644 (file)
@@ -138,7 +138,6 @@ SRC = $(TARGET).c                                                 \
       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