2 General interface for Isp based AVR programmers.
3 The ISP AVR programmer can load firmware into AVR chips. Which are commonly used on 3D printers.
5 Needs to be subclassed to support different programmers.
6 Currently only the stk500v2 subclass exists.
8 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
14 Base class for ISP based AVR programmers.
15 Functions in this class raise an IspError when something goes wrong.
17 def programChip(self, flashData):
18 """ Program a chip with the given flash data. """
20 self.chip = chipDB.getChipFromDB(self.getSignature())
22 raise IspError("Chip with signature: " + str(self.getSignature()) + "not found")
25 print("Flashing %i bytes" % len(flashData))
26 self.writeFlash(flashData)
27 print("Verifying %i bytes" % len(flashData))
28 self.verifyFlash(flashData)
30 def getSignature(self):
32 Get the AVR signature from the chip. This is a 3 byte array which describes which chip we are connected to.
33 This is important to verify that we are programming the correct type of chip and that we use proper flash block sizes.
36 sig.append(self.sendISP([0x30, 0x00, 0x00, 0x00])[3])
37 sig.append(self.sendISP([0x30, 0x00, 0x01, 0x00])[3])
38 sig.append(self.sendISP([0x30, 0x00, 0x02, 0x00])[3])
43 Do a full chip erase, clears all data, and lockbits.
45 self.sendISP([0xAC, 0x80, 0x00, 0x00])
47 def writeFlash(self, flashData):
49 Write the flash data, needs to be implemented in a subclass.
51 raise IspError("Called undefined writeFlash")
53 def verifyFlash(self, flashData):
55 Verify the flash data, needs to be implemented in a subclass.
57 raise IspError("Called undefined verifyFlash")
60 def __init__(self, value):
63 return repr(self.value)