X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=flash%2Fmain.c;h=a443f95f6bb58b59460e3231a5a650d637763d6c;hb=9eaafd0519ad2958a3c9a29fb903da4b90cf987f;hp=5fb6f1c97f902687250d4f238258749fd373d893;hpb=8abe4682dde1be9c66538eef50ca0f4eabcc23d4;p=fw%2Fstlink diff --git a/flash/main.c b/flash/main.c index 5fb6f1c..a443f95 100644 --- a/flash/main.c +++ b/flash/main.c @@ -17,6 +17,11 @@ struct opts size_t size; }; +static void usage(void) +{ + puts("stlinkv1 command line: ./flash {read|write} /dev/sgX path addr "); + puts("stlinkv2 command line: ./flash {read|write} path addr "); +} static int get_opts(struct opts* o, int ac, char** av) { @@ -75,6 +80,7 @@ int main(int ac, char** av) if (get_opts(&o, ac - 1, av + 1) == -1) { printf("invalid command line\n"); + usage(); goto on_error; } @@ -83,17 +89,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 */