CVS: jtag/msp430 JTAGfunc.c,1.9,1.10 MSP430mspgcc.c,1.18,1.19 funclets.c,1.19,1.20

Chris Liechti <[email protected]> Sat, 22 Apr 2006 15:08:01 -0700
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/jtag/msp430
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2071/jtag/msp430

Modified Files:
	JTAGfunc.c MSP430mspgcc.c funclets.c 
Log Message:
- update to changed progFlash funclet
- add more debugging outputs
- fixes for flash segment erase (more than one seg at once)
- cleanups

Index: JTAGfunc.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/JTAGfunc.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -w -d -r1.9 -r1.10
--- JTAGfunc.c	13 Apr 2006 20:20:59 -0000	1.9
+++ JTAGfunc.c	22 Apr 2006 22:07:58 -0000	1.10
@@ -221,7 +221,10 @@
         return STATUS_ERROR;
     }
     
-    SetInstrFetch();                            // Set CPU into instruction fetch mode, TCLK=1
+    if (SetInstrFetch() != STATUS_OK) {         // Set CPU into instruction fetch mode, TCLK=1
+        MSP430_Log(1, "SetReg: Not in fetch\n"); // DEBUG
+        return STATUS_ERROR;                    // Synchronization failed!
+    }
     
     // Load register with value
     HIL_JTAG_IR(IR_CNTRL_SIG_16BIT);
@@ -249,7 +252,10 @@
         return STATUS_ERROR;
     }
     
-    SetInstrFetch();                            // Set CPU into instruction fetch mode, TCLK=1
+    if (SetInstrFetch() != STATUS_OK) {         // Set CPU into instruction fetch mode, TCLK=1
+        MSP430_Log(1, "GetReg: Not in fetch\n"); // DEBUG
+        return STATUS_ERROR;                    // Synchronization failed!
+    }
     
     // Load PC with address
     HIL_JTAG_IR(IR_CNTRL_SIG_16BIT);
@@ -263,7 +269,7 @@
     HIL_TCLK(POS_EDGE);                         // (writes need 2 clks)
     HIL_TCLK(0);                                // instr exec
     HIL_JTAG_IR(IR_DATA_CAPTURE);
-    *Value = HIL_JTAG_DR(0, F_WORD);            // Read databus which contains the regsiters value
+    *Value = HIL_JTAG_DR(0, F_WORD);            // Read databus which contains the registers value
     HIL_JTAG_IR(IR_CNTRL_SIG_16BIT);
     HIL_JTAG_DR(0x2401, F_WORD);                // JTAG has control of RW & BYTE.
     return STATUS_OK;
@@ -328,6 +334,12 @@
     WORD POLY = 0x0805;                         // Polynom value for PSA calculation
     WORD PSA_CRC = StartAddr-2;                 // Start value for PSA calculation
     
+    MSP430_Log(8, "VerifyPSA(0x%04x, %d, %s)\n",
+        StartAddr,
+        Length,
+        (DataArray == 0) ? "erase check" : "check against data"
+    );   // DEBUG
+    
     ExecutePUC();          
     HIL_JTAG_IR(IR_CNTRL_SIG_16BIT);
     HIL_JTAG_DR(0x2401, F_WORD);
@@ -354,7 +366,7 @@
             PSA_CRC <<= 1;
         }
         // if pointer is 0 then use erase check mask, otherwise data  
-        &DataArray[0] == 0 ? (PSA_CRC ^= 0xFFFF) : (PSA_CRC ^= DataArray[i]);
+        (DataArray == 0) ? (PSA_CRC ^= 0xFFFF) : (PSA_CRC ^= DataArray[i]);
         
         // Clock through the PSA  
         SetTCLK();
@@ -380,7 +392,13 @@
     TDOword = HIL_JTAG_DR(0x0000, F_WORD);      // Read out the PSA value
     SetTCLK();
     
-    return ((TDOword == PSA_CRC) ? STATUS_OK : STATUS_ERROR);
+    if (TDOword == PSA_CRC) {
+        MSP430_Log(6, "VerifyPSA: Success\n");   // DEBUG
+        return STATUS_OK;
+    } else {
+        MSP430_Log(1, "VerifyPSA: failed (0x%04x != 0x%04x)\n", TDOword, PSA_CRC);   // DEBUG
+        return STATUS_ERROR;
+    }
 }  
 
 //----------------------------------------------------------------------------

