From dec12d4b15db918b74b7428f04648f819487f38b Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 23 May 2012 15:48:49 +0900 Subject: [PATCH] fix --- regnual/sys.c | 11 +++++------ tool/gnuk_upgrade.py | 6 ++++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/regnual/sys.c b/regnual/sys.c index e99fcb2..4fc4daa 100644 --- a/regnual/sys.c +++ b/regnual/sys.c @@ -351,6 +351,8 @@ handler vector_table[] __attribute__ ((section(".vectors"))) = { #define FLASH_CR_ERRIE 0x0400 #define FLASH_CR_EOPIE 0x1000 +#define FLASH_OBR_RDPRT 0x00000002 + static int flash_get_status (void) { @@ -430,15 +432,13 @@ flash_write (uint32_t dst_addr, const uint8_t *src, size_t len) return 1; } -#define FLASH_OPTION_BYTE_RDP 0x1ffff800 - int flash_protect (void) { int status; uint16_t rdp; - status = flash_wait_for_last_operation (FLASH_PROGRAM_TIMEOUT); + status = flash_wait_for_last_operation (FLASH_ERASE_TIMEOUT); intr_disable (); if (status == FLASH_COMPLETE) @@ -449,7 +449,7 @@ flash_protect (void) FLASH->CR |= FLASH_CR_OPTER; FLASH->CR |= FLASH_CR_STRT; - status = flash_wait_for_last_operation (FLASH_PROGRAM_TIMEOUT); + status = flash_wait_for_last_operation (FLASH_ERASE_TIMEOUT); if (status != FLASH_TIMEOUT) FLASH->CR &= ~FLASH_CR_OPTER; } @@ -458,8 +458,7 @@ flash_protect (void) if (status != FLASH_COMPLETE) return 0; - rdp = *(volatile uint16_t *)FLASH_OPTION_BYTE_RDP; - if (rdp == 0x00ff) + if ((FLASH->OBR & FLASH_OBR_RDPRT) != 0) return 1; else return 0; diff --git a/tool/gnuk_upgrade.py b/tool/gnuk_upgrade.py index c1dfbd3..d979a74 100755 --- a/tool/gnuk_upgrade.py +++ b/tool/gnuk_upgrade.py @@ -77,7 +77,7 @@ class regnual: value = i, index = 0, buffer = None, timeout = 10000) - time.sleep(0.01) + time.sleep(0.010) res = self.__devhandle.controlMsg(requestType = 0xc0, request = 2, value = 0, index = 0, buffer = 4, timeout = 10000) @@ -98,6 +98,7 @@ class regnual: value = i, index = 0, buffer = None, timeout = 10000) + time.sleep(0.010) res = self.__devhandle.controlMsg(requestType = 0xc0, request = 2, value = 0, index = 0, buffer = 4, timeout = 10000) @@ -109,12 +110,13 @@ class regnual: self.__devhandle.controlMsg(requestType = 0x40, request = 4, value = 0, index = 0, buffer = None, timeout = 10000) + time.sleep(0.100) res = self.__devhandle.controlMsg(requestType = 0xc0, request = 2, value = 0, index = 0, buffer = 4, timeout = 10000) r_value = ((res[3]*256 + res[2])*256 + res[1])*256 + res[0] if r_value == 0: - print "protect failure" + print "protection failure" def finish(self): self.__devhandle.controlMsg(requestType = 0x40, request = 5,