Пример #1
0
    def flash_update(self, buf):
        flash_offsets = [0x08000000, 0x08004000, 0x08008000, 0x0800C000,
                         0x08010000, 0x08020000, 0x08040000, 0x08060000,
                         0x08080000, 0x080A0000, 0x080C0000, 0x080E0000]

        # Erasing
        total = len(flash_offsets)

        progress = QProgressDialog(self)
        progress.setRange(0, total)
        progress.setValue(0)
        progress.setModal(True)
        progress.show()
        progress.setAutoReset(False)
        progress.setLabelText('Initializing')

        # call dfu-util
        openmv.enter_dfu()
        sleep(1.0)

        # Initialize
        pydfu.init()

        progress.setLabelText('Erasing')
        progress.setValue(0)

        pg = 0
        for offset in flash_offsets:
            progress.setValue(pg)
            pydfu.page_erase(flash_offsets[pg])
            pg += 1

        offset = 0
        size = len(buf)
        progress.setRange(0, size)
        progress.setLabelText('Downloading')

        while offset < size:
            progress.setValue(offset)
            pg_size = min(64, size - offset)
            page = buf[offset:offset + pg_size]
            pydfu.write_page(page, offset)
            offset += pg_size

        progress.hide()
        pydfu.exit_dfu()
Пример #2
0
    def initUi(self):
        self.log("Searching devices...")
        dfu_devices = pydfu.get_dfu_devices(idVendor=0x0483, idProduct=0xdf11)
        if not dfu_devices:
            # No devices found
            self.log("No DFU device found. Retrying")

        elif len(dfu_devices) > 1:
            self.log("Found multiple DFU devices:" + str(dfu_devices))
            self.log("Please disconnect other DFU devices to avoid mistakes")

        else:
            self.timer.stop()
            pydfu.init()
            self.log("Found DFU device. Please select an option")
            self.dfuDevice = dfu_devices[0]
            self.groupbox_controls.setEnabled(True)
            self.pushButton_filechooser.setEnabled(True)
            self.pushButton_fullerase.setEnabled(True)
Пример #3
0
    def fwupdate_task(self, state):
        if (state["init"]):
            pydfu.init()
            state["init"]=False
            state["erase"]=True
            state["bar"].set_text("Erasing...")
            return True
        elif (state["erase"]):
            page = state["page"]
            total = len(FLASH_OFFSETS)
            pydfu.page_erase(FLASH_OFFSETS[page])
            page +=1
            state["bar"].set_fraction(page/float(total))
            if (page == total):
                state["erase"] = False
                state["write"] = True
                state["bar"].set_text("Uploading...")
            state["page"] = page
            return True
        elif (state["write"]):
            buf = state["buf"]
            xfer_bytes = state["xfer_bytes"]
            xfer_total = state["xfer_total"]

            # Send chunk
            chunk = min (64, xfer_total-xfer_bytes)
            pydfu.write_page(buf[xfer_bytes:xfer_bytes+chunk], xfer_bytes)

            xfer_bytes += chunk
            state["xfer_bytes"] = xfer_bytes
            state["bar"].set_fraction(xfer_bytes/float(xfer_total))

            if (xfer_bytes == xfer_total):
                pydfu.exit_dfu()
                state["dialog"].hide()
                self.disconnect()
                return False

            return True
Пример #4
0
    def fwupdate_task(self, state):
        if (state["init"]):
            pydfu.init()
            state["init"] = False
            state["erase"] = True
            state["bar"].set_text("Erasing...")
            return True
        elif (state["erase"]):
            page = state["page"]
            total = len(FLASH_OFFSETS)
            pydfu.page_erase(FLASH_OFFSETS[page])
            page += 1
            state["bar"].set_fraction(page / float(total))
            if (page == total):
                state["erase"] = False
                state["write"] = True
                state["bar"].set_text("Uploading...")
            state["page"] = page
            return True
        elif (state["write"]):
            buf = state["buf"]
            xfer_bytes = state["xfer_bytes"]
            xfer_total = state["xfer_total"]

            # Send chunk
            chunk = min(64, xfer_total - xfer_bytes)
            pydfu.write_page(buf[xfer_bytes:xfer_bytes + chunk], xfer_bytes)

            xfer_bytes += chunk
            state["xfer_bytes"] = xfer_bytes
            state["bar"].set_fraction(xfer_bytes / float(xfer_total))

            if (xfer_bytes == xfer_total):
                pydfu.exit_dfu()
                state["dialog"].hide()
                self.disconnect()
                return False

            return True
Пример #5
0
    def initUi(self):
        self.log("Searching devices...")

        dfu_devices = pydfu.get_dfu_devices(idVendor=0x0483, idProduct=0xdf11)
        if not dfu_devices:
            # No devices found
            self.log("No DFU device found. Retrying")
            if self.firstFail:
                self.log(
                    "Make sure the bootloader is detected and drivers installed. Short boot0 to force the bootloader when connecting"
                )
                self.firstFail = False
        elif len(dfu_devices) > 1:
            self.log("Found multiple DFU devices:" + str(dfu_devices))
            self.log("Please disconnect other DFU devices to avoid mistakes")

        else:
            self.timer.stop()
            pydfu.init()
            self.log("Found DFU device. Please select an option")
            self.dfuDevice = dfu_devices[0]
            self.groupbox_controls.setEnabled(True)
            self.pushButton_filechooser.setEnabled(True)
            self.pushButton_fullerase.setEnabled(True)