CVS: jtag/msp430 JTAGfunc.c, 1.12, 1.13 MSP430mspgcc.c, 1.22, 1.23 funclets.c, 1.23, 1.24

Chris Liechti <[email protected]> Wed, 15 Nov 2006 12:28:53 -0800
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/jtag/msp430
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv26811/jtag/msp430

Modified Files:
	JTAGfunc.c MSP430mspgcc.c funclets.c 
Log Message:
- F20xx support (spy-bi-wire capable devices, use 4 wire JTAG mode)
- separate segment A lock handling (F2xx) so that the flash funclet + data fits again in 128 bytes
- debug messages and internal cleanups
- more updates for MSP430X arch

Index: JTAGfunc.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/JTAGfunc.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -w -d -r1.12 -r1.13
--- JTAGfunc.c	15 Nov 2006 12:35:53 -0000	1.12
+++ JTAGfunc.c	15 Nov 2006 20:28:51 -0000	1.13
@@ -123,6 +123,22 @@
     WORD ctrl;
     WORD jtagversion;
     
+    // F2xx Spy-Bi_Wire support/workaround -> enable 4 Wire JTAG
+    HIL_RST(0);
+    HIL_TST(0);
+    HIL_DelayMSec(5);
+
+    HIL_RST(1);
+    HIL_TST(1);
+
+    HIL_RST(0);
+
+    HIL_TST(0xff00);
+    HIL_TST(0xff01);
+    HIL_RST(1);
+    HIL_DelayMSec(10);
+    // end of Spy-Bi_Wire support/workaround
+    
     DEVICE = 0;                                         // Preset DEVICE with "not a device"
     ResetTAP();                                         // Reset JTAG state machine, check fuse HW
    

Index: MSP430mspgcc.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/MSP430mspgcc.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -w -d -r1.22 -r1.23
--- MSP430mspgcc.c	15 Nov 2006 12:35:54 -0000	1.22
+++ MSP430mspgcc.c	15 Nov 2006 20:28:51 -0000	1.23
@@ -266,7 +266,7 @@
     such a way that it does not begin to execute a resident program (or garbage).
 */
 STATUS_T WINAPI MSP430_Reset(LONG method, LONG execute, LONG releaseJTAG) {
-    MSP430_Log(1, "MSP430mspgcc: MSP430_Reset...\n");
+    MSP430_Log(1, "MSP430mspgcc: MSP430_Reset(0x%x, %d, %d)...\n", method, execute, releaseJTAG);
     if (!method) {
         RET_ERR(PARAMETER_ERR);
     }
@@ -294,6 +294,7 @@
                 RET_OK;
             }
         }
+        MSP430_Log(5, "MSP430mspgcc: PUC_RESET failed\n");
         //just try next reset method if this one did not succeed
         
         //~ if (ExecutePUC() == STATUS_OK) {
@@ -314,9 +315,12 @@
     }
     if (method & RST_RESET) {                           //if first method failed, try hard reset
         // Assert (hard) ~RST/NMI.
+        HIL_TST(0);
         HIL_RST(0);
         HIL_DelayMSec(50);                              // keep it low for some time (discharge caps)
         HIL_RST(1);                                     // adds an other delay after the pin is high
+        HIL_TST(1);
+        HIL_DelayMSec(50);                              // keep it high for some time (charge caps)
         if (releaseJTAG) {
             if (HIL_Release() != STATUS_OK) {   // Release the JTAG control signals.
                 MSP430_Log(2, "MSP430mspgcc: RST_RESET but JTAG release FAILED\n");
@@ -335,11 +339,17 @@
                 RET_OK;
             }
         }
+        MSP430_Log(5, "MSP430mspgcc: RST_RESET failed\n");
     }
