Make TPI programming protocol program in words, not bytes to satisfy the datasheet...
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 2 Feb 2010 03:22:45 +0000 (03:22 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 2 Feb 2010 03:22:45 +0000 (03:22 +0000)
Projects/AVRISP-MKII/AVRISP.txt
Projects/AVRISP-MKII/Lib/XPROG/TINYNVM.c
Projects/Webserver/Lib/HTTPServerApp.c

index b05bb4d..7688f7e 100644 (file)
  *\r
  *  <b><sup>1</sup></b> <i>Optional, see \ref SSec_Options section - for USB AVRs with ADC modules only</i> \n\r
  *  <b><sup>2</sup></b> <i>When XPROG_VIA_HARDWARE_USART is set, the AVR's Tx and Rx become the DATA line when connected together\r
  *\r
  *  <b><sup>1</sup></b> <i>Optional, see \ref SSec_Options section - for USB AVRs with ADC modules only</i> \n\r
  *  <b><sup>2</sup></b> <i>When XPROG_VIA_HARDWARE_USART is set, the AVR's Tx and Rx become the DATA line when connected together\r
- *                         via a pair of 300 ohm resistors, and the AVR's XCK pin becomes CLOCK.</i> \n\r
+ *                         via a pair of 220 ohm resistors, and the AVR's XCK pin becomes CLOCK.</i> \n\r
  *  <b><sup>3</sup></b> <i>See AUX line related tokens in the \ref SSec_Options section</i>\r
  *\r
  *  \section Sec_TPI TPI Connections\r
  *  <b><sup>3</sup></b> <i>See AUX line related tokens in the \ref SSec_Options section</i>\r
  *\r
  *  \section Sec_TPI TPI Connections\r
  *\r
  *  <b><sup>1</sup></b> <i>Optional, see \ref SSec_Options section - for USB AVRs with ADC modules only</i> \n\r
  *  <b><sup>2</sup></b> <i>When XPROG_VIA_HARDWARE_USART is set, the AVR's Tx and Rx become the DATA line when connected together\r
  *\r
  *  <b><sup>1</sup></b> <i>Optional, see \ref SSec_Options section - for USB AVRs with ADC modules only</i> \n\r
  *  <b><sup>2</sup></b> <i>When XPROG_VIA_HARDWARE_USART is set, the AVR's Tx and Rx become the DATA line when connected together\r
- *                         via a pair of 300 ohm resistors, and the AVR's XCK pin becomes CLOCK.</i> \n\r
+ *                         via a pair of 220 ohm resistors, and the AVR's XCK pin becomes CLOCK.</i> \n\r
  *  <b><sup>3</sup></b> <i>See AUX line related tokens in the \ref SSec_Options section</i>\r
  *\r
  *  \section SSec_Options Project Options\r
  *  <b><sup>3</sup></b> <i>See AUX line related tokens in the \ref SSec_Options section</i>\r
  *\r
  *  \section SSec_Options Project Options\r
index 4ed3da7..39cdf2e 100644 (file)
@@ -141,11 +141,11 @@ bool TINYNVM_ReadMemory(const uint16_t ReadAddress, uint8_t* ReadBuffer, uint16_
        return true;\r
 }\r
 \r
        return true;\r
 }\r
 \r
-/** Writes byte addressed memory to the target's memory spaces.\r
+/** Writes word addressed memory to the target's memory spaces.\r
  *\r
  *  \param[in]  WriteAddress  Start address to write to within the target's address space\r
  *  \param[in]  WriteBuffer   Buffer to source data from\r
  *\r
  *  \param[in]  WriteAddress  Start address to write to within the target's address space\r
  *  \param[in]  WriteBuffer   Buffer to source data from\r
- *  \param[in]  WriteLength   Total number of bytes to write to the device\r
+ *  \param[in]  WriteLength   Total number of bytes to write to the device (must be an integer multiple of 2)\r
  *\r
  *  \return Boolean true if the command sequence complete successfully\r
  */\r
  *\r
  *  \return Boolean true if the command sequence complete successfully\r
  */\r
