From 5a99a95f0218865a24cdfa0e7b9f49960b4634b1 Mon Sep 17 00:00:00 2001 From: Rafael Silva Date: Wed, 17 Jan 2024 11:40:36 +0000 Subject: [PATCH] hosted: fix ephemeral max frequency On hosted, the max frequency was being set on every scan routine to the value set by the command line options, even if the user set a new value with the monitor command This adds storage to the max frequency, meaning the frequency set by the user will be remembered over the initial command line value --- src/platforms/hosted/cli.c | 8 ++++---- src/platforms/hosted/cli.h | 2 +- src/platforms/hosted/platform.c | 22 +++++++++++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/platforms/hosted/cli.c b/src/platforms/hosted/cli.c index 64cf66434ac..9c3d79174cb 100644 --- a/src/platforms/hosted/cli.c +++ b/src/platforms/hosted/cli.c @@ -173,10 +173,10 @@ static void cl_help(char **argv) "\t can be repeated for as many commands you wish to run.\n" "\t If the command contains spaces, use quotes around the\n" "\t complete command\n" + "\t-f, --freq Set an operating frequency for the debug interface\n" "\n" "SWD-specific configuration options [-f FREQUENCY | -m TARGET]:\n" - "\t-f, --freq Set an operating frequency for SWD\n" - "\t-m, --mult-drop Use the given target ID for selection in SWD multi-drop\n" + "\t-m, --multi-drop Use the given target ID for selection in SWD multi-drop\n" "\n" "Flash operation selection options [-E | -w | -V | -r]:\n" "\t-E, --erase Erase the target device Flash\n" @@ -233,7 +233,7 @@ void cl_init(bmda_cli_options_s *opt, int argc, char **argv) opt->opt_target_dev = 1; opt->opt_flash_size = 0xffffffff; opt->opt_flash_start = 0xffffffff; - opt->opt_max_swj_frequency = 4000000; + opt->opt_max_frequency = 0; opt->opt_scanmode = BMP_SCAN_SWD; opt->opt_mode = BMP_MODE_DEBUG; while (true) { @@ -306,7 +306,7 @@ void cl_init(bmda_cli_options_s *opt, int argc, char **argv) frequency *= 1000U * 1000U; break; } - opt->opt_max_swj_frequency = frequency; + opt->opt_max_frequency = frequency; } break; case 's': diff --git a/src/platforms/hosted/cli.h b/src/platforms/hosted/cli.h index 2ebb3ee9657..fd992b6d22a 100644 --- a/src/platforms/hosted/cli.h +++ b/src/platforms/hosted/cli.h @@ -65,7 +65,7 @@ typedef struct bmda_cli_options { char *opt_monitor; uint32_t opt_target_dev; uint32_t opt_flash_start; - uint32_t opt_max_swj_frequency; + uint32_t opt_max_frequency; size_t opt_flash_size; } bmda_cli_options_s; diff --git a/src/platforms/hosted/platform.c b/src/platforms/hosted/platform.c index 234da2ac55c..de9c0e3a487 100644 --- a/src/platforms/hosted/platform.c +++ b/src/platforms/hosted/platform.c @@ -58,6 +58,8 @@ bmda_probe_s bmda_probe_info; jtag_proc_s jtag_proc; swd_proc_s swd_proc; +static uint32_t max_frequency = 4000000U; + static bmda_cli_options_s cl_opts; void gdb_ident(char *p, int count) @@ -154,6 +156,9 @@ void platform_init(int argc, char **argv) exit(1); } + if (cl_opts.opt_max_frequency) + max_frequency = cl_opts.opt_max_frequency; + if (cl_opts.opt_mode != BMP_MODE_DEBUG) exit(cl_execute(&cl_opts)); else { @@ -168,7 +173,7 @@ void platform_init(int argc, char **argv) bool bmda_swd_scan(const uint32_t targetid) { bmda_probe_info.is_jtag = false; - platform_max_frequency_set(cl_opts.opt_max_swj_frequency); + platform_max_frequency_set(max_frequency); switch (bmda_probe_info.type) { case PROBE_TYPE_BMP: @@ -224,8 +229,7 @@ void bmda_add_jtag_dev(const uint32_t dev_index, const jtag_dev_s *const jtag_de bool bmda_jtag_scan(void) { bmda_probe_info.is_jtag = true; - - platform_max_frequency_set(cl_opts.opt_max_swj_frequency); + platform_max_frequency_set(max_frequency); switch (bmda_probe_info.type) { case PROBE_TYPE_BMP: @@ -413,11 +417,15 @@ bool platform_nrst_get_val(void) } } -void platform_max_frequency_set(uint32_t freq) +void platform_max_frequency_set(const uint32_t freq) { if (!freq) return; + // Remember the frequency we were asked to set, + // this will be re-set every time a scan is issued. + max_frequency = freq; + switch (bmda_probe_info.type) { case PROBE_TYPE_BMP: remote_max_frequency_set(freq); @@ -442,14 +450,14 @@ void platform_max_frequency_set(uint32_t freq) #endif default: - DEBUG_WARN("Setting max SWD/JTAG frequency not yet implemented\n"); + DEBUG_WARN("Setting max debug interface frequency not available or not yet implemented\n"); break; } const uint32_t actual_freq = platform_max_frequency_get(); if (actual_freq == FREQ_FIXED) DEBUG_INFO("Device has fixed frequency for %s\n", bmda_probe_info.is_jtag ? "JTAG" : "SWD"); - else { + else if (actual_freq != 0) { const uint16_t freq_mhz = actual_freq / 1000000U; const uint16_t freq_khz = (actual_freq / 1000U) - (freq_mhz * 1000U); DEBUG_INFO("Speed set to %u.%03uMHz for %s\n", freq_mhz, freq_khz, bmda_probe_info.is_jtag ? "JTAG" : "SWD"); @@ -477,7 +485,7 @@ uint32_t platform_max_frequency_get(void) #endif default: - DEBUG_WARN("Reading max SWJ frequency not yet implemented\n"); + DEBUG_WARN("Reading max debug interface frequency not available or not yet implemented\n"); return 0; } }