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"};
99 return self.CCidentstr();
100 def CCidentstr(self):
101 ident=self.CCident();
102 chip=self.CCversions.get(ident&0xFF00);
103 return "%s/r%02x" % (chip, ident&0xFF);
105 """Get a chipcon's ID."""
106 self.writecmd(0x30,0x8B,0,None);
107 chip=ord(self.data[0]);
108 rev=ord(self.data[1]);
109 return (chip<<8)+rev;
110 def CCpagesize(self):
111 """Get a chipcon's ID."""
112 self.writecmd(0x30,0x8B,0,None);
113 chip=ord(self.data[0]);
114 size=self.CCpagesizes.get(chip);
116 print "ERROR: Pagesize undefined.";
117 print "chip=%02x" %chip;
122 """Get a chipcon's PC."""
123 self.writecmd(0x30,0x83,0,None);
124 hi=ord(self.data[0]);
125 lo=ord(self.data[1]);
127 def CCcmd(self,phrase):
128 self.writecmd(0x30,0x00,len(phrase),phrase);
129 val=ord(self.data[0]);
130 print "Got %02x" % val;
132 def CCdebuginstr(self,instr):
133 self.writecmd(0x30,0x88,len(instr),instr);
134 return ord(self.data[0]);
135 def peek8(self,address, memory="vn"):
136 return self.CCpeekcodebyte(address);
138 def CCpeekcodebyte(self,adr):
139 """Read the contents of code memory at an address."""
140 self.data=[adr&0xff, (adr&0xff00)>>8];
141 self.writecmd(0x30,0x90,2,self.data);
142 return ord(self.data[0]);
143 def CCpeekdatabyte(self,adr):
144 """Read the contents of data memory at an address."""
145 self.data=[adr&0xff, (adr&0xff00)>>8];
146 self.writecmd(0x30,0x91, 2, self.data);
147 return ord(self.data[0]);
148 def CCpeekirambyte(self,adr):
149 """Read the contents of IRAM at an address."""
150 self.data=[adr&0xff];
151 self.writecmd(0x30,0x02, 1, self.data);
152 return ord(self.data[0]);
153 def CCpeekiramword(self,adr):
154 """Read the little-endian contents of IRAM at an address."""
155 return self.CCpeekirambyte(adr)+(
156 self.CCpeekirambyte(adr+1)<<8);
157 def CCpokeiramword(self,adr,val):
158 self.CCpokeirambyte(adr,val&0xff);
159 self.CCpokeirambyte(adr+1,(val>>8)&0xff);
160 def CCpokeirambyte(self,adr,val):
161 """Write the contents of IRAM at an address."""
162 self.data=[adr&0xff, val&0xff];
163 self.writecmd(0x30,0x02, 2, self.data);
164 return ord(self.data[0]);
166 def CCpokedatabyte(self,adr,val):
167 """Write a byte to data memory."""
168 self.data=[adr&0xff, (adr&0xff00)>>8, val];
169 self.writecmd(0x30, 0x92, 3, self.data);
170 return ord(self.data[0]);
171 def CCchiperase(self):
172 """Erase all of the target's memory."""
173 self.writecmd(0x30,0x80,0,None);
175 """Erase all of the target's memory."""
179 """Check the status."""
180 self.writecmd(0x30,0x84,0,None);
181 return ord(self.data[0])
183 CCstatusbits={0x80 : "erase_busy",
187 0x08 : "halt_status",
192 CCconfigbits={0x20 : "soft_power_mode", #new for CC2530
195 0x02 : "timer_suspend",
196 0x01 : "sel_flash_info_page" #stricken from CC2530
200 """Check the status as a string."""
201 status=self.CCstatus();
206 str="%s %s" %(self.CCstatusbits[i],str);
210 """Start debugging."""
211 self.writecmd(0x30,0x20,0,self.data);
212 ident=self.CCidentstr();
213 #print "Target identifies as %s." % ident;
214 #print "Status: %s." % self.status();
217 #print "Status: %s." % self.status();
220 """Stop debugging."""
221 self.writecmd(0x30,0x21,0,self.data);
222 def CCstep_instr(self):
223 """Step one instruction."""
224 self.writecmd(0x30,0x89,0,self.data);
225 def CCeraseflashbuffer(self):
226 """Erase the 2kB flash buffer"""
227 self.writecmd(0x30,0x99);
228 def CCflashpage(self,adr):
229 """Flash 2kB a page of flash from 0xF000 in XDATA"""
234 print "Flashing buffer to 0x%06x" % adr;
235 self.writecmd(0x30,0x95,4,data);