X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/3a2c1db6751979ae3e5d7a6fa51026f9c44c71c0..39d56aeffecdd50d1e413c8da6edbe8485d5ac29:/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c?ds=inline diff --git a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c index a6a57670b..08936a202 100644 --- a/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c +++ b/Projects/AVRISP-MKII/Lib/XPROG/XPROGProtocol.c @@ -119,14 +119,14 @@ static void XPROGProtocol_EnterXPROGMode(void) { /* Enable PDI programming mode with the attached target */ XPROGTarget_EnableTargetPDI(); - + /* Store the RESET key into the RESET PDI register to keep the XMEGA in reset */ XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); XPROGTarget_SendByte(PDI_RESET_KEY); - /* Lower direction change guard time to 8 USART bits */ + /* Lower direction change guard time to 0 USART bits */ XPROGTarget_SendByte(PDI_CMD_STCS | PDI_CTRL_REG); - XPROGTarget_SendByte(0x04); + XPROGTarget_SendByte(0x07); /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */ XPROGTarget_SendByte(PDI_CMD_KEY); @@ -141,9 +141,9 @@ static void XPROGProtocol_EnterXPROGMode(void) /* Enable TPI programming mode with the attached target */ XPROGTarget_EnableTargetTPI(); - /* Lower direction change guard time to 8 USART bits */ + /* Lower direction change guard time to 0 USART bits */ XPROGTarget_SendByte(TPI_CMD_SSTCS | TPI_CTRL_REG); - XPROGTarget_SendByte(0x04); + XPROGTarget_SendByte(0x07); /* Enable access to the XPROG NVM bus by sending the documented NVM access key to the device */ XPROGTarget_SendByte(TPI_CMD_SKEY); @@ -170,14 +170,22 @@ static void XPROGProtocol_LeaveXPROGMode(void) if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI) { + XMEGANVM_WaitWhileNVMBusBusy(); + /* Clear the RESET key in the RESET PDI register to allow the XMEGA to run */ XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); XPROGTarget_SendByte(0x00); + + /* Clear /RESET key twice (for some reason this needs to be done twice to take effect) */ + XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); + XPROGTarget_SendByte(0x00); XPROGTarget_DisableTargetPDI(); } else { + TINYNVM_WaitWhileNVMBusBusy(); + /* Clear the NVMEN bit in the TPI CONTROL register to disable TPI mode */ XPROGTarget_SendByte(TPI_CMD_SSTCS | TPI_CTRL_REG); XPROGTarget_SendByte(0x00);