Skip to content

Commit

Permalink
Merge pull request swift-nav#88 from mfine/mfine-improve-bootloader
Browse files Browse the repository at this point in the history
Improve bootloader, update log output
  • Loading branch information
mfine committed Jun 25, 2015
2 parents 42d7a80 + 1f74567 commit 4593fde
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
16 changes: 8 additions & 8 deletions piksi_tools/bootload.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,26 @@ def _handshake_callback(self, sbp_msg):
MsgBootloaderHandshakeDevice(sbp_msg).flags & 0xF)
self.handshake_received = True

def wait_for_handshake(self, timeout=None):
def handshake(self, timeout=None):
if timeout is not None:
t0 = time.time()
self.handshake_received = False
expire = time.time() + 15.0
self.link.send(SBP_MSG_RESET, "")
while not self.handshake_received:
time.sleep(0.1)
if timeout is not None:
if time.time()-timeout > t0:
return False
return True

def reply_handshake(self):
if time.time() > expire:
expire = time.time() + 15.0
self.link.send(SBP_MSG_RESET, "")
# < 0.45 of SBP protocol, reuse single handshake message.
if self.sbp_version < (0, 45):
self.link.send(SBP_MSG_BOOTLOADER_HANDSHAKE_DEPRECATED, '\x00')
else:
self.link.send(SBP_MSG_BOOTLOADER_HANDSHAKE_REQUEST, '\x00')
return True

def jump_to_app(self):
self.link.send(SBP_MSG_BOOTLOADER_JUMP_TO_APP, '\x00')
Expand Down Expand Up @@ -151,19 +154,16 @@ def main():
with serial_link.get_driver(use_ftdi, port, baud) as driver:
# Handler with context
with Handler(driver.read, driver.write) as link:
link.send(SBP_MSG_RESET, "")
time.sleep(0.2)
link.add_callback(serial_link.printer, SBP_MSG_PRINT)

# Tell Bootloader we want to write to the flash.
with Bootloader(link) as piksi_bootloader:
print "Waiting for bootloader handshake message from Piksi ...",
sys.stdout.flush()
try:
piksi_bootloader.wait_for_handshake()
piksi_bootloader.handshake()
except KeyboardInterrupt:
return
piksi_bootloader.reply_handshake()
print "received."
print "Piksi Onboard Bootloader Version:", piksi_bootloader.version
if piksi_bootloader.sbp_version > (0, 0):
Expand Down
5 changes: 2 additions & 3 deletions piksi_tools/console/update_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def create_flash(self, flash_type):

self._write("Waiting for bootloader handshake message from Piksi ...")
reset_prompt = None
handshake_received = self.pk_boot.wait_for_handshake(1)
handshake_received = self.pk_boot.handshake(1)

# Prompt user to reset Piksi if we don't receive the handshake message
# within a reasonable amount of tiime (firmware might be corrupted).
Expand All @@ -607,12 +607,11 @@ def create_flash(self, flash_type):
reset_prompt.run(block=False)

while not reset_prompt.closed and not handshake_received:
handshake_received = self.pk_boot.wait_for_handshake(1)
handshake_received = self.pk_boot.handshake(1)

reset_prompt.kill()
reset_prompt.wait()

self.pk_boot.reply_handshake()
self._write("received bootloader handshake message.")
self._write("Piksi Onboard Bootloader Version: " + self.pk_boot.version)

Expand Down
4 changes: 2 additions & 2 deletions piksi_tools/testing/prepare_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ cd testing
./cycle_device_power.py $2
sleep 1
cd ..
./bootload.py -e -s -p $2 testing/$3 > testing/bootload_log1
./bootload.py -e -s -p $2 testing/$3 > testing/bootload_log2
cd testing
./cycle_device_power.py $2
sleep 1
cd ..
./bootload.py -m -p $2 testing/$4 >> testing/bootload_log1
./bootload.py -m -p $2 testing/$4 >> testing/bootload_log2
cd testing

# Sleep for a while to make sure both devices are booted up and ready to go
Expand Down

0 comments on commit 4593fde

Please sign in to comment.