|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +Flash the WiPy (format, update service pack and program). |
| 5 | +
|
| 6 | +Example: |
| 7 | +
|
| 8 | +> python uniflash.py -u "C:\ti\uniflash_3.2\uniflashCLI.bat" -c "C:\VirtualBoxShared\GitHub\wipy_uniflash.usf" -p 8 -s "C:\ti\CC31xx_CC32xx_ServicePack_1.0.0.10.0\servicepack_1.0.0.10.0.bin" |
| 9 | +
|
| 10 | +or: |
| 11 | +
|
| 12 | +> python uniflash.py -u "C:\ti\uniflash_3.2\uniflashCLI.bat" -c "C:\VirtualBoxShared\GitHub\launchxl_uniflash.usf" -p 8 -s "C:\ti\CC31xx_CC32xx_ServicePack_1.0.0.10.0\servicepack_1.0.0.10.0.bin" |
| 13 | +
|
| 14 | +""" |
| 15 | + |
| 16 | +import sys |
| 17 | +import argparse |
| 18 | +import subprocess |
| 19 | + |
| 20 | + |
| 21 | +def print_exception(e): |
| 22 | + print ('Exception: {}, on line {}'.format(e, sys.exc_info()[-1].tb_lineno)) |
| 23 | + |
| 24 | + |
| 25 | +def main(): |
| 26 | + cmd_parser = argparse.ArgumentParser(description='Flash the WiPy and optionally run a small test on it.') |
| 27 | + cmd_parser.add_argument('-u', '--uniflash', default=None, help='the path to the uniflash cli executable') |
| 28 | + cmd_parser.add_argument('-c', '--config', default=None, help='the path to the uniflash config file') |
| 29 | + cmd_parser.add_argument('-p', '--port', default=8, help='the com serial port') |
| 30 | + cmd_parser.add_argument('-s', '--servicepack', default=None, help='the path to the servicepack file') |
| 31 | + args = cmd_parser.parse_args() |
| 32 | + |
| 33 | + result = 1 |
| 34 | + com_port = 'com=' + str(args.port) |
| 35 | + servicepack_path = 'spPath=' + args.servicepack |
| 36 | + |
| 37 | + try: |
| 38 | + if args.uniflash == None or args.config == None: |
| 39 | + raise ValueError('uniflash path and config path are mandatory') |
| 40 | + if args.servicepack == None: |
| 41 | + subprocess.check_call([args.uniflash, '-config', args.config, '-setOptions', com_port, '-operations', 'format', 'program'], stderr=subprocess.STDOUT) |
| 42 | + else: |
| 43 | + subprocess.check_call([args.uniflash, '-config', args.config, '-setOptions', com_port, servicepack_path, '-operations', 'format', 'servicePackUpdate', 'program'], stderr=subprocess.STDOUT) |
| 44 | + result = 0 |
| 45 | + except Exception as e: |
| 46 | + print_exception(e) |
| 47 | + finally: |
| 48 | + if result: |
| 49 | + print ("ERROR: Programming failed!") |
| 50 | + else: |
| 51 | + print ("Board programmed OK") |
| 52 | + sys.exit(result) |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + main() |
0 commit comments