X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFET.py;h=263e368aa75ebd44cbdab70bf6c4d0ad05e11fbe;hp=a4d07c23d58c8c7deb3c1ff4ecd984d22fcd25d5;hb=2578d3d26d4b79f281f46ca36faf6d0c67edbace;hpb=3e900862cd87255c698e516c37078163ce343e77;ds=sidebyside diff --git a/client/GoodFET.py b/client/GoodFET.py index a4d07c2..263e368 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -20,7 +20,8 @@ class GoodFET: """Open the serial port""" self.serialport = serial.Serial( port, - 9600, + #9600, + 115200, parity = serial.PARITY_NONE ) #Drop DTR, which is !RST, low to begin the app. @@ -29,7 +30,7 @@ class GoodFET: self.serialport.flushOutput() #Read and handle the initial command. - time.sleep(1); + #time.sleep(1); self.readcmd(); #Read the first command. if(self.verb!=0x7F): print "Verb is wrong. Incorrect firmware?"; @@ -71,14 +72,19 @@ class GoodFET: def setBaud(self,baud): rates=[9600, 9600, 19200, 38400]; self.data=[baud]; - print "Changing baud." + print "Changing FET baud." self.serialport.write(chr(0x00)); self.serialport.write(chr(0x80)); self.serialport.write(chr(1)); self.serialport.write(chr(baud)); - print "Changed baud." + print "Changed host baud." self.serialport.setBaudrate(rates[baud]); + time.sleep(1); + self.serialport.flushInput() + self.serialport.flushOutput() + + print "Baud is now %i." % rates[baud]; return; def monitortest(self): """Self-test several functions through the monitor.""" @@ -110,6 +116,23 @@ class GoodFET: """Move the FET into the MSP430 JTAG application.""" print "Initializing MSP430."; self.writecmd(0x11,0x10,0,self.data); + def CCsetup(self): + """Move the FET into the CC2430/CC2530 application.""" + print "Initializing Chipcon."; + self.writecmd(0x30,0x10,0,self.data); + def CCrd_config(self): + """Read the config register of a Chipcon.""" + self.writecmd(0x30,0x82,0,self.data); + return ord(self.data[0]); + def CCwr_config(self,config): + """Write the config register of a Chipcon.""" + self.writecmd(0x30,0x81,1,[config&0xFF]); + def CCident(self): + """Get a chipcon's ID.""" + self.writecmd(0x30,0x8B,0,None); + chip=ord(self.data[0]); + rev=ord(self.data[1]); + return (chip<<8)+rev; def MSP430peek(self,adr): """Read the contents of memory at an address.""" self.data=[adr&0xff, (adr&0xff00)>>8]; @@ -126,6 +149,15 @@ class GoodFET: self.writecmd(0x11,0x20,0,self.data); ident=self.MSP430ident(); print "Target identifies as %04x." % ident; + + def CCstart(self): + """Start debugging.""" + self.writecmd(0x30,0x20,0,self.data); + ident=self.CCident(); + print "Target identifies as %04x." % ident; + def CCstop(self): + """Stop debugging.""" + self.writecmd(0x30,0x21,0,self.data); def MSP430stop(self): """Stop debugging.""" @@ -169,22 +201,24 @@ class GoodFET: def MSP430flashtest(self): self.MSP430masserase(); i=0x2500; - while(i<0x2600): + while(i<0xFFFF): if(self.MSP430peek(i)!=0xFFFF): print "ERROR: Unerased flash at %04x."%i; - self.MSP430writeflash(i,0x0000); + self.MSP430writeflash(i,0xDEAD); i+=2; def MSP430masserase(self): """Erase MSP430 flash memory.""" self.writecmd(0x11,0xE3,0,None); def MSP430writeflash(self,adr,val): """Write a word of flash memory.""" + if(self.MSP430peek(adr)!=0xFFFF): + print "FLASH ERROR: %04x not clear." % adr; data=[adr&0xFF,(adr&0xFF00)>>8,val&0xFF,(val&0xFF00)>>8]; self.writecmd(0x11,0xE1,4,data); 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); - sys.exit(1); + def MSP430dumpbsl(self): self.MSP430dumpmem(0xC00,0xfff); def MSP430dumpallmem(self): @@ -194,4 +228,7 @@ class GoodFET: while i