diff --git a/scripts/stm32_mem.py b/scripts/stm32_mem.py index d30a855..732685c 100755 --- a/scripts/stm32_mem.py +++ b/scripts/stm32_mem.py @@ -89,7 +89,10 @@ def stm32_scan(args, test): exit(-1) for dev in devs: - dfudev = dfu.dfu_device(*dev) + try: + dfudev = dfu.dfu_device(*dev) + except: + return 0 man = dfudev.handle.getString(dfudev.dev.iManufacturer, 30) if man == "Black Sphere Technologies": bmp = bmp + 1 if bmp == 0 : diff --git a/src/target/cortexm.c b/src/target/cortexm.c index 86e46fd..cbd769b 100644 --- a/src/target/cortexm.c +++ b/src/target/cortexm.c @@ -413,6 +413,8 @@ void cortexm_detach(target *t) /* Disable debug */ target_mem_write32(t, CORTEXM_DHCSR, CORTEXM_DHCSR_DBGKEY); + /* Add some clock cycles to get the CPU running again.*/ + target_mem_read32(t, 0); } enum { DB_DHCSR, DB_DCRSR, DB_DCRDR, DB_DEMCR };