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."""
18 self.writecmd(0x30,0x86,0,self.data);
19 def CCreleasecpu(self):
21 self.writecmd(0x30,0x87,0,self.data);
25 #print "Status: %s" % self.CCstatusstr();
27 #Grab ident three times, should be equal.
28 ident1=self.CCident();
29 ident2=self.CCident();
30 ident3=self.CCident();
31 if(ident1!=ident2 or ident2!=ident3):
32 print "Error, repeated ident attempts unequal."
33 print "%04x, %04x, %04x" % (ident1, ident2, ident3);
35 #Single step, printing PC.
36 print "Tracing execution at startup."
39 byte=self.CCpeekcodebyte(i);
40 #print "PC=%04x, %02x" % (pc, byte);
43 print "Verifying that debugging a NOP doesn't affect the PC."
46 self.CCdebuginstr([0x00]);
47 if(pc!=self.CCgetPC()):
48 print "ERROR: PC changed during CCdebuginstr([NOP])!";
50 print "Checking pokes to XRAM."
51 for i in range(0xf000,0xf020):
52 self.CCpokedatabyte(i,0xde);
53 if(self.CCpeekdatabyte(i)!=0xde):
54 print "Error in XDATA at 0x%04x" % i;
56 #print "Status: %s." % self.CCstatusstr();
62 """Move the FET into the CC2430/CC2530 application."""
63 #print "Initializing Chipcon.";
64 self.writecmd(0x30,0x10,0,self.data);
65 def CCrd_config(self):
66 """Read the config register of a Chipcon."""
67 self.writecmd(0x30,0x82,0,self.data);
68 return ord(self.data[0]);
69 def CCwr_config(self,config):
70 """Write the config register of a Chipcon."""
71 self.writecmd(0x30,0x81,1,[config&0xFF]);
73 """Set the flash lock bit in info mem."""
74 self.writecmd(0x30, 0x9A, 0, None);
77 CCversions={0x0100:"CC1110",
82 0xA500:"CC2530", #page 52 of SWRU191
85 CCpagesizes={0x01: 1024, #"CC1110",
86 0x85: 2048, #"CC2430",
87 0x89: 2048, #"CC2431",
88 0x81: 1024, #"CC2510",
89 0x91: 1024, #"CC2511",
90 0xA5: 2048, #"CC2530", #page 52 of SWRU191
91 0xB5: 2048, #"CC2531",
92 0xFF: 0 } #"CCmissing"};
96 chip=self.CCversions.get(ident&0xFF00);
97 return "%s/r%02x" % (chip, ident&0xFF);
99 """Get a chipcon's ID."""
100 self.writecmd(0x30,0x8B,0,None);
101 chip=ord(self.data[0]);
102 rev=ord(self.data[1]);
103 return (chip<<8)+rev;
104 def CCpagesize(self):
105 """Get a chipcon's ID."""
106 self.writecmd(0x30,0x8B,0,None);
107 chip=ord(self.data[0]);
109 return self.CCpagesizes.get(chip);
111 """Get a chipcon's PC."""
112 self.writecmd(0x30,0x83,0,None);
113 hi=ord(self.data[0]);
114 lo=ord(self.data[1]);
116 def CCcmd(self,phrase):
117 self.writecmd(0x30,0x00,len(phrase),phrase);
118 val=ord(self.data[0]);
119 print "Got %02x" % val;
121 def CCdebuginstr(self,instr):
122 self.writecmd(0x30,0x88,len(instr),instr);
123 return ord(self.data[0]);
124 def CCpeekcodebyte(self,adr):
125 """Read the contents of code memory at an address."""
126 self.data=[adr&0xff, (adr&0xff00)>>8];
127 self.writecmd(0x30,0x90,2,self.data);
128 return ord(self.data[0]);
129 def CCpeekdatabyte(self,adr):
130 """Read the contents of data memory at an address."""
131 self.data=[adr&0xff, (adr&0xff00)>>8];
132 self.writecmd(0x30,0x91, 2, self.data);
133 return ord(self.data[0]);
134 def CCpeekirambyte(self,adr):
135 """Read the contents of IRAM at an address."""
136 self.data=[adr&0xff];
137 self.writecmd(0x30,0x02, 1, self.data);
138 return ord(self.data[0]);
139 def CCpeekiramword(self,adr):
140 """Read the little-endian contents of IRAM at an address."""
141 return self.CCpeekirambyte(adr)+(
142 self.CCpeekirambyte(adr+1)<<8);
143 def CCpokeiramword(self,adr,val):
144 self.CCpokeirambyte(adr,val&0xff);
145 self.CCpokeirambyte(adr+1,(val>>8)&0xff);
146 def CCpokeirambyte(self,adr,val):
147 """Write the contents of IRAM at an address."""
148 self.data=[adr&0xff, val&0xff];
149 self.writecmd(0x30,0x02, 2, self.data);
150 return ord(self.data[0]);
152 def CCpokedatabyte(self,adr,val):
153 """Write a byte to data memory."""
154 self.data=[adr&0xff, (adr&0xff00)>>8, val];
155 self.writecmd(0x30, 0x92, 3, self.data);
156 return ord(self.data[0]);
157 def CCchiperase(self):
158 """Erase all of the target's memory."""
159 self.writecmd(0x30,0x80,0,None);
161 """Check the status."""
162 self.writecmd(0x30,0x84,0,None);
163 return ord(self.data[0])
165 CCstatusbits={0x80 : "erase_busy",
169 0x08 : "halt_status",
174 CCconfigbits={0x20 : "soft_power_mode", #new for CC2530
177 0x02 : "timer_suspend",
178 0x01 : "sel_flash_info_page" #stricken from CC2530
181 def CCstatusstr(self):
182 """Check the status as a string."""
183 status=self.CCstatus();
188 str="%s %s" %(self.CCstatusbits[i],str);
192 """Start debugging."""
193 self.writecmd(0x30,0x20,0,self.data);
194 ident=self.CCidentstr();
195 print "Target identifies as %s." % ident;
196 #print "Status: %s." % self.CCstatusstr();
199 #print "Status: %s." % self.CCstatusstr();
202 """Stop debugging."""
203 self.writecmd(0x30,0x21,0,self.data);
204 def CCstep_instr(self):
205 """Step one instruction."""
206 self.writecmd(0x30,0x89,0,self.data);
207 def CCeraseflashbuffer(self):
208 """Erase the 2kB flash buffer"""
209 self.writecmd(0x30,0x99);
210 def CCflashpage(self,adr):
211 """Flash 2kB a page of flash from 0xF000 in XDATA"""
216 print "Flashing buffer to 0x%06x" % adr;
217 self.writecmd(0x30,0x95,4,data);