├── .gitignore ├── LICENSE ├── build ├── dap_downloader.spec ├── readme.md └── requirements.txt ├── example ├── GD32F3x0_DFP.3.0.2.pack ├── pyocd.yaml └── readme.md ├── readme.md └── src └── dap_downloader.py /.gitignore: -------------------------------------------------------------------------------- 1 | build/venv/* 2 | build/build/dap_downloader/* 3 | build/dist/* 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /build/dap_downloader.spec: -------------------------------------------------------------------------------- 1 | # -*- mode: python ; coding: utf-8 -*- 2 | 3 | 4 | block_cipher = None 5 | 6 | 7 | a = Analysis( 8 | ['../src/dap_downloader.py'], 9 | pathex=[], 10 | binaries=[], 11 | datas=[('./venv/Lib/site-packages/libusb_package/libusb-1.0.dll', '.'),('./venv/Lib/site-packages/cmsis_pack_manager/cmsis_pack_manager/native.so','./cmsis_pack_manager/cmsis_pack_manager/.')], 12 | hiddenimports=[], 13 | hookspath=[], 14 | hooksconfig={}, 15 | runtime_hooks=[], 16 | excludes=[], 17 | win_no_prefer_redirects=False, 18 | win_private_assemblies=False, 19 | cipher=block_cipher, 20 | noarchive=False, 21 | ) 22 | pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) 23 | 24 | exe = EXE( 25 | pyz, 26 | a.scripts, 27 | a.binaries, 28 | a.zipfiles, 29 | a.datas, 30 | [], 31 | name='dap_downloader', 32 | debug=False, 33 | bootloader_ignore_signals=False, 34 | strip=False, 35 | upx=True, 36 | upx_exclude=[], 37 | runtime_tmpdir=None, 38 | console=False, 39 | disable_windowed_traceback=False, 40 | argv_emulation=False, 41 | target_arch=None, 42 | codesign_identity=None, 43 | entitlements_file=None, 44 | ) 45 | -------------------------------------------------------------------------------- /build/readme.md: -------------------------------------------------------------------------------- 1 | ## 环境准备 2 | 3 | pyOCD需要Python3.6版本及以上,这意味着本项目也至少需要Python3.6 4 | 5 | Pyocd,Pyinstaller和Pygubu理论上支持所有操作系统,但是这里只在Windows10 22H2 上测试通过。 6 | 7 | 8 | 9 | ## Instructions 10 | 11 | These instructions assume that you already have Python installed: 12 | 13 | The following script shows the basic steps that one must follow: 14 | 15 | ```cmd 16 | cd build 17 | # Setup a virtualenv and install dependencies 18 | python -m venv venv 19 | venv\Scripts\activate 20 | pip installer -r requirements.txt 21 | 22 | # Create single-file executables 23 | pyinstaller dap_downloader.spec 24 | ``` 25 | 26 | In ./dist folder, there will be a single executable file per tool which is ready to use or distribute it to other library. -------------------------------------------------------------------------------- /build/requirements.txt: -------------------------------------------------------------------------------- 1 | altgraph==0.17.3 2 | appdirs==1.4.4 3 | capstone==4.0.2 4 | cffi==1.15.1 5 | cmsis-pack-manager==0.5.2 6 | colorama==0.4.6 7 | future==0.18.3 8 | hidapi==0.13.1 9 | intelhex==2.3.0 10 | intervaltree==3.1.0 11 | libusb-package==1.0.26.1 12 | natsort==8.3.1 13 | pefile==2023.2.7 14 | prettytable==3.6.0 15 | psutil==5.9.4 16 | pycparser==2.21 17 | pyelftools==0.29 18 | pygubu==0.30 19 | pyinstaller==5.9.0 20 | pyinstaller-hooks-contrib==2023.1 21 | pylink-square==0.14.3 22 | pyocd==0.34.3 23 | pyusb==1.2.1 24 | pywin32-ctypes==0.2.0 25 | PyYAML==6.0 26 | six==1.16.0 27 | sortedcontainers==2.4.0 28 | typing_extensions==4.5.0 29 | wcwidth==0.2.6 30 | -------------------------------------------------------------------------------- /example/GD32F3x0_DFP.3.0.2.pack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USTHzhanglu/dap_download/e44c8197e3589cc3110aae584cdf312f6168630b/example/GD32F3x0_DFP.3.0.2.pack -------------------------------------------------------------------------------- /example/pyocd.yaml: -------------------------------------------------------------------------------- 1 | target_override: GD32F310G8 2 | pack: 3 | ./GD32F3x0_DFP.3.0.2.pack 4 | frequency: 10000000 -------------------------------------------------------------------------------- /example/readme.md: -------------------------------------------------------------------------------- 1 | ## *.bin 2 | 烧录所用到的固件 3 | ## *.pack 4 | 烧录算法文件,Keil补丁包。文件名需要与yaml中对应 5 | ## *.yaml 6 | 配置文件,描述了目标芯片型号,烧录算法所在位置,烧录速率等 7 | 8 | 9 | ​ 10 | ```yaml 11 | target_override: GD32F310G8 #目标芯片型号 12 | pack: #烧录算法所在位置,可以存放多个 13 | ./GD32F3x0_DFP.3.0.2.pack 14 | frequency: 10000000 #烧录速率 15 | ``` -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## 首先感谢以下项目 2 | 3 | [pyOCD](https://github.com/pyocd/pyOCD):一个开源的mcu调试以及下载项目,基本支持所有芯片 4 | 5 | [pygubu](https://github.com/alejandroautalan/pygubu):一个开源宜用的GUI draw项目,支持实时浏览界面 6 | 7 | ## 项目介绍 8 | 9 | 本项目是基于tkinter,pygubu和pyOCD设计的一个GUI,可以通过DAP-LINK直接下载固件。使用者只需要提供芯片的pack包,即可下载hex,elf以及bin文件。 10 | 11 | ## 使用说明 12 | ### 烧录 13 | 1. 选择下载文件 14 | 2. 选择芯片配置文件所在文件夹 15 | 3. 开始下载 16 | ### 擦除 17 | 1. 选择芯片配置文件所在文件夹 18 | 2. 擦除程序 19 | 注:目前只支持全盘擦除 20 | -------------------------------------------------------------------------------- /src/dap_downloader.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | import pathlib 5 | import tkinter as tk 6 | import tkinter.ttk as ttk 7 | from pygubu.widgets.pathchooserinput import PathChooserInput 8 | import threading 9 | import datetime 10 | import os,sys,time 11 | import webbrowser 12 | from pyocd.core.helpers import ConnectHelper 13 | from pyocd.flash.file_programmer import FileProgrammer 14 | from pyocd.flash.eraser import FlashEraser 15 | from pyocd.probe.aggregator import PROBE_CLASSES 16 | from pyocd.probe.cmsis_dap_probe import CMSISDAPProbe 17 | PROBE_CLASSES["cmsisdap"] = CMSISDAPProbe 18 | 19 | bin_path = '' 20 | yaml_path = '' 21 | version = '0.0.1' 22 | author = 'USTHzhanglu@outlook.com' 23 | copyright = 'USTHzhanglu' 24 | show_about = ( 25 | 'dap_downloader\r\n\r\n'+ 26 | 'Version:%s\r\n'%version+ 27 | 'Author:%s\r\n'%author+ 28 | 'Copyright@%s'%copyright 29 | ) 30 | 31 | def download_bin(ui): 32 | is_err_download = False 33 | try: 34 | with ConnectHelper.session_with_chosen_probe() as session: 35 | target = session.target 36 | # Load firmware into device. 37 | FileProgrammer(session,progress = None).program(bin_path) 38 | # Reset, run. 39 | target.reset_and_halt() 40 | target.resume() 41 | except Exception as r: 42 | ui.out.insert('end',r) 43 | ui.out.insert('end',"\r\n") 44 | is_err_download = True 45 | finally: 46 | if is_err_download == False: 47 | ui.out.edit_undo() 48 | app.out.insert('end','\r\n['+ 20*'='+'] 100%\r\n') 49 | # time.sleep(0.5) 50 | ui.out.insert('end',"-------------烧录成功--------------\r\n") 51 | else: 52 | ui.out.insert('end',"-------------烧录失败--------------\r\n") 53 | ui.out.insert('end',datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) 54 | ui.out.insert('end','\r\n') 55 | 56 | def erase_bin(ui): 57 | is_err_erase= False 58 | try: 59 | with ConnectHelper.session_with_chosen_probe() as session: 60 | FlashEraser(session,mode = FlashEraser.Mode.CHIP).erase() 61 | except Exception as r: 62 | ui.out.insert('end',r) 63 | ui.out.insert('end',"\r\n") 64 | is_err_erase = True 65 | finally: 66 | if is_err_erase == False: 67 | ui.out.insert('end',"-------------擦除完毕--------------\r\n") 68 | else: 69 | ui.out.insert('end',"-------------擦除失败--------------\r\n") 70 | ui.out.insert('end',datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) 71 | ui.out.insert('end','\r\n') 72 | 73 | class std2tk(object): 74 | def __init__(self,tk): 75 | self._buff = "" 76 | self.tk = tk 77 | def write(self, out_stream): 78 | self.tk.down_progress+=1 79 | if(self.tk.down_progress>169): 80 | self.tk.down_progress = 169 81 | self.tk.out.edit_undo() 82 | progress = (int)(self.tk.down_progress/17*2) 83 | self.tk.out.insert('end','\r\n['+ \ 84 | progress*'='+\ 85 | +(20 - progress)*' '+\ 86 | '] %.2f%%\r\n'%(self.tk.down_progress/1.7)) 87 | def flush(self): 88 | pass 89 | 90 | class PyocdApp: 91 | def __init__(self, master=None): 92 | # pragrm 93 | self.down_progress = 0 94 | 95 | 96 | 97 | # build ui 98 | self.toplevel1 = tk.Tk() if master is None else tk.Toplevel(master) 99 | #menu 100 | self.menu1 = tk.Menu(self.toplevel1,tearoff = True) 101 | 102 | self.mi_download = 1 103 | self.menu1.add('command', font='{宋体} 9 {}', label='获取') 104 | _wcmd = lambda itemid="download": self.menucallback(itemid) 105 | self.menu1.entryconfigure(self.mi_download, command=_wcmd) 106 | self.toplevel1.configure(menu=self.menu1) 107 | 108 | self.mi_help = 2 109 | self.menu1.add('command', font='{宋体} 9 {}', label='帮助') 110 | _wcmd = lambda itemid="help": self.menucallback(itemid) 111 | self.menu1.entryconfigure(self.mi_help, command=_wcmd) 112 | 113 | self.mi_about = 3 114 | self.menu1.add('command', font='{宋体} 9 {}', label='关于') 115 | _wcmd = lambda itemid="about": self.menucallback(itemid) 116 | self.menu1.entryconfigure(self.mi_about, command=_wcmd) 117 | self.toplevel1.configure(menu=self.menu1) 118 | 119 | 120 | self.gui = ttk.Frame(self.toplevel1) 121 | self.labelframe1 = ttk.Labelframe(self.gui) 122 | self.binchooserinput = PathChooserInput(self.labelframe1) 123 | self.binchooserinput.configure(state='normal', title='bin文件', type='file') 124 | self.binchooserinput.pack(fill='x', side='top') 125 | self.labelframe1.configure(text='选择Bin文件') 126 | self.labelframe1.pack(fill='x', side='top') 127 | 128 | self.labelframe2 = ttk.Labelframe(self.gui) 129 | self.pathchooserinput1 = PathChooserInput(self.labelframe2) 130 | self.pathchooserinput1.configure(state='normal', title='bin文件', type='directory') 131 | self.pathchooserinput1.pack(fill='x', side='top') 132 | self.labelframe2.configure(text='选择配置文件所在文件夹') 133 | self.labelframe2.pack(fill='x', side='top') 134 | self.frame1 = ttk.Frame(self.gui) 135 | 136 | self.out = tk.Text(self.frame1,undo=True,maxundo = 1) 137 | self.out.configure(background='#000000',font='{宋体} 10 {}', foreground='#00ff00', height='9', relief='groove') 138 | self.out.configure(width='50') 139 | self.out.pack(anchor='center', expand='true', fill='both', side='top') 140 | 141 | self.erase = tk.Button(self.frame1) 142 | self.erase.configure(relief='groove', text='擦除程序') 143 | self.erase.pack(anchor='center', ipadx='15', padx='20', pady='10', side='left') 144 | self.erase.configure(command=self.erasechip) 145 | self.start = tk.Button(self.frame1) 146 | self.start.configure(relief='groove', text='开始下载') 147 | self.start.pack(anchor='center', ipadx='15', padx='20', pady='10', side='right') 148 | self.start.configure(command=self.download) 149 | 150 | self.frame1.pack(anchor='center', expand='true', fill='both', side='bottom') 151 | self.gui.configure(height='480', relief='flat', width='320') 152 | self.gui.pack(anchor='center', side='top') 153 | self.gui.pack_propagate(0) 154 | self.toplevel1.configure(height='480', width='320') 155 | # self.toplevel1.geometry('320x480') 156 | #自适应屏幕居中 157 | self.toplevel1.geometry('320x480' + '+' 158 | + str((self.toplevel1.winfo_screenwidth() - 320) // 2) + '+' 159 | + str((self.toplevel1.winfo_screenheight() - 480) // 2 - 18)) 160 | 161 | self.toplevel1.title('dap_download') 162 | self.toplevel1.resizable(False, False) 163 | self.toplevel1.attributes('-alpha',0.95) 164 | 165 | # Main widget 166 | self.mainwindow = self.toplevel1 167 | self.mainwindow.attributes('-topmost', 1)#强制前台 168 | self.mainwindow.after_idle(self.mainwindow.attributes,'-topmost',False) 169 | self.mainwindow.focus_force() 170 | self.mainwindow.bind('',self.press_key) 171 | 172 | def run(self): 173 | self.mainwindow.mainloop() 174 | 175 | 176 | def menucallback(self, itemid): 177 | if itemid == 'about': 178 | tk.messagebox.showinfo(title="关于",message = show_about) 179 | elif itemid =='help': 180 | webbrowser.open('https://github.com/USTHzhanglu/dap_download/readme.md',new=0) 181 | elif itemid =='download': 182 | if tk.messagebox.askokcancel("download", "是否转到Github?"): 183 | webbrowser.open('https://github.com/USTHzhanglu/dap_download',new=0) 184 | 185 | def download(self): 186 | global bin_path 187 | global yaml_path 188 | bin_path = self.binchooserinput.cget('path') 189 | yaml_path = self.pathchooserinput1.cget('path') 190 | self.down_progress = 0 191 | if (bin_path and yaml_path): 192 | self.out.delete('1.0','end') 193 | self.out.insert('end',"bin:%s"%(bin_path)) 194 | self.out.insert('end','\r\n') 195 | self.out.insert('end',"dir:%s"%(yaml_path)) 196 | self.out.insert('end','\r\n') 197 | 198 | os.chdir(yaml_path) 199 | 200 | self.out.insert('end','-------------开始烧录--------------\r\n') 201 | self.out.insert('end',datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) 202 | self.out.edit_separator() 203 | self.out.insert('end','\r\n----------正在连接设备-------------\r\n') 204 | download = threading.Thread(target=download_bin,args=(app,)) 205 | if download.is_alive() is False: 206 | download.start() 207 | else: 208 | self.out.insert('end','烧录失败\r\n') 209 | else : 210 | self.out.delete('1.0','end') 211 | self.out.insert('end','请选择有效的bin文件或文件夹路径\r\n') 212 | 213 | def erasechip(self): 214 | global yaml_path 215 | yaml_path = self.pathchooserinput1.cget('path') 216 | if yaml_path: 217 | self.out.delete('1.0','end') 218 | self.out.insert('end',"dir:%s"%(yaml_path)) 219 | self.out.insert('end','\r\n') 220 | os.chdir(yaml_path) 221 | 222 | if tk.messagebox.askokcancel("erase", "你确定要擦除吗?"): 223 | self.out.insert('end','-------------开始擦除--------------\r\n') 224 | self.out.insert('end',datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) 225 | self.out.insert('end','\r\n') 226 | erase = threading.Thread(target=erase_bin,args=(app,)) 227 | if erase.is_alive() is False: 228 | erase.start() 229 | else: 230 | self.out.insert('end','擦除失败\r\n') 231 | else : 232 | self.out.delete('1.0','end') 233 | self.out.insert('end','请选择有效的文件夹路径\r\n') 234 | 235 | 236 | def press_key(self,event): 237 | key_index = event.keycode 238 | if key_index in [13,32]: 239 | self.download() 240 | elif key_index == 27: 241 | if tk.messagebox.askokcancel("Quit", "你确定要退出吗?"): 242 | self.mainwindow.destroy() 243 | 244 | 245 | if __name__ == '__main__': 246 | app = PyocdApp() 247 | _std = std2tk(app) 248 | sys.stdout = _std 249 | app.run() 250 | 251 | --------------------------------------------------------------------------------