stm32f2x: Fix sector numbering for dual bank flash erase 89/1689/2
authorAndreas Fritiofson <andreas.fritiofson@gmail.com>
Mon, 7 Oct 2013 18:56:16 +0000 (20:56 +0200)
committerSpencer Oliver <spen@spen-soft.co.uk>
Tue, 8 Oct 2013 13:02:59 +0000 (13:02 +0000)
Reference: RM0090 rev 5.

Change-Id: I9f7ae09c0ba91d166aebcdc25300d0ca58a5a56d
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reported-by: Nader Shehayed <nshehayed@gmail.com>
Reviewed-on: http://openocd.zylin.com/1689
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
src/flash/nor/stm32f2x.c

index de11b377572119d24630b2f622361b8a832fa81f..a7aba2b3bd98190d1b13cb0a08b46b89d836a9b9 100644 (file)
 #define FLASH_PSIZE_16 (1 << 8)
 #define FLASH_PSIZE_32 (2 << 8)
 #define FLASH_PSIZE_64 (3 << 8)
-#define FLASH_SNB(a)   ((a) << 3)
+/* The sector number encoding is not straight binary for dual bank flash.
+ * Warning: evaluates the argument multiple times */
+#define FLASH_SNB(a)   ((((a) >= 12) ? 0x10 | ((a) - 12) : (a)) << 3)
 #define FLASH_LOCK     (1 << 31)
 
 /* FLASH_SR register bits */
@@ -403,6 +405,9 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
        struct target *target = bank->target;
        int i;
 
+       assert(first < bank->num_sectors);
+       assert(last < bank->num_sectors);
+
        if (bank->target->state != TARGET_HALTED) {
                LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
@@ -418,7 +423,7 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
        To erase a sector, follow the procedure below:
        1. Check that no Flash memory operation is ongoing by checking the BSY bit in the
          FLASH_SR register
-       2. Set the SER bit and select the sector (out of the 12 sectors in the main memory block)
+       2. Set the SER bit and select the sector
          you wish to erase (SNB) in the FLASH_CR register
        3. Set the STRT bit in the FLASH_CR register
        4. Wait for the BSY bit to be cleared

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)