CVS: jtag/msp430 JTAGfunc.c, 1.11, 1.12 JTAGfunc.h, 1.3, 1.4 MSP430mspgcc.c, 1.21, 1.22 clock.c, 1.1, 1.2 funclets.c, 1.22, 1.23

Chris Liechti <[email protected]> Wed, 15 Nov 2006 04:35:57 -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-serv1496/jtag/msp430

Modified Files:
	JTAGfunc.c JTAGfunc.h MSP430mspgcc.c clock.c funclets.c 
Log Message:
- basic MSP430X architecture support
- code cleanups
- changed clock adjustment strategy for FLL+

Index: JTAGfunc.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/JTAGfunc.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -w -d -r1.11 -r1.12
--- JTAGfunc.c	9 Sep 2006 23:48:14 -0000	1.11
+++ JTAGfunc.c	15 Nov 2006 12:35:53 -0000	1.12
@@ -90,7 +90,7 @@
    Result:    WORD (STATUS_OK if JTAG ID is valid, STATUS_ERROR otherwise)
 */
 WORD ExecutePUC(void) {
-    WORD JTAGVERSION;
+    WORD jtagversion;
 
     HIL_JTAG_IR(IR_CNTRL_SIG_16BIT);
     HIL_JTAG_DR(0x2C01, F_WORD);                        // Apply Reset
@@ -98,13 +98,13 @@
     HIL_TCLK(POS_EDGE);
     HIL_TCLK(POS_EDGE);
     ClrTCLK();
-    JTAGVERSION = HIL_JTAG_IR(IR_ADDR_CAPTURE);
+    jtagversion = HIL_JTAG_IR(IR_ADDR_CAPTURE);
     SetTCLK();
     
     WriteMem(F_WORD, 0x0120, 0x5A80);                   // Disable Watchdog on target device  
     
-    if (JTAGVERSION != JTAG_ID) {
-        MSP430_Log(1, "JTAGfunc: JTAG ID wrong.\n");    // DEBUG
+    if (jtagversion != JTAG_ID) {
+        MSP430_Log(1, "JTAGfunc: JTAG ID wrong (0x%02x, expected 0x%02x).\n", jtagversion, JTAG_ID);    // DEBUG
         return(STATUS_ERROR);
     }
     
@@ -121,6 +121,7 @@
 WORD GetDevice(void) {
     WORD i;
     WORD ctrl;
+    WORD jtagversion;
     
     DEVICE = 0;                                         // Preset DEVICE with "not a device"
     ResetTAP();                                         // Reset JTAG state machine, check fuse HW
@@ -131,8 +132,9 @@
 
     HIL_JTAG_IR(IR_CNTRL_SIG_16BIT);
     HIL_JTAG_DR(0x2401, F_WORD);                        // Set device into JTAG mode + read
-    if (HIL_JTAG_IR(IR_CNTRL_SIG_CAPTURE) != JTAG_ID) {
-        MSP430_Log(1, "JTAGfunc: JTAG ID wrong\n");     // DEBUG
+    jtagversion = HIL_JTAG_IR(IR_CNTRL_SIG_CAPTURE);
+    if (jtagversion != JTAG_ID) {
+        MSP430_Log(1, "JTAGfunc: JTAG ID wrong (0x%02x, expected 0x%02x).\n", jtagversion, JTAG_ID);    // DEBUG
         return STATUS_ERROR;
     }
     
@@ -145,6 +147,9 @@
                                                         // (bytes are interchanged)
             DEVICE = (DEVICE << 8) + (DEVICE >> 8);     // Set global DEVICE type 
             MSP430_Log(1, "JTAGfunc: Sync OK, device: 0x%04x\n", DEVICE);   //DEBUG
+            if (IS_MSP430X) {
+                MSP430_Log(3, "JTAGfunc: MSP430X arch detected\n");   //DEBUG
+            }
             break;
         } else if (i == 1) {
             MSP430_Log(1, "JTAGfunc: Sync failed\n");   // DEBUG
@@ -177,10 +182,10 @@
     
     // Wait until CPU is in instr. fetch state, timeout after limited attempts
     for (i = 50; i > 0; i--) {
-        HIL_TCLK(POS_EDGE);
         if ((HIL_JTAG_DR(0x0000, F_WORD) & 0x0080) == 0x0080) {
             return STATUS_OK;
         }
+        HIL_TCLK(POS_EDGE);
     }
     return STATUS_ERROR; 
 }
@@ -197,6 +202,15 @@
     HIL_JTAG_IR(IR_CNTRL_SIG_16BIT);
     HIL_JTAG_DR(0x3401, F_WORD);                // CPU has control of RW & BYTE.
     HIL_JTAG_IR(IR_DATA_16BIT);
+    if (IS_MSP430X) {
+        HIL_JTAG_DR((WORD)(0x0080 | (((Addr)>>8) & 0x0F00)), F_WORD); // "mova #addr20,PC" instruction
+        HIL_TCLK(POS_EDGE);
+        HIL_JTAG_DR(Addr, F_WORD);              // Send addr value
+        HIL_TCLK(POS_EDGE);
+        HIL_TCLK(0);
+        // XXX fails for MSP430x arch
+        //~ if (Addr != HIL_JTAG_DR(0, F_20)) return STATUS_ERROR; // ERROR: SetPC failed!
+    } else {
     HIL_TCLK(1);                                // F2xx
     HIL_JTAG_DR(MOV_IMM_PC, F_WORD);            // "mov #addr,PC" instruction
     HIL_TCLK(POS_EDGE);
@@ -205,6 +219,7 @@
     HIL_TCLK(0);                                // F2xx
     HIL_JTAG_IR(IR_ADDR_CAPTURE);
     if (Addr != HIL_JTAG_DR(0, F_WORD)) return STATUS_ERROR; // ERROR: SetPC failed!
+    }
     HIL_JTAG_IR(IR_CNTRL_SIG_16BIT);
     HIL_JTAG_DR(0x2401, F_WORD);                // JTAG has control of RW & BYTE.
     return STATUS_OK;
@@ -419,7 +434,11 @@
         HIL_JTAG_DR(0x2418, F_WORD);            // Set byte write
     }
     HIL_JTAG_IR(IR_ADDR_16BIT);
+    if (IS_MSP430X) {
+        HIL_JTAG_DR(Addr, F_20);                // Set addr
+    } else {
     HIL_JTAG_DR(Addr, F_WORD);                  // Set addr
+    }
     HIL_JTAG_IR(IR_DATA_TO_ADDR);
     HIL_JTAG_DR(Data, F_WORD);                  // Shift in 16 bits
     SetTCLK();
@@ -472,7 +491,8 @@
         HIL_JTAG_DR(0x2419, F_WORD);            // Set byte read
     }
     HIL_JTAG_IR(IR_ADDR_16BIT);
-    HIL_JTAG_DR(Addr, F_WORD);                  // Set address
+    //~ HIL_JTAG_DR(Addr, F_WORD);                  // Set address
+    HIL_JTAG_DR(Addr, F_20);                  // Set address
     HIL_JTAG_IR(IR_DATA_TO_ADDR);
     SetTCLK();
     

Index: JTAGfunc.h
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/JTAGfunc.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -d -r1.3 -r1.4
--- JTAGfunc.h	21 Dec 2005 23:08:15 -0000	1.3
+++ JTAGfunc.h	15 Nov 2006 12:35:54 -0000	1.4
@@ -80,6 +80,7 @@
 // Constants for data formats, dedicated addresses
 #define F_BYTE                  8
 #define F_WORD                  16
+#define F_20                    20
 #define V_RESET                 0xFFFE
 
 //~ #define SLOWFUSECHECK_BUG
@@ -96,6 +97,12 @@
 
 extern WORD DEVICE;        // Global target device ID (e.g. 0xF149); is set 
 
+// check for X architecture
+#define IS_MSP430X ((DEVICE & 0xffff) == 0xf46f)
+#define IS_F1xx    (DEVICE & 0xff00) == 0xf100
+#define IS_F2xx    (DEVICE & 0xff00) == 0xf200
+#define IS_F4xx    (DEVICE & 0xff00) == 0xf400
+
 /****************************************************************************/
 /* Function prototypes                                                      */
 /****************************************************************************/

Index: MSP430mspgcc.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/MSP430mspgcc.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -w -d -r1.21 -r1.22
--- MSP430mspgcc.c	9 Sep 2006 23:48:14 -0000	1.21
+++ MSP430mspgcc.c	15 Nov 2006 12:35:54 -0000	1.22
@@ -54,13 +54,19 @@
 */
 static void MSP430_AdjustDCO() {
     if (!frequencySet) {
-        if (((DEVICE & 0xff00) == 0xf100) || ((DEVICE & 0xff00) == 0xf200)) { // is it a F1xx or F2xx series device?
-            setDCO();
+        if (IS_F1xx || IS_F2xx) { // is it a F1xx or F2xx series device?
+            if (setDCO() == STATUS_OK) {
             frequencySet = TRUE;
-        } else if ((DEVICE & 0xff00) == 0xf400) { //F4xx series
-            setDCOPlus();
+            } else {
+                MSP430_Log(0, "MSP430mspgcc: failed to set DCO frequency. Flash programming may be unreliable!\n");
+            }
+        } else if (IS_F4xx) { //F4xx series
+            if (setDCOPlus() == STATUS_OK) {
             frequencySet = TRUE;
         } else {
+                MSP430_Log(0, "MSP430mspgcc: failed to set DCO frequency. Flash programming may be unreliable!\n");
+            }
+        } else {
             MSP430_Log(0, "MSP430mspgcc: unknown device, cannot set DCO frequency. Flash programming may be unreliable!\n");
         }
     }

Index: clock.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/clock.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- clock.c	27 Dec 2005 13:48:50 -0000	1.1
+++ clock.c	15 Nov 2006 12:35:54 -0000	1.2
@@ -55,31 +55,39 @@
 
     MSP430_Log(1, "setDCOPlus: adjusting %lu < MCLK < %lu\n", MCLK_ABS_MIN, MCLK_ABS_MAX);
     
-    // Binary search through the available frequencies, selecting the highest
+    // Scan through the available frequencies, selecting the lowest
     // frequency whithin the acceptable range
-    while (first + 1 < last) {
-        mid = (last + first) / 2;
-        // Select DCO range from 0.23MHz to 11.2MHz. Specify frequency via Ndco.
-        // Disable Modulation. Enable DCO+.
+    for (mid = first; mid<last; mid++) {
         if (STATUS_OK != getDCOPlusFreq(0x00, (WORD) (mid << 3), 0x80, 0x80, 0, &frequency)) {
             return STATUS_ERROR;
         }
-        if (frequency > MCLK_MAX) {
-            MSP430_Log(3, "setDCOPlus: %luHz is too high, decreasing\n", frequency);
-            last = mid;
-            reload = TRUE;
-        } else {
-            MSP430_Log(3, "setDCOPlus: %luHz is too low, increasing\n", frequency);
-            first = mid;
-            reload = FALSE;
-        }
+        if (frequency > MCLK_ABS_MIN && frequency < MCLK_ABS_MAX) break;
     }
+    //~ // Binary search through the available frequencies, selecting the highest
+    //~ // frequency whithin the acceptable range
+    //~ while (first + 1 < last) {
+        //~ mid = (last + first) / 2;
+        //~ // Select DCO range from 0.23MHz to 11.2MHz. Specify frequency via Ndco.
+        //~ // Disable Modulation. Enable DCO+.
+        //~ if (STATUS_OK != getDCOPlusFreq(0x00, (WORD) (mid << 3), 0x80, 0x80, 0, &frequency)) {
+            //~ return STATUS_ERROR;
+        //~ }
+        //~ if (frequency > MCLK_MAX) {
+            //~ MSP430_Log(3, "setDCOPlus: %luHz is too high, decreasing\n", frequency);
+            //~ last = mid;
+            //~ reload = TRUE;
+        //~ } else {
+            //~ MSP430_Log(3, "setDCOPlus: %luHz is too low, increasing\n", frequency);
+            //~ first = mid;
+            //~ reload = FALSE;
+        //~ }
+    //~ }
 
-    if (reload) {
-        if (STATUS_OK != getDCOPlusFreq(0x00, (WORD) (first << 3), 0x80, 0x80, 0, &frequency)) {
-            return STATUS_ERROR;
-        }
-    }
+    //~ if (reload) {
+        //~ if (STATUS_OK != getDCOPlusFreq(0x00, (WORD) (first << 3), 0x80, 0x80, 0, &frequency)) {
+            //~ return STATUS_ERROR;
+        //~ }
+    //~ }
     MSP430_Log(3, "setDCOPlus: MCLK set to %luHz\n", frequency);
     // Ensure that frequency is within absolute min and max.
     if (frequency < MCLK_ABS_MIN || frequency > MCLK_ABS_MAX) {

Index: funclets.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/funclets.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -w -d -r1.22 -r1.23
--- funclets.c	9 Sep 2006 23:48:14 -0000	1.22
+++ funclets.c	15 Nov 2006 12:35:54 -0000	1.23
@@ -234,7 +234,7 @@
  */
 WORD readMab(void) {
     HIL_JTAG_IR(IR_ADDR_CAPTURE);
-    return (WORD)HIL_JTAG_DR(0, 16);
+    return (WORD)HIL_JTAG_DR(0, F_WORD);  //XXX number of bits!
 }
 
 /**
@@ -316,7 +316,7 @@
  */
 static STATUS_T setPCsafe(WORD addr) {
     HIL_JTAG_IR(IR_DATA_16BIT);
-    HIL_JTAG_DR(MOV_IMM_PC, F_WORD);            // Force PC into non-RAM area.
+    HIL_JTAG_DR(MOV_IMM_PC, F_WORD);            // "mov #addr,PC" instruction
     HIL_TCLK(NEG_EDGE);
     HIL_JTAG_DR(addr, F_WORD);
     HIL_TCLK(NEG_EDGE);
@@ -345,9 +345,11 @@
     int i;
 
     if (sizeCode == 0) {
+        MSP430_Log(1, "funclets: executeCodeSafe: code size\n"); //DEBUG
         return STATUS_OK;
     }
     if (code[0] & 1) {                          // Address must be even.
+        MSP430_Log(1, "funclets: executeCodeSafe: Address must be even\n"); //DEBUG
         return STATUS_ERROR;
     }
     if (SetInstrFetch() != STATUS_OK) {         // Must start on an instruction load boundary.
@@ -376,6 +378,7 @@
         MSP430_Log(5, "funclets: executeCodeSafe: verify...\n"); //DEBUG
         if (setPCsafe(code[0] - 2) != STATUS_OK) {
             free(Read);                         // Free read buffer
+            MSP430_Log(1, "funclets: executeCodeSafe: verify setPCsafe failed\n"); //DEBUG
             return STATUS_ERROR;
         }
         HIL_JTAG_IR(IR_DATA_16BIT);
@@ -419,6 +422,7 @@
 
     MSP430_Log(5, "funclets: executeCodeSafe: set PC\n");        // DEBUG
     if (setPCsafe(code[1]) != STATUS_OK) {      // Load the Program Counter.
+        MSP430_Log(1, "funclets: executeCodeSafe: setPCsafe failed\n"); //DEBUG
         return STATUS_ERROR;
     }
 
@@ -472,9 +476,11 @@
     int i;
 
     if (sizeCode == 0) {
+        MSP430_Log(1, "funclets: executeCode: code size\n"); //DEBUG
         return STATUS_OK;
     }
     if (code[0] & 1) {                          // Address must be even.
+        MSP430_Log(1, "funclets: executeCode: Address must be even\n"); //DEBUG
         return STATUS_ERROR;
     }
     if (SetInstrFetch() != STATUS_OK) {         // Must start on an instruction load boundary.
@@ -504,6 +510,7 @@
         MSP430_Log(5, "funclets: executeCode: verify...\n"); // DEBUG
         if (SetPC(code[0] - 2) != STATUS_OK) {
             free(Read);                         // Free read buffer
+            MSP430_Log(1, "funclets: executeCode: verify setPC failed\n"); //DEBUG
             return STATUS_ERROR;
         }
         HIL_JTAG_IR(IR_DATA_16BIT);
@@ -536,6 +543,7 @@
     // this block is needed if device has JTAG bug, but it shouldn't hurt anyway
     MSP430_Log(5, "funclets: executeCode: park PC...\n");    // DEBUG
     if (SetPC(ROM_ADDR) != STATUS_OK) {
+        MSP430_Log(1, "funclets: executeCode: setPC failed\n"); //DEBUG
         return STATUS_ERROR;
     }
     
@@ -614,7 +622,7 @@
  */
 STATUS_T executeCode(const WORD* code, WORD sizeCode, BOOL verify, ULONG wait, ULONG *runtime) {
     STATUS_T status = STATUS_ERROR;
-    if ((DEVICE & 0xff00) == 0xf200) {           //is it a F2xx series device?
+    if (IS_F2xx || IS_MSP430X) {           //is it a F2xx series device?
         // yes F2xx: use new variant
         status = executeCodeUnsafe(code, sizeCode, verify, wait, runtime);
     } else {


-------------------------------------------------------------------------
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