@@ -154,6 +154,10 @@ bool TINYNVM_WriteMemory(const uint16_t WriteAddress, const uint8_t* WriteBuffer
        /* Wait until the NVM controller is no longer busy */\r
        if (!(TINYNVM_WaitWhileNVMControllerBusy()))\r
          return false;\r
        /* Wait until the NVM controller is no longer busy */\r
        if (!(TINYNVM_WaitWhileNVMControllerBusy()))\r
          return false;\r
+         \r
+       /* Must have an integer number of words to write - if extra bytes, abort programming */\r
+       if (WriteLength & 0x01)\r
+         return false;\r
 \r
        /* Set the NVM control register to the WORD WRITE command for memory reading */\r
        TINYNVM_SendWriteNVMRegister(XPROG_Param_NVMCMDRegAddr);\r
 \r
        /* Set the NVM control register to the WORD WRITE command for memory reading */\r
        TINYNVM_SendWriteNVMRegister(XPROG_Param_NVMCMDRegAddr);\r
@@ -162,11 +166,22 @@ bool TINYNVM_WriteMemory(const uint16_t WriteAddress, const uint8_t* WriteBuffer
        /* Send the address of the location to write to */\r
        TINYNVM_SendPointerAddress(WriteAddress);\r
        \r
        /* Send the address of the location to write to */\r
        TINYNVM_SendPointerAddress(WriteAddress);\r
        \r
-       while (WriteLength--)\r
+       while (WriteLength)\r
        {\r
        {\r
-               /* Write the byte of data to the target */\r
+               /* Wait until the NVM controller is no longer busy */\r
+               if (!(TINYNVM_WaitWhileNVMControllerBusy()))\r
+                 return false;\r
+\r
+               /* Write the low byte of data to the target */\r
                XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI);\r
                XPROGTarget_SendByte(*(WriteBuffer++));\r
                XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI);\r
                XPROGTarget_SendByte(*(WriteBuffer++));\r
+               \r
+               /* Write the high byte of data to the target */\r
+               XPROGTarget_SendByte(TPI_CMD_SST | TPI_POINTER_INDIRECT_PI);\r
+               XPROGTarget_SendByte(*(WriteBuffer++));\r
+\r
+               /* Need to decrement the write length twice, since we read out a whole word */\r
+               WriteLength -= 2;\r
        }\r
        \r
        return true;\r
        }\r
        \r
        return true;\r
index e31bdbb..ed0be7b 100644 (file)
@@ -67,9 +67,9 @@ MIME_Type_t PROGMEM MIMETypes[] =
                {.Extension = "gif", .MIMEType = "image/gif"},\r
                {.Extension = "bmp", .MIMEType = "image/bmp"},\r
                {.Extension = "png", .MIMEType = "image/png"},\r
                {.Extension = "gif", .MIMEType = "image/gif"},\r
                {.Extension = "bmp", .MIMEType = "image/bmp"},\r
                {.Extension = "png", .MIMEType = "image/png"},\r
+               {.Extension = "ico", .MIMEType = "image/x-icon"},\r
                {.Extension = "exe", .MIMEType = "application/octet-stream"},\r
                {.Extension = "gz",  .MIMEType = "application/x-gzip"},\r
                {.Extension = "exe", .MIMEType = "application/octet-stream"},\r
                {.Extension = "gz",  .MIMEType = "application/x-gzip"},\r
-               {.Extension = "ico", .MIMEType = "image/x-icon"},\r
                {.Extension = "zip", .MIMEType = "application/zip"},\r
                {.Extension = "pdf", .MIMEType = "application/pdf"},\r
        };\r
                {.Extension = "zip", .MIMEType = "application/zip"},\r
                {.Extension = "pdf", .MIMEType = "application/pdf"},\r
        };\r
@@ -125,7 +125,7 @@ void WebserverApp_Callback(void)
                AppState->CurrentState = AppState->NextState;\r
        }\r
 \r
                AppState->CurrentState = AppState->NextState;\r
        }\r
 \r
-       if (uip_rexmit() || uip_newdata() || uip_acked() || uip_connected() || uip_poll())\r
+       if (uip_rexmit() || uip_acked() || uip_newdata() || uip_connected() || uip_poll())\r
        {\r
                switch (AppState->CurrentState)\r
                {\r
        {\r
                switch (AppState->CurrentState)\r
                {\r