diff python/st-flash.py @ 128:51cc127648e4

Splitup in interface and device
author Windel Bouwman
date Sun, 13 Jan 2013 17:31:35 +0100
parents 90b03bc018cf
children 9e350a7dde98
line wrap: on
line diff
--- a/python/st-flash.py	Sun Jan 13 13:02:29 2013 +0100
+++ b/python/st-flash.py	Sun Jan 13 17:31:35 2013 +0100
@@ -1,13 +1,13 @@
 #!/usr/bin/python
 
 import argparse, sys
-import stlink 
+import stlink, stm32
 
 def hex2int(s):
    if s.startswith('0x'):
       s = s[2:]
       return int(s, 16)
-   return int(s)
+   raise ValueError('Hexadecimal value must begin with 0x')
 
 parser = argparse.ArgumentParser(
    description='ST-link flash utility by Windel Bouwman')
@@ -36,7 +36,7 @@
    sys.exit(1)
 
 # In any command case, open a device:
-stl = stlink.STLink()
+stl = stlink.STLink2()
 stl.open()
 
 # Enter the right mode:
@@ -50,17 +50,20 @@
    print('Only working on stm32f4discovery board for now.')
    sys.exit(2)
 
+# Retrieve the connected device, if any:
+dev = stl.getDevice()
+
 if args.command == 'read':
-   dev_content = stl.readFlash(args.address, args.size)
+   dev_content = dev.readFlash(args.address, args.size)
    args.filename.write(dev_content)
 elif args.command == 'write':
    content = args.filename.read()
-   stl.writeFlash(args.address, content)
+   dev.writeFlash(args.address, content)
 elif args.command == 'verify':
    content = args.filename.read()
-   stl.verifyFlash(args.address, content)
+   dev.verifyFlash(args.address, content)
 elif args.command == 'erase':
-   stl.eraseFlash()
+   dev.eraseFlash()
 else:
    print('unknown command', args.command)