Skip to content

Commit

Permalink
hosted: fix ephemeral max frequency
Browse files Browse the repository at this point in the history
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
  • Loading branch information
perigoso authored and rg-silva committed Jan 17, 2024
1 parent cea35a6 commit 5a99a95
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/platforms/hosted/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/hosted/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
22 changes: 15 additions & 7 deletions src/platforms/hosted/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 5a99a95

Please sign in to comment.