[fix] stm32l flash write
[fw/stlink] / src / stlink-usb.c
index ff9ef71de7a4e6afc0b632342b473cc97826ff0b..e7a9ba6428f85e4b949775810cadd198e58bca85 100644 (file)
@@ -586,19 +586,6 @@ stlink_t* stlink_open_usb(const int verbose) {
     
     sl->core_stat = STLINK_CORE_STAT_UNKNOWN;
 
-    /* flash memory settings */
-    sl->flash_base = STM32_FLASH_BASE;
-    sl->flash_size = STM32_FLASH_SIZE;
-    sl->flash_pgsz = STM32_FLASH_PGSZ;
-
-    /* system memory */
-    sl->sys_base = STM32_SYSTEM_BASE;
-    sl->sys_size = STM32_SYSTEM_SIZE;
-
-    /* sram memory settings */
-    sl->sram_base = STM32_SRAM_BASE;
-    sl->sram_size = STM32L_SRAM_SIZE;
-
     if (libusb_init(&(slu->libusb_ctx))) {
        fprintf(stderr, "failed to init libusb context, wrong version of libraries?\n");
        goto on_error;
@@ -698,6 +685,41 @@ stlink_t* stlink_open_usb(const int verbose) {
       stlink_exit_dfu_mode(sl);
     }
     stlink_version(sl);
+
+    /* per device family initialization */
+    stlink_core_id(sl);
+    if (sl->core_id == 0x2ba01477) /* stm32l */ {
+
+      /* flash memory settings */
+      sl->flash_base = STM32_FLASH_BASE;
+      sl->flash_size = STM32_FLASH_SIZE;
+      sl->flash_pgsz = STM32L_FLASH_PGSZ;
+
+      /* system memory */
+      sl->sys_base = STM32_SYSTEM_BASE;
+      sl->sys_size = STM32_SYSTEM_SIZE;
+
+      /* sram memory settings */
+      sl->sram_base = STM32_SRAM_BASE;
+      sl->sram_size = STM32L_SRAM_SIZE;
+
+    } else /* stm32vl */ {
+
+      /* flash memory settings */
+      sl->flash_base = STM32_FLASH_BASE;
+      sl->flash_size = STM32_FLASH_SIZE;
+      sl->flash_pgsz = STM32_FLASH_PGSZ;
+
+      /* system memory */
+      sl->sys_base = STM32_SYSTEM_BASE;
+      sl->sys_size = STM32_SYSTEM_SIZE;
+
+      /* sram memory settings */
+      sl->sram_base = STM32_SRAM_BASE;
+      sl->sram_size = STM32_SRAM_SIZE;
+
+    }
+
     error = 0;
 
 on_libusb_error: