Add support for the STM32L1 Medium density device flash size calculation
authorJack Peel <jack.peel@synapse.com>
Fri, 5 Apr 2013 16:06:26 +0000 (09:06 -0700)
committerJack Peel <jack.peel@synapse.com>
Fri, 5 Apr 2013 16:06:26 +0000 (09:06 -0700)
In devices before "Rev X" the flash size register is 0 so we assume 128k
Note that "Rev X" is a LATER revision than "Rev Y" and others that might
seem like they are later!

src/stlink-common.c

index 9603cb264a2a811f4199af0be83866dcc7c901ea..05ee12cd3cdd44c77826f8f99ebda67ef065658e 100644 (file)
@@ -452,6 +452,14 @@ int stlink_load_device_params(stlink_t *sl) {
         sl->flash_size = 0x100000; /* Use maximum, User must care!*/
     } else if (sl->chip_id == STM32_CHIPID_F4) {
                sl->flash_size = 0x100000;                      //todo: RM0090 error; size register same address as unique ID
+    } else if (sl->chip_id == STM32_CHIPID_L1_MEDIUM) {
+        // if the flash size is zero, we assume it is 128k, if not we calculate the real value
+        uint32_t flash_size = stlink_read_debug32(sl,params->flash_size_reg) & 0xffff;
+        if ( flash_size == 0 ) {
+            sl->flash_size = 128 * 1024;
+        } else {
+            sl->flash_size = flash_size * 1024;
+        }
     } else if ((sl->chip_id & 0xFFF) == STM32_CHIPID_L1_MEDIUM_PLUS) {
         uint32_t flash_size = stlink_read_debug32(sl, params->flash_size_reg) & 0x1;
         // 0 is 384k and 1 is 256k