Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: native Trace/SWO support #1934

Merged
merged 48 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
1044882
common/stm32/traceswo: Cleaned up the copyright notice and corrected …
dragonmux Aug 12, 2024
3bcdbcb
common/stm32/traceswo: Implement handling for deinitialising Macheste…
dragonmux Aug 13, 2024
5286f29
common/stm32/traceswo: Cleaned up and started sorting out the Manches…
dragonmux Aug 13, 2024
3463818
common/stm32/traceswo: Cleanup and documentation comments to try and …
dragonmux Aug 13, 2024
53ae959
common/stm32/traceswo: More refinements and unbundling the capture bu…
dragonmux Aug 14, 2024
e30317c
common/stm32/traceswo: Fixed some initialisation order issues and mad…
dragonmux Aug 15, 2024
70a12f8
common/stm32/traceswo: Rebuilt the Manchester decoding logic with ple…
dragonmux Aug 15, 2024
18e47a9
common/stm32/traceswo: Fixed some of the entry conditions and decoder…
dragonmux Aug 21, 2024
5780c8c
command: Cleanup in the SWO command implementation and correction of …
dragonmux Sep 8, 2024
e37ca73
common/stm32: Renamed the SWO implementations to make it clearer whic…
dragonmux Sep 8, 2024
cf2aeaa
common/stm32/swo_itm_decode: Nomenclature and types corrections for t…
dragonmux Sep 9, 2024
b4f3bd2
common: Nomenclature corrections for the SWO buffer send USB callback…
dragonmux Sep 9, 2024
ba4ed1d
common/stm32/swo_manchester: Completed the nomenclature cleanup for t…
dragonmux Sep 9, 2024
441eea4
common/stm32/swo_uart: Cleaned up the nomenclature of the external fu…
dragonmux Sep 9, 2024
076a15c
command: Switched the SWO command to the new consitent nomenclature
dragonmux Sep 9, 2024
aee4c01
command: Cleaned up and better documented the SWO enable function
dragonmux Sep 9, 2024
9950cd3
command: Fixed a clang-tidy lint in cmd_swo()
dragonmux Sep 9, 2024
f1afe01
common: Switched the SWO definitions nomenclature to be consistent by…
dragonmux Sep 9, 2024
ff690e2
native/platform: Added defines for UART-encoded SWO data recovery
dragonmux Sep 9, 2024
0337654
common/stm32/swo_uart: Restructured the code to put the interaction c…
dragonmux Sep 9, 2024
5e1bc40
native/platform: Implemented a mechanism for dispatching to the appro…
dragonmux Sep 10, 2024
44cb5ce
native: Enabled building UART instead of Manchester mode for SWO in t…
dragonmux Sep 10, 2024
640b904
common: Bought the nomenclature for the SWO encoding definition into …
dragonmux Sep 10, 2024
93069f7
common/swo: Started building out a mechanism to allow the SWO impleme…
dragonmux Sep 12, 2024
e306eff
common/swo: Implemented switched initialisation for decoding
dragonmux Sep 12, 2024
ec41ce9
native: Enabled both SWO decoders and the switchable SWO support
dragonmux Sep 12, 2024
6c98aef
common/swo: Started refactoring all the buffer and ITM decode logic o…
dragonmux Sep 13, 2024
d495779
command: Provide for the multi-mode version of the SWO monitor command
dragonmux Sep 13, 2024
95aa24d
swo_manchester: Reworked some of the buffering logic to pull decoding…
dragonmux Sep 15, 2024
ced2e4c
common/stm32/swo: De-duplicated the UART-encoded SWO implementations …
dragonmux Sep 15, 2024
c497b6e
common/stm32/swo: Fixed a couple of comments that were misworded
dragonmux Sep 15, 2024
bff3c16
common/stm32/swo_uart: Nomenclature corrections for the USB bounce bu…
dragonmux Sep 15, 2024
42ba11f
common/stm32/swo_uart: Fixed an issue with deinitialisation leaving t…
dragonmux Sep 15, 2024
e65b762
common/stm32/swo: Rebuilt the buffering system using one single unifi…
dragonmux Sep 16, 2024
5025320
platforms: Cleaned up defunct SWO definitions
dragonmux Sep 17, 2024
7b11f50
ctxlink: Enabled switchable SWO on the platform
dragonmux Sep 17, 2024
312194c
swlink: Enabled switchable SWO on the platform
dragonmux Sep 17, 2024
c261082
stlink: Enabled switchable SWO on the platform
dragonmux Sep 17, 2024
2ea0787
common/blackpill-f4: Enabled switchable SWO on the platform
dragonmux Sep 17, 2024
891261e
platforms: Added missing definitions for the SWO support across vario…
dragonmux Sep 17, 2024
72b89da
common/stm32/swo: Deal with the STM32F7 platforms properly in the pin…
dragonmux Sep 17, 2024
4857750
platforms: Fixed the build system including the base SWO and ITM deco…
dragonmux Sep 17, 2024
97529a2
f072: Handle the missing atomics needed for SWO via `libatomic`
dragonmux Sep 17, 2024
25258af
common/stm32/swo_uart: Moved the baudrate checking and sanity code in…
dragonmux Sep 17, 2024
4088295
common/tm4c/swo_uart: Sorted out the initialisation and deinitialisat…
dragonmux Sep 17, 2024
f3b7549
common/blackpill-f4: The CCR's become swapped when the input is on ch…
dragonmux Sep 22, 2024
4c6bd0c
ctxlink/platform: The CCR's become swapped when the input is on chann…
dragonmux Sep 22, 2024
7ce749e
common/stm32/swo_uart: Cleaned up the copyright notice and corrected …
dragonmux Sep 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SRC = \
adiv5.c \
adiv5_jtag.c \
adiv5_swd.c \
apollo3.c \
apollo3.c \
adiv6.c \
command.c \
cortex.c \
Expand Down Expand Up @@ -106,6 +106,12 @@ ifneq ($(PROBE_HOST), ctxLink)
SRC += gdb_if.c
endif

