flash/nor/stm32l: unify waiting for busy flag functions 91/2491/3
authorPaul Fertser <fercerpav@gmail.com>
Fri, 23 Jan 2015 09:40:58 +0000 (12:40 +0300)
committerSpencer Oliver <spen@spen-soft.co.uk>
Wed, 4 Feb 2015 22:02:28 +0000 (22:02 +0000)
Change-Id: I5e6daff8232bb4807dd13a1951fbf335529661d4
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/2491
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
src/flash/nor/stm32lx.c

index 13db7b924a66a7fe76933bdb5c9204516c1541cd..6858d5afa2e7da83d224c3d07a3ed128be1b72ce 100644 (file)
@@ -104,7 +104,7 @@ static int stm32lx_enable_write_half_page(struct flash_bank *bank);
 static int stm32lx_erase_sector(struct flash_bank *bank, int sector);
 static int stm32lx_wait_until_bsy_clear(struct flash_bank *bank);
 static int stm32lx_mass_erase(struct flash_bank *bank);
-static int stm32lx_wait_status_busy(struct flash_bank *bank, int timeout);
+static int stm32lx_wait_until_bsy_clear_timeout(struct flash_bank *bank, int timeout);
 
 struct stm32lx_rev {
        uint16_t rev;
@@ -1105,38 +1105,7 @@ static inline int stm32lx_get_flash_status(struct flash_bank *bank, uint32_t *st
 
 static int stm32lx_wait_until_bsy_clear(struct flash_bank *bank)
 {
-       struct target *target = bank->target;
-       struct stm32lx_flash_bank *stm32lx_info = bank->driver_priv;
-       uint32_t status;
-       int retval = ERROR_OK;
-       int timeout = 100;
-
-       /* wait for busy to clear */
-       for (;;) {
-               retval = target_read_u32(target, stm32lx_info->flash_base + FLASH_SR, &status);
-               if (retval != ERROR_OK)
-                       return retval;
-
-               if ((status & FLASH_SR__BSY) == 0)
-                       break;
-               if (timeout-- <= 0) {
-                       LOG_ERROR("timed out waiting for flash");
-                       return ERROR_FAIL;
-               }
-               alive_sleep(1);
-       }
-
-       if (status & FLASH_SR__WRPERR) {
-               LOG_ERROR("access denied / write protected");
-               retval = ERROR_FAIL;
-       }
-
-       if (status & FLASH_SR__PGAERR) {
-               LOG_ERROR("invalid program address");
-               retval = ERROR_FAIL;
-       }
-
-       return retval;
+       return stm32lx_wait_until_bsy_clear_timeout(bank, 100);
 }
 
 static int stm32lx_unlock_options_bytes(struct flash_bank *bank)
@@ -1182,17 +1151,15 @@ static int stm32lx_unlock_options_bytes(struct flash_bank *bank)
        return ERROR_OK;
 }
 
-static int stm32lx_wait_status_busy(struct flash_bank *bank, int timeout)
+static int stm32lx_wait_until_bsy_clear_timeout(struct flash_bank *bank, int timeout)
 {
        struct target *target = bank->target;
+       struct stm32lx_flash_bank *stm32lx_info = bank->driver_priv;
        uint32_t status;
-
        int retval = ERROR_OK;
-       struct stm32lx_flash_bank *stm32lx_info = bank->driver_priv;
 
        /* wait for busy to clear */
        for (;;) {
-
                retval = stm32lx_get_flash_status(bank, &status);
                if (retval != ERROR_OK)
                        return retval;
@@ -1209,7 +1176,12 @@ static int stm32lx_wait_status_busy(struct flash_bank *bank, int timeout)
        }
 
        if (status & FLASH_SR__WRPERR) {
-               LOG_ERROR("stm32lx device protected");
+               LOG_ERROR("access denied / write protected");
+               retval = ERROR_FAIL;
+       }
+
+       if (status & FLASH_SR__PGAERR) {
+               LOG_ERROR("invalid program address");
                retval = ERROR_FAIL;
        }
 
@@ -1279,7 +1251,7 @@ static int stm32lx_mass_erase(struct flash_bank *bank)
        if (retval != ERROR_OK)
                return retval;
 
-       retval = stm32lx_wait_status_busy(bank, 30000);
+       retval = stm32lx_wait_until_bsy_clear_timeout(bank, 30000);
        if (retval != ERROR_OK)
                return retval;
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)