Don't try reading device params in bad USB modes.

You cannot read device params when we're not in debug mode and trying to will fill the USB buffer with garbage, and you will have to
unplug and replug and start again.  (which will fail, because, you're in the
wrong mode... :)
pull/29/head
Karl Palsson 2011-11-14 02:25:31 +00:00
rodzic 3c6f2f5231
commit 77f2d8b76c
1 zmienionych plików z 27 dodań i 9 usunięć

Wyświetl plik

@ -1104,8 +1104,7 @@ static stlink_t* stlink_open(const int verbose) {
}
stlink_t* stlink_v1_open(const int verbose) {
stlink_t* stlink_v1_open_inner(const int verbose) {
ugly_init(verbose);
stlink_t *sl = stlink_open(verbose);
if (sl == NULL) {
@ -1114,7 +1113,6 @@ stlink_t* stlink_v1_open(const int verbose) {
}
stlink_version(sl);
stlink_load_device_params(sl);
if ((sl->version.st_vid != USB_ST_VID) || (sl->version.stlink_pid != USB_STLINK_PID)) {
ugly_log(UERROR, LOG_TAG,
"WTF? successfully opened, but unable to read version details. BROKEN!\n");
@ -1123,11 +1121,14 @@ stlink_t* stlink_v1_open(const int verbose) {
DLOG("Reading current mode...\n");
switch (stlink_current_mode(sl)) {
case STLINK_DEV_MASS_MODE:
return sl;
case STLINK_DEV_DEBUG_MODE:
// TODO go to mass?
case STLINK_DEV_MASS_MODE:
return sl;
case STLINK_DEV_DEBUG_MODE:
// TODO go to mass?
return sl;
default:
ILOG("Current mode unusable, trying to get back to a useful state...\n");
break;
}
DLOG("Attempting to exit DFU mode\n");
@ -1145,8 +1146,25 @@ stlink_t* stlink_v1_open(const int verbose) {
fputs("Error: could not open stlink device\n", stderr);
return NULL;
}
// re-query device info
// re-query device info (and retest)
stlink_version(sl);
stlink_load_device_params(sl);
if ((sl->version.st_vid != USB_ST_VID) || (sl->version.stlink_pid != USB_STLINK_PID)) {
ugly_log(UERROR, LOG_TAG,
"WTF? successfully opened, but unable to read version details. BROKEN!\n");
return NULL;
}
return sl;
}
stlink_t* stlink_v1_open(const int verbose) {
stlink_t *sl = stlink_v1_open_inner(verbose);
if (sl == NULL) {
fputs("Error: could not open stlink device\n", stderr);
return NULL;
}
// by now, it _must_ be fully open and in a useful mode....
stlink_enter_swd_mode(sl);
stlink_load_device_params(sl);
ILOG("Successfully opened a stlink v1 debugger\n");
return sl;
}