[fix] flash tool. not working for stm32l, ok with stm32vl
authorFabien Le Mentec <texane@gmail.com>
Mon, 17 Oct 2011 19:52:57 +0000 (14:52 -0500)
committerFabien Le Mentec <texane@gmail.com>
Mon, 17 Oct 2011 19:52:57 +0000 (14:52 -0500)
flash/main.c

index 791b0730b90dee0c0f906184601d59edc6db758d..5fb6f1c97f902687250d4f238258749fd373d893 100644 (file)
@@ -48,7 +48,7 @@ static int get_opts(struct opts* o, int ac, char** av)
     o->do_read = 0;
 
     /* stlinkv1 mode */
-    if (ac == 5)
+    if (ac == 4)
     {
       o->devname = av[1];
       i = 1;
@@ -82,21 +82,22 @@ 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);
+    if (sl == NULL) goto on_error;
   }
 
-  if (sl == NULL) goto on_error;
+  stlink_enter_swd_mode(sl);
+  stlink_reset(sl);
 
   if (o.do_read == 0) /* write */
   {
-    if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE)
-      stlink_exit_dfu_mode(sl);
-    stlink_enter_swd_mode(sl);
-    stlink_reset(sl);
-
     err = stlink_fwrite_flash(sl, o.filename, o.addr);
     if (err == -1)
     {