From e80c8f1e8e2011c4c41e994a66bc9b0d8097e440 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Tue, 10 Jul 2012 08:50:32 +0900 Subject: [PATCH] USB disconnect tool/stlinkv2.py --- ChangeLog | 4 ++++ tool/stlinkv2.py | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b6e8581..7e7d938 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2012-07-10 Niibe Yutaka + + * tool/stlinkv2.py (stlinkv2.usb_disconnect): New. + 2012-07-09 Niibe Yutaka * src/openpgp.c (cmd_pso): For decryption, return error sooner for diff --git a/tool/stlinkv2.py b/tool/stlinkv2.py index 1fc42c6..d2af143 100755 --- a/tool/stlinkv2.py +++ b/tool/stlinkv2.py @@ -216,23 +216,27 @@ class stlinkv2(object): v = self.execute_get("\xf2\x22\x00", 4) return v[0] + (v[1]<<8) + (v[2]<<16) + (v[3]<<24) - # For FST-01-00 and FST-01: LED on, USB off + # For FST-01-00 and FST-01: LED on, USB connect def setup_gpio(self): apb2enr = self.read_memory_u32(0x40021018) apb2enr = apb2enr | 4 | 8 | 0x1000 # Enable port A, port B, and SPI1 self.write_memory_u32(0x40021018, apb2enr) # RCC->APB2ENR self.write_memory_u32(0x4002100c, 4|8|0x1000) # RCC->APB2RSTR self.write_memory_u32(0x4002100c, 0) - self.write_memory_u32(GPIOA+0x0c, 0xfffffbff) # ODR + self.write_memory_u32(GPIOA+0x0c, 0xffffffff) # ODR self.write_memory_u32(GPIOA+0x04, 0x88888383) # CRH self.write_memory_u32(GPIOA+0x00, 0xBBB38888) # CRL self.write_memory_u32(GPIOB+0x0c, 0xffffffff) # ODR self.write_memory_u32(GPIOB+0x04, 0x88888888) # CRH self.write_memory_u32(GPIOB+0x00, 0x88888883) # CRL - # For FST-01-00 and FST-01: LED off, USB off + # For FST-01-00 and FST-01: LED on, USB disconnect + def usb_disconnect(self): + self.write_memory_u32(GPIOA+0x0c, 0xfffffbff) # ODR + + # For FST-01-00 and FST-01: LED off, USB connect def finish_gpio(self): - self.write_memory_u32(GPIOA+0x0c, 0xfffffaff) # ODR + self.write_memory_u32(GPIOA+0x0c, 0xfffffeff) # ODR self.write_memory_u32(GPIOB+0x0c, 0xfffffffe) # ODR apb2enr = self.read_memory_u32(0x40021018) apb2enr = apb2enr & ~(4 | 8 | 0x1000) @@ -562,6 +566,8 @@ def main(show_help, erase_only, no_protect, spi_flash_check, if unlock: stl.reset_sys() stl.option_bytes_write(OPTION_BYTES_ADDR,RDP_KEY) + stl.usb_disconnect() + time.sleep(0.100) stl.finish_gpio() print "Flash ROM read protection disabled. Reset the board, now." return 0 @@ -579,6 +585,8 @@ def main(show_help, erase_only, no_protect, spi_flash_check, stl.flash_erase_all() if erase_only: + stl.usb_disconnect() + time.sleep(0.100) stl.finish_gpio() return 0 @@ -607,6 +615,7 @@ def main(show_help, erase_only, no_protect, spi_flash_check, print "Flash ROM read protection enabled. Reset the board to enable protection." if reset_after_successful_write: + stl.usb_disconnect() stl.reset_sys() stl.run() stl.exit_debug()