stm32f2x.c: Handle STM32F42x/43x 1 MiByte devices with DB1M option set. 38/2938/5
authorUwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Mon, 17 Aug 2015 14:36:19 +0000 (16:36 +0200)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Fri, 30 Oct 2015 17:47:30 +0000 (17:47 +0000)
Change-Id: Ic51d34a9abe9693fd21e9b3247523821b6fb1fe3
Signed-off-by: Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Reviewed-on: http://openocd.zylin.com/2938
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
src/flash/nor/stm32f2x.c

index 8dea951f2daecba7ac1aa1beb2f1b3d22de276ad..490cccc4a6641f2c6b58e857a2ca16255c45a7b7 100644 (file)
  * To reduce testing complexity and dangers of regressions,
  * a seperate file is used for stm32fx2x.
  *
- * 1mByte part with 4 x 16, 1 x 64, 7 x 128kBytes sectors
+ * Sector sizes in kiBytes:
+ * 1 MiByte part with 4 x 16, 1 x 64, 7 x 128.
+ * 2 MiByte part with 4 x 16, 1 x 64, 7 x 128, 4 x 16, 1 x 64, 7 x 128.
+ * 1 MiByte STM32F42x/43x part with DB1M Option set:
+ *                    4 x 16, 1 x 64, 3 x 128, 4 x 16, 1 x 64, 3 x 128.
  *
- * What's the protection page size???
+ * Protection size is sector size.
  *
  * Tested with STM3220F-EVAL board.
  *
- * STM32F21xx series for reference.
+ * STM32F4xx series for reference.
  *
- * RM0033
- * http://www.st.com/internet/mcu/product/250192.jsp
+ * RM0090
+ * http://www.st.com/web/en/resource/technical/document/reference_manual/DM00031020.pdf
  *
  * PM0059
  * www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/
 #define OPT_RDRSTSTOP  3
 #define OPT_RDRSTSTDBY 4
 #define OPT_BFB2       5       /* dual flash bank only */
+#define OPT_DB1M       14      /* 1 MiB devices dual flash bank option */
 
 /* register unlock keys */
 
@@ -807,10 +812,6 @@ static int stm32x_probe(struct flash_bank *bank)
                flash_size_in_kb = stm32x_info->user_bank_size / 1024;
        }
 
-       /* only devices with > 1024kB have dual banks */
-       if (flash_size_in_kb > 1024)
-               stm32x_info->has_large_mem = true;
-
        LOG_INFO("flash size = %dkbytes", flash_size_in_kb);
 
        /* did we assign flash size? */
@@ -819,7 +820,25 @@ static int stm32x_probe(struct flash_bank *bank)
        /* calculate numbers of pages */
        int num_pages = (flash_size_in_kb / 128) + 4;
 
-       /* check for larger 2048 bytes devices */
+       /* Devices with > 1024 kiByte always are dual-banked */
+       if (flash_size_in_kb > 1024)
+               stm32x_info->has_large_mem = true;
+
+       /* F42x/43x 1024 kiByte devices have a dual bank option */
+       if ((device_id & 0xfff) == 0x419 && (flash_size_in_kb == 1024)) {
+               uint32_t optiondata;
+               retval = target_read_u32(target, STM32_FLASH_OPTCR, &optiondata);
+               if (retval != ERROR_OK) {
+                       LOG_DEBUG("unable to read option bytes");
+                       return retval;
+               }
+               if (optiondata & (1 << OPT_DB1M)) {
+                       stm32x_info->has_large_mem = true;
+                       LOG_INFO("Dual Bank 1024 kiB STM32F42x/43x found");
+               }
+       }
+
+       /* check for dual-banked devices */
        if (stm32x_info->has_large_mem)
                num_pages += 4;
 
@@ -840,19 +859,21 @@ static int stm32x_probe(struct flash_bank *bank)
        setup_sector(bank, 0, 4, 16 * 1024);
        setup_sector(bank, 4, 1, 64 * 1024);
 
-       /* dynamic memory */
-       setup_sector(bank, 4 + 1, MIN(12, num_pages) - 5, 128 * 1024);
-
        if (stm32x_info->has_large_mem) {
-
-               /* fixed memory for larger devices */
-               setup_sector(bank, 12, 4, 16 * 1024);
-               setup_sector(bank, 16, 1, 64 * 1024);
-
-               /* dynamic memory for larger devices */
-               setup_sector(bank, 16 + 1, num_pages - 5 - 12, 128 * 1024);
+               if (flash_size_in_kb == 1024) {
+                       setup_sector(bank,  5, 3, 128 * 1024);
+                       setup_sector(bank, 12, 4,  16 * 1024);
+                       setup_sector(bank, 16, 1,  64 * 1024);
+                       setup_sector(bank, 17, 3, 128 * 1024);
+               } else {
+                       setup_sector(bank,  5, 7, 128 * 1024);
+                       setup_sector(bank, 12, 4,  16 * 1024);
+                       setup_sector(bank, 16, 1,  64 * 1024);
+                       setup_sector(bank, 17, 7, 128 * 1024);
+               }
+       } else {
+               setup_sector(bank, 4 + 1, MIN(12, num_pages) - 5, 128 * 1024);
        }
-
        for (i = 0; i < num_pages; i++) {
                bank->sectors[i].is_erased = -1;
                bank->sectors[i].is_protected = 0;

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)