From cda0c8b5d352ab50aa06bcd4ab27f8da554b6db4 Mon Sep 17 00:00:00 2001 From: Georg von Zengen Date: Mon, 17 Oct 2016 16:06:43 +0200 Subject: [PATCH 1/2] flash: added easy way to reset the target st-flash does now have a 'reset' command makes it easy to reset the Target --- include/stlink/tools/flash.h | 2 +- src/tools/flash.c | 12 ++++++++++++ src/tools/flash_opts.c | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/stlink/tools/flash.h b/include/stlink/tools/flash.h index dbc9ad881..bb7bd739e 100644 --- a/include/stlink/tools/flash.h +++ b/include/stlink/tools/flash.h @@ -7,7 +7,7 @@ #define DEBUG_LOG_LEVEL 100 #define STND_LOG_LEVEL 50 -enum flash_cmd {FLASH_CMD_NONE = 0, FLASH_CMD_WRITE = 1, FLASH_CMD_READ = 2, FLASH_CMD_ERASE = 3}; +enum flash_cmd {FLASH_CMD_NONE = 0, FLASH_CMD_WRITE = 1, FLASH_CMD_READ = 2, FLASH_CMD_ERASE = 3, CMD_RESET = 4}; enum flash_format {FLASH_FORMAT_BINARY = 0, FLASH_FORMAT_IHEX = 1}; struct flash_opts { diff --git a/src/tools/flash.c b/src/tools/flash.c index 5cedb3815..1b6c7a7da 100644 --- a/src/tools/flash.c +++ b/src/tools/flash.c @@ -33,6 +33,7 @@ static void usage(void) puts("stlinkv1 command line: ./st-flash [--debug] /dev/sgX erase"); puts("stlinkv2 command line: ./st-flash [--debug] [--reset] [--serial ] [--format ] {read|write} "); puts("stlinkv2 command line: ./st-flash [--debug] [--serial ] erase"); + puts("stlinkv2 command line: ./st-flash [--debug] [--serial ] reset"); puts(" Use hex format for addr, and ."); puts(" Format may be 'binary' (default) or 'ihex', although must be specified for binary format only."); puts(" ./st-flash [--version]"); @@ -168,6 +169,17 @@ int main(int ac, char** av) printf("stlink_erase_flash_mass() == -1\n"); goto on_error; } + } else if (o.cmd == CMD_RESET) + { + if (stlink_jtag_reset(sl, 2)) { + printf("Failed to reset JTAG\n"); + goto on_error; + } + + if (stlink_reset(sl)) { + printf("Failed to reset device\n"); + goto on_error; + } } else /* read */ { diff --git a/src/tools/flash_opts.c b/src/tools/flash_opts.c index 1a0d0cd9b..1ccf55334 100644 --- a/src/tools/flash_opts.c +++ b/src/tools/flash_opts.c @@ -99,6 +99,10 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) if (o->cmd != FLASH_CMD_NONE) return -1; o->cmd = FLASH_CMD_WRITE; } + else if (strcmp(av[0], "reset") == 0) { + if (o->cmd != FLASH_CMD_NONE) return -1; + o->cmd = CMD_RESET; + } else if(starts_with(av[0], "/dev/")) { if (o->devname) return -1; o->devname = av[0]; From 26a21e8f40ebd86fdf44c66dabbfdd63102e063b Mon Sep 17 00:00:00 2001 From: Georg von Zengen Date: Tue, 18 Oct 2016 09:46:39 +0200 Subject: [PATCH 2/2] Doc: added man page entry for reset command of st-flash --- doc/man/st-flash.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/man/st-flash.md b/doc/man/st-flash.md index 981bf3cd6..ee833aee9 100644 --- a/doc/man/st-flash.md +++ b/doc/man/st-flash.md @@ -32,6 +32,8 @@ read *FILE* *ADDR* *SIZE* erase : Perform a mass erasing of the device firmware +reset +: Reset the target # OPTIONS