2 # GoodFET Client Library
4 # (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
6 # This code is being rewritten and refactored. You've been warned!
11 from GoodFET import GoodFET;
12 from intelhex import IntelHex;
14 class GoodFETCC(GoodFET):
15 """A GoodFET variant for use with Chipcon 8051 Zigbeema SoC."""
20 self.writecmd(0x30,0x86,0,self.data);
21 def CCreleasecpu(self):
23 self.writecmd(0x30,0x87,0,self.data);
27 #print "Status: %s" % self.CCstatusstr();
29 #Grab ident three times, should be equal.
30 ident1=self.CCident();
31 ident2=self.CCident();
32 ident3=self.CCident();
33 if(ident1!=ident2 or ident2!=ident3):
34 print "Error, repeated ident attempts unequal."
35 print "%04x, %04x, %04x" % (ident1, ident2, ident3);
37 #Single step, printing PC.
38 print "Tracing execution at startup."
41 byte=self.CCpeekcodebyte(i);
42 #print "PC=%04x, %02x" % (pc, byte);
45 print "Verifying that debugging a NOP doesn't affect the PC."
48 self.CCdebuginstr([0x00]);
49 if(pc!=self.CCgetPC()):
50 print "ERROR: PC changed during CCdebuginstr([NOP])!";
52 print "Checking pokes to XRAM."
53 for i in range(0xf000,0xf020):
54 self.CCpokedatabyte(i,0xde);
55 if(self.CCpeekdatabyte(i)!=0xde):
56 print "Error in XDATA at 0x%04x" % i;
58 #print "Status: %s." % self.CCstatusstr();
64 """Move the FET into the CC2430/CC2530 application."""
65 #print "Initializing Chipcon.";
66 self.writecmd(0x30,0x10,0,self.data);
67 def CCrd_config(self):
68 """Read the config register of a Chipcon."""
69 self.writecmd(0x30,0x82,0,self.data);
70 return ord(self.data[0]);
71 def CCwr_config(self,config):
72 """Write the config register of a Chipcon."""
73 self.writecmd(0x30,0x81,1,[config&0xFF]);
75 """Set the flash lock bit in info mem."""
76 self.writecmd(0x30, 0x9A, 0, None);
78 """Set the flash lock bit in info mem."""
82 CCversions={0x0100:"CC1110",
87 0xA500:"CC2530", #page 52 of SWRU191
90 CCpagesizes={0x01: 1024, #"CC1110",
91 0x85: 2048, #"CC2430",
92 0x89: 2048, #"CC2431",
93 0x81: 1024, #"CC2510",
94 0x91: 1024, #"CC2511",
95 0xA5: 2048, #"CC2530", #page 52 of SWRU191
96 0xB5: 2048, #"CC2531",
97 0xFF: 0 } #"CCmissing"};
100 ident=self.CCident();
101 chip=self.CCversions.get(ident&0xFF00);
102 return "%s/r%02x" % (chip, ident&0xFF);
104 """Get a chipcon's ID."""
105 self.writecmd(0x30,0x8B,0,None);
106 chip=ord(self.data[0]);
107 rev=ord(self.data[1]);
108 return (chip<<8)+rev;
109 def CCpagesize(self):
110 """Get a chipcon's ID."""
111 self.writecmd(0x30,0x8B,0,None);
112 chip=ord(self.data[0]);
113 size=self.CCpagesizes.get(chip);
115 print "ERROR: Pagesize undefined.";
116 print "chip=%02x" %chip;
121 """Get a chipcon's PC."""
122 self.writecmd(0x30,0x83,0,None);
123 hi=ord(self.data[0]);
124 lo=ord(self.data[1]);
126 def CCcmd(self,phrase):
127 self.writecmd(0x30,0x00,len(phrase),phrase);
128 val=ord(self.data[0]);
129 print "Got %02x" % val;
131 def CCdebuginstr(self,instr):
132 self.writecmd(0x30,0x88,len(instr),instr);
133 return ord(self.data[0]);
134 def CCpeekcodebyte(self,adr):
135 """Read the contents of code memory at an address."""
136 self.data=[adr&0xff, (adr&0xff00)>>8];
137 self.writecmd(0x30,0x90,2,self.data);
138 return ord(self.data[0]);
139 def CCpeekdatabyte(self,adr):
140 """Read the contents of data memory at an address."""
141 self.data=[adr&0xff, (adr&0xff00)>>8];
142 self.writecmd(0x30,0x91, 2, self.data);
143 return ord(self.data[0]);
144 def CCpeekirambyte(self,adr):
145 """Read the contents of IRAM at an address."""
146 self.data=[adr&0xff];
147 self.writecmd(0x30,0x02, 1, self.data);
148 return ord(self.data[0]);
149 def CCpeekiramword(self,adr):
150 """Read the little-endian contents of IRAM at an address."""
151 return self.CCpeekirambyte(adr)+(
152 self.CCpeekirambyte(adr+1)<<8);
153 def CCpokeiramword(self,adr,val):
154 self.CCpokeirambyte(adr,val&0xff);
155 self.CCpokeirambyte(adr+1,(val>>8)&0xff);
156 def CCpokeirambyte(self,adr,val):
157 """Write the contents of IRAM at an address."""
158 self.data=[adr&0xff, val&0xff];
159 self.writecmd(0x30,0x02, 2, self.data);
160 return ord(self.data[0]);
162 def CCpokedatabyte(self,adr,val):
163 """Write a byte to data memory."""
164 self.data=[adr&0xff, (adr&0xff00)>>8, val];
165 self.writecmd(0x30, 0x92, 3, self.data);
166 return ord(self.data[0]);
167 def CCchiperase(self):
168 """Erase all of the target's memory."""
169 self.writecmd(0x30,0x80,0,None);
171 """Erase all of the target's memory."""
175 """Check the status."""
176 self.writecmd(0x30,0x84,0,None);
177 return ord(self.data[0])
179 CCstatusbits={0x80 : "erase_busy",
183 0x08 : "halt_status",
188 CCconfigbits={0x20 : "soft_power_mode", #new for CC2530
191 0x02 : "timer_suspend",
192 0x01 : "sel_flash_info_page" #stricken from CC2530
195 def CCstatusstr(self):
196 """Check the status as a string."""
197 status=self.CCstatus();
202 str="%s %s" %(self.CCstatusbits[i],str);
206 """Start debugging."""
207 self.writecmd(0x30,0x20,0,self.data);
208 ident=self.CCidentstr();
209 #print "Target identifies as %s." % ident;
210 #print "Status: %s." % self.CCstatusstr();
213 #print "Status: %s." % self.CCstatusstr();
216 """Stop debugging."""
217 self.writecmd(0x30,0x21,0,self.data);
218 def CCstep_instr(self):
219 """Step one instruction."""
220 self.writecmd(0x30,0x89,0,self.data);
221 def CCeraseflashbuffer(self):
222 """Erase the 2kB flash buffer"""
223 self.writecmd(0x30,0x99);
224 def CCflashpage(self,adr):
225 """Flash 2kB a page of flash from 0xF000 in XDATA"""
230 print "Flashing buffer to 0x%06x" % adr;
231 self.writecmd(0x30,0x95,4,data);