Skip to content

Commit

Permalink
flash: added easy way to reset the target (#505)
Browse files Browse the repository at this point in the history
* flash: added easy way to reset the target

st-flash does now have a 'reset' command
makes it easy to reset the Target

* Doc: added man page entry for reset command of st-flash
  • Loading branch information
gvz authored and xor-gate committed Nov 3, 2016
1 parent 9c05837 commit 7ab4645
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/man/st-flash.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ read *FILE* *ADDR* *SIZE*
erase
: Perform a mass erasing of the device firmware

reset
: Reset the target

# OPTIONS

Expand Down
2 changes: 1 addition & 1 deletion include/stlink/tools/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
12 changes: 12 additions & 0 deletions src/tools/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <serial>] [--format <format>] {read|write} <path> <addr> <size>");
puts("stlinkv2 command line: ./st-flash [--debug] [--serial <serial>] erase");
puts("stlinkv2 command line: ./st-flash [--debug] [--serial <serial>] reset");
puts(" Use hex format for addr, <serial> and <size>.");
puts(" Format may be 'binary' (default) or 'ihex', although <addr> must be specified for binary format only.");
puts(" ./st-flash [--version]");
Expand Down Expand Up @@ -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 */
{
Expand Down
4 changes: 4 additions & 0 deletions src/tools/flash_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 7ab4645

Please sign in to comment.