summaryrefslogtreecommitdiffstats
path: root/libtoprammer/chips
diff options
context:
space:
mode:
authorMichael Buesch <m@bues.ch>2013-06-16 20:36:00 +0200
committerMichael Buesch <m@bues.ch>2013-06-16 20:36:00 +0200
commit46b4d210eb05b659761681362a636025514ff4e6 (patch)
tree68e0ffe2255a7ec292d4d5f82623f9896a0a1890 /libtoprammer/chips
parenta96a314d18d7135c785f15516142a2f101583f44 (diff)
downloadtoprammer-46b4d210eb05b659761681362a636025514ff4e6.tar.xz
toprammer-46b4d210eb05b659761681362a636025514ff4e6.zip
Add support for more Microchip and Atmel microcontrollers
Implementation by Pavel Štemberk <stemberk@gmail.com> Signed-off-by: Michael Buesch <m@bues.ch>
Diffstat (limited to 'libtoprammer/chips')
-rw-r--r--libtoprammer/chips/__init__.py6
-rw-r--r--libtoprammer/chips/at89s51dip40.py322
-rw-r--r--libtoprammer/chips/at89s52dip40.py321
-rw-r--r--libtoprammer/chips/microchip01/__init__.py6
-rw-r--r--libtoprammer/chips/microchip01/microchip01_common.py (renamed from libtoprammer/chips/microchip_common.py)144
-rw-r--r--libtoprammer/chips/microchip01/pic10f200dip8.py (renamed from libtoprammer/chips/pic10f200dip8.py)34
-rw-r--r--libtoprammer/chips/microchip01/pic10f202dip8.py (renamed from libtoprammer/chips/pic10f202dip8.py)33
-rw-r--r--libtoprammer/chips/microchip01/pic12f508dip8.py75
-rw-r--r--libtoprammer/chips/microchip01/pic16f59sip6.py81
-rw-r--r--libtoprammer/chips/microchip02/__init__.py5
-rw-r--r--libtoprammer/chips/microchip02/microchip02_common.py449
-rw-r--r--libtoprammer/chips/microchip02/pic10f322dip8.py86
-rw-r--r--libtoprammer/chips/microchip02/pic12f1822dip8.py103
-rw-r--r--libtoprammer/chips/microchip02/pic16f1824dip14.py103
14 files changed, 1718 insertions, 50 deletions
diff --git a/libtoprammer/chips/__init__.py b/libtoprammer/chips/__init__.py
index a90351b..9efbb02 100644
--- a/libtoprammer/chips/__init__.py
+++ b/libtoprammer/chips/__init__.py
@@ -3,6 +3,8 @@
from _27cxxx import *
from _74hc4094 import *
from at89c2051dip20 import *
+from at89s51dip40 import *
+from at89s52dip40 import *
from atmega32dip40 import *
from atmega88dip28 import *
from atmega8dip28 import *
@@ -11,7 +13,7 @@ from attiny26dip20 import *
from hm62256dip28 import *
from m24cxxdip8 import *
from m8cissp import *
-from pic10f200dip8 import *
-from pic10f202dip8 import *
from unitest import *
from w29ee011dip32 import *
+from microchip01 import *
+from microchip02 import *
diff --git a/libtoprammer/chips/at89s51dip40.py b/libtoprammer/chips/at89s51dip40.py
new file mode 100644
index 0000000..e9327be
--- /dev/null
+++ b/libtoprammer/chips/at89s51dip40.py
@@ -0,0 +1,322 @@
+"""
+# TOP2049 Open Source programming suite
+#
+# Atmel AT89C2051 DIP20 Support
+#
+# Copyright (c) 2010 Guido
+# Copyright (c) 2010 Michael Buesch <m@bues.ch>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""
+
+from libtoprammer.chip import *
+
+
+class Chip_AT89S51dip40(Chip):
+ STAT_BUSY = 0x01 # Programmer is running a command
+ STAT_ERR = 0x02 # Error during write
+
+ def __init__(self):
+ Chip.__init__(self,
+ chipPackage = "DIP40",
+ chipPinVCC = 40,
+ chipPinsVPP = 31,
+ chipPinGND = 20)
+ self.flashPageSize = 0x2000
+ self.flashPages = 1
+
+ def __initChip(self):
+ self.applyVCC(False)
+ self.applyVPP(False)
+ self.applyGND(True)
+ self.top.cmdSetVCCVoltage(5)
+ self.top.cmdSetVPPVoltage(5)
+
+ def readSignature(self):
+ self.__initChip()
+ self.top.cmdEnableZifPullups(True)
+ self.applyGND(True)
+ self.applyVCC(True)
+ self.top.cmdSetVPPVoltage(5)
+ self.__loadCommand(5) # VPP on
+ self.applyVPP(True)
+ self.__loadCommand(1) # set nPROG
+ self.__loadAddress(0x0100)
+ self.__setPx()
+ data = ""
+ self.top.cmdFPGARead(0x10)
+ self.__loadAddress(0x0200)
+ self.top.cmdFPGARead(0x10)
+ data += self.top.cmdReadBufferReg()
+ self.applyVPP(False)
+ self.__loadCommand(6) # VPP off
+ signature = ""
+ signature += data[0]
+ signature += data[1]
+ self.top.printInfo("Signature: %X, %X" % (byte2int(signature[0]), byte2int(signature[1])))
+ return signature
+
+ def erase(self):
+ self.__initChip()
+ self.applyGND(True)
+ self.applyVCC(True)
+ self.__loadCommand(1) # set P3.2
+ self.top.cmdSetVPPVoltage(5)
+ self.__loadCommand(5) # VPP on
+ self.applyVPP(True)
+ self.top.cmdDelay(0.5)
+ self.__setPx(P26=1, P33=1)
+ self.top.cmdSetVPPVoltage(12)
+ self.__runCommandSync(3)
+ self.top.cmdDelay(0.5)
+ self.applyVPP(False)
+ self.top.cmdSetVPPVoltage(5)
+ self.__setPx()
+ self.__loadCommand(6) # VPP off
+ self.top.flushCommands()
+ self.top.printInfo("{chipid}: Erasing flash, verifying ...".format(chipid=self.chipDescription.chipID))
+ ok = self.__verifyErase()
+ if ok == 0:
+ self.top.printInfo("{chipid}: Erase done.".format(chipid=self.chipDescription.chipID))
+ else:
+ self.top.printInfo("{chipid}: Erase failed!".format(chipid=self.chipDescription.chipID))
+
+ def readProgmem(self):
+ self.__initChip()
+ self.top.cmdEnableZifPullups(True)
+ self.applyGND(True)
+ self.applyVCC(True)
+ self.top.cmdSetVPPVoltage(5)
+ self.__loadCommand(5) # VPP on
+ self.applyVPP(True)
+ self.__loadCommand(1) # set nPROG
+ self.__setPx(P36=1, P37=1)
+ #self.__setPx(P26=1, P27=1, P36=1)
+ #self.__setPx()
+ image = ""
+ byteCount = 0
+ self.progressMeterInit("Reading Flash", self.flashPageSize*self.flashPages)
+ for addr in range(0, self.flashPageSize*self.flashPages):
+ self.progressMeter(addr)
+ self.__loadAddress(addr)
+ #self.__runCommandSync(4)
+ self.top.cmdFPGARead(0x10)
+ byteCount += 1
+ if byteCount == self.top.getBufferRegSize():
+ image += self.top.cmdReadBufferReg(byteCount)
+ byteCount = 0
+ image += self.top.cmdReadBufferReg(byteCount)
+ self.applyVPP(False)
+ self.__setPx()
+ self.__loadCommand(6) # VPP off
+ self.top.flushCommands()
+ self.progressMeterFinish()
+
+ return image
+
+ def writeProgmem(self, image):
+ if len(image) > self.flashPageSize*self.flashPages:
+ self.throwError("Invalid FLASH image size %d (expected <=%d)" %\
+ (len(image), self.flashPageSize*self.flashPages))
+ self.__initChip()
+ self.top.cmdEnableZifPullups(True)
+ self.applyGND(True)
+ self.applyVCC(True)
+ self.__loadCommand(1) # set P3.2
+ self.top.cmdSetVPPVoltage(5)
+ self.__loadCommand(5) # VPP on
+ self.applyVPP(True)
+ self.__setPx(P27=1, P33=1, P36=1, P37=1)
+ self.top.cmdSetVPPVoltage(12)
+ self.progressMeterInit("Writing Flash", len(image))
+ for addr in range(0, len(image)):
+ self.progressMeter(addr)
+ data = byte2int(image[addr])
+ if data != 0xFF:
+ self.__loadData(data)
+ self.__loadAddress(addr)
+ self.__loadCommand(3)
+ ok = self.__progWait()
+ if (ok & self.STAT_ERR) != 0:
+ self.throwError("Write byte failed.")
+ self.top.flushCommands()
+ self.applyVPP(False)
+ self.top.cmdSetVPPVoltage(5)
+ self.__setPx()
+ self.__loadCommand(6) # VPP off
+ self.progressMeterFinish()
+ ok = self.__verifyProgmem(image)
+ if ok == 0:
+ self.top.printInfo("{chipid}: Write flash done.".format(chipid = self.chipDescription.chipID))
+ else:
+ self.top.printInfo("{chipid}: Write flash failed!".format(chipid = self.chipDescription.chipID))
+
+ def readLockbits(self):
+ self.__initChip()
+ self.top.cmdEnableZifPullups(True)
+ self.applyGND(True)
+ self.applyVCC(True)
+ self.top.cmdSetVPPVoltage(5)
+ self.__loadCommand(5) # VPP on
+ self.applyVPP(True)
+ self.__loadCommand(1) # set nPROG
+ self.__setPx(P26=1, P27=1, P36=1)
+ data = ""
+ self.top.cmdFPGARead(0x10)
+ data += self.top.cmdReadBufferReg()
+ self.applyVPP(False)
+ self.__loadCommand(6) # VPP off
+ lockbits = ""
+ lockbits += data[0]
+ return lockbits
+
+ def writeLockbits(self, image):
+ if len(image) != 1:
+ self.throwError("Invalid lock-bits image size %d (expected %d)" %\
+ (len(image), 1))
+ self.progressMeterInit("Writing lock bits", 3)
+ lbMask = 0x04
+ lb=byte2int(image[0])
+ if(lb & lbMask ):
+ self.progressMeter(1)
+ self.__writeLockbit(1)
+ lbMask <<= 1
+ if(lb & lbMask ):
+ self.progressMeter(2)
+ self.__writeLockbit(2)
+ lbMask <<= 1
+ if(lb & lbMask ):
+ self.progressMeter(3)
+ self.__writeLockbit(3)
+ self.progressMeterFinish()
+
+ def __writeLockbit(self, lb):
+ self.__initChip()
+ self.applyGND(True)
+ self.applyVCC(True)
+ self.__loadCommand(1)
+ self.top.cmdSetVPPVoltage(5)
+ self.__loadCommand(5) # VPP on
+ self.applyVPP(True)
+ self.top.cmdSetVPPVoltage(12)
+ if(lb == 1 ):
+ self.__setPx(P26=1, P27=1, P33=1, P36=1, P37=1)
+ self.__runCommandSync(3)
+ elif(lb == 2 ):
+ self.__setPx(P26=1, P27=1, P33=1, P36=0, P37=0)
+ self.__runCommandSync(3)
+ elif(lb == 3 ):
+ self.__setPx(P26=1, P27=0, P33=1, P36=1, P37=0)
+ self.__runCommandSync(3)
+ self.top.flushCommands()
+ self.applyVPP(False)
+ self.top.cmdSetVPPVoltage(5)
+ self.__setPx()
+ self.__loadCommand(6) # VPP off
+
+ def __verifyErase(self):
+ ok = 0
+ image = self.readProgmem()
+ for addr in range(0, self.flashPageSize*self.flashPages):
+ if byte2int(image[addr]) != 0xFF:
+ ok = 1
+ return ok
+
+ def __verifyProgmem(self,image):
+ data = self.readProgmem()
+ ok = 0
+ for addr in range(0, len(image)-1):
+ if byte2int(image[addr]) != byte2int(data[addr]):
+ ok = 1
+ return ok
+
+ def __loadData(self, data):
+ self.top.cmdFPGAWrite(0x10, data)
+
+ def __loadAddress(self, addr):
+ self.top.cmdFPGAWrite(0x11, addr & 0x00FF)
+ self.top.cmdFPGAWrite(0x12, (addr >> 8) & 0x3FFF)
+
+ def __loadCommand(self, command):
+ self.top.cmdFPGAWrite(0x13, command & 0xFF)
+
+ def __runCommandSync(self, command):
+ self.__loadCommand(command)
+ self.__busyWait()
+
+ def __setPx(self, P26=0, P27=0, P33=0, P36=0, P37=0, nPSEN=0, RST=1):
+ data = 0
+ if P26:
+ data |= 1
+ if P27:
+ data |= 2
+ if P33:
+ data |= 4
+ if P36:
+ data |= 8
+ if P37:
+ data |= 16
+ if nPSEN:
+ data |= 32
+ if RST:
+ data |= 64
+ self.top.cmdFPGAWrite(0x16, data)
+
+ def __getStatusFlags(self):
+ self.top.cmdFPGARead(0x12)
+ stat = self.top.cmdReadBufferReg()
+ return byte2int(stat[0])
+
+ def __busy(self):
+ return bool(self.__getStatusFlags() & self.STAT_BUSY)
+
+ def __busyWait(self):
+ for i in range(0, 26):
+ if not self.__busy():
+ return
+ self.top.hostDelay(0.001)
+ self.throwError("Timeout in busywait.")
+
+ def __progWait(self):
+ for i in range(0,4):
+ self.top.cmdFPGARead(0x12)
+ stat = self.top.cmdReadBufferReg()
+ if (byte2int(stat[0]) & self.STAT_BUSY) == 0:
+ return byte2int(stat[0])
+ self.top.hostDelay(0.001)
+ self.throwError("Timeout in busywait.")
+lockbitDesc = (
+ BitDescription(0, "Unused"),
+ BitDescription(1, "Unused"),
+ BitDescription(2, "BLB01 - further programming of flash mem. is disabled"),
+ BitDescription(3, "BLB02 - verify disabled"),
+ BitDescription(4, "BLB03 - external execution disabled"),
+ BitDescription(5, "Unused"),
+ BitDescription(6, "Unused"),
+ BitDescription(7, "Unused"),
+ BitDescription(8, "Unused"),
+)
+
+ChipDescription(
+ Chip_AT89S51dip40,
+ bitfile = "at89s5xdip40",
+ chipID = "at89s51dip40",
+ runtimeID = (0x0005, 0x01),
+ chipVendors = "Atmel",
+ description = "AT89S51",
+ lockbitDesc = lockbitDesc,
+ maintainer = None,
+ packages = ( ("DIP40", ""), )
+)
diff --git a/libtoprammer/chips/at89s52dip40.py b/libtoprammer/chips/at89s52dip40.py
new file mode 100644
index 0000000..238a50a
--- /dev/null
+++ b/libtoprammer/chips/at89s52dip40.py
@@ -0,0 +1,321 @@
+"""
+# TOP2049 Open Source programming suite
+#
+# Atmel AT89C2051 DIP20 Support
+#
+# Copyright (c) 2010 Guido
+# Copyright (c) 2010 Michael Buesch <m@bues.ch>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""
+
+from libtoprammer.chip import *
+
+
+class Chip_AT89S52dip40(Chip):
+ STAT_BUSY = 0x01 # Programmer is running a command
+ STAT_ERR = 0x02 # Error during write
+
+ def __init__(self):
+ Chip.__init__(self,
+ chipPackage = "DIP40",
+ chipPinVCC = 40,
+ chipPinsVPP = 31,
+ chipPinGND = 20)
+ self.flashPageSize = 0x4000
+ self.flashPages = 1
+
+ def __initChip(self):
+ self.applyVCC(False)
+ self.applyVPP(False)
+ self.applyGND(True)
+ self.top.cmdSetVCCVoltage(5)
+ self.top.cmdSetVPPVoltage(5)
+
+ def readSignature(self):
+ self.__initChip()
+ self.top.cmdEnableZifPullups(True)
+ self.applyGND(True)
+ self.applyVCC(True)
+ self.top.cmdSetVPPVoltage(5)
+ self.__loadCommand(5) # VPP on
+ self.applyVPP(True)
+ self.__loadCommand(1) # set nPROG
+ self.__loadAddress(0x0100)
+ self.__setPx()
+ data = ""
+ self.top.cmdFPGARead(0x10)
+ self.__loadAddress(0x0200)
+ self.top.cmdFPGARead(0x10)
+ data += self.top.cmdReadBufferReg()
+ self.applyVPP(False)
+ self.__loadCommand(6) # VPP off
+ signature = ""
+ signature += data[0]
+ signature += data[1]
+ self.top.printInfo("Signature: %X, %X" % (byte2int(signature[0]), byte2int(signature[1])))
+ return signature
+
+ def erase(self):
+ self.__initChip()
+ self.applyGND(True)
+ self.applyVCC(True)
+ self.__loadCommand(1) # set P3.2
+ self.top.cmdSetVPPVoltage(5)
+ self.__loadCommand(5) # VPP on
+ self.applyVPP(True)
+ self.top.cmdDelay(0.5)
+ self.__setPx(P26=1, P33=1)
+ self.top.cmdSetVPPVoltage(12)
+ self.__runCommandSync(3)
+ self.top.cmdDelay(0.5)
+ self.applyVPP(False)
+ self.top.cmdSetVPPVoltage(5)
+ self.__setPx()
+ self.__loadCommand(6) # VPP off
+ self.top.flushCommands()
+ self.top.printInfo("{chipid}: Erasing flash, verifying ...".format(chipid=self.chipDescription.chipID))
+ ok = self.__verifyErase()
+ if ok == 0:
+ self.top.printInfo("{chipid}: Erase done.".format(chipid=self.chipDescription.chipID))
+ else:
+ self.top.printInfo("{chipid}: Erase failed!".format(chipid=self.chipDescription.chipID))
+
+ def readProgmem(self):
+ self.__initChip()
+ self.top.cmdEnableZifPullups(True)
+ self.applyGND(True)
+ self.applyVCC(True)
+ self.top.cmdSetVPPVoltage(5)
+ self.__loadCommand(5) # VPP on
+ self.applyVPP(True)
+ self.__loadCommand(1) # set nPROG
+ self.__setPx(P36=1, P37=1)
+ #self.__setPx(P26=1, P27=1, P36=1)
+ #self.__setPx()
+ image = ""
+ byteCount = 0
+ self.progressMeterInit("Reading Flash", self.flashPageSize*self.flashPages)
+ for addr in range(0, self.flashPageSize*self.flashPages):
+ self.progressMeter(addr)
+ self.__loadAddress(addr)
+ #self.__runCommandSync(4)
+ self.top.cmdFPGARead(0x10)
+ byteCount += 1
+ if byteCount == self.top.getBufferRegSize():
+ image += self.top.cmdReadBufferReg(byteCount)
+ byteCount = 0
+ image += self.top.cmdReadBufferReg(byteCount)
+ self.applyVPP(False)
+ self.__setPx()
+ self.__loadCommand(6) # VPP off
+ self.top.flushCommands()
+ self.progressMeterFinish()
+
+ return image
+
+ def writeProgmem(self, image):
+ if len(image) > self.flashPageSize*self.flashPages:
+ self.throwError("Invalid FLASH image size %d (expected <=%d)" %\
+ (len(image), self.flashPageSize*self.flashPages))
+ self.__initChip()
+ self.top.cmdEnableZifPullups(True)
+ self.applyGND(True)
+ self.applyVCC(True)
+ self.__loadCommand(1) # set P3.2
+ self.top.cmdSetVPPVoltage(5)
+ self.__loadCommand(5) # VPP on
+ self.applyVPP(True)
+ self.__setPx(P27=1, P33=1, P36=1, P37=1)
+ self.top.cmdSetVPPVoltage(12)
+ self.progressMeterInit("Writing Flash", len(image))
+ for addr in range(0, len(image)):
+ self.progressMeter(addr)
+ data = byte2int(image[addr])
+ if data != 0xFF:
+ self.__loadData(data)
+ self.__loadAddress(addr)
+ self.__loadCommand(3)
+ ok = self.__progWait()
+ if (ok & self.STAT_ERR) != 0:
+ self.throwError("Write byte failed.")
+ self.top.flushCommands()
+ self.applyVPP(False)
+ self.top.cmdSetVPPVoltage(5)
+ self.__setPx()
+ self.__loadCommand(6) # VPP off
+ self.progressMeterFinish()
+ ok = self.__verifyProgmem(image)
+ if ok == 0:
+ self.top.printInfo("{chipid}: Write flash done.".format(chipid = self.chipDescription.chipID))
+ else:
+ self.top.printInfo("{chipid}: Write flash failed!".format(chipid = self.chipDescription.chipID))
+
+ def readLockbits(self):
+ self.__initChip()
+ self.top.cmdEnableZifPullups(True)
+ self.applyGND(True)
+ self.applyVCC(True)
+ self.top.cmdSetVPPVoltage(5)
+ self.__loadCommand(5) # VPP on
+ self.applyVPP(True)
+ self.__loadCommand(1) # set nPROG
+ self.__setPx(P26=1, P27=1, P36=1)
+ data = ""
+ self.top.cmdFPGARead(0x10)
+ data += self.top.cmdReadBufferReg()
+ self.applyVPP(False)
+ self.__loadCommand(6) # VPP off
+ lockbits = ""
+ lockbits += data[0]
+ return lockbits
+
+ def writeLockbits(self, image):
+ if len(image) != 1:
+ self.throwError("Invalid lock-bits image size %d (expected %d)" %\
+ (len(image), 1))
+ self.progressMeterInit("Writing lock bits", 3)
+ lbMask = 0x04
+ lb=byte2int(image[0])
+ if(lb & lbMask ):
+ self.progressMeter(1)
+ self.__writeLockbit(1)
+ lbMask <<= 1
+ if(lb & lbMask ):
+ self.progressMeter(2)
+ self.__writeLockbit(2)
+ lbMask <<= 1
+ if(lb & lbMask ):
+ self.progressMeter(3)
+ self.__writeLockbit(3)
+ self.progressMeterFinish()
+
+ def __writeLockbit(self, lb):
+ self.__initChip()
+ self.applyGND(True)
+ self.applyVCC(True)
+ self.__loadCommand(1)
+ self.top.cmdSetVPPVoltage(5)
+ self.__loadCommand(5) # VPP on
+ self.applyVPP(True)
+ self.top.cmdSetVPPVoltage(12)
+ if(lb == 1 ):
+ self.__setPx(P26=1, P27=1, P33=1, P36=1, P37=1)
+ self.__runCommandSync(3)
+ elif(lb == 2 ):
+ self.__setPx(P26=1, P27=1, P33=1, P36=0, P37=0)
+ self.__runCommandSync(3)
+ elif(lb == 3 ):
+ self.__setPx(P26=1, P27=0, P33=1, P36=1, P37=0)
+ self.__runCommandSync(3)
+ self.top.flushCommands()
+ self.applyVPP(False)
+ self.top.cmdSetVPPVoltage(5)
+ self.__setPx()
+ self.__loadCommand(6) # VPP off
+
+ def __verifyErase(self):
+ ok = 0
+ image = self.readProgmem()
+ for addr in range(0, self.flashPageSize*self.flashPages):
+ if byte2int(image[addr]) != 0xFF:
+ ok = 1
+ return ok
+
+ def __verifyProgmem(self,image):
+ data = self.readProgmem()
+ ok = 0
+ for addr in range(0, len(image)-1):
+ if byte2int(image[addr]) != byte2int(data[addr]):
+ ok = 1
+ return ok
+
+ def __loadData(self, data):
+ self.top.cmdFPGAWrite(0x10, data)
+
+ def __loadAddress(self, addr):
+ self.top.cmdFPGAWrite(0x11, addr & 0x00FF)
+ self.top.cmdFPGAWrite(0x12, (addr >> 8) & 0x3FFF)
+
+ def __loadCommand(self, command):
+ self.top.cmdFPGAWrite(0x13, command & 0xFF)
+
+ def __runCommandSync(self, command):
+ self.__loadCommand(command)
+ self.__busyWait()
+
+ def __setPx(self, P26=0, P27=0, P33=0, P36=0, P37=0, nPSEN=0, RST=1):
+ data = 0
+ if P26:
+ data |= 1
+ if P27:
+ data |= 2
+ if P33:
+ data |= 4
+ if P36:
+ data |= 8
+ if P37:
+ data |= 16
+ if nPSEN:
+ data |= 32
+ if RST:
+ data |= 64
+ self.top.cmdFPGAWrite(0x16, data)
+
+ def __getStatusFlags(self):
+ self.top.cmdFPGARead(0x12)
+ stat = self.top.cmdReadBufferReg()
+ return byte2int(stat[0])
+
+ def __busy(self):
+ return bool(self.__getStatusFlags() & self.STAT_BUSY)
+
+ def __busyWait(self):
+ for i in range(0, 26):
+ if not self.__busy():
+ return
+ self.top.hostDelay(0.001)
+ self.throwError("Timeout in busywait.")
+
+ def __progWait(self):
+ for i in range(0,4):
+ self.top.cmdFPGARead(0x12)
+ stat = self.top.cmdReadBufferReg()
+ if (byte2int(stat[0]) & self.STAT_BUSY) == 0:
+ return byte2int(stat[0])
+ self.top.hostDelay(0.001)
+ self.throwError("Timeout in busywait.")
+lockbitDesc = (
+ BitDescription(0, "Unused"),
+ BitDescription(1, "Unused"),
+ BitDescription(2, "BLB01 - further programming of flash mem. is disabled"),
+ BitDescription(3, "BLB02 - verify disabled"),
+ BitDescription(4, "BLB03 - external execution disabled"),
+ BitDescription(5, "Unused"),
+ BitDescription(6, "Unused"),
+ BitDescription(7, "Unused"),
+ BitDescription(8, "Unused"),
+)
+ChipDescription(
+ Chip_AT89S52dip40,
+ bitfile = "at89s5xdip40",
+ chipID = "at89s52dip40",
+ runtimeID = (0x0005, 0x01),
+ chipVendors = "Atmel",
+ description = "AT89S52",
+ lockbitDesc = lockbitDesc,
+ maintainer = None,
+ packages = ( ("DIP40", ""), )
+)
diff --git a/libtoprammer/chips/microchip01/__init__.py b/libtoprammer/chips/microchip01/__init__.py
new file mode 100644
index 0000000..bc1cdbd
--- /dev/null
+++ b/libtoprammer/chips/microchip01/__init__.py
@@ -0,0 +1,6 @@
+# Import all chip modules in **ALPHABETICAL** order
+
+from pic10f200dip8 import *
+from pic10f202dip8 import *
+from pic12f508dip8 import *
+from pic16f59sip6 import *
diff --git a/libtoprammer/chips/microchip_common.py b/libtoprammer/chips/microchip01/microchip01_common.py
index db05cb8..b121392 100644
--- a/libtoprammer/chips/microchip_common.py
+++ b/libtoprammer/chips/microchip01/microchip01_common.py
@@ -22,7 +22,7 @@
from libtoprammer.chip import *
-class Chip_Microchip_common(Chip):
+class Chip_Microchip01_common(Chip):
CMD_LOAD_DATA_FOR_PGM = 0x02
CMD_READ_DATA_FROM_PGM = 0x04
CMD_INCREMENT_ADDRESS = 0x06
@@ -56,6 +56,7 @@ class Chip_Microchip_common(Chip):
self.eepromPages = eepromPages # Nr of EEPROM pages
self.fuseBytes = fuseBytes # Nr of fuse bytes
self.PC=0
+ self.isInPmMode=False
def readSignature(self):
@@ -65,15 +66,19 @@ class Chip_Microchip_common(Chip):
return signature
def erase(self):
- self.__erase()
+ if(hasattr(self,'osccalAddr')):
+ self.__erase()
+ else:
+ self.__erase(keepOSCCAL=False)
- def __erase(self, keepConfigWord=False):
+ def __erase(self, keepConfigWord=False, keepOSCCAL=True, keepUserIDLocation=False):
OSCCAL = 0xfff
+ self.__enterPM()
if(keepConfigWord):
self.progressMeterInit("Reading ConfigWord for backup", 0)
CW = self.__getConfigWord()
self.progressMeterFinish()
- self.__enterPM()
+ if(keepOSCCAL):
self.progressMeterInit("Reading OSCCAL)", 0)
self.__setPC(self.osccalAddr)
self.__sendReadFlashInstr()
@@ -82,22 +87,25 @@ class Chip_Microchip_common(Chip):
self.__readSDOBufferHigh()
OSCCAL=self.top.cmdReadBufferReg16()
self.progressMeterFinish()
- if(OSCCAL == 0xfff):
- self.progressMeterInit("OSCCAL value lost, restoring from backup location ...", 0)
- self.__setPC(self.osccalBackupAddr-self.osccalAddr)
- self.__sendReadFlashInstr()
- self.top.cmdDelay(0.00005)
- self.__readSDOBufferLow()
- self.__readSDOBufferHigh()
- OSCCAL=self.top.cmdReadBufferReg16()
- self.progressMeterFinish()
- #print ("osccal: %x\n" % OSCCAL)
+ if(OSCCAL == 0xfff):
+ self.progressMeterInit("OSCCAL value lost, restoring from backup location ...", 0)
+ self.__setPC(self.osccalBackupAddr-self.osccalAddr)
+ self.__sendReadFlashInstr()
+ self.top.cmdDelay(0.00005)
+ self.__readSDOBufferLow()
+ self.__readSDOBufferHigh()
+ OSCCAL=self.top.cmdReadBufferReg16()
+ self.progressMeterFinish()
+ #print ("osccal: %x\n" % OSCCAL)
+ #erase User ID Location and backup osccal Tooo
+ if(not keepUserIDLocation):
+ self.__setPC(self.userIDLocationAddr)
self.progressMeterInit("Erasing chip", 0)
self.__sendInstr(self.CMD_BULK_ERASE_PGM)
self.top.hostDelay(0.01) #Tera
self.progressMeterFinish()
- #OSCCAL=0xC18
- if(OSCCAL != 0xfff):
+ #OSCCAL=0xC12
+ if(keepOSCCAL and OSCCAL != 0xfff):
self.__enterPM()
self.progressMeterInit("Writing osccal, value %x" % OSCCAL, 0)
self.__setPC(self.osccalAddr)
@@ -110,6 +118,7 @@ class Chip_Microchip_common(Chip):
self.progressMeterInit("Write read ConfigWord, value %x" % CW, 0)
self.__writeConfigWord(CW)
self.progressMeterFinish()
+ self.__exitPM()
def readProgmem(self):
@@ -133,9 +142,11 @@ class Chip_Microchip_common(Chip):
bufferedBytes = 0
image += self.top.cmdReadBufferReg(bufferedBytes)
self.progressMeterFinish()
+ self.__exitPM()
return image
def writeProgmem(self, image):
+ self.__enterPM()
nrWords = self.flashPages * self.flashPageSize
if len(image) > nrWords * 2 or len(image) % 2 != 0:
self.throwError("Invalid flash image size %d (expected <=%d and word aligned)" %\
@@ -154,54 +165,113 @@ class Chip_Microchip_common(Chip):
self.__sendWriteFlashInstr()
self.progressMeterFinish()
+ self.__exitPM()
def readFuse(self):
+ self.__enterPM()
fuses = []
self.progressMeterInit("Reading fuses (configuration word)", 0)
- CW = self.__getConfigWord()
- fuses.append(int2byte(CW & 0x00ff))
- fuses.append(int2byte((CW >> 8) & 0x00ff))
+ for CW in self.__getConfigWord():
+ fuses.append(int2byte(CW & 0x00ff))
+ fuses.append(int2byte((CW >> 8) & 0x00ff))
self.progressMeterFinish()
+ self.__exitPM()
return b"".join(fuses)
+
+ def readUserIdLocation(self):
+ self.__enterPM()
+ self.__setPC(self.userIDLocationAddr)
+ for i in range(0, self.userIDLocationSize):
+ self.__incrementPC(1)
+ self.__sendReadFlashInstr()
+ self.top.hostDelay(0.00002)
+ self.__readSDOBufferLow()
+ self.__readSDOBufferHigh()
+ self.__exitPM()
+ return self.top.cmdReadBufferReg()[0:2*self.userIDLocationSize-1]
+
+ def writeUserIdLocation(self, image):
+ if len(image) > self.userIDLocationSize * 2 or len(image) % 2 != 0:
+ self.throwError("Invalid flash image size %d (expected <=%d and word aligned)" %\
+ (len(image), self.userIDLocationSize * 2))
+ self.__enterPM()
+ self.__setPC(self.userIDLocationAddr)
+ self.progressMeterInit("Writing User ID Location", len(image) // 2)
+ for word in range(0, len(image) // 2):
+ self.progressMeter(word)
+ #do not swap following two lines
+ self.__incrementPC(1)
+ self.__sendInstr(self.CMD_LOAD_DATA_FOR_PGM)
+ WD = (byte2int(image[word * 2 + 1])<<8) | byte2int(image[word * 2 + 0])
+ if(WD != 0xfff):
+ self.__setSDI(WD)
+ self.top.hostDelay(0.00002)
+ self.__sendWriteFlashInstr()
+ self.progressMeterFinish()
+ self.__exitPM()
+
+ def __getConfigWordSize(self):
+ return self.fuseBytes // 2
def __getConfigWord(self):
self.__enterPM()
self.__setPC(self.configWordAddr)
- self.__sendReadFlashInstr()
- self.top.cmdDelay(0.00002)
- self.__readSDOBufferLow()
- self.__readSDOBufferHigh()
- return self.top.cmdReadBufferReg16()
+ retVal=[]
+ for i in range(0,self.__getConfigWordSize()):
+ self.__sendReadFlashInstr()
+ self.top.cmdDelay(0.00002)
+ self.__readSDOBufferLow()
+ self.__readSDOBufferHigh()
+ retVal.append(self.top.cmdReadBufferReg16())
+ self.__incrementPC(1)
+ return retVal
def writeFuse(self, image):
- if len(image) != 2:
+ self.__enterPM()
+ if len(image) != 2*self.__getConfigWordSize():
self.throwError("Invalid Fuses image size %d (expected %d)" %\
- (len(image), 2))
+ (len(image), 2*self.__getConfigWordSize()))
self.progressMeterInit("Writing fuses", 0)
#print "image1:%x,,%x,,%x" % (byte2int(image[0]),byte2int(image[1]),byte2int(image[1])<<8)
- self.__writeConfigWord((byte2int(image[1])<<8) | byte2int(image[0]))
+ CW=[]
+ for tBytes in zip(image[::2],image[1::2]):
+ CW.append((byte2int(image[1])<<8) | byte2int(image[0]))
+ self.__writeConfigWord(CW)
self.progressMeterFinish()
+ self.__exitPM()
- def __writeConfigWord(self, configWord16):
+ def __writeConfigWord(self, listConfigWord16):
self.__enterPM()
self.__setPC(self.configWordAddr)
- self.__sendInstr(self.CMD_LOAD_DATA_FOR_PGM)
- self.__setSDI(configWord16)
- self.top.hostDelay(0.00002)
- self.__sendWriteFlashInstr()
+ for configWord16 in listConfigWord16:
+ self.__sendInstr(self.CMD_LOAD_DATA_FOR_PGM)
+ self.__setSDI(configWord16)
+ self.top.hostDelay(0.00002)
+ self.__sendWriteFlashInstr()
+ self.__incrementPC(1)
def __readSignature(self):
+ if(hasattr(self,'deviceIDAddr')):
+ idAddr = self.deviceIDAddr
+ idSize = 1
+ else:
+ idAddr = self.userIDLocationAddr
+ idSize = self.userIDLocationSize
self.__enterPM()
- self.__incrementPC(self.userIDLocationAddr)
- for i in range(0, self.userIDLocationSize):
+ self.__incrementPC(idAddr)
+ for i in range(0, idSize):
self.__incrementPC(1)
self.__sendReadFlashInstr()
self.top.hostDelay(0.00002)
self.__readSDOBufferLow()
self.__readSDOBufferHigh()
- return self.top.cmdReadBufferReg()[0:2*self.userIDLocationSize-1]
-
+ self.__exitPM()
+ return self.top.cmdReadBufferReg()[0:2*idSize-1]
+
def __enterPM(self):
+ if self.isInPmMode:
+ self.__setPC(self.logicalFlashSize - 1)
+ return
self.PC = self.logicalFlashSize - 1
"Enter HV programming mode. Vdd first entry mode"
self.applyVCC(False)
@@ -225,6 +295,7 @@ class Chip_Microchip_common(Chip):
#self.top.cmdEnableZifPullups(True)
self.top.cmdDelay(0.000005) #least 5us is required to reach Vdd first entry PM
+ self.isInPmMode=True
def __checkSignature(self):
signature = self.__readSignature()
@@ -247,6 +318,7 @@ class Chip_Microchip_common(Chip):
self.applyGND(False)
self.top.hostDelay(0.000005)
self.applyVCC(False)
+ self.isInPmMode=False
def __sendReadFlashInstr(self):
'''
diff --git a/libtoprammer/chips/pic10f200dip8.py b/libtoprammer/chips/microchip01/pic10f200dip8.py
index b2ccc2a..855f7a1 100644
--- a/libtoprammer/chips/pic10f200dip8.py
+++ b/libtoprammer/chips/microchip01/pic10f200dip8.py
@@ -20,19 +20,21 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
-from microchip_common import *
+from microchip01_common import *
-class Chip_Pic18F200dip8(Chip_Microchip_common):
+class Chip_Pic10F200dip8(Chip_Microchip01_common):
voltageVDD = 5
voltageVPP =13
#CONFIGURATION WORD FOR PIC10F200/202/204/206
#X X X X X X X MCLRE /CP WDT X X
logicalFlashSize = 0x200
userIDLocationSize = 4
+ SUPPORT_SIGREAD = (0 << 1)
+
def __init__(self):
- Chip_Microchip_common.__init__(self,
+ Chip_Microchip01_common.__init__(self,
chipPackage = "DIP8",
chipPinVCC = 2,
chipPinsVPP = 8,
@@ -48,14 +50,34 @@ class Chip_Pic18F200dip8(Chip_Microchip_common):
self.osccalAddr = self.flashPageSize-1
self.userIDLocationAddr = self.flashPageSize
self.osccalBackupAddr = self.userIDLocationAddr + self.userIDLocationSize
+ self.programMemoryByteAddressRange = [(0,2*self.flashPageSize)]
+ self.configWordByteAddressRange = [(2*self.configWordAddr,2*self.configWordAddr+1), (2*0xFFF, 2*0xFFF+1)]
+ self.userIDLocationByteAddressRange = [(2*self.userIDLocationAddr, 2*(self.userIDLocationAddr+self.userIDLocationSize)-1)]
+
+
+fuseDesc = (
+ BitDescription(0, "Unused"),
+ BitDescription(1, "Unused"),
+ BitDescription(2, "WDTE"),
+ BitDescription(3, "!CP"),
+ BitDescription(4, "MCLRE"),
+ BitDescription(5, "Unused"),
+ BitDescription(6, "Unused"),
+ BitDescription(7, "Unused"),
+ BitDescription(8, "Unused"),
+ BitDescription(9, "Unused"),
+ BitDescription(10, "Unused"),
+ BitDescription(11, "Unused"),
+)
ChipDescription(
- Chip_Pic18F200dip8,
- bitfile = "pic10fXXXdip8",
+ Chip_Pic10F200dip8,
+ bitfile = "pic10fxxxdip8",
chipID = "pic10f200dip8",
- runtimeID = (0x000D, 0x01),
+ runtimeID = (0xDE01, 0x01),
chipVendors = "Microchip",
description = "PIC10F200, PIC10F204, PIC10F220",
packages = ( ("DIP8", ""), ),
+ fuseDesc = fuseDesc,
maintainer = "Pavel Stemberk <stemberk@gmail.com>",
)
diff --git a/libtoprammer/chips/pic10f202dip8.py b/libtoprammer/chips/microchip01/pic10f202dip8.py
index a7a95e7..5c835bb 100644
--- a/libtoprammer/chips/pic10f202dip8.py
+++ b/libtoprammer/chips/microchip01/pic10f202dip8.py
@@ -20,18 +20,19 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
-from microchip_common import *
+from microchip01_common import *
-class Chip_Pic18F202dip8(Chip_Microchip_common):
+class Chip_Pic10F202dip8(Chip_Microchip01_common):
voltageVDD = 5
voltageVPP = 13
#CONFIGURATION WORD FOR PIC10F200/202/204/206
#X X X X X X X MCLRE /CP WDT X X
logicalFlashSize = 0x400
userIDLocationSize = 4
+ SUPPORT_SIGREAD = (0 << 1)
def __init__(self):
- Chip_Microchip_common.__init__(self,
+ Chip_Microchip01_common.__init__(self,
chipPackage="DIP8",
chipPinVCC=2,
chipPinsVPP=8,
@@ -47,14 +48,34 @@ class Chip_Pic18F202dip8(Chip_Microchip_common):
self.osccalAddr = self.flashPageSize - 1
self.userIDLocationAddr = self.flashPageSize
self.osccalBackupAddr = self.userIDLocationAddr + self.userIDLocationSize
+ self.programMemoryByteAddressRange = [(0,2*self.flashPageSize)]
+ self.configWordByteAddressRange = [(2*self.configWordAddr,2*self.configWordAddr+1), (2*0xFFF, 2*0xFFF+1)]
+ self.userIDLocationByteAddressRange = [(2*self.userIDLocationAddr, 2*(self.userIDLocationAddr+self.userIDLocationSize)-1)]
+
+
+fuseDesc = (
+ BitDescription(0, "Unused"),
+ BitDescription(1, "Unused"),
+ BitDescription(2, "WDTE"),
+ BitDescription(3, "!CP"),
+ BitDescription(4, "MCLRE"),
+ BitDescription(5, "Unused"),
+ BitDescription(6, "Unused"),
+ BitDescription(7, "Unused"),
+ BitDescription(8, "Unused"),
+ BitDescription(9, "Unused"),
+ BitDescription(10, "Unused"),
+ BitDescription(11, "Unused"),
+)
ChipDescription(
- Chip_Pic18F202dip8,
- bitfile = "pic10fXXXdip8",
+ Chip_Pic10F202dip8,
+ bitfile = "pic10fxxxdip8",
chipID = "pic10f202dip8",
- runtimeID = (0x000D, 0x01),
+ runtimeID = (0xDE01, 0x01),
chipVendors = "Microchip",
description = "PIC10F202, PIC10F206, PIC10F222",
packages = (("DIP8", ""),),
+ fuseDesc = fuseDesc,
maintainer = "Pavel Stemberk <stemberk@gmail.com>",
)
diff --git a/libtoprammer/chips/microchip01/pic12f508dip8.py b/libtoprammer/chips/microchip01/pic12f508dip8.py
new file mode 100644
index 0000000..63024fa
--- /dev/null
+++ b/libtoprammer/chips/microchip01/pic12f508dip8.py
@@ -0,0 +1,75 @@
+"""
+# TOP2049 Open Source programming suite
+#
+# Microchip PIC12F508 DIP8
+#
+# Copyright (c) 2013 Pavel Stemberk <stemberk@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""
+
+from microchip01_common import *
+
+class Chip_Pic12F508dip8(Chip_Microchip01_common):
+ voltageVDD = 5
+ voltageVPP = 13
+ #CONFIGURATION WORD FOR PIC10F200/202/204/206
+ #X X X X X X X MCLRE /CP WDT X X
+ logicalFlashSize = 0x400
+ userIDLocationSize = 4
+ SUPPORT_SIGREAD = (0 << 1)
+
+ def __init__(self):
+ Chip_Microchip01_common.__init__(self,
+ chipPackage="DIP8",
+ chipPinVCC=1,
+ chipPinsVPP=4,
+ chipPinGND=8,
+ signature="",
+ flashPageSize=0x200,
+ flashPages=1,
+ eepromPageSize=0,
+ eepromPages=0,
+ fuseBytes=2
+ )
+ self.configWordAddr = self.logicalFlashSize - 1
+ self.osccalAddr = self.flashPageSize - 1
+ self.userIDLocationAddr = self.flashPageSize
+ self.osccalBackupAddr = self.userIDLocationAddr + self.userIDLocationSize
+fuseDesc = (
+ BitDescription(0, "FOSC[0] 00=LP, 01=XT, 10=INTOSC, 11=EXTRC"),
+ BitDescription(1, "FOSC[1]"),
+ BitDescription(2, "WDTE"),
+ BitDescription(3, "!CP"),
+ BitDescription(4, "MCLRE"),
+ BitDescription(5, "Unused"),
+ BitDescription(6, "Unused"),
+ BitDescription(7, "Unused"),
+ BitDescription(8, "Unused"),
+ BitDescription(9, "Unused"),
+ BitDescription(10, "Unused"),
+ BitDescription(11, "Unused"),
+)
+ChipDescription(
+ Chip_Pic12F508dip8,
+ bitfile = "microchip01dip8",
+ chipID = "pic12f508dip8",
+ runtimeID = (0xDE02, 0x01),
+ chipVendors = "Microchip",
+ description = "PIC12F508",
+ fuseDesc = fuseDesc,
+ packages = (("DIP8", ""),),
+ maintainer = "Pavel Stemberk <stemberk@gmail.com>",
+)
diff --git a/libtoprammer/chips/microchip01/pic16f59sip6.py b/libtoprammer/chips/microchip01/pic16f59sip6.py
new file mode 100644
index 0000000..e6c9287
--- /dev/null
+++ b/libtoprammer/chips/microchip01/pic16f59sip6.py
@@ -0,0 +1,81 @@
+"""
+# TOP2049 Open Source programming suite
+#
+# Microchip PIC16F59 SIP6
+#
+# Copyright (c) 2013 Pavel Stemberk <stemberk@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""
+
+from microchip01_common import *
+
+
+class Chip_Pic16F59sip6(Chip_Microchip01_common):
+ voltageVDD = 5
+ voltageVPP =13
+ #CONFIGURATION WORD FOR PIC10F200/202/204/206
+ #X X X X X X X MCLRE /CP WDT X X
+ logicalFlashSize = 0x1000
+ userIDLocationSize = 4
+ SUPPORT_SIGREAD = (0 << 1)
+
+
+ def __init__(self):
+ Chip_Microchip01_common.__init__(self,
+ chipPackage = "DIP10",
+ chipPinVCC = 9,
+ chipPinsVPP = 10,
+ chipPinGND = 8,
+ signature = "",
+ flashPageSize = 0x200,
+ flashPages = 4,
+ eepromPageSize = 0,
+ eepromPages = 0,
+ fuseBytes = 2
+ )
+ self.configWordAddr = self.logicalFlashSize-1
+ self.userIDLocationAddr = self.flashPageSize
+ self.programMemoryByteAddressRange = [(0,2*self.flashPageSize)]
+ self.configWordByteAddressRange = [(2*self.configWordAddr,2*self.configWordAddr+self.fuseBytes-1)]
+ self.userIDLocationByteAddressRange = [(2*self.userIDLocationAddr, 2*(self.userIDLocationAddr+self.userIDLocationSize)-1)]
+
+
+fuseDesc = (
+ BitDescription(0, "FOSC0"),
+ BitDescription(1, "FOSC1 - 00=LP, 01=XT, 10=HS, 11=RC"),
+ BitDescription(2, "WDTE"),
+ BitDescription(3, "!CP"),
+ BitDescription(4, "Unused"),
+ BitDescription(5, "Unused"),
+ BitDescription(6, "Unused"),
+ BitDescription(7, "Unused"),
+ BitDescription(8, "Unused"),
+ BitDescription(9, "Unused"),
+ BitDescription(10, "Unused"),
+ BitDescription(11, "Unused"),
+)
+
+ChipDescription(
+ Chip_Pic16F59sip6,
+ bitfile = "microchip01sip6",
+ chipID = "pic16f59sip6",
+ runtimeID = (0xDE05, 0x01),
+ chipVendors = "Microchip",
+ description = "PIC16F59",
+ packages = ( ("DIP10", ""), ),
+ fuseDesc = fuseDesc,
+ maintainer = "Pavel Stemberk <stemberk@gmail.com>",
+)
diff --git a/libtoprammer/chips/microchip02/__init__.py b/libtoprammer/chips/microchip02/__init__.py
new file mode 100644
index 0000000..fd04f4e
--- /dev/null
+++ b/libtoprammer/chips/microchip02/__init__.py
@@ -0,0 +1,5 @@
+# Import all chip modules in **ALPHABETICAL** order
+
+from pic10f322dip8 import *
+from pic12f1822dip8 import *
+from pic16f1824dip14 import *
diff --git a/libtoprammer/chips/microchip02/microchip02_common.py b/libtoprammer/chips/microchip02/microchip02_common.py
new file mode 100644
index 0000000..b31874d
--- /dev/null
+++ b/libtoprammer/chips/microchip02/microchip02_common.py
@@ -0,0 +1,449 @@
+"""
+# TOP2049 Open Source programming suite
+#
+# Microchip common
+#
+# Copyright (c) 2012 Pavel Stemberk <stemberk@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""
+
+from libtoprammer.chip import *
+
+class Chip_Microchip02_common(Chip):
+ CMD_LOAD_CONFIGURATION = 0x00
+ CMD_LOAD_DATA_FOR_PGM = 0x02
+ CMD_READ_DATA_FROM_PGM = 0x04
+ CMD_INCREMENT_ADDRESS = 0x06
+ CMD_RESET_ADDRESS = 0x16
+ CMD_BEGIN_INTERNALLY_TIMED_PROGRAMMING = 0x08
+ CMD_BEGIN_EXTERNALLY_TIMED_PROGRAMMING = 0x18
+ CMD_END_EXTERNALLY_TIMED_PROGRAMMING = 0x0A
+ CMD_BULK_ERASE_PGM = 0x09
+ CMD_ROW_ERASE_PGM = 0x11
+
+ PROGCMD_SENDINSTR = 1
+ PROGCMD_SENDDATA = 2
+ PROGCMD_READDATA = 3
+
+ STAT_BUSY= 0x01
+ STAT_SDIO = 0x02
+
+ def __init__(self,
+ chipPackage, chipPinVCC, chipPinsVPP, chipPinGND,
+ signature,
+ flashPageSize, flashPages,
+ eepromPageSize, eepromPages,
+ fuseBytes
+ ):
+ Chip.__init__(self,
+ chipPackage = chipPackage,
+ chipPinVCC = chipPinVCC,
+ chipPinsVPP = chipPinsVPP,
+ chipPinGND = chipPinGND)
+ self.signature = signature
+ self.flashPageSize = flashPageSize # Flash page size, in words
+ self.flashPages = flashPages # Nr of flash pages
+ self.eepromPageSize = eepromPageSize # EEPROM page size, in bytes
+ self.eepromPages = eepromPages # Nr of EEPROM pages
+ self.fuseBytes = fuseBytes # Nr of fuse bytes
+ self.PC=0
+ self.isInPmMode = False
+ self.isInsideProgramMemoryArea = True
+ #self.rowSize = rowSize
+ #self.nLatches = nLatches
+ #self.logicalFlashProgramMemorySize = logicalFlashProgramMemorySize
+ #self.logicalFlashConfigurationMemorySize = logicalFlashConfigurationMemorySize
+
+
+ def readSignature(self):
+ self.progressMeterInit("Reading signature", 0)
+ signature = self.__readSignature()
+ self.progressMeterFinish()
+ return signature
+
+ def erase(self):
+ self.__erase()
+
+ def __erase(self, keepConfigWord=False, keepUserIDLocation=False):
+ OSCCAL = 0xfff
+ self.__enterPM()
+ if(keepConfigWord):
+ self.progressMeterInit("Reading ConfigWord for backup", 0)
+ CW = self.__getConfigWord()
+ self.progressMeterFinish()
+ #erase User ID Location and backup osccal Tooo
+ if(not keepUserIDLocation):
+ self.__enterConfigArea()
+ self.__setPC(self.userIDLocationAddr)
+ self.progressMeterInit("Erasing chip", 0)
+ self.__sendInstr(self.CMD_BULK_ERASE_PGM)
+ self.top.hostDelay(0.01) #Tera
+ self.progressMeterFinish()
+ if(keepConfigWord):
+ self.progressMeterInit("Write ConfigWord, value %x" % CW, 0)
+ self.__writeConfigWord(CW)
+ self.progressMeterFinish()
+ self.__exitPM()
+
+
+ def readProgmem(self):
+ nrWords = self.flashPages * self.flashPageSize
+ image = ""
+ self.__enterPM()
+ self.progressMeterInit("Reading flash", nrWords)
+ bufferedBytes = 0
+ for word in range(0, nrWords):
+ self.__incrementPC(1)
+ self.__sendReadFlashInstr()
+ #self.__busyWait()
+ self.top.cmdDelay(0.00002) #20us wait - inconsistent data if skipped
+ self.__readSDOBufferLow()
+ bufferedBytes += 1
+ self.__readSDOBufferHigh()
+ bufferedBytes += 1
+ if bufferedBytes == self.top.getBufferRegSize():
+ image += self.top.cmdReadBufferReg(bufferedBytes)
+ self.progressMeter(word)
+ bufferedBytes = 0
+ image += self.top.cmdReadBufferReg(bufferedBytes)
+ self.progressMeterFinish()
+ self.__exitPM()
+ return image
+
+ def writeProgmem(self, image):
+ self.__enterPM()
+ nrWords = self.flashPages * self.flashPageSize
+ if len(image) > nrWords * 2 or len(image) % 2 != 0:
+ self.throwError("Invalid flash image size %d (expected <=%d and word aligned)" %\
+ (len(image), nrWords * 2))
+ self.__enterPM()
+ self.progressMeterInit("Writing flash", len(image) // 2)
+ for wordAddr in range(0, len(image) // 2):
+ self.progressMeter(wordAddr)
+ #do not swap following two lines
+ self.__incrementPC(1)
+ self.__sendInstr(self.CMD_LOAD_DATA_FOR_PGM)
+ WD = (byte2int(image[wordAddr * 2 + 1])<<8) | byte2int(image[wordAddr * 2 + 0])
+ if(WD != 0xfff):
+ self.__setSDI(WD)
+ self.top.hostDelay(0.00002)
+ self.__loadCommand(self.PROGCMD_SENDDATA)
+ self.top.hostDelay(0.000005)
+ self.__sendWriteFlashInstr()
+
+ self.progressMeterFinish()
+ self.__exitPM()
+
+ def readFuse(self):
+ self.__enterPM()
+ fuses = []
+ self.progressMeterInit("Reading fuses (configuration word)", 0)
+ for CW in self.__getConfigWord():
+ fuses.append(int2byte(CW & 0x00ff))
+ fuses.append(int2byte((CW >> 8) & 0x00ff))
+ self.progressMeterFinish()
+ self.__exitPM()
+ return b"".join(fuses)
+
+ def readUserIdLocation(self):
+ self.__enterPM()
+ self.__enterConfigArea()
+ self.__setPC(self.userIDLocationAddr)
+ self.progressMeterInit("Reading User ID Location", 0)
+ for i in range(0, self.userIDLocationSize):
+ self.__sendReadFlashInstr()
+ self.top.hostDelay(0.00002)
+ self.__readSDOBufferLow()
+ self.__readSDOBufferHigh()
+ self.__incrementPC(1)
+ self.__exitPM()
+ self.progressMeterFinish()
+ return self.top.cmdReadBufferReg()[0:2*self.userIDLocationSize]
+
+ def writeUserIdLocation(self, image):
+ if len(image) > self.userIDLocationSize * 2 or len(image) % 2 != 0:
+ self.throwError("Invalid flash image size %d (expected <=%d and word aligned)" %\
+ (len(image), self.userIDLocationSize * 2))
+ self.__enterPM()
+ self.__enterConfigArea()
+ #self.__setPC(self.userIDLocationAddr)
+ self.__setPC(0x2004)
+ self.progressMeterInit("Writing User ID Location", (len(image) // 2) - 1)
+ for word in range(0, (len(image) // 2)):
+ self.progressMeter(word)
+ #do not swap following two lines
+ self.__sendInstr(self.CMD_LOAD_DATA_FOR_PGM)
+ WD = (byte2int(image[word * 2 + 1])<<8) | byte2int(image[word * 2 + 0])
+ self.__setSDI(WD)
+ #self.top.hostDelay(0.00002)
+ self.__loadCommand(self.PROGCMD_SENDDATA)
+ self.__incrementPC(1)
+ self.top.hostDelay(0.000005)
+ self.__sendWriteFlashInstr()
+ self.progressMeterFinish()
+ self.__exitPM()
+
+ def __getConfigWordSize(self):
+ return self.fuseBytes // 2
+
+ def __getConfigWord(self):
+ self.__enterPM()
+ self.__enterConfigArea()
+ self.__setPC(self.configWordAddr)
+ retVal=[]
+ for i in range(0,self.__getConfigWordSize()):
+ self.__sendReadFlashInstr()
+ self.top.cmdDelay(0.00002)
+ self.__readSDOBufferLow()
+ self.__readSDOBufferHigh()
+ self.__incrementPC(1)
+ retVal.append(self.top.cmdReadBufferReg16())
+
+ return retVal
+
+ def writeFuse(self, image):
+ self.__enterPM()
+ if len(image) != 2*self.__getConfigWordSize():
+ self.throwError("Invalid Fuses image size %d (expected %d)" %\
+ (len(image), 2*self.__getConfigWordSize()))
+ self.progressMeterInit("Writing fuses", 0)
+ #print "image1:%x,,%x,,%x" % (byte2int(image[0]),byte2int(image[1]),byte2int(image[1])<<8)
+ CW=[]
+ for tBytes in zip(image[::2],image[1::2]):
+ CW.append((byte2int(tBytes[1])<<8) | byte2int(tBytes[0]))
+ self.__writeConfigWord(CW)
+ self.progressMeterFinish()
+ self.__exitPM()
+
+ def __writeConfigWord(self, listConfigWord16):
+ #Externally timed writes are not supported
+ #for Configuration and Calibration bits. Any
+ #externally timed write to the Configuration
+ #or Calibration Word will have no effect on
+ #the targeted word.
+ self.__enterPM()
+ self.__enterConfigArea()
+ self.__setPC(self.configWordAddr-1)
+ print "PC:{:x}".format(self.PC)
+ for configWord16 in listConfigWord16:
+ self.__incrementPC(1)
+ print "write CW {:x}".format(configWord16)
+ self.__sendInstr(self.CMD_LOAD_DATA_FOR_PGM)
+ self.__setSDI(configWord16)
+ self.top.hostDelay(0.00002)
+ self.__loadCommand(self.PROGCMD_SENDDATA)
+ self.top.hostDelay(0.000005)
+ self.__sendInstr(self.CMD_BEGIN_INTERNALLY_TIMED_PROGRAMMING)
+ self.top.hostDelay(0.005)#TPINT
+
+
+ def __readSignature(self):
+ self.__enterPM()
+ self.__enterConfigArea()
+ self.__setPC(self.deviceIDAddr)
+ idSize = 1
+ for i in range(0, idSize):
+ self.__sendReadFlashInstr()
+ self.top.hostDelay(0.00002)
+ self.__readSDOBufferLow()
+ self.__readSDOBufferHigh()
+ self.__incrementPC(1)
+ self.__exitPM()
+ return self.top.cmdReadBufferReg()[0:2*idSize]
+
+ def __enterPM(self):
+ if self.isInPmMode:
+ self.__resetPC()
+ return
+ self.PC = 0
+ "Enter HV programming mode. Vdd first entry mode"
+ self.applyVCC(False)
+ self.applyVPP(False)
+ self.applyGND(False)
+ self.__setPins(0,0)
+ self.top.cmdSetVCCVoltage(self.voltageVDD)
+ self.top.cmdSetVPPVoltage(self.voltageVPP)
+ #self.top.cmdEnableZifPullups(True)
+ self.applyGND(True)
+
+ self.applyVCC(True)
+ self.top.cmdDelay(0.000005)
+
+ for i in range(0,2):
+ self.applyVPP(True)
+ self.top.cmdDelay(0.000005)
+ self.applyVPP(False)
+ self.top.cmdDelay(0.000031)
+ self.applyVPP(True)
+ #self.top.cmdEnableZifPullups(True)
+
+ self.top.cmdDelay(0.000005) #least 5us is required to reach Vdd first entry PM
+ self.isInPmMode=True
+
+ def __checkSignature(self):
+ signature = self.__readSignature()
+ if signature != self.signature:
+ msg = "Unexpected device signature. " +\
+ "Want %02X%02X%02X, but got %02X%02X%02X" % \
+ (byte2int(self.signature[0]), byte2int(self.signature[1]),
+ byte2int(self.signature[2]),
+ byte2int(signature[0]), byte2int(signature[1]),
+ byte2int(signature[2]))
+ if self.top.getForceLevel() >= 1:
+ self.printWarning(msg)
+ else:
+ self.throwError(msg)
+
+ def __exitPM(self):
+ "Exit HV programming mode. Vdd last exit mode"
+ self.__setPins(0,0)
+ self.applyVPP(False)
+ self.applyGND(False)
+ self.top.hostDelay(0.000005)
+ self.applyVCC(False)
+ self.isInPmMode=False
+
+ def __sendReadFlashInstr(self):
+ '''
+ '''
+ self.__sendInstr(self.CMD_READ_DATA_FROM_PGM)
+ self.__loadCommand(self.PROGCMD_READDATA)
+
+ def __sendWriteFlashInstr(self):
+ '''
+ '''
+ self.__sendInstr(self.CMD_BEGIN_EXTERNALLY_TIMED_PROGRAMMING)
+ self.top.hostDelay(0.001)#025) #Tprog
+ self.__sendInstr(self.CMD_END_EXTERNALLY_TIMED_PROGRAMMING)
+ self.top.hostDelay(0.0001) #Tdis
+
+ def __sendInstr(self, SDI):
+ '''
+ see __loadCommand for availabla commands
+ '''
+ self.top.cmdFPGAWrite(0x13, SDI & 0xFF)
+ self.__loadCommand(self.PROGCMD_SENDINSTR)
+ # We do not poll the busy flag, because that would result
+ # in a significant slowdown. We delay long enough for the
+ # command to finish execution, instead.
+ #self.top.hostDelay(0.001)
+ self.top.hostDelay(0.000005)
+
+ def __setSDI(self, sdi):
+ '''
+ set 14 bit sdi value
+ '''
+ self.top.cmdFPGAWrite(0x13, sdi & 0xFF)
+ self.top.cmdFPGAWrite(0x14, (sdi>>8) & 0x3F)
+
+ def __loadCommand(self, command):
+ '''
+ `define CMD_SENDINSTR 1
+ `define CMD_SENDDATA 2
+ `define CMD_READDATA 3
+ '''
+ self.top.cmdFPGAWrite(0x12, command & 0xFF)
+
+ def __runCommandSync(self, command):
+ self.__loadCommand(command)
+ self.__busyWait()
+
+ def __setPC(self, address):
+ if(self.isInsideProgramMemoryArea):
+ if(address >= self.logicalFlashProgramMemorySize):
+ raise(TOPException('Cannot set PC to address {:x}'.format(address)))
+ if(address < self.PC):
+ self.__resetPC()
+ self.__setPC(address)
+ else:
+ if(address < self.logicalFlashProgramMemorySize):
+ raise(TOPException('Cannot set PC to address {:x}'.format(address)))
+ if(address < self.PC):
+ self.__resetPC()
+ self.__enterConfigArea()
+ self.__setPC(address)
+ while(self.PC!=address):
+ self.__incrementPC(1)
+
+ def __incrementPC(self, count):
+ for address in range(0, count):
+ self.__sendInstr(self.CMD_INCREMENT_ADDRESS)
+ self.PC += 1
+ if(self.isInsideProgramMemoryArea):
+ if (self.PC == self.logicalFlashProgramMemorySize):
+ self.PC = 0
+ else:
+ if (self.PC == self.logicalFlashConfigurationMemorySize):
+ self.PC = self.logicalFlashProgramMemorySize
+
+ def __resetPC(self):
+ self.__sendInstr(self.CMD_RESET_ADDRESS)
+ self.PC = 0
+ self.isInsideProgramMemoryArea = True
+
+ def __enterConfigArea(self, wordLatched = 0):
+ self.__sendInstr(self.CMD_LOAD_CONFIGURATION)
+ self.__setSDI(wordLatched)
+ #self.top.hostDelay(0.00002)
+ self.__loadCommand(self.PROGCMD_SENDDATA)
+ self.PC = self.logicalFlashProgramMemorySize
+ self.isInsideProgramMemoryArea = False
+
+ def __setPins(self, ICSPCLK=0, SDIODRIVEN=0, SDIOVALUE=0):
+ '''
+ setPins
+ '''
+ data = 0
+ if ICSPCLK:
+ data |= 1
+ if SDIODRIVEN:
+ data |= 2
+ if SDIOVALUE:
+ data |= 4
+ self.top.cmdFPGAWrite(0x15, data)
+
+ def __getStatusFlags(self):
+ '''
+ '''
+ self.top.cmdFPGARead(0x12)
+ stat = self.top.cmdReadBufferReg()
+ return byte2int(stat[0])
+
+ def __readSDOBufferHigh(self):
+ self.top.cmdFPGARead(0x10)
+
+ def __readSDOBufferLow(self):
+ self.top.cmdFPGARead(0x13)
+
+ def __rawSDIOState(self):
+ return bool(self.__getStatusFlags() & self.STAT_SDIO)
+
+ def __busy(self):
+ return bool(self.__getStatusFlags() & self.STAT_BUSY)
+
+ def __busyWait(self):
+ for i in range(0, 100):
+ if not self.__busy():
+ return
+ self.top.hostDelay(0.01)
+ self.throwError("Timeout in busywait.")
+
+ def __waitHighSDIO(self):
+ for i in range(0, 100):
+ if self.__rawSDOState():
+ return
+ self.top.hostDelay(0.01)
+ self.throwError("Timeout waiting for SDO.")
diff --git a/libtoprammer/chips/microchip02/pic10f322dip8.py b/libtoprammer/chips/microchip02/pic10f322dip8.py
new file mode 100644
index 0000000..6bf7ae6
--- /dev/null
+++ b/libtoprammer/chips/microchip02/pic10f322dip8.py
@@ -0,0 +1,86 @@
+"""
+# TOP2049 Open Source programming suite
+#
+# Microchip PIC10F322 DIP8
+#
+# Copyright (c) 2013 Pavel Stemberk <stemberk@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""
+
+from microchip02_common import *
+
+class Chip_Pic10F322dip8(Chip_Microchip02_common):
+ voltageVDD = 3
+ voltageVPP = 8.5
+ #CONFIGURATION WORD FOR PIC10F200/202/204/206
+ #X X X X X X X MCLRE /CP WDT X X
+ logicalFlashProgramMemorySize = 0x2000
+ logicalFlashConfigurationMemorySize = 0x2000
+ userIDLocationSize = 4
+ rowSize = 32
+ nLatches = 16
+
+ def __init__(self):
+ Chip_Microchip02_common.__init__(self,
+ chipPackage="DIP8",
+ chipPinVCC=2,
+ chipPinsVPP=8,
+ chipPinGND=7,
+ signature="\x02\x84",
+ flashPageSize=0x200,
+ flashPages=1,
+ eepromPageSize=0,
+ eepromPages=0,
+ fuseBytes=2
+ )
+ self.configWordAddr = 0x2007
+ #self.osccalAddr = 0x2000
+ self.userIDLocationAddr = 0x2000
+ self.deviceIDAddr = 0x2006
+ self.programMemoryByteAddressRange = [(0,2*self.flashPageSize)]
+ self.configWordByteAddressRange = [(2*self.configWordAddr,2*self.configWordAddr+1)]
+ self.userIDLocationByteAddressRange = [(2*self.userIDLocationAddr, 2*(self.userIDLocationAddr+self.userIDLocationSize)-1)]
+
+ #self.osccalBackupAddr = self.userIDLocationAddr + self.userIDLocationSize
+
+fuseDesc = (
+ BitDescription(0, "FOSC, 1=CLKIN, 0=internal"),
+ BitDescription(1, "BOREN[0]"),
+ BitDescription(2, "BOREN[1]"),
+ BitDescription(3, "WDTE[0]"),
+ BitDescription(4, "WDTE[1]"),
+ BitDescription(5, "nPWRTE"),
+ BitDescription(6, "MCLRE, 1=RA3 is nMCLR, weak pull-up enabled"),
+ BitDescription(7, "nCP"),
+ BitDescription(8, "LVP"),
+ BitDescription(9, "LPBOREN"),
+ BitDescription(10, "BORV"),
+ BitDescription(11, "WRT[0]"),
+ BitDescription(12, "WRT[1] 11=write protection off"),
+ BitDescription(13, "Unused"),
+)
+
+ChipDescription(
+ Chip_Pic10F322dip8,
+ bitfile = "pic10fxxxdip8",
+ chipID = "pic10f322dip8",
+ runtimeID = (0xDE01, 0x01),
+ chipVendors = "Microchip",
+ description = "PIC10F322, PIC10LF322",
+ packages = (("DIP8", ""),),
+ fuseDesc = fuseDesc,
+ maintainer = "Pavel Stemberk <stemberk@gmail.com>",
+)
diff --git a/libtoprammer/chips/microchip02/pic12f1822dip8.py b/libtoprammer/chips/microchip02/pic12f1822dip8.py
new file mode 100644
index 0000000..cf69d32
--- /dev/null
+++ b/libtoprammer/chips/microchip02/pic12f1822dip8.py
@@ -0,0 +1,103 @@
+"""
+# TOP2049 Open Source programming suite
+#
+# Microchip PIC12F1822 DIP8
+#
+# Copyright (c) 2012 Pavel Stemberk <stemberk@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""
+
+from microchip02_common import *
+
+class Chip_Pic12F1822dip8(Chip_Microchip02_common):
+ voltageVDD = 3
+ voltageVPP = 8.5
+ #CONFIGURATION WORD FOR PIC10F200/202/204/206
+ #X X X X X X X MCLRE /CP WDT X X
+ logicalFlashProgramMemorySize = 0x8000
+ logicalFlashConfigurationMemorySize = 0x8000
+ rowSize = 16
+ nLatches = 16
+ userIDLocationSize = 4
+
+ def __init__(self):
+ Chip_Microchip02_common.__init__(self,
+ chipPackage="DIP8",
+ chipPinVCC=1,
+ chipPinsVPP=4,
+ chipPinGND=8,
+ signature="\x08\x27",
+ flashPageSize=0x800,
+ flashPages=1,
+ eepromPageSize=0,
+ eepromPages=0,
+ fuseBytes=4
+ )
+ self.configWordAddr = 0x8007
+ #self.osccalAddr = 0x2000
+ self.userIDLocationAddr = 0x8000
+ self.deviceIDAddr = 0x8006
+ self.programMemoryByteAddressRange = [(0,2*self.flashPageSize)]
+ self.configWordByteAddressRange = [(2*self.configWordAddr,2*self.configWordAddr+self.fuseBytes-1)]
+ self.userIDLocationByteAddressRange = [(2*self.userIDLocationAddr, 2*(self.userIDLocationAddr+self.userIDLocationSize)-1)]
+
+ #self.osccalBackupAddr = self.userIDLocationAddr + self.userIDLocationSize
+
+fuseDesc = (
+ BitDescription(0, "FOSC[0], 0=LP, 100=INTOSC"),
+ BitDescription(1, "FOSC[1]"),
+ BitDescription(2, "FOSC[2]"),
+ BitDescription(3, "WDTE[0], 00=WDT disabled, 11=WDT enabled"),
+ BitDescription(4, "WDTE[1]"),
+ BitDescription(5, "nPWRTE"),
+ BitDescription(6, "MCLRE, 1=nMCLR/Vpp pin is nMCLR, weak pull-up enabled, ignored if LVP=1 "),
+ BitDescription(7, "nCP 1=program memory code protection is disabled"),
+ BitDescription(8, "nCPD, 1=data memory code protection is disabled"),
+ BitDescription(9, "BOREN[0], 00=BOR disabled"),
+ BitDescription(10, "BOREN[1]"),
+ BitDescription(11, "nCLKOUTEN, 0=CLKOUT is enabled on CLKOUT pin"),
+ BitDescription(12, "IESO, 0=Internal/External Switchover mode is disabled"),
+ BitDescription(13, "FCMEM, 0=Fail-Safe Clock Monitor is disabled"),
+ BitDescription(14, "NA"),
+ BitDescription(15, "NA"),
+
+ BitDescription(16, "WRT[0], 11=Write protection off"),
+ BitDescription(17, "WRT[1]"),
+ BitDescription(18, "Unused"),
+ BitDescription(19, "Unused"),
+ BitDescription(20, "Unused"),
+ BitDescription(21, "Unused"),
+ BitDescription(22, "Unused"),
+ BitDescription(23, "Unused"),
+ BitDescription(24, "PLLEN, 0=4xPLL disabled"),
+ BitDescription(25, "STVREN, 1=Stack overflow or underflow will cause a reset"),
+ BitDescription(26, "BORV"),
+ BitDescription(27, "Unused"),
+ BitDescription(28, "nDEBUG, 0=ICSPCLK and ICSPDAT are dedicated to the debugger"),
+ BitDescription(29, "LVP 1=Low-voltage programming enabled"),
+)
+
+ChipDescription(
+ Chip_Pic12F1822dip8,
+ bitfile = "microchip01dip8",
+ chipID = "pic12f1822dip8",
+ runtimeID = (0xDE02, 0x01),
+ chipVendors = "Microchip",
+ description = "PIC12F1822, PIC12LF1822",
+ packages = (("DIP8", ""),),
+ fuseDesc = fuseDesc,
+ maintainer = "Pavel Stemberk <stemberk@gmail.com>",
+)
diff --git a/libtoprammer/chips/microchip02/pic16f1824dip14.py b/libtoprammer/chips/microchip02/pic16f1824dip14.py
new file mode 100644
index 0000000..2acf422
--- /dev/null
+++ b/libtoprammer/chips/microchip02/pic16f1824dip14.py
@@ -0,0 +1,103 @@
+"""
+# TOP2049 Open Source programming suite
+#
+# Microchip PIC16F1824 DIP14
+#
+# Copyright (c) 2013 Pavel Stemberk <stemberk@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""
+
+from microchip02_common import *
+
+class Chip_Pic16F1824dip14(Chip_Microchip02_common):
+ voltageVDD = 3
+ voltageVPP = 8.5
+ #CONFIGURATION WORD FOR PIC10F200/202/204/206
+ #X X X X X X X MCLRE /CP WDT X X
+ logicalFlashProgramMemorySize = 0x8000
+ logicalFlashConfigurationMemorySize = 0x8000
+ rowSize = 32
+ nLatches = 32
+ userIDLocationSize = 4
+
+ def __init__(self):
+ Chip_Microchip02_common.__init__(self,
+ chipPackage="DIP14",
+ chipPinVCC=1,
+ chipPinsVPP=4,
+ chipPinGND=14,
+ signature="\x43\x27",
+ flashPageSize=0x1000,
+ flashPages=1,
+ eepromPageSize=0,
+ eepromPages=0,
+ fuseBytes=4
+ )
+ self.configWordAddr = 0x8007
+ #self.osccalAddr = 0x2000
+ self.userIDLocationAddr = 0x8000
+ self.deviceIDAddr = 0x8006
+ self.programMemoryByteAddressRange = [(0,2*self.flashPageSize)]
+ self.configWordByteAddressRange = [(2*self.configWordAddr,2*self.configWordAddr+self.fuseBytes-1)]
+ self.userIDLocationByteAddressRange = [(2*self.userIDLocationAddr, 2*(self.userIDLocationAddr+self.userIDLocationSize)-1)]
+
+ #self.osccalBackupAddr = self.userIDLocationAddr + self.userIDLocationSize
+
+fuseDesc = (
+ BitDescription(0, "FOSC[0], 0=LP, 100=INTOSC"),
+ BitDescription(1, "FOSC[1]"),
+ BitDescription(2, "FOSC[2]"),
+ BitDescription(3, "WDTE[0], 00=WDT disabled, 11=WDT enabled"),
+ BitDescription(4, "WDTE[1]"),
+ BitDescription(5, "nPWRTE"),
+ BitDescription(6, "MCLRE, 1=nMCLR/Vpp pin is nMCLR, weak pull-up enabled, ignored if LVP=1 "),
+ BitDescription(7, "nCP 1=program memory code protection is disabled"),
+ BitDescription(8, "nCPD, 1=data memory code protection is disabled"),
+ BitDescription(9, "BOREN[0], 00=BOR disabled"),
+ BitDescription(10, "BOREN[1]"),
+ BitDescription(11, "nCLKOUTEN, 0=CLKOUT is enabled on CLKOUT pin"),
+ BitDescription(12, "IESO, 0=Internal/External Switchover mode is disabled"),
+ BitDescription(13, "FCMEM, 0=Fail-Safe Clock Monitor is disabled"),
+ BitDescription(14, "NA"),
+ BitDescription(15, "NA"),
+
+ BitDescription(16, "WRT[0], 11=Write protection off"),
+ BitDescription(17, "WRT[1]"),
+ BitDescription(18, "Unused"),
+ BitDescription(19, "Unused"),
+ BitDescription(20, "Unused"),
+ BitDescription(21, "Unused"),
+ BitDescription(22, "Unused"),
+ BitDescription(23, "Unused"),
+ BitDescription(24, "PLLEN, 0=4xPLL disabled"),
+ BitDescription(25, "STVREN, 1=Stack overflow or underflow will cause a reset"),
+ BitDescription(26, "BORV"),
+ BitDescription(27, "Unused"),
+ BitDescription(28, "nDEBUG, 0=ICSPCLK and ICSPDAT are dedicated to the debugger"),
+ BitDescription(29, "LVP 1=Low-voltage programming enabled"),
+)
+
+ChipDescription(
+ Chip_Pic16F1824dip14,
+ bitfile = "microchip01dip14dip20",
+ chipID = "pic16f1824dip14",
+ runtimeID = (0xDE03, 0x01),
+ chipVendors = "Microchip",
+ description = "PIC16F1824, PIC16LF1824",
+ packages = (("DIP14", ""),),
+ fuseDesc = fuseDesc,
+ maintainer = "Pavel Stemberk <stemberk@gmail.com>",
+)
bues.ch cgit interface