예제 #1
0
    def program(self, filename, memtype="flash", verify=True):
        f = IntelHex(filename)

        startaddr = self.xmega._chip.memtypes[memtype]["offset"]
        maxsize = self.xmega._chip.memtypes[memtype]["size"]
        fsize = f.maxaddr() - f.minaddr()

        if fsize > maxsize:
            raise IOError("File %s appears to be %d bytes, larger than %s size of %d" % (filename, fsize, memtype, maxsize))

        print "Programming..."
        fdata = f.tobinarray(start=0)
        self.xmega.writeMemory(startaddr, fdata, memtype)
        
        print "Reading..."
        #Do verify run
        rdata = self.xmega.readMemory(startaddr, len(fdata), memtype)

        for i in range(0, len(fdata)):
            if fdata[i] != rdata[i]:
                # raise IOError("Verify failed at 0x%04x, %x != %x" % (i, fdata[i], rdata[i]))
                print i
                pass

        print "Verifed OK"
예제 #2
0
    def program(self, filename, memtype="flash", verify=True, logfunc=print_fun, waitfunc=None):
        """Programs memory type, dealing with opening filename as either .hex or .bin file"""
        self.lastFlashedFile = filename

        f = IntelHex(filename)

        fsize = f.maxaddr() - f.minaddr()
        fdata = f.tobinarray(start=f.minaddr())
        startaddr = f.minaddr()

        logging.info("Programming %d bytes at 0x%x", fsize, startaddr)

        logfunc("STM32F Programming %s..." % memtype)
        if waitfunc: waitfunc()
        self.writeMemory(startaddr, fdata)  # , erasePage=True

        logfunc("STM32F Reading %s..." % memtype)
        if waitfunc: waitfunc()
        # Do verify run
        rdata = self.readMemory(startaddr, len(fdata))

        for i in range(0, len(fdata)):
            if fdata[i] != rdata[i]:
                raise IOError("Verify failed at 0x%04x, %x != %x" % (i, fdata[i], rdata[i]))

        logfunc("Verified %s OK, %d bytes" % (memtype, fsize))
예제 #3
0
    def program(self,
                filename,
                memtype="flash",
                verify=True,
                logfunc=print_fun,
                waitfunc=None):

        f = IntelHex(filename)

        maxsize = self._chip.memtypes[memtype]["size"]
        fsize = f.maxaddr() - f.minaddr()

        if fsize > maxsize:
            raise IOError(
                "File %s appears to be %d bytes, larger than %s size of %d" %
                (filename, fsize, memtype, maxsize))

        logfunc("AVR Programming %s..." % memtype)
        fdata = f.tobinarray(start=0)
        self.writeMemory(0, fdata, memtype)

        logfunc("AVR Reading %s..." % memtype)
        # Do verify run
        rdata = self.readMemory(0, len(fdata))  # memtype ?

        for i in range(0, len(fdata)):
            if fdata[i] != rdata[i]:
                raise IOError("Verify failed at 0x%04x, %x != %x" %
                              (i, fdata[i], rdata[i]))

        logfunc("Verified %s OK, %d bytes" % (memtype, fsize))
    def program(self,
                filename,
                memtype="flash",
                verify=True,
                logfunc=print_fun,
                waitfunc=None):
        """Programs memory type, dealing with opening filename as either .hex or .bin file"""
        self.lastFlashedFile = filename

        f = IntelHex(filename)

        fsize = f.maxaddr() - f.minaddr()
        fdata = f.tobinarray(start=f.minaddr())
        startaddr = f.minaddr()

        logfunc("Attempting to program %d bytes at 0x%x" % (fsize, startaddr))

        logfunc("STM32F Programming %s..." % memtype)
        if waitfunc: waitfunc()
        self.writeMemory(startaddr, fdata)  # , erasePage=True

        logfunc("STM32F Reading %s..." % memtype)
        if waitfunc: waitfunc()

        try:
            self.verifyMemory(startaddr, fdata, self.small_blocks)
        except CmdException:
            logfunc("Error during verify. Retrying with small blocks...")
            self.verifyMemory(startaddr, fdata, True)

        logfunc("Verified %s OK, %d bytes" % (memtype, fsize))
