分享一下Jlink编程器的添加器件和打包过程

2019-12-10 18:12发布

最近项目中需要用到F0批量下载,找到了坛友分享的下载器:https://www.amobbs.com/thread-5707404-1-1.html?_dsign=c0fd7dd4
作为一个新手,遇到了很多坑,第一步就是安装python一定要安装python2.7 并且是32位版本
python2.7:https://www.python.org/ftp/python/2.7.14/python-2.7.14rc1.msi
Pyqt一定也要是32位的
PyQT4:https://master.dl.sourceforge.ne ... 2.7-Qt4.8.6-x32.exe

安装64位的python会导致Python调试出现OSError: [WinError 193] %1 不是有效的 Win32 应用程序,
一般来讲是因为python位数和dll位数不一样导致的,dll是32位的,而python是64位的。

我的系统是64位Win10安装了64位的python,当调用32位dll的时候,就报错。

如何解决:

1、安装64位的dll(一般很难找到JlinkArm.dll好像没有64位的)

2、安装32位的python
但是在安装pyinstaller,进入目录输入pyinstaller -F MCUProg.py后又会一闪而过,截图截到提示的 API 'QString' has already been set to version 1
这里就需要进入D:Python27Libsite-packagesPyInstallerloader thookspyi_rth_qt4plugins.py修改如下:

  1. import os
  2. import sys
  3. import sip

  4. sip.setapi(u'QDate', 2)
  5. sip.setapi(u'QDateTime', 2)
  6. sip.setapi(u'QString', 2)
  7. sip.setapi(u'QTextStream', 2)
  8. sip.setapi(u'QTime', 2)
  9. sip.setapi(u'QUrl', 2)
  10. sip.setapi(u'QVariant', 2)
  11. d = "qt4_plugins"
  12. d = os.path.join(sys._MEIPASS, d)


  13. # We remove QT_PLUGIN_PATH variable, beasuse we want Qt4 to load
  14. # plugins only from one path.
  15. if 'QT_PLUGIN_PATH' in os.environ:
  16.     # On some platforms (e.g. AIX) 'os.unsetenv()' is not available and then
  17.     # deleting the var from os.environ does not delete it from the environment.
  18.     # In those cases we cannot delete the variable but only set it to the
  19.     # empty string.
  20.     os.environ['QT_PLUGIN_PATH'] = ''
  21.     del os.environ['QT_PLUGIN_PATH']


  22. # We cannot use QT_PLUGIN_PATH here, because it would not work when
  23. # PyQt4 is compiled with a different CRT from Python (eg: it happens
  24. # with Riverbank's GPL package).

  25. # Suppose that the user usually does not use both (PySide and PyQt4)
  26. # in the same app.
  27. # First try importing PySide and then fallback to PyQt4.
  28. try:
  29.     from PySide.QtCore import QCoreApplication
  30. except ImportError:
  31.     from PyQt4.QtCore import QCoreApplication

  32. # We set "qt4_plugins" as only one path for Qt4 plugins
  33. QCoreApplication.setLibraryPaths([os.path.abspath(d)])
复制代码
改好后打包即可。
在这两个都安装好了之后即可运行添加器件的操作,
我以STM32F0单片机为例说明以下:

第一步:从Keil MDK的*.FLM文件中解析出烧写算法代码和信息
将 D:SoftwareKeil_v5ARMPacksKeilSTM32F0xx_DFP1.5.0FlashSTM32F0xx_16.FLM 文件拷贝到 JMCUProgFastFlashAlgo 目录下,双击该目录下的 flash_algo.py 文件执行,会在该目录下生成 STM32F0xx_16.py

