diff options
author | Michael Hope <michael.hope@linaro.org> | 2010-09-29 20:20:32 +1300 |
---|---|---|
committer | Michael Hope <michael.hope@linaro.org> | 2010-09-29 20:20:32 +1300 |
commit | 97f6b77b580646f5771ff283a3c586045c0e8425 (patch) | |
tree | 0052056a24afe2ed58895bee7d528f1aa6f9adba | |
parent | 3b48e2101810db085972a02d682b576076f1f94c (diff) | |
download | librambutan-97f6b77b580646f5771ff283a3c586045c0e8425.tar.gz librambutan-97f6b77b580646f5771ff283a3c586045c0e8425.zip |
Make the initial chip detection much more robust.
-rwxr-xr-x | support/stm32loader.py | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/support/stm32loader.py b/support/stm32loader.py index a817efc..7509871 100755 --- a/support/stm32loader.py +++ b/support/stm32loader.py @@ -26,6 +26,7 @@ import sys, getopt import serial import time import glob +import time try: from progressbar import * @@ -54,7 +55,7 @@ class CommandInterface: stopbits=1, xonxoff=0, # enable software flow control rtscts=0, # disable RTS/CTS flow control - timeout=5 # set a timeout value, None for waiting forever + timeout=0.5 # set a timeout value, None for waiting forever ) @@ -62,7 +63,7 @@ class CommandInterface: got = self.sp.read(1) if not got: - raise CmdException("No response") + raise CmdException("No response to %s" % info) # wait for ask ask = ord(got) @@ -73,10 +74,10 @@ class CommandInterface: else: if ask == 0x1F: # NACK - raise CmdException("NACK "+info) + raise CmdException("Chip replied with a NACK during %s" % info) else: - # Unknow responce - raise CmdException("Unknow response. "+info+": "+hex(ask)) + # Unknown responce + raise CmdException("Unrecognised response %x to %s" % (ask, info)) def reset(self): self.sp.setDTR(0) @@ -89,8 +90,21 @@ class CommandInterface: self.sp.setRTS(0) self.reset() - self.sp.write("\x7F") # Syncro - return self._wait_for_ask("Syncro") + # Be a bit more persistant when trying to initialise the chip + stop = time.time() + 5.0 + + while time.time() <= stop: + self.sp.write('\x7f') + + got = self.sp.read() + + # The chip will ACK a sync the very first time and + # NACK it every time afterwards + if got and got in '\x79\x1f': + # Synced up + return + + raise CmdException('No response while trying to sync') def releaseChip(self): self.sp.setRTS(1) |