예제 #5
0
    def program(self, filename, memtype="flash", verify=True):
        f = IntelHex(filename)

        startaddr = self.xmega._chip.memtypes[memtype]["offset"]
        maxsize = self.xmega._chip.memtypes[memtype]["size"]
        fsize = f.maxaddr() - f.minaddr()

        if fsize > maxsize:
            raise IOError(
                "File %s appears to be %d bytes, larger than %s size of %d" %
                (filename, fsize, memtype, maxsize))

        self.log("XMEGA Programming %s..." % memtype)
        QCoreApplication.processEvents()
        fdata = f.tobinarray(start=0)
        self.xmega.writeMemory(startaddr, fdata, memtype)  # , erasePage=True

        self.log("XMEGA Reading %s..." % memtype)
        QCoreApplication.processEvents()
        #Do verify run
        rdata = self.xmega.readMemory(startaddr, len(fdata), memtype)

        for i in range(0, len(fdata)):
            if fdata[i] != rdata[i]:
                raise IOError("Verify failed at 0x%04x, %x != %x" %
                              (i, fdata[i], rdata[i]))

        self.log("Verified %s OK, %d bytes" % (memtype, fsize))
예제 #6
0
    def program(self, filename, memtype="flash", verify=True):
        f = IntelHex(filename)

        startaddr = self.xmega._chip.memtypes[memtype]["offset"]
        maxsize = self.xmega._chip.memtypes[memtype]["size"]
        fsize = f.maxaddr() - f.minaddr()

        if fsize > maxsize:
            raise IOError(
                "File %s appears to be %d bytes, larger than %s size of %d" % (filename, fsize, memtype, maxsize)
            )

        self.log("XMEGA Programming %s..." % memtype)
        QCoreApplication.processEvents()
        fdata = f.tobinarray(start=0)
        self.xmega.writeMemory(startaddr, fdata, memtype)  # , erasePage=True

        self.log("XMEGA Reading %s..." % memtype)
        QCoreApplication.processEvents()
        # Do verify run
        rdata = self.xmega.readMemory(startaddr, len(fdata), memtype)

        for i in range(0, len(fdata)):
            if fdata[i] != rdata[i]:
                raise IOError("Verify failed at 0x%04x, %x != %x" % (i, fdata[i], rdata[i]))

        self.log("Verified %s OK, %d bytes" % (memtype, fsize))
    def program(self, filename, memtype="flash", verify=True):
        Programmer.lastFlashedFile = filename
        f = IntelHex(filename)

        maxsize = self.avr._chip.memtypes[memtype]["size"]
        fsize = f.maxaddr() - f.minaddr()

        if fsize > maxsize:
            raise IOError(
                "File %s appears to be %d bytes, larger than %s size of %d" %
                (filename, fsize, memtype, maxsize))

        self.log("AVR Programming %s..." % memtype)
        util.updateUI()
        fdata = f.tobinarray(start=0)
        self.avr.writeMemory(0, fdata, memtype)

        self.log("AVR Reading %s..." % memtype)
        util.updateUI()
        # Do verify run
        rdata = self.avr.readMemory(0, len(fdata))  # memtype ?

        for i in range(0, len(fdata)):
            if fdata[i] != rdata[i]:
                raise IOError("Verify failed at 0x%04x, %x != %x" %
                              (i, fdata[i], rdata[i]))

        self.log("Verified %s OK, %d bytes" % (memtype, fsize))
예제 #8
0
    def program(self, filename, memtype="flash", verify=True):
        Programmer.lastFlashedFile = filename
        f = IntelHex(filename)

        maxsize = self.avr._chip.memtypes[memtype]["size"]
        fsize = f.maxaddr() - f.minaddr()

        if fsize > maxsize:
            raise IOError("File %s appears to be %d bytes, larger than %s size of %d" % (filename, fsize, memtype, maxsize))

        self.log("AVR Programming %s..." % memtype)
        util.updateUI()
        fdata = f.tobinarray(start=0)
        self.avr.writeMemory(0, fdata, memtype)

        self.log("AVR Reading %s..." % memtype)
        util.updateUI()
        # Do verify run
        rdata = self.avr.readMemory(0, len(fdata))  # memtype ?

        for i in range(0, len(fdata)):
            if fdata[i] != rdata[i]:
                raise IOError("Verify failed at 0x%04x, %x != %x" % (i, fdata[i], rdata[i]))

        self.log("Verified %s OK, %d bytes" % (memtype, fsize))
예제 #9
0
def FileReader(filename):
    if filename.lower().endswith(".hex") or filename.lower().endswith(".ihex"):
        f = IntelHex(filename)
        fdata = f.tobinarray(0)
        fsize = f.maxaddr() - f.minaddr()
    elif filename.lower().endswith(".bin"):
        f = open(filename, "rb")
        fdata = bytearray(f.read())
        fsize = len(fdata)
        f.close()
    else:
        raise IOError("Unknown file extension for file %s" % filename)

    return fdata, fsize