def read(mw, transport, args): bl = MW.Bootloader() bl.start() sleep(1) retval = 1 uid = MW.BootMsg.UID.getUIDFromHexString(args.uid[0]) # address = 0x08000000 + 20480 + 2048 +2048 address = int(args.address[0]) if not bl.select(uid): print("Cannot select device") return 1 if not bl.ihex_read(uid, address): print("Cannot write module name") return 1 bl.deselect(uid) # bl.select("000000000000000000000000") # if not bl.deselect(uid): # print("Cannot deselect device") # return 1 bl.stop() return retval
def name(mw, transport, args): uid = MW.BootMsg.UID.getUIDFromHexString(args.uid[0]) name = args.name[0] if len(name) > MW.BootMsg.UIDAndName.NAME_LENGTH: print("Name must be at most %d bytes long" % (MW.BootMsg.UIDAndName.NAME_LENGTH)) return 1 bl = MW.Bootloader() bl.start() sleep(1) retval = 0 if not bl.select(uid): print("Cannot select device") retval = 1 if not bl.write_name(uid, name): print("Cannot write module name") retval = 1 if not bl.deselect(uid): print("Cannot deselect device") retval = 1 bl.stop() return retval
def moduleid(mw, transport, args): uid = MW.BootMsg.UID.getUIDFromHexString(args.uid[0]) id = int(args.id[0]) if id > 255: print("ID must be <= 255 ") return 1 bl = MW.Bootloader() bl.start() sleep(1) retval = 0 if not bl.select(uid): print("Cannot select device") retval = 1 if not bl.write_id(uid, id): print("Cannot write module id") retval = 1 if not bl.deselect(uid): print("Cannot deselect device") retval = 1 bl.stop() return retval
def protocol_version(mw, transport, args): uid = MW.BootMsg.UID.getUIDFromHexString(args.uid[0]) bl = MW.Bootloader() bl.start() sleep(1) retval = 0 if not bl.select(uid): print("Cannot select device") retval = 1 else: pv = bl.protocol_version(uid) if pv is None: print("Cannot read protocol version") retval = 1 else: print(pv) if not bl.deselect(uid): print("Cannot deselect device") retval = 1 bl.stop() return retval
def read_tags(mw, transport, args): uid = MW.BootMsg.UID.getUIDFromHexString(args.uid[0]) bl = MW.Bootloader() bl.start() sleep(1) retval = 0 if not bl.select(uid): print("Cannot select device") retval = 1 tags = bl.tags_read(uid, 0) if tags is None: print("Cannot read tags") retval = 1 else: tmp = tags.replace(b'\xff', b'\x00') x = tmp.split(b'\0') for y in x: if len(y) > 0: print(y.decode('ascii')) if not bl.deselect(uid): print("Cannot deselect device") retval = 1 bl.stop() return retval
def erase(mw, transport, args): what = args.what[0] if what == 'program': pass elif what == 'user': pass elif what == 'configuration': pass elif what == 'all': pass else: print("Erase what?") return 1 uid = MW.BootMsg.UID.getUIDFromHexString(args.uid[0]) bl = MW.Bootloader() bl.start() sleep(1) retval = 0 if not bl.select(uid): print("Cannot select device") return 1 what = args.what[0] if what == 'program': if not bl.eraseProgram(uid): print("Cannot erase program") retval = 2 if what == 'user': if not bl.eraseUserConfiguration(uid): print("Cannot erase user configuration") retval = 2 if what == 'configuration': if not bl.eraseConfiguration(uid): print("Cannot erase user configuration") retval = 2 if what == 'all': if not bl.eraseConfiguration(uid): print("Cannot erase configuration") retval = 2 if not bl.eraseProgram(uid): print("Cannot erase program") retval = 2 if not bl.deselect(uid): print("Cannot deselect device") retval = 1 bl.stop() return retval
def reset_all(mw, transport, args): bl = MW.Bootloader() bl.start() sleep(1) retval = 0 if not bl.reset_all(): retval = 1 bl.stop() return retval
def boot(mw, transport, args): bl = MW.Bootloader() bl.start() sleep(1) bl.deselect(0) while MW.ok(): sleep(0.25) bl.bootload() bl.stop() return 0
def identify(mw, transport, args): bl = MW.Bootloader() bl.start() sleep(1) uid = MW.BootMsg.UID.getUIDFromHexString(args.uid[0]) retval = 1 if bl.identify(uid): retval = 0 bl.stop() return retval
def deselect(mw, transport, args): bl = MW.Bootloader() bl.start() sleep(1) uid = MW.BootMsg.UID.getUIDFromHexString(args.uid[0]) retval = 0 if not bl.deselect(uid): print("Cannot deselect device") retval = 1 bl.stop() return retval
def ls(mw, transport, args): bl = MW.Bootloader() bl.start() sleep(1) if args.interactive: while MW.ok(): print("------------------------") for k in bl.getSlaves(): print(("%08X" % k) + ', ' + bl._slavesTypes[k] + ', ' + bl._slavesNames[k]) pass bl.clear() sleep(2) else: sleep(3) for k in bl.getSlaves(): print("%08X" % k) bl.stop() return 0
def load(mw, transport, args): bl = MW.Bootloader() bl.start() sleep(1) retval = 1 uid = MW.BootMsg.UID.getUIDFromHexString(args.uid[0]) ihex_file = args.file[0] if not uid in bl.getSlaves(): print("Device is not in bootload mode") return 1 if not bl.select(uid): print("Cannot select device") return 1 try_again = True if try_again: desc = bl.describe_v3(uid) if desc is None: try_again = True else: print("TARGET:" + formatDescription_V3(uid, desc)) try_again = False if try_again: desc = bl.describe_v2(uid) if desc is None: try_again = True else: print("TARGET:" + formatDescription_V2(uid, desc)) try_again = False if try_again: retval = 1 else: programSize = desc.program ih = IntelHex() ih.loadfile(ihex_file, format="hex") ih.padding = 0xFF bin = ih.tobinarray(size=programSize) crc = stm32_crc32_bytes(0xffffffff, bin) print("CRC: " + hex(crc)) what = args.what[0] if what == 'program': if not bl.eraseProgram(uid): print("Cannot erase program") return 1 with open(ihex_file) as f: data = f.read().splitlines() write_ihex(bl, data, crc) if what == 'program': if not bl.write_program_crc(uid, crc): print("Cannot write CRC") return 1 bl.deselect(uid) bl.stop() return retval
def update(mw, transport, args): bl = MW.Bootloader() bl.start() sleep(1) retval = 1 uid = 0 if len(args.uid) == 0 and len(bl.getSlaves()) == 1: uid = next(iter(bl.getSlaves())) else: uid = MW.BootMsg.UID.getUIDFromHexString(args.uid[0]) if not uid in bl.getSlaves(): print("Device is not in bootload mode") return 1 if not bl.select(uid): print("Cannot select device") return 1 try_again = True if try_again: desc = bl.describe_v3(uid) if desc is None: try_again = True else: print("TARGET:" + formatDescription_V3(uid, desc)) try_again = False if try_again: desc = bl.describe_v2(uid) if desc is None: try_again = True else: print("TARGET:" + formatDescription_V2(uid, desc)) try_again = False if try_again: retval = 1 else: fwu_file = args.file[0] fwu = fwu_parse(fwu_file) if len(fwu.program) > 0: if not bl.eraseProgram(uid): print("Cannot erase program") return 1 write_ihex(bl, fwu.program, fwu.program_crc) if len(fwu.program) > 0: if not bl.write_program_crc(uid, fwu.program_crc): print("Cannot write CRC") return 1 bl.deselect(uid) bl.stop() return retval
def describe(mw, transport, args): bl = MW.Bootloader() bl.start() retval = 0 if len(args.uid) == 1: sleep(1) uid = MW.BootMsg.UID.getUIDFromHexString(args.uid[0]) if not bl.select(uid): print("Cannot select device") return 1 try_again = True if try_again: desc = bl.describe_v3(uid) if desc is None: try_again = True else: print(formatDescription_V3(uid, desc)) try_again = False if try_again: desc = bl.describe_v2(uid) if desc is None: try_again = True else: print(formatDescription_V2(uid, desc)) try_again = False if try_again: retval = 1 if not bl.deselect(uid): print("Cannot deselect device") retval = 1 else: sleep(3) uids = bl.getSlaves() for k in uids: uid = k if not bl.select(uid): print("Cannot select device") return 1 try_again = True if try_again: desc = bl.describe_v3(uid) if desc is None: try_again = True else: print(formatDescription_V3(uid, desc)) try_again = False if try_again: desc = bl.describe_v2(uid) if desc is None: try_again = True else: print(formatDescription_V2(uid, desc)) try_again = False if try_again: retval = 1 if not bl.deselect(uid): print("Cannot deselect device") retval = 1 #bl.select(0xFFFFFFFF) #bl.deselect(0xFFFFFFFF) bl.stop() return retval