From 95e8a707ca19da29d734ef5fa6b0865448e0fee1 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Tue, 26 Apr 2022 10:37:49 -0400 Subject: [PATCH] flash_can: attempt to reset the mcu if an error is encountered Signed-off-by: Eric Callahan --- scripts/flash_can.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/scripts/flash_can.py b/scripts/flash_can.py index bd559aa..2441f96 100755 --- a/scripts/flash_can.py +++ b/scripts/flash_can.py @@ -165,6 +165,11 @@ class CanFlasher: ) except asyncio.TimeoutError: if tries: + # clear the read buffer + try: + await self.node.read(2048, timeout=.1) + except asyncio.TimeoutError: + pass output_line("\nRead Timeout, Retrying...") else: if len(buf) == self.block_size: @@ -383,10 +388,15 @@ class CanSocket: node = self._set_node_id(uuid) flasher = CanFlasher(node, fw_path) await asyncio.sleep(.5) - await flasher.connect_btl() - await flasher.send_file() - await flasher.verify_file() - await flasher.finish() + try: + await flasher.connect_btl() + await flasher.send_file() + await flasher.verify_file() + finally: + # always attempt to send the complete command. If + # there is an error it will exit the bootloader + # unless comms were broken + await flasher.finish() async def run_query(self, intf: str): try: