示例#1
0
    def on_btnOpen_clicked(self):
        if self.btnOpen.text() == '打开连接':
            try:
                if self.cmbDLL.currentIndex() == 0:
                    self.xlk = xlink.XLink(
                        jlink.JLink(self.cmbDLL.currentText(), 'Cortex-M0'))

                else:
                    from pyocd.coresight import dap, ap, cortex_m
                    daplink = self.daplinks[self.cmbDLL.currentIndex() - 1]
                    daplink.open()

                    _dp = dap.DebugPort(daplink, None)
                    _dp.init()
                    _dp.power_up_debug()

                    _ap = ap.AHB_AP(_dp, 0)
                    _ap.init()

                    self.xlk = xlink.XLink(cortex_m.CortexM(None, _ap))

                addr = int(self.linRTT.text(), 16)
                for i in range(128):
                    data = self.xlk.read_mem_U8(addr + 1024 * i,
                                                1024 + 32)  # 多读32字节,防止搜索内容在边界处
                    index = bytes(data).find(b'SEGGER RTT')
                    if index != -1:
                        self.RTTAddr = addr + 1024 * i + index

                        data = self.xlk.read_mem_U8(
                            self.RTTAddr, ctypes.sizeof(SEGGER_RTT_CB))

                        rtt_cb = SEGGER_RTT_CB.from_buffer(bytearray(data))
                        self.aUpAddr = self.RTTAddr + 16 + 4 + 4
                        self.aDownAddr = self.aUpAddr + ctypes.sizeof(
                            RingBuffer) * rtt_cb.MaxNumUpBuffers

                        self.txtMain.append(
                            f'\n_SEGGER_RTT @ 0x{self.RTTAddr:08X} with {rtt_cb.MaxNumUpBuffers} aUp and {rtt_cb.MaxNumDownBuffers} aDown\n'
                        )
                        break

                else:
                    raise Exception('Can not find _SEGGER_RTT')

            except Exception as e:
                self.txtMain.append(f'\n{str(e)}\n')

            else:
                self.cmbDLL.setEnabled(False)
                self.btnDLL.setEnabled(False)
                self.linRTT.setEnabled(False)
                self.btnOpen.setText('关闭连接')

        else:
            self.xlk.close()
            self.cmbDLL.setEnabled(True)
            self.btnDLL.setEnabled(True)
            self.linRTT.setEnabled(True)
            self.btnOpen.setText('打开连接')
示例#2
0
    def connect(self):
        try:
            if self.cmbDLL.currentIndex() == 0:
                self.xlk = xlink.XLink(
                    jlink.JLink(
                        self.cmbDLL.currentText(),
                        device.Devices[self.cmbMCU.currentText()].CHIP_CORE))

            else:
                from pyocd.coresight import dap, ap, cortex_m
                daplink = self.daplinks[self.cmbDLL.currentIndex() - 1]
                daplink.open()

                _dp = dap.DebugPort(daplink, None)
                _dp.init()
                _dp.power_up_debug()

                _ap = ap.AHB_AP(_dp, 0)
                _ap.init()

                self.xlk = xlink.XLink(cortex_m.CortexM(None, _ap))

            self.dev = device.Devices[self.cmbMCU.currentText()](self.xlk)

        except Exception as e:
            QMessageBox.critical(self, '连接失败', str(e), QMessageBox.Yes)

            return False

        return True
示例#3
0
 def on_btnErase_clicked(self):
     self.jlk = jlink.JLink(
         self.linDLL.text().encode('gbk'),
         device.Devices[self.cmbMCU.currentText()].CHIP_CORE)
     self.dev = device.Devices[self.cmbMCU.currentText()](self.jlk)
     self.dev.sect_erase(self.addr, self.size)
     QtGui.QMessageBox.information(self, u'擦除完成', u'        芯片擦除完成        ',
                                   QtGui.QMessageBox.Yes)
