microchip8_18f97j60family.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. """
  2. # TOP2049 Open Source programming suite
  3. #
  4. # Microchip8 - 18f97j60 family - 8bit PIC MCU
  5. #
  6. # Copyright (c) 2013 Pavel Stemberk <stemberk@gmail.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. """
  22. from libtoprammer.chips.microchip8.microchip8_18_common import *
  23. class microchip8_18f97j60family(Chip_Microchip8_18_common):
  24. voltageVDD = 3
  25. voltageVPP = 3
  26. delayP5A = 0.000000040 # Delay between 4-bit command operand and next 4-bit command
  27. delayP9 = 0.0034 # SCK High time (minimum programming time)
  28. delayP10 = 0.000005 # SCK Low time after programming (high-voltage discharge time)
  29. delayP11 = 0.475 # Delay to allow self-timed data write or bulk erase to occur
  30. delayP12 = 0.0004 # Input data hold time from nMCLR/Vpp rise
  31. delayP19 = 0.000001 # Delay from first nMCLR fall to first PGC rise for key sequence on PGD
  32. delayP20 = 0.00000004 # Delay from last PGC fall for key sequence on PGD to second nMCLR rise
  33. def __init__(self,
  34. chipPackage, chipPinVCC, chipPinsVPP, chipPinGND,
  35. signature,
  36. flashPageSize, flashPages,
  37. eepromPageSize, eepromPages,
  38. fuseBytes
  39. ):
  40. Chip_Microchip8_18_common.__init__(self,
  41. chipPackage, chipPinVCC, chipPinsVPP, chipPinGND,
  42. signature,
  43. flashPageSize, flashPages,
  44. eepromPageSize, eepromPages,
  45. fuseBytes)
  46. def enterPM(self, force=False):
  47. if self.isInPmMode and not force:
  48. return
  49. "Enter HV programming mode. Vdd first entry mode"
  50. self.applyVCC(False)
  51. self.applyVPP(False)
  52. self.applyGND(False)
  53. self.setPins(0, 0)
  54. #self.top.cmdSetVCCVoltage(self.voltageVDD)
  55. self.top.cmdSetVPPVoltage(self.voltageVPP)
  56. self.applyGND(True)
  57. self.applyVCC(True)
  58. self.top.hostDelay(self.delayP13)
  59. self.applyVPP(True)
  60. self.applyVPP(False)
  61. self.top.hostDelay(self.delayP19)
  62. self.setTopProgrammerDelays()
  63. #program entry code
  64. #print("sending enterpm")
  65. self.top.cmdFPGAWrite(0x18,0xFF)
  66. self.top.hostDelay(self.delayP20)
  67. self.applyVPP(True)
  68. self.top.hostDelay(self.delayP12)
  69. self.isInPmMode = True
  70. def erase(self):
  71. self.progressMeterInit("Erasing chip", 0)
  72. self.enterPM(True)
  73. self.executeCode(self.getCodeAddrToTBLPTR(0x3C0004))
  74. self.send4bitWriteInstruction(self.CMD_TW, 0x0080)
  75. self.executeCode((0x0000,))
  76. self.sendCommand(1)
  77. self.top.hostDelay(self.delayP11 + self.delayP10)
  78. for i in range(0,4):
  79. self.sendCommand(1)
  80. self.top.flushCommands()
  81. self.progressMeterFinish()
  82. def writeSequentialBlock(self, startAddr, image, size, infoText):
  83. if len(image) > size:
  84. self.throwError("Invalid flash image size %d (expected <=%d)" % \
  85. (len(image), self.userIDLocationSize))
  86. self.enterPM()
  87. self.executeCode((0x8EA6, 0x9CA6))
  88. self.progressMeterInit(infoText, len(image) // 8)
  89. self.executeCode(self.getCodeAddrToTBLPTR(startAddr))
  90. for blockAddr in range(0, len(image), 8):
  91. self.write8bytes(image[blockAddr:])
  92. self.progressMeter(blockAddr)
  93. self.progressMeterFinish()
  94. self.exitPM()