From a5aede52cbd391989aadc3b05ef3a60e0d1dcd8f Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 10 Mar 2019 14:35:25 -0400 Subject: [PATCH] flash_usb: Try to make the bossac atsam reboot logic more stable Signed-off-by: Kevin O'Connor --- scripts/flash_usb.py | 20 +++++++++++++++----- src/atsam/Makefile | 5 ++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/scripts/flash_usb.py b/scripts/flash_usb.py index 5b1a6865..a27f905d 100755 --- a/scripts/flash_usb.py +++ b/scripts/flash_usb.py @@ -54,16 +54,18 @@ def flash_bossac(device, binfile, extra_flags=[]): if os.path.exists(ttyname) and not os.path.exists(pathname): pathname = ttyname baseargs = ["lib/bossac/bin/bossac", "-U", "-p", pathname] - args = baseargs + extra_flags + ["-w", binfile, "-v", "-b"] + args = baseargs + extra_flags + ["-w", binfile, "-v"] sys.stderr.write(" ".join(args) + '\n\n') res = subprocess.call(args) if res != 0: raise error("Error running bossac") if "-R" not in extra_flags: - time.sleep(0.500) args = baseargs + ["-b", "-R"] try: subprocess.check_output(args, stderr=subprocess.STDOUT) + if "-b" not in extra_flags: + time.sleep(1.) + subprocess.check_output(args, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: pass @@ -90,7 +92,15 @@ def flash_dfuutil(device, binfile, extra_flags=[]): # Device specific helpers ###################################################################### -def flash_atsam(options, binfile): +def flash_atsam3(options, binfile): + try: + flash_bossac(options.device, binfile, ["-e", "-b"]) + except error as e: + sys.stderr.write("Failed to flash to %s: %s\n" % ( + options.device, str(e))) + sys.exit(-1) + +def flash_atsam4(options, binfile): try: flash_bossac(options.device, binfile, ["-e"]) except error as e: @@ -99,7 +109,7 @@ def flash_atsam(options, binfile): sys.exit(-1) def flash_atsamd(options, binfile): - extra_flags = ["--offset=" + options.offset, "-R"] + extra_flags = ["--offset=" + options.offset, "-b", "-R"] try: flash_bossac(options.device, binfile, extra_flags) except error as e: @@ -153,7 +163,7 @@ def flash_stm32f1(options, binfile): sys.exit(-1) MCUTYPES = { - 'atsam': flash_atsam, 'atsamd': flash_atsamd, + 'atsam3': flash_atsam3, 'atsam4': flash_atsam4, 'atsamd': flash_atsamd, 'lpc176x': flash_lpc176x, 'stm32f1': flash_stm32f1 } diff --git a/src/atsam/Makefile b/src/atsam/Makefile index 3bafd20f..780a478a 100644 --- a/src/atsam/Makefile +++ b/src/atsam/Makefile @@ -58,6 +58,9 @@ lib/bossac/bin/bossac: @echo " Building bossac" $(Q)make -C lib/bossac bin/bossac +FLASH_TYPE-$(CONFIG_MACH_SAM3X) := atsam3 +FLASH_TYPE-$(CONFIG_MACH_SAM4) := atsam4 + flash: $(OUT)klipper.bin lib/bossac/bin/bossac @echo " Flashing $< to $(FLASH_DEVICE)" - $(Q)$(PYTHON) ./scripts/flash_usb.py -t atsam -d "$(FLASH_DEVICE)" $(OUT)klipper.bin + $(Q)$(PYTHON) ./scripts/flash_usb.py -t $(FLASH_TYPE-y) -d "$(FLASH_DEVICE)" $(OUT)klipper.bin