2 # GoodFET Client Library
4 # (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
6 # Presently being rewritten.
8 import sys, time, string, cStringIO, struct, glob, serial, os;
10 from GoodFET import GoodFET;
12 class GoodFETMSP430(GoodFET):
13 MSP430APP=0x11; #Changed by inheritors.
14 def MSP430setup(self):
15 """Move the FET into the MSP430 JTAG application."""
16 print "Initializing MSP430.";
17 self.writecmd(0x11,0x10,0,self.data);
20 self.writecmd(self.MSP430APP,0x21,0,self.data);
22 def MSP430peek(self,adr):
23 """Read the contents of memory at an address."""
24 self.data=[adr&0xff, (adr&0xff00)>>8];
25 self.writecmd(self.MSP430APP,0x02,2,self.data);
26 return ord(self.data[0])+(ord(self.data[1])<<8);
27 def MSP430poke(self,adr,val):
28 """Read the contents of memory at an address."""
29 self.data=[adr&0xff, (adr&0xff00)>>8, val&0xff, (val&0xff00)>>8];
30 self.writecmd(self.MSP430APP,0x03,4,self.data);
31 return;# ord(self.data[0])+(ord(self.data[1])<<8);
32 def MSP430start(self):
33 """Start debugging."""
34 self.writecmd(self.MSP430APP,0x20,0,self.data);
35 ident=self.MSP430ident();
36 print "Target identifies as %04x." % ident;
38 def MSP430haltcpu(self):
40 self.writecmd(self.MSP430APP,0xA0,0,self.data);
41 def MSP430releasecpu(self):
43 self.writecmd(self.MSP430APP,0xA1,0,self.data);
44 def MSP430shiftir8(self,ins):
45 """Shift the 8-bit Instruction Register."""
47 self.writecmd(self.MSP430APP,0x80,1,data);
48 return ord(self.data[0]);
49 def MSP430shiftdr16(self,dat):
50 """Shift the 16-bit Data Register."""
51 data=[dat&0xFF,(dat&0xFF00)>>8];
52 self.writecmd(self.MSP430APP,0x81,2,data);
53 return ord(self.data[0])#+(ord(self.data[1])<<8);
54 def MSP430setinstrfetch(self):
55 """Set the instruction fetch mode."""
56 self.writecmd(self.MSP430APP,0xC1,0,self.data);
58 def MSP430ident(self):
59 """Grab self-identification word from 0x0FF0 as big endian."""
60 i=self.MSP430peek(0x0ff0);
61 return ((i&0xFF00)>>8)+((i&0xFF)<<8)
63 """Test MSP430 JTAG. Requires that a chip be attached."""
64 if self.MSP430ident()==0xffff:
65 print "Is anything connected?";
67 temp=self.MSP430peek(0x0200);
68 self.MSP430poke(0x0200,0xdead);
69 if(self.MSP430peek(0x0200)!=0xdead):
70 print "Poke of 0x0200 did not set to 0xDEAD properly.";
72 self.MSP430poke(0x0200,temp); #restore old value.
73 def MSP430flashtest(self):
74 self.MSP430masserase();
77 if(self.MSP430peek(i)!=0xFFFF):
78 print "ERROR: Unerased flash at %04x."%i;
79 self.MSP430writeflash(i,0xDEAD);
81 def MSP430masserase(self):
82 """Erase MSP430 flash memory."""
83 self.writecmd(self.MSP430APP,0xE3,0,None);
84 def MSP430writeflash(self,adr,val):
85 """Write a word of flash memory."""
86 if(self.MSP430peek(adr)!=0xFFFF):
87 print "FLASH ERROR: %04x not clear." % adr;
88 data=[adr&0xFF,(adr&0xFF00)>>8,val&0xFF,(val&0xFF00)>>8];
89 self.writecmd(self.MSP430APP,0xE1,4,data);
90 rval=ord(self.data[0])+(ord(self.data[1])<<8);
92 print "FLASH WRITE ERROR AT %04x. Found %04x, wrote %04x." % (adr,rval,val);
94 def MSP430dumpbsl(self):
95 self.MSP430dumpmem(0xC00,0xfff);
96 def MSP430dumpallmem(self):
97 self.MSP430dumpmem(0x200,0xffff);
98 def MSP430dumpmem(self,begin,end):
101 print "%04x %04x" % (i, self.MSP430peek(i));