2 # GoodFET SPI and SPIFlash Client Library
4 # (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
6 # This code is being rewritten and refactored. You've been warned!
8 import sys, time, string, cStringIO, struct, glob, serial, os;
10 from GoodFET import GoodFET;
12 class GoodFETAVR(GoodFET):
14 AVRVendors={0x1E: "Atmel",
18 #List from avr910.asm and other sources.
19 #More devices at http://avr.fenceline.de/device_data.html
56 """Move the FET into the SPI application."""
57 self.writecmd(self.AVRAPP,0x10,0,self.data); #SPI/SETUP
60 """Exchange data by AVR.
61 Input should probably be 4 bytes."""
63 self.writecmd(self.AVRAPP,0x00,len(data),data);
67 """Start the connection."""
68 self.writecmd(self.AVRAPP,0x20,0,None);
70 """Erase the target chip."""
71 self.writecmd(self.AVRAPP,0xF0,0,None);
73 """Read the target's lockbits."""
74 self.writecmd(self.AVRAPP,0x82,0,None);
75 return ord(self.data[0]);
76 def eeprompeek(self, adr):
77 """Read a byte of the target's EEPROM."""
78 self.writecmd(self.AVRAPP,0x81 ,2,
79 [ (adr&0xFF), (adr>>8)]
80 );#little-endian address
81 return ord(self.data[0]);
82 def flashpeek(self, adr):
83 """Read a byte of the target's EEPROM."""
84 self.writecmd(self.AVRAPP,0x02 ,2,
85 [ (adr&0xFF), (adr>>8)]
86 );#little-endian address
87 return ord(self.data[0]);
88 def flashpeekblock(self, adr):
89 """Read a byte of the target's EEPROM."""
90 self.writecmd(self.AVRAPP,0x02 ,4,
91 [ (adr&0xFF), (adr>>8) &0xFF, 0x80, 0x00]
95 def eeprompoke(self, adr, val):
96 """Write a byte of the target's EEPROM."""
97 self.writecmd(self.AVRAPP,0x91 ,3,
98 [ (adr&0xFF), (adr>>8), val]
99 );#little-endian address
100 return ord(self.data[0]);
103 """Return an identifying string."""
104 self.writecmd(self.AVRAPP,0x83,0, None);
105 vendor=self.AVRVendors.get(ord(self.data[0]));
106 deviceid=(ord(self.data[1])<<8)+ord(self.data[2]);
107 device=self.AVRDevices.get(deviceid);
109 #Return hex if device is unknown.
110 #They are similar enough that it needn't be known.
112 device=("0x%04x" % deviceid);