X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFETMSP430.py;h=743ba55056d84abc7834f0ebc9c25cc72643206a;hp=fc507c5065855db6d46ea14cdac72443df818c50;hb=1283fdb830f9ecd0e27e10ef66927562aff674a7;hpb=412f5e22fe35d4aed40d3a145f1d9213d42d23f9;ds=sidebyside diff --git a/client/GoodFETMSP430.py b/client/GoodFETMSP430.py index fc507c5..743ba55 100644 --- a/client/GoodFETMSP430.py +++ b/client/GoodFETMSP430.py @@ -11,30 +11,61 @@ from GoodFET import GoodFET; class GoodFETMSP430(GoodFET): MSP430APP=0x11; #Changed by inheritors. + CoreID=0; + DeviceID=0; + JTAGID=0; + MSP430ident=0; def MSP430setup(self): """Move the FET into the MSP430 JTAG application.""" - print "Initializing MSP430."; - self.writecmd(0x11,0x10,0,self.data); + self.writecmd(self.MSP430APP,0x10,0,None); + def MSP430stop(self): """Stop debugging.""" self.writecmd(self.MSP430APP,0x21,0,self.data); - + + def MSP430coreid(self): + """Get the Core ID.""" + self.writecmd(self.MSP430APP,0xF0); + CoreID=ord(self.data[0])+(ord(self.data[1])<<8); + return CoreID; + def MSP430deviceid(self): + """Get the Core ID.""" + self.writecmd(self.MSP430APP,0xF1); + DeviceID=( + ord(self.data[0])+(ord(self.data[1])<<8)+ + (ord(self.data[2])<<16)+(ord(self.data[3])<<24)); + return DeviceID; def MSP430peek(self,adr): - """Read the contents of memory at an address.""" - self.data=[adr&0xff, (adr&0xff00)>>8]; - self.writecmd(self.MSP430APP,0x02,2,self.data); + """Read a word at an address.""" + self.data=[adr&0xff, (adr&0xff00)>>8, + (adr&0xff0000)>>16,(adr&0xff000000)>>24, + ]; + self.writecmd(self.MSP430APP,0x02,4,self.data,1); return ord(self.data[0])+(ord(self.data[1])<<8); + def MSP430peekblock(self,adr,blocks=1): + """Grab a few block from an SPI Flash ROM. Block size is unknown""" + data=[adr&0xff, (adr&0xff00)>>8, + (adr&0xff0000)>>16,(adr&0xff000000)>>24, + blocks]; + + self.writecmd(self.MSP430APP,0x02,5,data,blocks); + return self.data; + def MSP430poke(self,adr,val): - """Read the contents of memory at an address.""" - self.data=[adr&0xff, (adr&0xff00)>>8, val&0xff, (val&0xff00)>>8]; - self.writecmd(self.MSP430APP,0x03,4,self.data); - return;# ord(self.data[0])+(ord(self.data[1])<<8); + """Write the contents of memory at an address.""" + self.data=[adr&0xff, (adr&0xff00)>>8, + (adr&0xff0000)>>16,(adr&0xff000000)>>24, + val&0xff, (val&0xff00)>>8]; + self.writecmd(self.MSP430APP,0x03,6,self.data); + return ord(self.data[0])+(ord(self.data[1])<<8); def MSP430start(self): """Start debugging.""" self.writecmd(self.MSP430APP,0x20,0,self.data); - ident=self.MSP430ident(); - print "Target identifies as %04x." % ident; - + self.JTAGID=ord(self.data[0]); + #print "Identified as %02x." % self.JTAGID; + if(not (self.JTAGID==0x89 or self.JTAGID==0x91)): + print "Error, misidentified as %02x." % id; + def MSP430haltcpu(self): """Halt the CPU.""" self.writecmd(self.MSP430APP,0xA0,0,self.data); @@ -57,19 +88,32 @@ class GoodFETMSP430(GoodFET): return self.data[0]; def MSP430ident(self): """Grab self-identification word from 0x0FF0 as big endian.""" - i=self.MSP430peek(0x0ff0); - return ((i&0xFF00)>>8)+((i&0xFF)<<8) + if(self.JTAGID==0x89): + i=self.MSP430peek(0x0ff0); + ident=((i&0xFF00)>>8)+((i&0xFF)<<8) + + if(self.JTAGID==0x91): + i=self.MSP430peek(0x1A04); + ident=((i&0xFF00)>>8)+((i&0xFF)<<8) + #ident=0x0091; + + return ident; def MSP430test(self): """Test MSP430 JTAG. Requires that a chip be attached.""" if self.MSP430ident()==0xffff: print "Is anything connected?"; - print "Testing RAM."; - temp=self.MSP430peek(0x0200); - self.MSP430poke(0x0200,0xdead); - if(self.MSP430peek(0x0200)!=0xdead): - print "Poke of 0x0200 did not set to 0xDEAD properly."; - return; - self.MSP430poke(0x0200,temp); #restore old value. + print "Testing RAM from 1c00 to 1d00."; + for a in range(0x1c00,0x1d00): + self.MSP430poke(a,0); + if(self.MSP430peek(a)!=0): + print "Fault at %06x" % a; + self.MSP430poke(a,0xffff); + if(self.MSP430peek(a)!=0xffff): + print "Fault at %06x" % a; + print "RAM Test Complete." + for a in range(1,5): + print "Identity %04x" % self.MSP430ident(); + def MSP430flashtest(self): self.MSP430masserase(); i=0x2500; @@ -90,7 +134,7 @@ class GoodFETMSP430(GoodFET): rval=ord(self.data[0])+(ord(self.data[1])<<8); if(val!=rval): print "FLASH WRITE ERROR AT %04x. Found %04x, wrote %04x." % (adr,rval,val); - + def MSP430dumpbsl(self): self.MSP430dumpmem(0xC00,0xfff); def MSP430dumpallmem(self):