diff --git a/src/gdbserver/gdb-server.c b/src/gdbserver/gdb-server.c index 1c45c2538..2b5b1d3cb 100644 --- a/src/gdbserver/gdb-server.c +++ b/src/gdbserver/gdb-server.c @@ -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); @@ -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); @@ -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) { diff --git a/src/tools/flash.c b/src/tools/flash.c index e91001659..3a9cc3674 100644 --- a/src/tools/flash.c +++ b/src/tools/flash.c @@ -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; diff --git a/src/usb.c b/src/usb.c index 206600f14..c9ea7039a 100644 --- a/src/usb.c +++ b/src/usb.c @@ -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) { @@ -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: @@ -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; } @@ -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; }