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

handle probed stlink with unconnected target properly #943

Merged
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
17 changes: 11 additions & 6 deletions src/gdbserver/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,14 @@ int main(int argc, char** argv) {
printf("st-util %s\n", STLINK_VERSION);

sl = do_connect(&state);
if (sl == NULL) return 1;
if (sl == NULL) {
return 1;
}

if (sl->chip_id == STLINK_CHIPID_UNKNOWN) {
ELOG("Unsupported Target (Chip ID is %#010x, Core ID is %#010x).\n", sl->chip_id, sl->core_id);
return 1;
}

connected_stlink = sl;
signal(SIGINT, &cleanup);
Expand All @@ -245,10 +252,7 @@ int main(int argc, char** argv) {
stlink_reset(sl);
}


// This is low-level information for debugging, not useful for normal use.
// So: Demoted to a debug meesage. -- REW
DLOG("Chip ID is %08x, Core ID is %08x.\n", sl->chip_id, sl->core_id);
DLOG("Chip ID is %#010x, Core ID is %#08x.\n", sl->chip_id, sl->core_id);

sl->verbose=0;
current_memory_map = make_memory_map(sl);
Expand Down Expand Up @@ -1852,7 +1856,8 @@ int serve(stlink_t *sl, st_state_t *st) {
stlink_close(sl);

sl = do_connect(st);
if (sl == NULL) cleanup(0);
if (sl == NULL || sl->chip_id == STLINK_CHIPID_UNKNOWN)
cleanup(0);
connected_stlink = sl;

if (st->reset) {
Expand Down
8 changes: 7 additions & 1 deletion src/tools/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ int main(int ac, char** av)

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

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

if (sl->flash_type == STLINK_FLASH_TYPE_UNKNOWN) {
printf("Failed to connect to target\n");
return -1;
}

if ( o.flash_size != 0u && o.flash_size != sl->flash_size ) {
sl->flash_size = o.flash_size;
Expand Down
19 changes: 9 additions & 10 deletions src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ stlink_t *stlink_open_usb(enum ugly_loglevel verbose, bool reset, char serial[ST
stlink_set_swdclk(sl, STLINK_SWDCLK_1P8MHZ_DIVISOR);

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

if (reset) {
Expand All @@ -1054,11 +1054,8 @@ stlink_t *stlink_open_usb(enum ugly_loglevel verbose, bool reset, char serial[ST
usleep(10000);
}

ret = stlink_load_device_params(sl);
if (ret == -1) {
// This one didn't have any message.
goto on_libusb_error;
}
stlink_load_device_params(sl);

return sl;

on_libusb_error:
Expand Down Expand Up @@ -1133,9 +1130,9 @@ static size_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[]) {
ret = libusb_open(dev, &handle);
if (ret < 0) {
if (ret == LIBUSB_ERROR_ACCESS) {
WLOG("failed to open USB device (LIBUSB_ERROR_ACCESS), try running as root?\n");
} else {
WLOG("failed to open USB device (libusb error: %d)\n", ret);
ELOG("Could not open USB device %#06x:%#06x, access error.\n", desc.idVendor, desc.idProduct, ret);
} else {
ELOG("Failed to open USB device %#06x:%#06x, libusb error: %d)\n", desc.idVendor, desc.idProduct, ret);
}
break;
}
Expand All @@ -1149,8 +1146,10 @@ static size_t stlink_probe_usb_devs(libusb_device **devs, stlink_t **sldevs[]) {
}

stlink_t *sl = stlink_open_usb(0, 1, serial);
if (!sl)
if (!sl) {
ELOG("Failed to open USB device %#06x:%#06x\n", desc.idVendor, desc.idProduct);
continue;
}

_sldevs[slcur++] = sl;
}
Expand Down