Skip to content

Commit

Permalink
target: split swd scan function into with and without a targetid
Browse files Browse the repository at this point in the history
This gives the swd scan function an equivalent signature to the other scan commands allowing us to group them for the auto scan command
  • Loading branch information
perigoso authored and Rafael Silva committed Feb 6, 2025
1 parent d66c726 commit 25671eb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ bool cmd_swd_scan(target_s *target, int argc, const char **argv)
bool scan_result = false;
TRY (EXCEPTION_ALL) {
#if CONFIG_BMDA == 1
scan_result = bmda_swd_scan(targetid);
scan_result = bmda_swd_scan_targetid(targetid);
#else
scan_result = adiv5_swd_scan(targetid);
scan_result = adiv5_swd_scan_targetid(targetid);
#endif
}
CATCH () {
Expand Down Expand Up @@ -390,9 +390,9 @@ bool cmd_auto_scan(target_s *target, int argc, const char **argv)
gdb_out("JTAG scan found no devices, trying SWD!\n");

#if CONFIG_BMDA == 1
scan_result = bmda_swd_scan(0);
scan_result = bmda_swd_scan();
#else
scan_result = adiv5_swd_scan(0);
scan_result = adiv5_swd_scan();
#endif
if (!scan_result) {
gdb_out("SWD scan found no devices.\n");
Expand Down
6 changes: 4 additions & 2 deletions src/include/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ typedef target_addr32_t target_addr_t;
typedef struct target_controller target_controller_s;

#if CONFIG_BMDA == 1
bool bmda_swd_scan(uint32_t targetid);
bool bmda_swd_scan(void);
bool bmda_swd_scan_targetid(uint32_t targetid);
bool bmda_jtag_scan(void);
#if defined(CONFIG_RVSWD) && defined(PLATFORM_HAS_RVSWD)
bool bmda_rvswd_scan(void);
#endif
#endif
bool adiv5_swd_scan(uint32_t targetid);
bool adiv5_swd_scan(void);
bool adiv5_swd_scan_targetid(uint32_t targetid);
bool jtag_scan(void);

size_t target_foreach(void (*callback)(size_t index, target_s *target, void *context), void *context);
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/hosted/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,11 @@ bool scan_for_targets(const bmda_cli_options_s *const opt)
if (opt->opt_scanmode == BMP_SCAN_JTAG)
return bmda_jtag_scan();
if (opt->opt_scanmode == BMP_SCAN_SWD)
return bmda_swd_scan(opt->opt_targetid);
return bmda_swd_scan_targetid(opt->opt_targetid);
if (bmda_jtag_scan())
return true;
DEBUG_WARN("JTAG scan found no devices, trying SWD.\n");
if (bmda_swd_scan(opt->opt_targetid))
if (bmda_swd_scan_targetid(opt->opt_targetid))
return true;
DEBUG_ERROR("SWD scan failed!\n");
return false;
Expand Down
9 changes: 7 additions & 2 deletions src/platforms/hosted/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ void platform_init(int argc, char **argv)
}
}

bool bmda_swd_scan(const uint32_t targetid)
bool bmda_swd_scan(void)
{
return bmda_swd_scan_targetid(0);
}

bool bmda_swd_scan_targetid(const uint32_t targetid)
{
bmda_probe_info.is_jtag = false;
platform_max_frequency_set(max_frequency);
Expand All @@ -209,7 +214,7 @@ bool bmda_swd_scan(const uint32_t targetid)
#ifdef ENABLE_GPIOD
case PROBE_TYPE_GPIOD:
#endif
return adiv5_swd_scan(targetid);
return adiv5_swd_scan_targetid(targetid);

#if HOSTED_BMP_ONLY == 0
case PROBE_TYPE_STLINK_V2:
Expand Down
7 changes: 6 additions & 1 deletion src/target/adiv5_swd.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ uint32_t adiv5_swd_read_no_check(const uint16_t addr)
return res == SWD_ACK_OK ? data : 0;
}

bool adiv5_swd_scan(const uint32_t targetid)
bool adiv5_swd_scan()
{
return adiv5_swd_scan_targetid(0);
}

bool adiv5_swd_scan_targetid(const uint32_t targetid)
{
/* Free the device list if any */
target_list_free();
Expand Down

0 comments on commit 25671eb

Please sign in to comment.