Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flash: added easy way to reset the target #505

Merged
merged 2 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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