Index: MSP430mspgcc.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/MSP430mspgcc.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -w -d -r1.18 -r1.19
--- MSP430mspgcc.c	20 Apr 2006 22:55:18 -0000	1.18
+++ MSP430mspgcc.c	22 Apr 2006 22:07:58 -0000	1.19
@@ -377,7 +377,7 @@
 */
 STATUS_T WINAPI MSP430_Erase(LONG type, LONG address, LONG length) {
     STATUS_T result = STATUS_OK;
-    MSP430_Log(1, "MSP430mspgcc: MSP430_Erase...\n");
+    MSP430_Log(1, "MSP430mspgcc: MSP430_Erase(%d, 0x%04x, 0x%04x)...\n", type, address, length);
     
     if (((type != ERASE_SEGMENT) && (type != ERASE_MAIN) && (type != ERASE_ALL)) ||
            (address < 0) || (address + length > FLASH_END_ADDR + 1)) {
@@ -396,7 +396,9 @@
             // Erase each of the segments.
             for (segmentAddr = address; segmentAddr < (address + length); segmentAddr += segmentSize) {
                 MSP430_Log(3, "MSP430mspgcc: MSP430_Erase segment 0x%04x\n", segmentAddr);
-                if ((result = eraseFlash(ERASE_SEGMENT, (WORD) segmentAddr)) != STATUS_OK) {
+                result = eraseFlash(ERASE_SEGMENT, (WORD)segmentAddr);
+                if (result != STATUS_OK) {
+                    MSP430_Log(3, "MSP430mspgcc: MSP430_Erase segment failed at 0x%04x\n", segmentAddr);
                     break;
                 }
             
@@ -414,9 +416,12 @@
                 }
                 MSP430_Log(3, "MSP430mspgcc: MSP430_Erase advance %u bytes\n", segmentSize);
             }
-            if (result != STATUS_ERROR) {
+            if (result == STATUS_OK) {
                 //check the entire length for erasure.
                 result = VerifyPSA(address, length/2, 0);
+                if (result != STATUS_OK) {
+                    MSP430_Log(3, "MSP430mspgcc: MSP430_Erase VerifyPSA failed\n");
+                }
             }
             break; // ERASE_SEGMENT.
         }
@@ -432,7 +437,7 @@
     if (result != STATUS_OK) {
         RET_ERR(ERASE_ERR);
     }
-
+    MSP430_Log(3, "MSP430mspgcc: MSP430_Erase success\n");
     RET_OK;
 }
 
@@ -547,23 +552,36 @@
                 
                 // The flash only supports writing words on word boundaries. Force alignment
                 // if odd address and/or odd count.
-                // Even address and odd length: pad last, count + 1.
                 if (!(address & 1) && (count & 1)) {
+                    // Even address and odd length: pad last, count + 1.
+                    MSP430_Log(6, "MSP430mspgcc: MSP430_MemoryWrite Even address and odd length: %d Bytes @0x%04x\n",
+                        count, address
+                    );
                     prgBuffer = malloc(count + 1); mallocedBuffer = TRUE;
                     memcpy(prgBuffer, buffer, count);
-                    prgBuffer[count++] = (CHAR)0xff;
+                    prgBuffer[count] = (CHAR)(ReadMem(F_WORD, (WORD)(address + count - 1)) >> 8);
+                    count++;
                 } else if ((address & 1) && !(count & 1)) {
                     // Odd address and even length: pad first and last, count + 2, address--.
+                    MSP430_Log(6, "MSP430mspgcc: MSP430_MemoryWrite Odd address and even length: %d Bytes @0x%04x\n",
+                        count, address
+                    );
                     prgBuffer = malloc(count + 2); mallocedBuffer = TRUE;
-                    memcpy(prgBuffer + 1, buffer, count++);
-                    prgBuffer[0] = prgBuffer[count++ + 1] = (CHAR)0xff;
+                    memcpy(prgBuffer + 1, buffer, count);
                     address--;
+                    prgBuffer[0] = (CHAR)ReadMem(F_WORD, (WORD)(address));
+                    prgBuffer[count+1] = (CHAR)(ReadMem(F_WORD, (WORD)(address + count)) >> 8);
+                    count += 2;
                 } else if ((address & 1) && (count & 1)) {
                     // Odd address and odd length: pad first, count + 1, address--.
                     prgBuffer = malloc(count + 1); mallocedBuffer = TRUE;
-                    memcpy(prgBuffer + 1, buffer, count++);
-                    prgBuffer[0] = (CHAR)0xff;
+                    memcpy(prgBuffer + 1, buffer, count);
                     address--;
+                    prgBuffer[0] = (CHAR)ReadMem(F_WORD, (WORD)(address));
+                    count++;
+                    MSP430_Log(6, "MSP430mspgcc: MSP430_MemoryWrite Odd address and odd length: %d Bytes @0x%04x\n",
+                        count, address
+                    );
                 }
                 
                 // Program the flash (assuming that it is erased).
@@ -685,7 +703,7 @@
 */
 LONG WINAPI MSP430_Error_Number(void) {
     int tempErrorNumber = errorNumber;
-    MSP430_Log(1, "MSP430mspgcc: MSP430_Error_Number...\n");
+    MSP430_Log(1, "MSP430mspgcc: MSP430_Error_Number -> %d\n", tempErrorNumber);
     errorNumber = NO_ERR;
     return (tempErrorNumber);
 }
@@ -700,10 +718,10 @@
  The string associated with errorNumber.
 */
 const CHAR* WINAPI MSP430_Error_String(LONG errorNumber) {
-    MSP430_Log(1, "MSP430mspgcc: MSP430_Error_String...\n");
     if ((errorNumber < 0) || (errorNumber >= INVALID_ERR)) {
         errorNumber = INVALID_ERR;
     }
+    MSP430_Log(1, "MSP430mspgcc: MSP430_Error_String -> %s\n", errorStrings[errorNumber]);
     return (errorStrings[errorNumber]);
 }
 

Index: funclets.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/funclets.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -w -d -r1.19 -r1.20
--- funclets.c	21 Apr 2006 23:28:40 -0000	1.19
+++ funclets.c	22 Apr 2006 22:07:58 -0000	1.20
@@ -47,20 +47,29 @@
         for (tries=3; tries; tries--) {
             res = executeCode(code, (sizeof(funclet_progFlash) + blocksize)/sizeof(WORD), 1, 1000, NULL);
             if (res == STATUS_OK) {
-                if (STATUS_OK == GetReg(15, &funclet_result)) {
+                if (STATUS_OK == GetReg(8, &funclet_result)) {
                     if (funclet_result) {               //read return value
-                        MSP430_Log(1, "funclets: programFlash: Flash write error in block @0x%04x\n", address);
+                        GetReg(9, &address);            // get address where the write failed
+                        MSP430_Log(1, "funclets: programFlash: Flash write error around 0x%04x (0x%04x)\n", address, funclet_result);
                         res = STATUS_ERROR;
+                        ExecutePUC();
                     } else {
                         // funclet returned success
                         break;
                     }
                 } else {
                     MSP430_Log(1, "funclets: programFlash: failed to read funclet answer, retrying in block @0x%04x\n", address);
+                    HIL_DelayMSec(200);
+                    //~ ReleaseDevice(V_RESET);
+                    //~ GetDevice();
+                    ExecutePUC();
                 }
             } else {
                 MSP430_Log(1, "funclets: programFlash: Flash write retrying in block @0x%04x\n", address);
-                GetDevice();
+                HIL_DelayMSec(200);
+                //~ ReleaseDevice(V_RESET);
+                //~ GetDevice();
+                ExecutePUC();
             }
         }
         if (res != STATUS_OK) break;
@@ -342,6 +351,7 @@
         return STATUS_ERROR;
     }
     if (SetInstrFetch() != STATUS_OK) {         // Must start on an instruction load boundary.
+        MSP430_Log(1, "funclets: executeCodeSafe: SetInstrFetch() failed\n"); //DEBUG
         return STATUS_ERROR;
     }
 
@@ -412,13 +422,16 @@
         return STATUS_ERROR;
     }
 
