comparison python/st-flash.py @ 246:f254b87258e6

Added hexfile to zcc
author Windel Bouwman
date Thu, 25 Jul 2013 08:11:30 +0200
parents 58155c7c4a8e
children
comparison
equal deleted inserted replaced
245:66912720d712 246:f254b87258e6
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 import argparse, sys 3 import argparse, sys
4 import stlink, stm32 4 import stlink, stm32
5 import hexfile
5 6
6 def hex2int(s): 7 def hex2int(s):
7 if s.startswith('0x'): 8 if s.startswith('0x'):
8 s = s[2:] 9 s = s[2:]
9 return int(s, 16) 10 return int(s, 16)
22 writeparser = subparsers.add_parser('write', help='write flash contents') 23 writeparser = subparsers.add_parser('write', help='write flash contents')
23 writeparser.add_argument('filename', type=argparse.FileType('rb')) 24 writeparser.add_argument('filename', type=argparse.FileType('rb'))
24 writeparser.add_argument('address', type=hex2int) 25 writeparser.add_argument('address', type=hex2int)
25 26
26 hexwriteparser = subparsers.add_parser('hexwrite', help='write hexfile to flash') 27 hexwriteparser = subparsers.add_parser('hexwrite', help='write hexfile to flash')
27 hexwriteparser.add_argument('filename', type=argparse.FileType('r')) 28 hexwriteparser.add_argument('hexfile', type=argparse.FileType('r'))
28 29
29 verifyparser = subparsers.add_parser('verify', help='verify flash contents') 30 verifyparser = subparsers.add_parser('verify', help='verify flash contents')
30 verifyparser.add_argument('filename', type=argparse.FileType('rb')) 31 verifyparser.add_argument('filename', type=argparse.FileType('rb'))
31 verifyparser.add_argument('address', type=hex2int) 32 verifyparser.add_argument('address', type=hex2int)
32 33
59 dev_content = dev.readFlash(args.address, args.size) 60 dev_content = dev.readFlash(args.address, args.size)
60 args.filename.write(dev_content) 61 args.filename.write(dev_content)
61 elif args.command == 'write': 62 elif args.command == 'write':
62 content = args.filename.read() 63 content = args.filename.read()
63 dev.writeFlash(args.address, content) 64 dev.writeFlash(args.address, content)
65 elif args.command == 'hexwrite':
66 hf = hexfile.HexFile()
67 hf.load(args.hexfile)
68 r = hf.regions[0]
69 dev.writeFlash(r.address, r.data)
64 elif args.command == 'verify': 70 elif args.command == 'verify':
65 content = args.filename.read() 71 content = args.filename.read()
66 dev.verifyFlash(args.address, content) 72 dev.verifyFlash(args.address, content)
67 elif args.command == 'erase': 73 elif args.command == 'erase':
68 dev.eraseFlash() 74 dev.eraseFlash()