2012-03-05 21:30:54 +00:00
|
|
|
import os, struct, sys, time
|
|
|
|
|
|
|
|
from serial import Serial
|
|
|
|
|
|
|
|
import chipDB
|
|
|
|
|
|
|
|
class IspBase():
|
|
|
|
def programChip(self, flashData):
|
|
|
|
self.curExtAddr = -1
|
|
|
|
self.chip = chipDB.getChipFromDB(self.getSignature())
|
|
|
|
if self.chip == False:
|
2012-03-06 16:48:56 +00:00
|
|
|
raise IspError("Chip with signature: " + str(self.getSignature()) + "not found")
|
2012-03-05 21:30:54 +00:00
|
|
|
self.chipErase()
|
|
|
|
|
2012-06-21 17:53:18 +00:00
|
|
|
print("Flashing %i bytes" % len(flashData))
|
2012-03-05 21:30:54 +00:00
|
|
|
self.writeFlash(flashData)
|
2012-06-21 17:53:18 +00:00
|
|
|
print("Verifying %i bytes" % len(flashData))
|
2012-03-05 21:30:54 +00:00
|
|
|
self.verifyFlash(flashData)
|
|
|
|
|
|
|
|
#low level ISP commands
|
|
|
|
def getSignature(self):
|
|
|
|
sig = []
|
|
|
|
sig.append(self.sendISP([0x30, 0x00, 0x00, 0x00])[3])
|
|
|
|
sig.append(self.sendISP([0x30, 0x00, 0x01, 0x00])[3])
|
|
|
|
sig.append(self.sendISP([0x30, 0x00, 0x02, 0x00])[3])
|
|
|
|
return sig
|
|
|
|
|
|
|
|
def chipErase(self):
|
|
|
|
self.sendISP([0xAC, 0x80, 0x00, 0x00])
|
|
|
|
|
|
|
|
class IspError():
|
|
|
|
def __init__(self, value):
|
|
|
|
self.value = value
|
|
|
|
def __str__(self):
|
|
|
|
return repr(self.value)
|