{\r
/* Enable PDI programming mode with the attached target */\r
XPROGTarget_EnableTargetPDI();\r
- \r
+\r
/* Store the RESET key into the RESET PDI register to keep the XMEGA in reset */\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(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
/* 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(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
if (XPROG_SelectedProtocol == XPRG_PROTOCOL_PDI)\r
{\r
+ XMEGANVM_WaitWhileNVMBusBusy();\r
+\r
/* Clear the RESET key in the RESET PDI register to allow the XMEGA to run */\r
XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); \r
XPROGTarget_SendByte(0x00);\r
+ \r
+ /* Clear /RESET key twice (for some reason this needs to be done twice to take effect) */\r
+ XPROGTarget_SendByte(PDI_CMD_STCS | PDI_RESET_REG); \r
+ XPROGTarget_SendByte(0x00);\r
\r
XPROGTarget_DisableTargetPDI();\r
}\r
else\r
{\r
+ TINYNVM_WaitWhileNVMBusBusy();\r
+\r
/* Clear the NVMEN bit in the TPI CONTROL register to disable TPI mode */\r
XPROGTarget_SendByte(TPI_CMD_SSTCS | TPI_CTRL_REG); \r
XPROGTarget_SendByte(0x00);\r