Exemple #1
0
    def ChipErase(self):
        """Erase all memory on target chip"""

        s = PicKit2ScriptBuilder()

        s += SpiUtils.CSLowScript()
        s.SpiWriteByte(0x60)
        s += SpiUtils.CSHighScript()

        self.__pickit.RunScriptImmediate(s)
Exemple #2
0
    def WriteDisable(self):
        """Send the write disable command"""

        s = PicKit2ScriptBuilder()

        s += SpiUtils.CSLowScript()
        s.SpiWriteByte(0x04)
        s += SpiUtils.CSHighScript()

        self.__pickit.RunScriptImmediate(s)
Exemple #3
0
    def ReadDecodedStatus(self):
        """Read and decode the status register"""

        s = PicKit2ScriptBuilder()

        s += SpiUtils.CSLowScript()
        s.SpiWriteByte(0x05)
        s.SpiReadByteBuffer()
        s += SpiUtils.CSHighScript()

        self.__pickit.RunScriptImmediate(s)
        return self.DecodeStatus(self.__pickit.ReadData()[0])
Exemple #4
0
    def ReadJedecId(self):
        """Read the JEDEC ID from the flash chip"""

        s = PicKit2ScriptBuilder()

        s += SpiUtils.CSLowScript()
        s.SpiWriteByte(0x9f)
        s.SpiReadByteBuffer()
        s.SpiReadByteBuffer()
        s.SpiReadByteBuffer()
        s += SpiUtils.CSHighScript()

        self.__pickit.RunScriptImmediate(s)
        return self.__pickit.ReadData()
Exemple #5
0
    def WritePage(self, address):
        """Issue the page program instruction for the given address, reading 256 bytes from the writebuffer"""

        s = PicKit2ScriptBuilder()

        s += SpiUtils.CSLowScript()
        s.SpiWriteByte(0x02)
        s.SpiWriteByte(address >> 16)
        s.SpiWriteByte(address >> 8)
        s.SpiWriteByte(address)

        s.SetLabel('loop')
        s.SpiWriteByteBuffer()
        s.Repeat('loop', 256)

        s += SpiUtils.CSHighScript()

        self.__pickit.RunScriptImmediate(s)
Exemple #6
0
    def StartReadData(self, address=0):
        """Issue the continuous data read instruction (leaves CS# low)"""

        s = PicKit2ScriptBuilder()

        s += SpiUtils.CSLowScript()
        s.SpiWriteByte(0x03)
        s.SpiWriteByte((address >> 16) & 0xff)
        s.SpiWriteByte((address >> 8) & 0xff)
        s.SpiWriteByte(address & 0xff)

        self.__pickit.RunScriptImmediate(s)
pickits = PicKit2LibUsbTransport.findpickits()
if len(pickits) == 0:
    print "Couldn't find a pickit"
    sys.exit(1)

transport = PicKit2LibUsbTransport(pickits[0])
pickit = PicKit2(transport)
spiflash = SpiFlash(pickit)
pickit.ClearReadBuffer()
pickit.ClearWriteBuffer()
pickit.ClearScriptBuffer()

# setup the pickit
pickit.SetVppVoltage(3.3, 0.5)
pickit.SetVddVoltage(3.3, 0.5)
pickit.RunScriptImmediate(SpiUtils.SetupExternalPowerScript())

# Read the SPI flash ID
print "JEDEC id: %s" % " ".join([hex(i) for i in spiflash.ReadJedecId()])

# Erase the chip
spiflash.WriteEnable()
spiflash.ChipErase()
while 'WIP' in spiflash.ReadDecodedStatus():
    print "Waiting for erase to complete...\r",
    sys.stdout.flush()
    time.sleep(1)
print

# Write data to the chip
f = open(infile, "rb")
Exemple #8
0
    def StopReadData(self):
        """Complete the data read process"""

        self.__pickit.RunScriptImmediate(SpiUtils.CSHighScript())