def main(): inifile = configparser.ConfigParser() inifile.read('bootloader.ini') comport = inifile.get('settings', 'comport') # baudrate = inifile.get('settings', 'baudrate') print('-------------------------------------------------------- START {}'. format(sys.argv[0])) hex_filename = 'template.hex' if 2 == len(sys.argv): hex_filename = sys.argv[1] bl = stm32bootloader(comport) if bl.init() < 0: return 1 # error if 0 != bl.set_loadermode(): print('boot loaderに同期できません。') return 1 # error # --------------------------------------------------------------- print('blank checking...', end='') mem = bl.ReadMemory(0x08000000, 0x100) for b in mem: if b != 255: bl.FlashDump() print('write.py:フラッシュメモリーが消去されていません。') return 1 # error print('OK.') try: ih = IntelHex(hex_filename) except FileNotFoundError: print('ファイルが見つかりません [{}]'.format(hex_filename)) return 1 # error file_buf = ih.tobinarray() bl.WriteMemory(0x08000000, file_buf) return 0 # no error
def main(): inifile = configparser.ConfigParser() inifile.read('bootloader.ini') comport = inifile.get('settings', 'comport') baudrate = inifile.get('settings', 'baudrate') print('--------------------------------------') bl = stm32bootloader(comport) if bl.init() < 0: return 1 # error if 0 != bl.set_loadermode(): print('boot loaderに同期できません。') return 1 # error bl.FlashDump() return 0 # no error
def main(): inifile = configparser.ConfigParser() inifile.read('bootloader.ini') comport = inifile.get('settings', 'comport') # baudrate = inifile.get('settings', 'baudrate') print('-------------------------------------------------------- START {}'. format(sys.argv[0])) bl = stm32bootloader(comport) if bl.init() < 0: return 1 # error if 0 != bl.set_loadermode(): print('boot loaderに同期できません。') return 1 # error bl.cmdErase() return 0 # no error
def main(): inifile = configparser.ConfigParser() inifile.read('bootloader.ini') comport = inifile.get('settings', 'comport') # baudrate = inifile.get('settings', 'baudrate') print('--------------------------------------') bl = stm32bootloader(comport) if bl.init() < 0: return 1 # error if 0 != bl.set_loadermode(): print('boot loaderに同期できません。') return 1 # error add = 0x08000000 buf = bl.ReadMemoryQuiet(add, 0x100) dump(add, buf) print('Program start') bl.ProgramStart() return 0 # no error
def main(): inifile = configparser.ConfigParser() inifile.read('bootloader.ini') comport = inifile.get('settings', 'comport') # baudrate = inifile.get('settings', 'baudrate') fn = inifile.get('settings','hex_filename') print('filename is[{}]'.format(fn)) return bl = stm32bootloader(comport) print('-------------------------------------------------------- START {}'.format(sys.argv[0])) # bl.cmdGet() mem = maketest() dump(0x20004000, mem) add = 0x20004000 bl.WriteMemory(add, mem) mem = bl.ReadMemory(0x20004000, 0x100) dump(0x0000, mem) return
def main(): inifile = configparser.ConfigParser() inifile.read('bootloader.ini') comport = inifile.get('settings', 'comport') # baudrate = inifile.get('settings', 'baudrate') print('-------------------------------------------------------- START {}'. format(sys.argv[0])) bl = stm32bootloader(comport) if bl.init() < 0: return 1 # error if 0 != bl.set_loadermode(): print('boot loaderに同期できません。') return 1 # error # --------------------------------------------------------------- fn = 'template.hex' try: ih = IntelHex(fn) except FileNotFoundError: print('ファイルが見つかりません [{}]'.format(fn)) return 1 # error file_buf = ih.tobinarray() file_size = len(file_buf) file_md5 = hashlib.md5(file_buf).hexdigest() flash_buf = bl.ReadMemory(0x08000000, file_size) flash_size = len(flash_buf) flash_md5 = hashlib.md5(flash_buf).hexdigest() print('{} {:7d} {}'.format(fn, file_size, file_md5)) print(' FLASH {:7d} {}'.format(flash_size, flash_md5)) with open('flash.bin', 'wb') as f: f.write(flash_buf) if flash_md5 != file_md5: print('MD5 チェックサムエラー') return 1 # error print('MD5 チェックサム OK') return 0 # no error