+    
     if (method & VCC_RESET) {                           //if a hard reset does not work, maybe switching off the power
         HIL_VCC(0);
+        HIL_TST(0);
+        HIL_RST(0);
         HIL_DelayMSec(3000); // Delay 3 seconds to give the device time to power-down,
-        HIL_VCC(DEFAULT_VCC);;
+        HIL_VCC(DEFAULT_VCC);
+        HIL_RST(1);                                     // adds an other delay after the pin is high
+        HIL_TST(1);
         HIL_DelayMSec(10); // Delay 10mSec to give the device time to power-up.
         // Connect and synchronize with the CPU. The CPU is clocked with TCLK. Read/Write will be set.
         if (GetDevice() == STATUS_OK) {

Index: funclets.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/funclets.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -w -d -r1.23 -r1.24
--- funclets.c	15 Nov 2006 12:35:54 -0000	1.23
+++ funclets.c	15 Nov 2006 20:28:51 -0000	1.24
@@ -6,9 +6,23 @@
 #include "JTAGfunc.h"
 #include "MSP430mspgcc.h"
 
-#ifndef min
-    #define min(a,b) (((a)<(b)) ? (a) : (b))
-#endif
+// ----------------------------------------------------------------------------
+#include "lockSegmentA.ci"             // include the lock switch program
+
+/**
+ * Lock or unlock the protected segment in F2xx devices.
+ *
+ * @param lock          [in] 0 unlocks, other values lock
+ * @return              STATUS_OK if the funclet was executed
+ */
+STATUS_T lockSegmentA(WORD lock) {
+    MSP430_Log(2, "funclets: SegmentA %s\n", lock ? "lock" : "unlock");
+    funclet_lockSegmentA[3] = lock;
+    if (STATUS_OK == executeCode(funclet_lockSegmentA, sizeof(funclet_lockSegmentA)/sizeof(WORD), 1, 100, NULL)) {
+        return STATUS_OK;
+    }
+    return STATUS_ERROR;
+}
 
 // ----------------------------------------------------------------------------
 #include "progFlash.ci"         // include the flash program
@@ -26,17 +40,38 @@
  */
 STATUS_T programFlash(WORD address, const CHAR* buffer, WORD count) {
     STATUS_T res = STATUS_OK;
-    WORD blocksize;
-    WORD done = 0;
-    WORD tries;
+    WORD blocksize;                                     // payload size per step
+    WORD done = 0;                                      // bytes done
+    WORD tries;                                         // retry counter
+    WORD unlocked = 0;                                  // remember if segmentA was unlocked
     WORD funclet_result;
-    WORD *code = malloc(ramsize);
+    WORD *code = malloc(ramsize); // allocate space for funclet + data
+    MSP430_Log(2, "funclets: programFlash(0x%04x, ..., %d)\n", address, count);
+    // sanity checks
     if (code == NULL)   return STATUS_ERROR;            // Out of memory
+    if (ramsize < sizeof(funclet_progFlash)) {
+        MSP430_Log(1, "funclets: ramsize (%d) too small for funclet (%d)\n", ramsize, sizeof(funclet_progFlash));
+        return STATUS_ERROR;
+    }
     
-    MSP430_Log(2, "funclets: programFlash(0x%04x, ..., %d)\n", address, count);
-    memcpy(code, funclet_progFlash, sizeof(funclet_progFlash));         // copy program to working buffer
-    while (done < count) {                                              // download in blocks
-        blocksize = min(count-done, ramsize-sizeof(funclet_progFlash)); // calculate blocksize
+    // F2xx segmentA handling
+    // simple descision: if start address is in the information memory, unlock the segment
+    // otherwise don't unlock when not needed
+    if (IS_F2xx && address < 0x1100) {
+        lockSegmentA(0);
+        unlocked = 1;
+    }
+    // copy funclet at the beginning of the buffer
+     memcpy(code, funclet_progFlash, sizeof(funclet_progFlash));
+    // download blocks
+    while (done < count) {
+        // calculate blocksize
+        blocksize = count-done;
+        if (blocksize > (ramsize - sizeof(funclet_progFlash))) {
+            blocksize = ramsize - sizeof(funclet_progFlash);
+        }
+        //~ MSP430_Log(3, "funclets: ramsize: %d blocksize %d (%d)\n", ramsize, blocksize, sizeof(funclet_progFlash));
+        // copy block
         memcpy(&code[sizeof(funclet_progFlash)/sizeof(WORD)], &buffer[done], blocksize); // copy new data to be flashed
         //fill in arguments
         code[3] = 0;//srinit;                           // TODO: need arg for DCO+?
@@ -81,6 +116,9 @@
         }
     }
     free(code);                                                         // clean up memory
+    if (IS_F2xx && unlocked) {
+        lockSegmentA(1);
+    }
     if (STATUS_OK == res) {
         MSP430_Log(2, "funclets: programFlash: Flash write finished\n");
     } else {
@@ -108,7 +146,7 @@
         case ERASE_SEGMENT:
             // fill in arguments
             funclet_eraseFlashSegment[3] = 0;//srinit;  // TODO: need arg for DCO+?
-            funclet_eraseFlashSegment[4] = 0xA502;      // set FCTL1 contents
+            funclet_eraseFlashSegment[4] = 0xA502;      // set FCTL1 contents to ERASE_SGMT
             funclet_eraseFlashSegment[5] = address;     // address within the segment to be erased
             // download erase prog and execute
             return executeCode(funclet_eraseFlashSegment, sizeof(funclet_eraseFlashSegment)/sizeof(WORD), 1, 1000, NULL);
@@ -116,7 +154,11 @@
         case ERASE_MAIN:
             // fill in arguments
             funclet_eraseFlash[3] = 0;//srinit;         // TODO: need arg for DCO+?
-            funclet_eraseFlash[4] = 0xA504;             // set FCTL1 contents
+            if (IS_MSP430X) {
+                funclet_eraseFlash[4] = 0xA50C;         // set FCTL1 contents to ERASE_ALLMAIN
+            } else {
+                funclet_eraseFlash[4] = 0xA504;         // set FCTL1 contents to ERASE_MAIN
+            }
             funclet_eraseFlash[5] = address;            // address within the segment to be erased
             // download erase prog and execute
             return executeCode(funclet_eraseFlash, sizeof(funclet_eraseFlash)/sizeof(WORD), 1, 1000, NULL);
@@ -124,7 +166,11 @@
         case ERASE_ALL:
             // fill in arguments
             funclet_eraseFlash[3] = 0;//srinit;         // TODO: need arg for DCO+?
-            funclet_eraseFlash[4] = 0xA506;             // set FCTL1 contents
+            if (IS_MSP430X) {
+                funclet_eraseFlash[4] = 0xA50E;         // set FCTL1 contents to ERASE_GLOB
+            } else {
+                funclet_eraseFlash[4] = 0xA506;         // set FCTL1 contents to ERASE_MASS
+            }
             funclet_eraseFlash[5] = address;            // address within the segment to be erased
             // download erase prog and execute
             return executeCode(funclet_eraseFlash, sizeof(funclet_eraseFlash)/sizeof(WORD), 1, 1000, NULL);


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV