Fixed software PDI/TPI programming mode in the AVRISP project not correctly toggling...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / XPROG / XPROGProtocol.c
index 24305dc..805eaa3 100644 (file)
@@ -124,9 +124,9 @@ static void XPROGProtocol_EnterXPROGMode(void)
                XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG);     \r
                XPROGTarget_SendByte(PDI_RESET_KEY);\r
 \r
                XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG);     \r
                XPROGTarget_SendByte(PDI_RESET_KEY);\r
 \r
-               /* Lower direction change guard time to 8 USART bits */\r
+               /* Lower direction change guard time to 0 USART bits */\r
                XPROGTarget_SendByte(PDI_CMD_STCS | PDI_CTRL_REG);      \r
                XPROGTarget_SendByte(PDI_CMD_STCS | PDI_CTRL_REG);      \r
-               XPROGTarget_SendByte(0x04);\r
+               XPROGTarget_SendByte(0x07);\r
 \r
                /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */\r
                XPROGTarget_SendByte(PDI_CMD_KEY);      \r
 \r
                /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */\r
                XPROGTarget_SendByte(PDI_CMD_KEY);      \r
@@ -141,9 +141,9 @@ static void XPROGProtocol_EnterXPROGMode(void)
                /* Enable TPI programming mode with the attached target */\r
                XPROGTarget_EnableTargetTPI();\r
                \r
                /* Enable TPI programming mode with the attached target */\r
                XPROGTarget_EnableTargetTPI();\r
                \r
-               /* Lower direction change guard time to 8 USART bits */\r
+               /* Lower direction change guard time to 0 USART bits */\r
                XPROGTarget_SendByte(TPI_CMD_SSTCS | TPI_CTRL_REG);\r
                XPROGTarget_SendByte(TPI_CMD_SSTCS | TPI_CTRL_REG);\r
-               XPROGTarget_SendByte(0x04);\r
+               XPROGTarget_SendByte(0x07);\r
                \r
                /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */\r
                XPROGTarget_SendByte(TPI_CMD_SKEY);     \r
                \r
                /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */\r
                XPROGTarget_SendByte(TPI_CMD_SKEY);     \r
@@ -208,10 +208,10 @@ static void XPROGProtocol_Erase(void)
        Endpoint_ClearOUT();\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
        \r
        Endpoint_ClearOUT();\r
        Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
        \r
+       uint8_t EraseCommand;\r
+\r
        if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI)\r
        if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI)\r
-       {\r
-               uint8_t EraseCommand = XMEGA_NVM_CMD_NOOP;\r
-       \r
+       {       \r
                /* Determine which NVM command to send to the device depending on the memory to erase */\r
                switch (Erase_XPROG_Params.MemoryType)\r
                {\r
                /* Determine which NVM command to send to the device depending on the memory to erase */\r
                switch (Erase_XPROG_Params.MemoryType)\r
                {\r
@@ -239,6 +239,9 @@ static void XPROGProtocol_Erase(void)
                        case XPRG_ERASE_USERSIG:\r
                                EraseCommand = XMEGA_NVM_CMD_ERASEUSERSIG;\r
                                break;\r
                        case XPRG_ERASE_USERSIG:\r
                                EraseCommand = XMEGA_NVM_CMD_ERASEUSERSIG;\r
                                break;\r
+                       default:\r
+                               EraseCommand = XMEGA_NVM_CMD_NOOP;\r
+                               break;\r
                }\r
                \r
                /* Erase the target memory, indicate timeout if ocurred */\r
                }\r
                \r
                /* Erase the target memory, indicate timeout if ocurred */\r
@@ -247,8 +250,13 @@ static void XPROGProtocol_Erase(void)
        }\r
        else\r
        {\r
        }\r
        else\r
        {\r
+               if (Erase_XPROG_Params.MemoryType == XPRG_ERASE_CHIP)\r
+                 EraseCommand = TINY_NVM_CMD_CHIPERASE;\r
+               else\r
+                 EraseCommand = TINY_NVM_CMD_SECTIONERASE;\r
+       \r
                /* Erase the target memory, indicate timeout if ocurred */\r
                /* Erase the target memory, indicate timeout if ocurred */\r
-               if (!(TINYNVM_EraseMemory(TINY_NVM_CMD_CHIPERASE, Erase_XPROG_Params.Address)))\r
+               if (!(TINYNVM_EraseMemory(EraseCommand, Erase_XPROG_Params.Address)))\r
                  ReturnStatus = XPRG_ERR_TIMEOUT;\r
        }\r
        \r
                  ReturnStatus = XPRG_ERR_TIMEOUT;\r
        }\r
        \r