#!/usr/bin/env python3 # -*- coding: cp1251 -*- import jlinkarm as jl import os, sys, time, struct dllfilename = 'D:/MCU/SEGGER/JLink_V612i/JLinkARM.dll' if __name__ == '__main__': if len(sys.argv) >= 2: if sys.argv[1] == '-h': print 'Usage: ldram.py ram_all.bin' exit(0) imgfilename = 'build/bin/ram_all.bin' if len(sys.argv) > 1: if sys.argv[1]: imgfilename = sys.argv[1] try: ff = open(imgfilename, "rb") except: print "Error file open " + imgfilename exit(1) jl.loadJLinkARMdll(dllfilename) jl.open() if jl.is_connected == 0: raise RuntimeError('Jlink not connected') jl.exec_command('device Cortex-M3', 0, 0) jl.exec_command('endian little', 0, 0) jl.tif_select(1) jl.set_speed(1000) jl.clear_RESET() jl.clear_TRST() time.sleep(0.01) jl.set_RESET() jl.set_TRST() jl.reset() jl.halt() jl.set_speed(3500) bin = ff.read() get_dword = lambda address: struct.unpack('