Mercurial > lcfOS
diff python/st-flash.py @ 116:90b03bc018cf
Added loader code from openocd
author | Windel Bouwman |
---|---|
date | Mon, 07 Jan 2013 19:30:01 +0100 |
parents | 92b2bf0da1ec |
children | 51cc127648e4 |
line wrap: on
line diff
--- a/python/st-flash.py Sun Jan 06 18:13:17 2013 +0100 +++ b/python/st-flash.py Mon Jan 07 19:30:01 2013 +0100 @@ -9,19 +9,24 @@ return int(s, 16) return int(s) -parser = argparse.ArgumentParser(description='ST-link flash utility') +parser = argparse.ArgumentParser( + description='ST-link flash utility by Windel Bouwman') subparsers = parser.add_subparsers(title='commands', description='possible commands', dest='command') readparser = subparsers.add_parser('read', help='read flash contents') -readparser.add_argument('filename', type=argparse.FileType(mode='wb')) +readparser.add_argument('filename', type=argparse.FileType('wb', 0)) readparser.add_argument('address', type=hex2int) readparser.add_argument('size', type=hex2int) writeparser = subparsers.add_parser('write', help='write flash contents') -writeparser.add_argument('filename', type=argparse.FileType(mode='rb')) +writeparser.add_argument('filename', type=argparse.FileType('rb')) writeparser.add_argument('address', type=hex2int) +verifyparser = subparsers.add_parser('verify', help='verify flash contents') +verifyparser.add_argument('filename', type=argparse.FileType('rb')) +verifyparser.add_argument('address', type=hex2int) + eraseparser = subparsers.add_parser('erase', help='erase flash contents') args = parser.parse_args() @@ -32,11 +37,7 @@ # In any command case, open a device: stl = stlink.STLink() -try: - stl.open() -except stlink.STLinkException as e: - print(e) - sys.exit(2) +stl.open() # Enter the right mode: if stl.CurrentMode == stlink.DFU_MODE: @@ -50,13 +51,16 @@ sys.exit(2) if args.command == 'read': - print('Reading!') + dev_content = stl.readFlash(args.address, args.size) + args.filename.write(dev_content) elif args.command == 'write': content = args.filename.read() - print('Write flash :)', len(content)) stl.writeFlash(args.address, content) +elif args.command == 'verify': + content = args.filename.read() + stl.verifyFlash(args.address, content) elif args.command == 'erase': - print('erase') + stl.eraseFlash() else: print('unknown command', args.command)