diff --git a/src/platforms/hosted/ftdi_bmp.c b/src/platforms/hosted/ftdi_bmp.c index 002955a3..fb106f98 100644 --- a/src/platforms/hosted/ftdi_bmp.c +++ b/src/platforms/hosted/ftdi_bmp.c @@ -150,7 +150,8 @@ cable_desc_t cable_desc[] = { .jtag.set_data_low = PIN6, .target_voltage_cmd = GET_BITS_HIGH, .target_voltage_pin = ~PIN2, - .name = "ftdiswd" + .name = "ftdiswd", + .description = "FTDISWD" }, { .vendor = 0x15b1, @@ -179,7 +180,8 @@ cable_desc_t cable_desc[] = { .deassert_srst.data_low = ~PIN6, .srst_get_port_cmd = GET_BITS_HIGH, .srst_get_pin = PIN0, - .name = "turtelizer" + .name = "turtelizer", + .description = "Turtelizer JTAG/RS232 Adapter" }, { /* https://reference.digilentinc.com/jtag_hs1/jtag_hs1 @@ -247,23 +249,25 @@ cable_desc_t cable_desc[] = { .init.ddr_high = PIN4 | PIN3 | PIN1 | PIN0, .name = "arm-usb-ocd-h" }, + { + } }; int ftdi_bmp_init(BMP_CL_OPTIONS_t *cl_opts, bmp_info_t *info) { int err; - unsigned index = 0; - for(index = 0; index < sizeof(cable_desc)/sizeof(cable_desc[0]); - index++) - if (strcmp(cable_desc[index].name, cl_opts->opt_cable) == 0) + cable_desc_t *cable = &cable_desc[0]; + for(; cable->name; cable++) { + if (strcmp(cable->name, cl_opts->opt_cable) == 0) break; + } - if (index == sizeof(cable_desc)/sizeof(cable_desc[0])) { - DEBUG_WARN( "No cable matching %s found\n", cl_opts->opt_cable); + if (!cable->name ) { + DEBUG_WARN( "No cable matching found for %s\n", cl_opts->opt_cable); return -1; } - active_cable = &cable_desc[index]; + active_cable = cable; memcpy(&active_state, &active_cable->init, sizeof(data_desc_t)); /* If swd_(read|write) is not given for the selected cable and the 'r' command line argument is give, assume resistor SWD @@ -282,7 +286,6 @@ int ftdi_bmp_init(BMP_CL_OPTIONS_t *cl_opts, bmp_info_t *info) active_cable->mpsse_swd_write.set_data_low = MPSSE_DO; } - DEBUG_WARN("Black Magic Probe for FTDI/MPSSE\n"); if(ftdic) { ftdi_usb_close(ftdic); ftdi_free(ftdic); diff --git a/src/platforms/hosted/ftdi_bmp.h b/src/platforms/hosted/ftdi_bmp.h index 584b7067..fab102a1 100644 --- a/src/platforms/hosted/ftdi_bmp.h +++ b/src/platforms/hosted/ftdi_bmp.h @@ -98,6 +98,7 @@ typedef struct cable_desc_s { char * name; }cable_desc_t; +extern cable_desc_t cable_desc[]; extern cable_desc_t *active_cable; extern struct ftdi_context *ftdic; extern data_desc_t active_state; diff --git a/src/platforms/hosted/platform.c b/src/platforms/hosted/platform.c index 2b639598..2b08aed2 100644 --- a/src/platforms/hosted/platform.c +++ b/src/platforms/hosted/platform.c @@ -98,6 +98,8 @@ static int find_debuggers( BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info) char product[128]; bmp_type_t type = BMP_TYPE_NONE; bool access_problems = false; + char *active_cable = NULL; + bool ftdi_unknown = false; rescan: found_debuggers = 0; for (int i = 0; devs[i]; i++) { @@ -178,12 +180,43 @@ static int find_debuggers( BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info) } } else if (desc.idVendor == VENDOR_ID_SEGGER) { type = BMP_TYPE_JLINK; - } else{ - continue; + } else { + cable_desc_t *cable = &cable_desc[0]; + for (; cable->name; cable++) { + bool found = false; + if ((cable->vendor != desc.idVendor) || (cable->product != desc.idProduct)) + continue; /* VID/PID do not match*/ + if (cl_opts->opt_cable) { + if (strcmp(cable->name, cl_opts->opt_cable)) + continue; /* cable names do not match*/ + else + found = true; + } + if (cable->description) { + if (strcmp(cable->description, product)) + continue; /* discriptions do not match*/ + else + found = true; + } else { /* VID/PID fits, but no cl_opts->opt_cable and no description*/ + if ((cable->vendor == 0x0403) && /* FTDI*/ + ((cable->product == 0x6010) || /* FT2232C/D/H*/ + (cable->product == 0x6011) || /* FT4232H Quad HS USB-UART/FIFO IC */ + (cable->product == 0x6014))) { /* FT232H Single HS USB-UART/FIFO IC */ + ftdi_unknown = true; + continue; /* Cable name is needed */ + } + } + if (found) { + active_cable = cable->name; + type = BMP_TYPE_LIBFTDI; + break; + } + } + if (!cable->name) + continue; } - found_debuggers ++; if (report) { - DEBUG_WARN("%2d: %s, %s, %s\n", found_debuggers, + DEBUG_WARN("%2d: %s, %s, %s\n", found_debuggers + 1, serial, manufacturer,product); } @@ -194,11 +227,19 @@ static int find_debuggers( BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info) strncpy(info->product, product, sizeof(info->product)); strncpy(info->manufacturer, manufacturer, sizeof(info->manufacturer)); if (cl_opts->opt_position && - (cl_opts->opt_position == found_debuggers)) { + (cl_opts->opt_position == (found_debuggers + 1))) { found_debuggers = 1; break; + } else { + found_debuggers++; } } + if ((found_debuggers == 0) && ftdi_unknown) + DEBUG_WARN("Generic FTDI MPSSE VID/PID found. Please specify exact type with \"-c \" !\n"); + if ((found_debuggers == 1) && !cl_opts->opt_cable && (type == BMP_TYPE_LIBFTDI)) + cl_opts->opt_cable = active_cable; + if (!found_debuggers && cl_opts->opt_list_only) + DEBUG_WARN("No usable debugger found\n"); if ((found_debuggers > 1) || ((found_debuggers == 1) && (cl_opts->opt_list_only))) { if (!report) { @@ -266,6 +307,8 @@ void platform_init(int argc, char **argv) exit(-1); break; case BMP_TYPE_LIBFTDI: + if (ftdi_bmp_init(&cl_opts, &info)) + exit(-1); break; case BMP_TYPE_JLINK: if (jlink_init(&info))