+    if (wait) {
+        MSP430_Log(3, "funclets: executeCodeSafe: run and wait for up to %ums\n", wait); //DEBUG
+    } else {
     MSP430_Log(5, "funclets: executeCodeSafe: run...\n");        // DEBUG
+    }
     HIL_JTAG_IR(IR_CNTRL_SIG_RELEASE);          // Release the CPU (but retain JTAG control signals).
     HIL_TCLK(1);
 
     if (wait) {
         ULONG runtime_internal;
-        MSP430_Log(3, "funclets: executeCodeSafe: wait for up to %ums\n", wait); //DEBUG
         HIL_StartTimer();
         // Limit the number of cycles for the code to execute.
         while ((runtime_internal = HIL_ReadTimer()) < wait) {
@@ -465,6 +478,7 @@
         return STATUS_ERROR;
     }
     if (SetInstrFetch() != STATUS_OK) {         // Must start on an instruction load boundary.
+        MSP430_Log(1, "funclets: executeCodeSafe: SetInstrFetch() failed\n"); //DEBUG
         return STATUS_ERROR;
     }
 
@@ -538,13 +552,16 @@
         return STATUS_ERROR;
     }
 
-    MSP430_Log(5, "funclets: executeCode: run...\n");        // DEBUG
+    if (wait) {
+        MSP430_Log(3, "funclets: executeCodeSafe: run and wait for up to %ums\n", wait); //DEBUG
+    } else {
+        MSP430_Log(5, "funclets: executeCodeSafe: run...\n");        // DEBUG
+    }
     HIL_JTAG_IR(IR_CNTRL_SIG_RELEASE);          // Release the CPU (but retain JTAG control signals).
     HIL_TCLK(1);
 
     if (wait) {
         ULONG runtime_internal;
-        MSP430_Log(3, "funclets: executeCode: wait for up to %ums\n", wait); // DEBUG
         HIL_StartTimer();
         // Limit the number of cycles for the code to execute.
         while ((runtime_internal = HIL_ReadTimer()) < wait) {



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642