第二步:为想要添加的器件新建一个类
在 JMCUProgFastdevice 目录下新建 STM32F030.py 文件,并添加如下内容:
  1. #coding: utf-8
  2. from .flash import Flash

  3. class STM32F030F4(object):
  4.     CHIP_CORE = 'Cortex-M0'
  5.    
  6.     PAGE_SIZE = 1024 * 1
  7.     SECT_SIZE = 1024 * 1
  8.     CHIP_SIZE = 1024 * 16

  9.     def __init__(self, jlink):
  10.         super(STM32F030F4, self).__init__()
  11.         
  12.         self.jlink = jlink

  13.         self.flash = Flash(self.jlink, STM32F030F4_flash_algo)

  14.     def sect_erase(self, addr, size):
  15.         self.flash.Init(0, 0, 1)
  16.         for i in range(addr // self.SECT_SIZE, (addr + size + (self.SECT_SIZE - 1)) // self.SECT_SIZE):
  17.             self.flash.EraseSector(self.SECT_SIZE * i)
  18.         self.flash.UnInit(1)

  19.     def chip_write(self, addr, data):
  20.         if len(data)%self.PAGE_SIZE:
  21.             data = data + [0xFF] * (self.PAGE_SIZE - len(data)%self.PAGE_SIZE)

  22.         self.sect_erase(addr, len(data))

  23.         self.flash.Init(0, 0, 2)
  24.         for i in range(0, len(data)//self.PAGE_SIZE):
  25.             self.flash.ProgramPage(0x08000000 + addr + self.PAGE_SIZE * i, data[self.PAGE_SIZE*i : self.PAGE_SIZE*(i+1)])
  26.         self.flash.UnInit(2)

  27.     def chip_read(self, addr, size, buff):
  28.         data = self.jlink.read_mem(0x08000000 + addr, size)

  29.         buff.extend([ord(x) for x in data])


  30. STM32F030F4_flash_algo = {
  31.     'load_address' : 0x20000000,
  32.     'instructions' : [
  33.         0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2,
  34.         0x49454846, 0x49466041, 0x21006041, 0x68C16001, 0x43112214, 0x69C060C1, 0xD4060740, 0x49414842,
  35.         0x21066001, 0x49416041, 0x20006081, 0x483B4770, 0x22806901, 0x61014311, 0x47702000, 0x4837B530,
  36.         0x241468C1, 0x60C14321, 0x25046901, 0x61014329, 0x22406901, 0x61014311, 0x4A334935, 0x6011E000,
  37.         0x07DB68C3, 0x6901D1FB, 0x610143A9, 0x422168C1, 0x68C1D004, 0x60C14321, 0xBD302001, 0xBD302000,
  38.         0x4926B530, 0x231468CA, 0x60CA431A, 0x2402690A, 0x610A4322, 0x69086148, 0x43102240, 0x48246108,
  39.         0xE0004A21, 0x68CD6010, 0xD1FB07ED, 0x43A06908, 0x68C86108, 0xD0034018, 0x431868C8, 0x200160C8,
  40.         0xB5F0BD30, 0x1C494D15, 0x68EB0849, 0x24040049, 0x60EB4323, 0x4C162714, 0x692BE01A, 0x43332601,
  41.         0x8813612B, 0x4B108003, 0x601CE000, 0x07F668EE, 0x692BD1FB, 0x005B085B, 0x68EB612B, 0xD004423B,
  42.         0x433868E8, 0x200160E8, 0x1C80BDF0, 0x1E891C92, 0xD1E22900, 0xBDF02000, 0x45670123, 0x40022000,
  43.         0xCDEF89AB, 0x00005555, 0x40003000, 0x00000FFF, 0x0000AAAA, 0x00000000
  44.     ],

  45.     'pc_Init'            : 0x20000021,
  46.     'pc_UnInit'          : 0x2000004F,
  47.     'pc_EraseSector'     : 0x200000A1,
  48.     'pc_ProgramPage'     : 0x200000E3,
  49.     'pc_Verify'          : 0x12000001F,
  50.     'pc_EraseChip'       : 0x2000005D,
  51.     'pc_BlankCheck'      : 0x12000001F,
  52.     'pc_Read'            : 0x12000001F,
  53.    
  54.     'static_base'        : 0x20000400,
  55.     'begin_data'         : 0x20000800,
  56.     'begin_stack'        : 0x20001000,

  57.     'analyzer_supported' : False,

  58.     # Relative region addresses and sizes
  59.     'ro_start'           : 0x00000000,
  60.     'ro_size'            : 0x00000134,
  61.     'rw_start'           : 0x00000134,
  62.     'rw_size'            : 0x00000004,
  63.     'zi_start'           : 0x00000138,
  64.     'zi_size'            : 0x00000000,

  65.     # Flash information
  66.     'flash_start'        : 0x08000000,
  67.     'flash_size'         : 0x00004000,
  68.     'flash_page_size'    : 0x00000400,
  69.     'sector_sizes': (
  70.         (0x00000, 0x00400),
  71.     )
  72. }
复制代码

然后即可运行打包!
附上我打包好的: 编程器.zip (11.63 MB, 下载次数: 6) 2019-10-11 13:58 上传 点击文件名下载附件
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
Excellence
1楼-- · 2019-12-10 19:57
谢谢分享,有64dll
Excellence
2楼-- · 2019-12-10 21:32
有64位dll文件
weiwei4
3楼-- · 2019-12-11 03:27
谢谢分享

一周热门 更多>