示例#4
0
    def emptyline(self):
        try:
            if self.xlk == None:
                try:
                    from pyocd.probe import aggregator
                    from pyocd.coresight import dap, ap, cortex_m
                    daplinks = aggregator.DebugProbeAggregator.get_all_connected_probes(
                    )
                except Exception as e:
                    daplinks = []

                if daplinks and os.path.isfile(self.dllpath):
                    use_dap = yes_no_dialog(
                        title='J-Link or DAPLink',
                        text=f'Do you want to use {daplinks[0].product_name}?'
                    ).run()

                elif os.path.isfile(self.dllpath):
                    use_dap = False

                elif daplinks:
                    use_dap = True

                else:
                    raise Exception('No link found')

                if use_dap:
                    daplink = daplinks[0]
                    daplink.open()

                    _dp = dap.DebugPort(daplink, None)
                    _dp.init()
                    _dp.power_up_debug()

                    _ap = ap.AHB_AP(_dp, 0)
                    _ap.init()

                    self.xlk = xlink.XLink(cortex_m.CortexM(None, _ap))

                else:
                    self.xlk = xlink.XLink(
                        jlink.JLink(self.dllpath, self.mcucore))

            else:
                self.xlk.close()
                self.xlk.open(self.mcucore)

            print(f'CPU core is {self.xlk.read_core_type()}\n')
        except Exception as e:
            print('connection fail\n')
            self.xlk = None
示例#5
0
    def on_btnRead_clicked(self):
        self.jlk = jlink.JLink(
            self.linDLL.text().encode('gbk'),
            device.Devices[self.cmbMCU.currentText()].CHIP_CORE)
        self.dev = device.Devices[self.cmbMCU.currentText()](self.jlk)

        self.setEnabled(False)
        self.prgInfo.setVisible(True)

        self.buff = []
        self.threadRead = ThreadAsync(self.dev.chip_read, self.addr, self.size,
                                      self.buff)
        self.threadRead.taskFinished.connect(self.on_btnRead_finished)
        self.threadRead.start()
示例#6
0
    def on_btnWrite_clicked(self):
        if self.cmbHEX.currentText().endswith('.hex'):
            data = parseHex(self.cmbHEX.currentText())
        else:
            data = open(self.cmbHEX.currentText(), 'rb').read()

        self.jlk = jlink.JLink(
            self.linDLL.text().encode('gbk'),
            device.Devices[self.cmbMCU.currentText()].CHIP_CORE)
        self.dev = device.Devices[self.cmbMCU.currentText()](self.jlk)

        self.setEnabled(False)
        self.prgInfo.setVisible(True)

        self.threadWrite = ThreadAsync(
            self.dev.chip_write, self.addr,
            [ord(x) for x in data])  # 进出文件都是bytes,进出Device都是list
        self.threadWrite.taskFinished.connect(self.on_btnWrite_finished)
        self.threadWrite.start()
示例#7
0
    def on_btnWrite_clicked(self):
        if self.cmbHEX.currentText().endswith('.hex'):
            data = parseHex(self.cmbHEX.currentText())
        else:
            data = open(self.cmbHEX.currentText(), 'rb').read()

        self.jlk = jlink.JLink(
            self.linDLL.text(),
            device.Devices[self.cmbMCU.currentText()].CHIP_CORE)
        self.dev = device.Devices[self.cmbMCU.currentText()](self.jlk)

        self.setEnabled(False)
        self.prgInfo.setVisible(True)

        if len(data) % self.dev.PAGE_SIZE:
            data += b'\xFF' * (self.dev.PAGE_SIZE -
                               len(data) % self.dev.PAGE_SIZE)

        self.threadWrite = ThreadAsync(self.dev.chip_write, self.addr, data)
        self.threadWrite.taskFinished.connect(self.on_btnWrite_finished)
        self.threadWrite.start()
示例#8
0
    def on_btnRefresh_clicked(self):
        try:
            self.jlink = jlink.JLink(self.linDLL.text(), 'Cortex-M0')

            reg_buf = self.jlink.read_mem_U32(
                self.periph._base_address,
                (self.periph.registers[-1].address_offset + 4) // 4)
        except Exception as e:
            print(e)
        else:
            for i in range(self.tree.topLevelItemCount()):
                Reg = self.tree.topLevelItem(i)

                value = reg_buf[int(Reg.text(1), 16) // 4]

                Reg.setText(2, '%08X' % value)

                for j in range(Reg.childCount()):
                    Field = Reg.child(j)

                    offset, width, mask = self.get_field_info(Field.text(1))

                    Field.setText(2, '%u' % ((value >> offset) & mask))