JTAGARM7 is back up and running, folks! Tested Halt/Release, Get/Set Registers,...
[goodfet] / client / goodfet.msp430
index 3140e13..b606edc 100755 (executable)
@@ -7,29 +7,31 @@ from GoodFETMSP430 import GoodFETMSP430;
 from intelhex import IntelHex16bit, IntelHex;
 
 
-
 if(len(sys.argv)==1):
     print "Usage: %s verb [objects]\n" % sys.argv[0];
     print "%s test" % sys.argv[0];
+    print "%s selftest" % sys.argv[0];
     print "%s dump $foo.hex [0x$start 0x$stop]" % sys.argv[0];
     print "%s erase" % sys.argv[0];
+    print "%s eraseinfo" % sys.argv[0];
     print "%s flash $foo.hex [0x$start 0x$stop]" % sys.argv[0];
     print "%s verify $foo.hex [0x$start 0x$stop]" % sys.argv[0];
+    print "%s poke 0x$adr 0x$val" % sys.argv[0];
+    print "%s serial [$val]" % sys.argv[0];
+    print "%s peek 0x$start [0x$stop]" % sys.argv[0];
+    print "%s run" % sys.argv[0];
     sys.exit();
 
 #Initialize FET and set baud rate
 client=GoodFETMSP430();
 client.serInit()
 
-#Connect to target
-client.MSP430setup();
-#print "setup"
-
-#Identify model number.
-client.MSP430start();
-client.MSP430haltcpu();
-#print "started"
+client.setup();
+client.start();
 
+if(sys.argv[1]=="starttest"):
+    for foo in range(1,10):
+        client.start();
 if(sys.argv[1]=="info"):
     #print "Model    %08x " % client.MSP430deviceid();
     #print "Core     %04x " % client.MSP430coreid();
@@ -39,6 +41,9 @@ if(sys.argv[1]=="info"):
         client.MSP430ident());
 if(sys.argv[1]=="test"):
     client.MSP430test();
+if(sys.argv[1]=="glitch"):
+    for foo in range(0,100):
+        print "Identifies as %04x" % client.MSP430ident();
 if(sys.argv[1]=="dump"):
     f = sys.argv[2];
     start=0x0200;
@@ -53,20 +58,58 @@ if(sys.argv[1]=="dump"):
     h = IntelHex(None);
     i=start;
     while i<=stop:
-        data=client.MSP430peekblock(i,0x20);
+        data=client.MSP430peekblock(i);
         print "Dumped %06x."%i;
         for j in data:
             if i<=stop: h[i]=ord(j);
             i+=1;
     h.write_hex_file(f);
 if(sys.argv[1]=="erase"):
+    print "Erasing main flash memory."
     client.MSP430masserase();
+if(sys.argv[1]=="eraseinfo"):
+    print "Erasing info memory."
+    client.MSP430infoerase();
+
+if(sys.argv[1]=="selftest"):
+    import time;
+    
+    entry=client.peek16(0xFFC0);
+    print "Calling self-test at 0x%04x." %entry;
+    print "Memory from 0x3020 to 0x3030 should be zeroed.";
+    
+    for i in range(0x3020,0x3030):
+        client.MSP430poke(i,0xFFFF);
+    client.MSP430setPC(entry);
+    time.sleep(5);
+    errors=0;
+    
+    if(client.peek8(0x302F)==0xFF):
+        print "Test not run.  Try again.";
+        exit(0);
+    
+    for i in range(0x3020,0x3030,2):
+        ret=client.peek16(i);
+        if ret!=0:
+            errors=errors+1;
+            print "Failure at 0x%04x, returned %02xh." % (i,ret);
+        
+    if errors==0:
+        print "Test succeeded.  Board is ready to ship."
+    else:
+        print "Test failed.  Is it soldered correctly?"
+    #client.MSP430dumpmem(0x3020,0x3030);
+    
 if(sys.argv[1]=="ivt"):
-    client.MSP430dumpmem(0xFFE0,0xFFFF);
+    client.MSP430dumpmem(0xFFC0,0xFFFF);
+if(sys.argv[1]=="regs"):
+    for i in range(0,16):
+        print "r%i=%04x" % (i,client.MSP430getreg(i));
+
 if(sys.argv[1]=="flash"):
     f=sys.argv[2];
     start=0;
-    stop=0xFFFF;
+    stop=0x10000;
     if(len(sys.argv)>3):
         start=int(sys.argv[3],16);
     if(len(sys.argv)>4):
@@ -74,15 +117,33 @@ if(sys.argv[1]=="flash"):
     
     h = IntelHex16bit(f);
     
-    client.MSP430masserase();
+    #Should this be default?
+    #Makes flashing multiple images inconvenient.
+    #client.MSP430masserase();
+    
+    count=0; #Bytes in commit.
+    first=0;
+    vals=[];
+    last=0;  #Last address committed.
     for i in h._buf.keys():
-        #print "%04x: %04x"%(i,h[i>>1]);
+        if((count>0x40 or last+2!=i) and count>0 and i&1==0):
+            #print "%i, %x, %x" % (len(vals), last, i);
+            client.MSP430pokeflashblock(first,vals);
+            count=0;
+            first=0;
+            last=0;
+            vals=[];
         if(i>=start and i<stop  and i&1==0):
-            client.MSP430pokeflash(i,h[i>>1]);
+            val=h[i>>1];
+            if(count==0):
+                first=i;
+            last=i;
+            count+=2;
+            vals+=[val&0xff,(val&0xff00)>>8];
             if(i%0x100==0):
                 print "%04x" % i;
-if(sys.argv[1]=="flashtest"):
-    client.MSP430flashtest();
+    if count>0: #last commit, ivt
+        client.MSP430pokeflashblock(first,vals);
 if(sys.argv[1]=="verify"):
     f=sys.argv[2];
     start=0;
@@ -121,15 +182,37 @@ if(sys.argv[1]=="poke"):
         val=int(sys.argv[3],16);
     print "Poking %06x to become %04x." % (start,val);
     
-    while client.MSP430peek(start)!=val:
+    while client.MSP430peek(start)&(~val)>0:
         client.MSP430pokeflash(start,val);
         print "Poked to %04x" % client.MSP430peek(start);
+if(sys.argv[1]=="serial"):
+    oid=0xdeadbeef;
+    if(len(sys.argv)>2):
+        oid=eval(sys.argv[2]);
+    else:
+        #Crashes Windows.
+        #simpchin=u=unichr(24207)+unichr(21015)+unichr(21495);  #Chinese for "Serial Number".
+        #print simpchin;
+        
+        oid=input(u"Serial Number? ");
+    adr=0xFFB0;
+    if(len(sys.argv)>2):
+        start=int(sys.argv[2],16);
+    if(len(sys.argv)>3):
+        val=int(sys.argv[3],16);
+    print "Poking 32-bit OID to 0x%04x as %08x." % (adr,oid);
+    client.MSP430pokeflash(adr,oid&0xFFFF);
+    client.MSP430pokeflash(adr+2,(oid>>16)&0xFFFF);
 
-
+if(sys.argv[1]=="run"):
+    #Set PC to RESET vector's value.
+    #client.MSP430setPC(client.MSP430peek(0xfffe));
+    #client.MSP430releasecpu();
+    client.MSP430run();
 
 if(sys.argv[1]=="whatever"):
     for i in [0x24FF, 0x2500, 0x2502, 0x2504]:
         print "%04x" % client.MSP430peek(i);
 
-client.MSP430releasecpu();
-client.MSP430stop();
+#client.MSP430releasecpu();
+#client.MSP430stop();