diff --git a/src/platforms/hosted/cli.c b/src/platforms/hosted/cli.c index 4669d0f..efe38ee 100644 --- a/src/platforms/hosted/cli.c +++ b/src/platforms/hosted/cli.c @@ -232,7 +232,8 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) opt->opt_flash_size = 0xffffffff; opt->opt_flash_start = 0xffffffff; opt->opt_max_swj_frequency = 4000000; - while((c = getopt_long(argc, argv, "eEhHv:d:f:s:I:c:Cln:m:M:wVtTa:S:jpP:rR::", long_options, NULL)) != -1) { + opt->opt_scanmode = BMP_SCAN_SWD; + while((c = getopt_long(argc, argv, "eEhHv:d:f:s:I:c:Cln:m:M:wVtTa:S:jApP:rR::", long_options, NULL)) != -1) { switch(c) { case 'c': if (optarg) @@ -250,7 +251,10 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) cl_debuglevel = strtol(optarg, NULL, 0) & (BMP_DEBUG_MAX - 1); break; case 'j': - opt->opt_usejtag = true; + opt->opt_scanmode = BMP_SCAN_JTAG; + break; + case 'A': + opt->opt_scanmode = BMP_SCAN_AUTO; break; case 'l': opt->opt_list_only = true; @@ -419,11 +423,24 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) if (opt->opt_mode == BMP_MODE_TEST) DEBUG_INFO("Running in Test Mode\n"); DEBUG_INFO("Target voltage: %s Volt\n", platform_target_voltage()); - if (opt->opt_usejtag) - num_targets = platform_jtag_scan(NULL); - else - num_targets = platform_adiv5_swdp_scan(opt->opt_targetid); + if (opt->opt_scanmode == BMP_SCAN_JTAG) + num_targets = platform_jtag_scan(NULL); + else if (opt->opt_scanmode == BMP_SCAN_SWD) + num_targets = platform_adiv5_swdp_scan(opt->opt_targetid); + else + { + num_targets = platform_jtag_scan(NULL); + if (num_targets > 0) + goto found_targets; + DEBUG_INFO("JTAG scan found no devices, trying SWD.\n"); + num_targets = platform_adiv5_swdp_scan(opt->opt_targetid); + if (num_targets > 0) + goto found_targets; + DEBUG_INFO("SW-DP scan failed!\n"); + } + +found_targets: if (!num_targets) { DEBUG_WARN("No target found\n"); return -1; diff --git a/src/platforms/hosted/cli.h b/src/platforms/hosted/cli.h index b858694..78de1f0 100644 --- a/src/platforms/hosted/cli.h +++ b/src/platforms/hosted/cli.h @@ -40,9 +40,15 @@ enum bmp_cl_mode { BMP_MODE_MONITOR, }; +typedef enum bmp_scan_mode_e { + BMP_SCAN_JTAG, + BMP_SCAN_SWD, + BMP_SCAN_AUTO +} bmp_scan_mode_t; + typedef struct BMP_CL_OPTIONS_s { enum bmp_cl_mode opt_mode; - bool opt_usejtag; + bmp_scan_mode_t opt_scanmode; bool opt_tpwr; bool opt_list_only; bool opt_connect_under_reset; diff --git a/src/platforms/hosted/ftdi_bmp.c b/src/platforms/hosted/ftdi_bmp.c index 944279d..bd393d1 100644 --- a/src/platforms/hosted/ftdi_bmp.c +++ b/src/platforms/hosted/ftdi_bmp.c @@ -375,9 +375,9 @@ int ftdi_bmp_init(BMP_CL_OPTIONS_t *cl_opts, bmp_info_t *info) active_cable->mpsse_swd_read.set_data_low = MPSSE_DO; active_cable->mpsse_swd_write.set_data_low = MPSSE_DO; } else if (!libftdi_swd_possible(NULL, NULL) && - !cl_opts->opt_usejtag) { + cl_opts->opt_scanmode != BMP_SCAN_JTAG) { DEBUG_WARN("SWD with cable not possible, trying JTAG\n"); - cl_opts->opt_usejtag = true; + cl_opts->opt_scanmode = BMP_SCAN_JTAG; } if(ftdic) { ftdi_usb_close(ftdic);