def __init__(self): super(XMEGAProgrammer, self).__init__() self._usbiface = None self.supported_chips = supported_xmega self.xmega = XMEGAPDI() self._logging = None self._foundchip = False
def __init__(self): super(XMEGAProgrammer, self).__init__() self._usbiface = None self.supported_chips = [XMEGA128A4U()] self.xmega = XMEGAPDI() self._logging = None self._foundchip = False
class XMEGAProgrammer(object): def __init__(self): super(XMEGAProgrammer, self).__init__() self._usbiface = None self.supported_chips = [XMEGA128A4U()] self.xmega = XMEGAPDI() self._logging = None self._foundchip = False def setUSBInterface(self, iface): self._usbiface = iface self._foundchip = False self.xmega.setUSB(iface) self.xmega.setChip(self.supported_chips[0]) def find(self): self._foundchip = False self.xmega.setParamTimeout(200) self.xmega.enablePDI(True) # Read signature bytes data = self.xmega.readMemory(0x01000090, 3, "signature") # Check if it's one we know about? for t in self.supported_chips: if ((data[0] == t.signature[0]) and (data[1] == t.signature[1]) and (data[2] == t.signature[2])): self._foundchip = True self.log("Detected %s" % t.name) self.xmega.setChip(t) break # Print signature of unknown device if self._foundchip == False: self.log("Detected Unknown Chip, sig=%2x %2x %2x" % (data[0], data[1], data[2])) def erase(self, memtype="chip"): if memtype == "app": self.xmega.eraseApp() elif memtype == "chip": self.xmega.eraseChip() else: raise ValueError("Invalid memtype: %s" % memtype) def program(self, filename, memtype="flash", verify=True): f = IntelHex(filename) startaddr = self.xmega._chip.memtypes[memtype]["offset"] maxsize = self.xmega._chip.memtypes[memtype]["size"] fsize = f.maxaddr() - f.minaddr() if fsize > maxsize: raise IOError("File %s appears to be %d bytes, larger than %s size of %d" % (filename, fsize, memtype, maxsize)) print "Programming..." fdata = f.tobinarray(start=0) self.xmega.writeMemory(startaddr, fdata, memtype) print "Reading..." #Do verify run rdata = self.xmega.readMemory(startaddr, len(fdata), memtype) for i in range(0, len(fdata)): if fdata[i] != rdata[i]: # raise IOError("Verify failed at 0x%04x, %x != %x" % (i, fdata[i], rdata[i])) print i pass print "Verifed OK" def close(self): self.xmega.enablePDI(False) def log(self, text): if self._logging is None: print text else: self._logging(text)
class XMEGAProgrammer(object): def __init__(self): super(XMEGAProgrammer, self).__init__() self._usbiface = None self.supported_chips = supported_xmega self.xmega = XMEGAPDI() self._logging = None self._foundchip = False def setUSBInterface(self, iface): self._usbiface = iface self._foundchip = False self.xmega.setUSB(iface) self.xmega.setChip(self.supported_chips[0]) def find(self): self._foundchip = False self.xmega.setParamTimeout(400) self.xmega.enablePDI(True) # Read signature bytes data = self.xmega.readMemory(0x01000090, 3, "signature") # Check if it's one we know about? for t in self.supported_chips: if ((data[0] == t.signature[0]) and (data[1] == t.signature[1]) and (data[2] == t.signature[2])): self._foundchip = True self.log("Detected %s" % t.name) self.xmega.setChip(t) break # Print signature of unknown device if self._foundchip == False: self.log("Detected Unknown Chip, sig=%2x %2x %2x" % (data[0], data[1], data[2])) def erase(self, memtype="chip"): if memtype == "app": self.xmega.eraseApp() elif memtype == "chip": self.xmega.eraseChip() else: raise ValueError("Invalid memtype: %s" % memtype) def program(self, filename, memtype="flash", verify=True): f = IntelHex(filename) startaddr = self.xmega._chip.memtypes[memtype]["offset"] maxsize = self.xmega._chip.memtypes[memtype]["size"] fsize = f.maxaddr() - f.minaddr() if fsize > maxsize: raise IOError( "File %s appears to be %d bytes, larger than %s size of %d" % (filename, fsize, memtype, maxsize)) self.log("XMEGA Programming %s..." % memtype) QCoreApplication.processEvents() fdata = f.tobinarray(start=0) self.xmega.writeMemory(startaddr, fdata, memtype) # , erasePage=True self.log("XMEGA Reading %s..." % memtype) QCoreApplication.processEvents() #Do verify run rdata = self.xmega.readMemory(startaddr, len(fdata), memtype) for i in range(0, len(fdata)): if fdata[i] != rdata[i]: raise IOError("Verify failed at 0x%04x, %x != %x" % (i, fdata[i], rdata[i])) self.log("Verified %s OK, %d bytes" % (memtype, fsize)) def close(self): self.xmega.enablePDI(False) def log(self, text): if self._logging is None: print text else: self._logging(text)