Skip to content

Commit

Permalink
Added --connect-under-reset to st-flash and st-info
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreymbrown committed May 23, 2020
1 parent ce0df3b commit 25d0e56
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
3 changes: 2 additions & 1 deletion include/stlink/tools/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ struct flash_opts
size_t flash_size; /* --flash=n[k][m] */
int opt; /* enable empty tail data drop optimization */
int freq; /* --freq=n[k][m] frequency of JTAG/SWD */
bool connect_under_reset;
};

#define FLASH_OPTS_INITIALIZER {0, { 0 }, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
#define FLASH_OPTS_INITIALIZER {0, { 0 }, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

int flash_get_opts(struct flash_opts* o, int ac, char** av);

Expand Down
3 changes: 3 additions & 0 deletions src/tools/flash_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
if (result != 0) return bad_arg ("--flash");
else o->flash_size = (size_t) flash_size;
}
else if (strcmp(av[0],"--connect-under-reset")== 0){
o->connect_under_reset = true;
}
else {
break; // non-option found
}
Expand Down
39 changes: 27 additions & 12 deletions src/tools/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ static void usage(void)
puts("st-info --probe");
puts("st-info --serial");
puts("st-info --hla-serial");
puts("st-info --flash");
puts("st-info --pagesize");
puts("st-info --sram");
puts("st-info --chipid");
puts("st-info --descr");
puts("st-info --flash [--connect-under-reset]");
puts("st-info --pagesize [--connect-under-reset]");
puts("st-info --sram [--connect-under-reset]");
puts("st-info --chipid [--connect-under-reset]");
puts("st-info --descr [--connect-under-reset]");
}

/* Print normal or OpenOCD hla_serial with newline */
Expand Down Expand Up @@ -76,19 +76,25 @@ static void stlink_probe(void)
stlink_probe_usb_free(&stdevs, size);
}

static stlink_t *stlink_open_first(void)
static stlink_t *stlink_open_first(bool under_reset)
{
stlink_t* sl = NULL;
sl = stlink_v1_open(0, 1);
if (sl == NULL)
sl = stlink_open_usb(0, 1, NULL, 0);

if (sl == NULL) {
if (under_reset) {
sl = stlink_open_usb(0, 2, NULL, 0);
} else {
sl = stlink_open_usb(0, 1, NULL, 0);
}
}

return sl;
}

static int print_data(char **av)
static int print_data(int ac, char **av)
{
stlink_t* sl = NULL;
bool under_reset = false;

// Probe needs all devices unclaimed
if (strcmp(av[1], "--probe") == 0) {
Expand All @@ -99,7 +105,16 @@ static int print_data(char **av)
return 0;
}

sl = stlink_open_first();
if (ac == 3) {
if (strcmp(av[2],"--connect-under-reset") == 0) {
under_reset = true;
} else {
usage();
return -1;
}
}

sl = stlink_open_first(under_reset);

if (sl == NULL) {
return -1;
Expand Down Expand Up @@ -149,7 +164,7 @@ int main(int ac, char** av)
return -1;
}

err = print_data(av);
err = print_data(ac,av);

return err;
}
10 changes: 9 additions & 1 deletion src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,15 @@ stlink_t *stlink_open_usb(enum ugly_loglevel verbose, int reset, char serial[STL
break;
}

if (reset == 2) stlink_jtag_reset(sl,0);
if (reset == 2) {
stlink_jtag_reset(sl,0);
if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) stlink_enter_swd_mode(sl);
stlink_force_debug(sl);
stlink_jtag_reset(sl,1);
usleep(10000);
}


if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) stlink_enter_swd_mode(sl);

if (reset == 1) {
Expand Down

0 comments on commit 25d0e56

Please sign in to comment.