# Check if the old name for the SWO encoding setting has been used
ifdef TRACESWO_PROTOCOL
$(warning the TRACESWO_PROTOCOL variable is deprecated, please use SWO_ENCODING instead)
SWO_ENCODING = $(TRACESWO_PROTOCOL)
endif

ifeq (,$(filter all_platforms,$(MAKECMDGOALS)))
include $(PLATFORM_DIR)/Makefile.inc
endif
Expand Down
141 changes: 82 additions & 59 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

#ifdef PLATFORM_HAS_TRACESWO
#include "serialno.h"
#include "traceswo.h"
#include "swo.h"
#include "usb.h"
#endif

Expand All @@ -68,7 +68,7 @@ static bool cmd_tdi_low_reset(target_s *t, int argc, const char **argv);
static bool cmd_target_power(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_swo(target_s *t, int argc, const char **argv);
#endif
static bool cmd_heapinfo(target_s *t, int argc, const char **argv);
#ifdef ENABLE_RTT
Expand Down Expand Up @@ -109,11 +109,14 @@ const command_s cmd_list[] = {
"MAXERR]]"},
#endif
#ifdef PLATFORM_HAS_TRACESWO
#if defined TRACESWO_PROTOCOL && TRACESWO_PROTOCOL == 2
{"traceswo", cmd_traceswo, "Start trace capture, NRZ mode: [BAUDRATE] [decode [CHANNEL_NR ...]]"},
#else
{"traceswo", cmd_traceswo, "Start trace capture, Manchester mode: [decode [CHANNEL_NR ...]]"},
#if SWO_ENCODING == 1
{"swo", cmd_swo, "Start SWO capture, Manchester mode: <enable|disable> [decode [CHANNEL_NR ...]]"},
#elif SWO_ENCODING == 2
{"swo", cmd_swo, "Start SWO capture, UART mode: <enable|disable> [BAUDRATE] [decode [CHANNEL_NR ...]]"},
#elif SWO_ENCODING == 3
{"swo", cmd_swo, "Start SWO capture: <enable|disable> [manchester|uart] [BAUDRATE] [decode [CHANNEL_NR ...]]"},
#endif
{"traceswo", cmd_swo, "Deprecated: use swo instead"},
#endif
{"heapinfo", cmd_heapinfo, "Set semihosting heapinfo: HEAP_BASE HEAP_LIMIT STACK_BASE STACK_LIMIT"},
#if defined(PLATFORM_HAS_DEBUG) && PC_HOSTED == 0
Expand Down Expand Up @@ -603,89 +606,109 @@ static bool cmd_rtt(target_s *t, int argc, const char **argv)
#endif

#ifdef PLATFORM_HAS_TRACESWO
static bool cmd_traceswo_enable(int argc, const char **argv)
static bool cmd_swo_enable(int argc, const char **argv)
{
uint32_t swo_channelmask = 0; /* swo decoding off */
uint8_t decode_arg = 1;
#if TRACESWO_PROTOCOL == 2
/* Set up which mode we're going to default to */
#if SWO_ENCODING == 1
const swo_coding_e capture_mode = swo_manchester;
#elif SWO_ENCODING == 2
const swo_coding_e capture_mode = swo_nrz_uart;
#elif SWO_ENCODING == 3
swo_coding_e capture_mode = swo_none;
#endif
/* Set up the presumed baudrate for the stream */
uint32_t baudrate = SWO_DEFAULT_BAUD;
/* argument: optional baud rate for async mode */
if (argc > 1 && argv[1][0] >= '0' && argv[1][0] <= '9') {
baudrate = strtoul(argv[1], NULL, 0);
if (baudrate == 0)
/*
* Before we can enable SWO data recovery, potentially with decoding,
* start with the assumption ITM decoding is off
*/
uint32_t itm_stream_mask = 0U;
uint8_t decode_arg = 1U;
#if SWO_ENCODING == 3
/* Next, determine which decoding mode to use */
if (argc > decode_arg) {
const size_t arg_length = strlen(argv[decode_arg]);
if (!strncmp(argv[decode_arg], "manchester", arg_length))
capture_mode = swo_manchester;
if (!strncmp(argv[decode_arg], "uart", arg_length))
capture_mode = swo_nrz_uart;
}
/* If a mode was given, make sure the rest of the parser skips the mode verb */
if (capture_mode != swo_none)
++decode_arg;
/* Otherwise set a default mode up */
else
capture_mode = swo_nrz_uart;
#endif
#if SWO_ENCODING == 2 || SWO_ENCODING == 3
/* Handle the optional baud rate argument if present */
if (capture_mode == swo_nrz_uart && argc > decode_arg && argv[decode_arg][0] >= '0' && argv[decode_arg][0] <= '9') {
baudrate = strtoul(argv[decode_arg], NULL, 0);
if (baudrate == 0U)
baudrate = SWO_DEFAULT_BAUD;
decode_arg = 2;
++decode_arg;
}
#endif
/* argument: 'decode' literal */
/* Check if `decode` has been given and if it has, enable ITM decoding */
if (argc > decode_arg && !strncmp(argv[decode_arg], "decode", strlen(argv[decode_arg]))) {
swo_channelmask = 0xffffffffU; /* decoding all channels */
/* arguments: channels to decode */
/* Check if there are specific ITM streams to enable and build a bitmask of them */
if (argc > decode_arg + 1) {
swo_channelmask = 0U;
for (size_t i = decode_arg + 1U; i < (size_t)argc; ++i) { /* create bitmask of channels to decode */
const uint32_t channel = strtoul(argv[i], NULL, 0);
if (channel < 32U)
swo_channelmask |= 1U << channel;
/* For each of the specified streams */
for (size_t i = decode_arg + 1U; i < (size_t)argc; ++i) {
/* Figure out which the next one is */
const uint32_t stream = strtoul(argv[i], NULL, 0);
/* If it's a valid ITM stream number, set it in the mask */
if (stream < 32U)
itm_stream_mask |= 1U << stream;
}
}
} else
/* Decode all ITM streams if non given */
itm_stream_mask = 0xffffffffU;
}

#if TRACESWO_PROTOCOL == 2
traceswo_init(baudrate, swo_channelmask);
gdb_outf("Baudrate: %lu ", traceswo_get_baudrate());
#else
traceswo_init(swo_channelmask);
#endif
/* Now enable SWO data recovery */
swo_init(capture_mode, baudrate, itm_stream_mask);
/* And show the user what we've done - first the channel mask from MSb to LSb */
gdb_outf("Channel mask: ");
for (size_t i = 0; i < 32U; ++i) {
const uint32_t bit = (swo_channelmask >> (31U - i)) & 1U;
gdb_outf("%" PRIu32, bit);
const char bit = '0' + ((itm_stream_mask >> (31U - i)) & 1U);
gdb_outf("%c", bit);
}
gdb_outf("\n");

gdb_outf("Trace enabled for BMP serial %s, USB EP %u\n", serial_no, TRACE_ENDPOINT);
/* Then the connection information for programs that are scraping BMD's output to know what to connect to */
gdb_outf("Trace enabled for BMP serial %s, USB EP %u\n", serial_no, SWO_ENDPOINT);
return true;
}

static bool cmd_traceswo_disable(void)
static bool cmd_swo_disable(void)
{
#if TRACESWO_PROTOCOL == 2
traceswo_deinit();
swo_deinit(true);
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)
static bool cmd_swo(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();
bool enable_swo = false;
if (argc >= 2 && !parse_enable_or_disable(argv[1], &enable_swo)) {
gdb_out("Usage: traceswo <enable|disable> [2000000] [decode [0 1 3 31]]\n");
return false;
}

if (enable_swo)
return cmd_swo_enable(argc - 1, argv + 1);
return cmd_swo_disable();
}
#endif

#if defined(PLATFORM_HAS_DEBUG) && PC_HOSTED == 0
static bool cmd_debug_bmp(target_s *t, int argc, const char **argv)
{
(void)t;
if (argc == 2) {
if (!parse_enable_or_disable(argv[1], &debug_bmp))
return false;
} else if (argc > 2) {
if (argc == 2 && !parse_enable_or_disable(argv[1], &debug_bmp))
return false;
if (argc > 2) {
gdb_outf("usage: monitor debug [enable|disable]\n");
return false;
}
Expand Down Expand Up @@ -723,8 +746,8 @@ static bool cmd_heapinfo(target_s *t, int argc, const char **argv)
target_addr_t heap_limit = strtoul(argv[2], NULL, 16);
target_addr_t stack_base = strtoul(argv[3], NULL, 16);
target_addr_t stack_limit = strtoul(argv[4], NULL, 16);
gdb_outf("heap_base: %08" PRIx32 " heap_limit: %08" PRIx32 " stack_base: %08" PRIx32 " stack_limit: %08" PRIx32
"\n",
gdb_outf("heap_base: %08" PRIx32 " heap_limit: %08" PRIx32 " stack_base: %08" PRIx32 " stack_limit: "
"%08" PRIx32 "\n",
heap_base, heap_limit, stack_base, stack_limit);
target_set_heapinfo(t, heap_base, heap_limit, stack_base, stack_limit);
} else
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/96b_carbon/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "timing_stm32.h"
#include "version.h"

#define PLATFORM_IDENT "(Carbon)"
#define PLATFORM_IDENT "(96b Carbon) "

/*
* Important pin mappings for Carbon implementation:
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/common/aux_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
#include "aux_serial.h"

static char aux_serial_receive_buffer[AUX_UART_BUFFER_SIZE];
/* Fifo in pointer, writes assumed to be atomic, should be only incremented within RX ISR */
/* FIFO in pointer, writes assumed to be atomic, should be only incremented within RX ISR */
static uint16_t aux_serial_receive_write_index = 0;
/* Fifo out pointer, writes assumed to be atomic, should be only incremented outside RX ISR */
/* FIFO out pointer, writes assumed to be atomic, should be only incremented outside RX ISR */
static uint16_t aux_serial_receive_read_index = 0;

#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4) || defined(STM32F7)
Expand Down
28 changes: 20 additions & 8 deletions src/platforms/common/blackpill-f4/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,30 @@ VPATH += \

SRC += \
blackpill-f4.c \
traceswodecode.c \
serialno.c \
timing.c \
timing_stm32.c
timing_stm32.c \
swo.c \
swo_itm_decode.c

ifeq ($(TRACESWO_PROTOCOL), 1)
SRC += traceswo.c
CFLAGS += -DTRACESWO_PROTOCOL=1
else
SRC += traceswoasync.c
CFLAGS += -DTRACESWO_PROTOCOL=2
# If SWO_ENCODING has not been given, default it to including both modes
ifndef SWO_ENCODING
SWO_ENCODING = 3
endif

# Include the files for either: Manchester-only (1), UART-only (2) or both modes (3)
ifeq ($(SWO_ENCODING), 1)
SRC += swo_manchester.c
else ifeq ($(SWO_ENCODING), 2)
SRC += swo_uart.c
else ifeq ($(SWO_ENCODING), 3)
SRC += \
swo_manchester.c \
swo_uart.c
else # If we got some other value, that's an error so report it
$(error Invalid value for SWO encoding, must be one of 1, 2, or 3)
endif
CFLAGS += -DSWO_ENCODING=$(SWO_ENCODING)

ifneq ($(BMD_BOOTLOADER), 1)
all: blackmagic.bin
Expand Down
Loading
Loading