这里写自定义目录标题
python 烧录:
说明:
效果图:
个人微信: wzdhh991
邮箱: wzd991@126.com
https://gitee.com/wzd991/embedded-system-tools
个人比较懒,CSDN更新缓慢,有相关问题可发邮箱或个人微信交流!
self.jlink.set_reset_pin_low()
time.sleep(0.05)
self.jlink.set_reset_pin_high()
此代码存在的价值就是,当所连接MCU低功耗运行时,使MCU复位,以便能擦除MCU的flash。
def slot_jlink_download(self):
try:
self.signal_jlink_log_clear.emit()
filex = os.path.join(
self.cfg[self.ui.comboBox_3.currentText()]['dir'] + '\\' + self.ui.comboBox_5.currentText(),
self.cfg[self.ui.comboBox_3.currentText()]['file_name'])
self.signal_jlink_log_add.emit(get_time_str() + ' ' + filex + '\n')
self.jlink = pylink.JLink()
self.jlink.open()
self.jlink.set_tif(pylink.enums.JLinkInterfaces.SWD) # 成功返回True
self.jlink.connect(self.ui.DevicelineEdit.text()) # 成功无返回
self.jlink.set_reset_pin_low()
time.sleep(0.05)
self.jlink.set_reset_pin_high()
self.jlink.reset()
self.jlink.erase()
if '.hex' in filex:
ret = get_hex_info(filex)
if ret[0] == ERR_NONE:
for key,val in ret[1].items():
hd = open('./temp.bin', 'wb')
hd.write(val)
hd.close()
dis = 'addresss:0x%x size:%d'%( key, len(val))
main_app_wdbg.info(dis)
self.signal_jlink_log_add.emit(get_time_str() + ' ' + dis + '\n')
self.jlink.flash_file('./temp.bin', key)
pass
elif '.bin' in filex:
a = os.path.abspath(filex)
hd = open(a, 'rb')
temp = hd.read(102400000)
hd.close()
hd = open('./temp.bin', 'wb')
hd.write(temp)
hd.close()
if 'base_addr' in self.cfg[self.ui.comboBox_3.currentText()].keys():
self.jlink.flash_file('./temp.bin', int(self.cfg[self.ui.comboBox_3.currentText()]['base_addr'], 16))
elif '.s19' in filex:
ret = get_s19_data(filex)
if ret[0] == ERR_NONE:
for key,val in ret[1].items():
hd = open('./temp.bin', 'wb')
hd.write(val)
hd.close()
dis = 'addresss:0x%x size:%d'%( key, len(val))
main_app_wdbg.info(dis)
self.signal_jlink_log_add.emit(get_time_str() + ' ' + dis + '\n')
self.jlink.flash_file('./temp.bin', key, 16)
pass
self.jlink.reset()
self.signal_jlink_log_add.emit('下载成功')
except Exception as e:
msg = '{}:{} {} '.format(e.__traceback__.tb_frame.f_globals["__file__"], e.__traceback__.tb_lineno, e)
self.signal_jlink_log_add.emit(msg)
finally:
self.jlink.close()
jlink读取MCU 内存数据:
def slot_jlink_read_mem(self):
try:
self.signal_jlink_log_clear.emit()
self.signal_jlink_log_add.emit('{}'.format(get_time_str()))
hex_val = int(self.ui.lineEdit_10.text(), 16)
self.jlink = pylink.JLink()
self.jlink.open()
self.jlink.set_tif(pylink.enums.JLinkInterfaces.SWD) # 成功返回True
self.jlink.connect(self.ui.DevicelineEdit.text()) # 成功无返回
temp = bytearray(self.jlink.memory_read(hex_val, int(self.ui.spinBox_12.value())))
cfg = {}
cfg['type'] = self.ui.comboBox_14.currentText()
cfg['scale'] = self.ui.comboBox_13.currentText()
cfg['biglit'] = self.ui.comboBox_10.currentText()
self.signal_jlink_log_add.emit(get_dis_data(cfg,temp, self.ui.spinBox_15.value()))
except Exception as e:
msg = '读取失败.. {}:{} {} '.format(e.__traceback__.tb_frame.f_globals["__file__"],
e.__traceback__.tb_lineno, e)
self.signal_jlink_log_add.emit(msg)
finally:
self.jlink.close()
擦除MCU flash 操作:
def slot_jlink_erase_chip(self):
try:
self.signal_jlink_log_clear.emit()
self.signal_jlink_log_add.emit(get_time_str() + ’ 开始执行擦除…\n’)
self.jlink = pylink.JLink()
self.jlink.open()
self.jlink.set_tif(pylink.enums.JLinkInterfaces.SWD) # 成功返回True
self.jlink.connect(self.ui.DevicelineEdit.text()) # 成功无返回
self.jlink.set_reset_pin_low()
time.sleep(0.05)
self.jlink.set_reset_pin_high()
self.jlink.reset()
self.jlink.erase()
log = ‘core id:0x%x device:%d connected:%d\n’ % (
self.jlink.core_id(), self.jlink.device_family(), self.jlink.target_connected())
self.signal_jlink_log_add.emit(log)
self.signal_jlink_log_add.emit('擦除成功… ')
except Exception as e:
self.jlink.close()
self.signal_jlink_log_add.emit('擦除失败... \n')
msg = '{}:{} {} '.format(e.__traceback__.tb_frame.f_globals["__file__"], e.__traceback__.tb_lineno, e)
self.signal_jlink_log_add.emit(msg)
finally:
if self.jlink is not None:
self.jlink.close()