Skip to content

Commit

Permalink
command: Add support for disabling traceswo
Browse files Browse the repository at this point in the history
* Insert a new verb, enable|disable, before optional `baudrate` and optional `decode channel-list` parameters
* Hook to traceswo_deinit of async impl which frees a giant buffer from heap
  • Loading branch information
ALTracer committed Jul 22, 2024
1 parent ccdcb31 commit 26e9dca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,8 @@ static bool cmd_rtt(target_s *t, int argc, const char **argv)
#endif

#ifdef PLATFORM_HAS_TRACESWO
static bool cmd_traceswo(target_s *t, int argc, const char **argv)
static bool cmd_traceswo_enable(int argc, const char **argv)
{
(void)t;
#if TRACESWO_PROTOCOL == 2
uint32_t baudrate = SWO_DEFAULT_BAUD;
#endif
Expand Down Expand Up @@ -637,6 +636,35 @@ static bool cmd_traceswo(target_s *t, int argc, const char **argv)
gdb_outf("Trace enabled for BMP serial %s, USB EP %u\n", serial_no, TRACE_ENDPOINT);
return true;
}

static bool cmd_traceswo_disable(void)
{
#if TRACESWO_PROTOCOL == 2
traceswo_deinit();
gdb_out("Trace disabled\n");
return true;
#else
gdb_out("Not implemented\n");
return false;
#endif
}

static bool cmd_traceswo(target_s *t, int argc, const char **argv)
{
(void)t;
bool mode = false;
if (argc >= 2) {
if (!parse_enable_or_disable(argv[1], &mode)) {
gdb_out("Usage: traceswo <enable|disable> [2000000] [decode [0 1 3 31]]\n");
return false;
}
}
if (mode) {
return cmd_traceswo_enable(argc - 1, argv + 1);
} else {
return cmd_traceswo_disable();
}
}
#endif

#if defined(PLATFORM_HAS_DEBUG) && PC_HOSTED == 0
Expand Down
1 change: 1 addition & 0 deletions src/platforms/common/traceswo.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
/* Default line rate, used as default for a request without baudrate */
#define SWO_DEFAULT_BAUD 2250000U
void traceswo_init(uint32_t baudrate, uint32_t swo_chan_bitmask);
void traceswo_deinit(void);
#else
void traceswo_init(uint32_t swo_chan_bitmask);
#endif
Expand Down

0 comments on commit 26e9dca

Please sign in to comment.