Fixed compile of flash program
[fw/stlink] / flash / main.c
index 5fb6f1c97f902687250d4f238258749fd373d893..0fd7232b9916d58c1bed823b48ed70e004afa289 100644 (file)
@@ -83,17 +83,19 @@ int main(int ac, char** av)
     static const int scsi_verbose = 2;
     sl = stlink_quirk_open(o.devname, scsi_verbose);
     if (sl == NULL) goto on_error;
-
-    if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE)
-      stlink_exit_dfu_mode(sl);
   }
   else /* stlinkv2 */
   {
-    sl = stlink_open_usb(NULL, 10);
+    sl = stlink_open_usb(10);
     if (sl == NULL) goto on_error;
   }
 
-  stlink_enter_swd_mode(sl);
+  if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE)
+    stlink_exit_dfu_mode(sl);
+
+  if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE)
+    stlink_enter_swd_mode(sl);
+
   stlink_reset(sl);
 
   if (o.do_read == 0) /* write */