Skip to content

Commit

Permalink
Added 'connect under reset' option for USB.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightwalker-87 committed Jun 17, 2020
1 parent e250773 commit f767b82
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion doc/dev/app-example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ static stlink_t *stlink_open_first(void) {
stlink_t* sl = NULL;
sl = stlink_v1_open(0, 1);
if (sl == NULL)
sl = stlink_open_usb(0, 1, NULL);
sl = stlink_open_usb(0, 0, 1, NULL);

return sl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/st-flash/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main(int ac, char** av) {

printf("st-flash %s\n", STLINK_VERSION);

sl = stlink_open_usb(o.log_level, 1, (char *)o.serial, o.freq);
sl = stlink_open_usb(o.log_level, 0, 1, (char *)o.serial, o.freq);

if (sl == NULL) { return(-1); }

Expand Down
6 changes: 3 additions & 3 deletions src/st-info/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ static void stlink_probe(void) {

static stlink_t *stlink_open_first(bool under_reset) {
stlink_t* sl = NULL;
sl = stlink_v1_open(0, 1);
sl = stlink_v1_open(0, 1); // TODO: deprecated?

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

Expand Down
4 changes: 2 additions & 2 deletions src/st-util/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ static stlink_t* do_connect(st_state_t *st) {
stlink_t *sl = NULL;

if (serial_specified) {
sl = stlink_open_usb(st->logging_level, st->reset, serialnumber, 0);
sl = stlink_open_usb(st->logging_level, 0, st->reset, serialnumber, 0);
} else {
sl = stlink_open_usb(st->logging_level, st->reset, NULL, 0);
sl = stlink_open_usb(st->logging_level, 0, st->reset, NULL, 0);
}

return(sl);
Expand Down
4 changes: 2 additions & 2 deletions src/stlink-gui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,9 @@ static void connect_button_cb(GtkWidget *widget, gpointer data) {

if (gui->sl != NULL) { return; }

gui->sl = stlink_v1_open(0, 1); // try version 1 then version 2
gui->sl = stlink_v1_open(0, 1); // try version 1 then version 2 // TODO: deprecated?

if (gui->sl == NULL) { gui->sl = stlink_open_usb(0, 1, NULL, 0); }
if (gui->sl == NULL) { gui->sl = stlink_open_usb(0, 0, 1, NULL, 0); }

if (gui->sl == NULL) {
stlink_gui_set_info_error_message(gui, "Failed to connect to STLink.");
Expand Down
10 changes: 7 additions & 3 deletions src/stlink-lib/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ static stlink_backend_t _stlink_usb_backend = {
_stlink_usb_set_swdclk
};

stlink_t *stlink_open_usb(enum ugly_loglevel verbose, int reset, char serial[STLINK_SERIAL_MAX_SIZE], int freq) {
stlink_t *stlink_open_usb(enum ugly_loglevel verbose, bool connect_under_reset, int reset, char serial[STLINK_SERIAL_MAX_SIZE], int freq) {
stlink_t* sl = NULL;
struct stlink_libusb* slu = NULL;
int ret = -1;
Expand Down Expand Up @@ -1226,7 +1226,11 @@ stlink_t *stlink_open_usb(enum ugly_loglevel verbose, int reset, char serial[STL
if (reset == 2) {
stlink_jtag_reset(sl, 0);

if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) { stlink_enter_swd_mode(sl); }
if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) {
if (connect_under_reset) { stlink_jtag_reset(sl, 0); }
stlink_enter_swd_mode(sl);
if (connect_under_reset) { stlink_jtag_reset(sl, 1); }
}

stlink_force_debug(sl);
stlink_jtag_reset(sl, 1);
Expand Down Expand Up @@ -1332,7 +1336,7 @@ static size_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[]) {

if (ret < 0) { continue; }

stlink_t *sl = stlink_open_usb(0, 1, serial, 0);
stlink_t *sl = stlink_open_usb(0, 0, 1, serial, 0);

if (!sl) {
ELOG("Failed to open USB device %#06x:%#06x\n", desc.idVendor, desc.idProduct);
Expand Down
2 changes: 1 addition & 1 deletion src/stlink-lib/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct stlink_libusb {
* @retval NULL Error while opening the stlink
* @retval !NULL Stlink found and ready to use
*/
stlink_t *stlink_open_usb(enum ugly_loglevel verbose, int reset, char serial[STLINK_SERIAL_MAX_SIZE], int freq);
stlink_t *stlink_open_usb(enum ugly_loglevel verbose, bool connect_under_reset, int reset, char serial[STLINK_SERIAL_MAX_SIZE], int freq);
size_t stlink_probe_usb(stlink_t **stdevs[]);
void stlink_probe_usb_free(stlink_t **stdevs[], size_t size);

Expand Down
2 changes: 1 addition & 1 deletion tests/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main(int ac, char** av) {
return(0);
}

sl = stlink_open_usb(10, reset, NULL, 0);
sl = stlink_open_usb(10, 0, reset, NULL, 0);

if (sl != NULL) {
printf("-- version\n");
Expand Down

0 comments on commit f767b82

Please sign in to comment.