From 8abe4682dde1be9c66538eef50ca0f4eabcc23d4 Mon Sep 17 00:00:00 2001 From: Fabien Le Mentec Date: Mon, 17 Oct 2011 14:52:57 -0500 Subject: [PATCH] [fix] flash tool. not working for stm32l, ok with stm32vl --- flash/main.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/flash/main.c b/flash/main.c index 791b073..5fb6f1c 100644 --- a/flash/main.c +++ b/flash/main.c @@ -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) { -- 2.30.2