aboutsummaryrefslogtreecommitdiff
path: root/src/jtag/hla/hla_interface.c
diff options
context:
space:
mode:
authorAndrey Yurovsky <yurovsky@gmail.com>2013-07-22 23:39:51 -0700
committerSpencer Oliver <spen@spen-soft.co.uk>2013-08-07 21:02:28 +0000
commitd998ea40f3a323cfbc7b80d9c9d5057fbc76c6a9 (patch)
treefb0150fc8164f3f6e98e27869b44a5c05c25906e /src/jtag/hla/hla_interface.c
parent0961987a1916a498e65240cded359ab3c9b73f95 (diff)
downloadriscv-openocd-d998ea40f3a323cfbc7b80d9c9d5057fbc76c6a9.zip
riscv-openocd-d998ea40f3a323cfbc7b80d9c9d5057fbc76c6a9.tar.gz
riscv-openocd-d998ea40f3a323cfbc7b80d9c9d5057fbc76c6a9.tar.bz2
stlink: add SWO tracing support
Enable reading the SWO trace output via STLinkv2 dongles that support it. This adds an optional initialization parameter "trace" with which the user specifies a destination file where SWO trace output is appended as it comes in as well as the trace module's source clock rate. STLink will be configured for a 2MHz SWO data rate (STLink's highest supported rate) if the source clock is > 2MHz, otherwise the source clock is used as the data rate directly. For example: trace swo.log 168000000 If "trace" is specified with a usable file path, the stlink_usb driver will attempt to configure and read SWO trace data as follows: - on _run(), the target's TPI and TMI are configured and the STLinkv2 is told to enable tracing. Only generic ARM TPI and TMI registers are configured, any MCU-specific settings (ex: pin routing) are the responsibility of the target firmware. The configuration applied is based on the STLinkv2's capabilities (UART emulation). - on _v2_get_status(), the trace data (if any) is fetched from the STLink after the target status is checked and the target is found to be running. - on _halt(), the STLink is told to disable tracing. When fetching trace data, the entire trace frame is written to the output file and that data is flushed. An external tool may be used to parse the trace data into a more human-readable format. Tested on ARM Cortex M4F and M3 MCUs (STM32F407 and STM32L152). Change-Id: Ic3983d46c82ba77010c23b0e18ce7b275d917f12 Signed-off-by: Andrey Yurovsky <yurovsky@gmail.com> Reviewed-on: http://openocd.zylin.com/1524 Tested-by: jenkins Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk> Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Diffstat (limited to 'src/jtag/hla/hla_interface.c')
-rw-r--r--src/jtag/hla/hla_interface.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/jtag/hla/hla_interface.c b/src/jtag/hla/hla_interface.c
index 8faf922..f8b5c61 100644
--- a/src/jtag/hla/hla_interface.c
+++ b/src/jtag/hla/hla_interface.c
@@ -37,7 +37,7 @@
#include <target/target.h>
-static struct hl_interface_s hl_if = { {0, 0, 0, 0, 0, HL_TRANSPORT_UNKNOWN, 0, false}, 0, 0 };
+static struct hl_interface_s hl_if = { {0, 0, 0, 0, 0, HL_TRANSPORT_UNKNOWN, 0, false, NULL, 0}, 0, 0 };
int hl_interface_open(enum hl_transports tr)
{
@@ -114,6 +114,11 @@ static int hl_interface_quit(void)
{
LOG_DEBUG("hl_interface_quit");
+ if (hl_if.param.trace_f) {
+ fclose(hl_if.param.trace_f);
+ hl_if.param.trace_f = NULL;
+ }
+
return ERROR_OK;
}
@@ -220,6 +225,30 @@ COMMAND_HANDLER(stlink_interface_handle_api_command)
return ERROR_OK;
}
+COMMAND_HANDLER(interface_handle_trace_command)
+{
+ FILE *f;
+ unsigned source_hz;
+
+ if (CMD_ARGC != 2)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ f = fopen(CMD_ARGV[0], "a");
+ if (!f)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], source_hz);
+ if (source_hz == 0) {
+ fclose(f);
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+
+ hl_if.param.trace_f = f;
+ hl_if.param.trace_source_hz = source_hz;
+
+ return ERROR_OK;
+}
+
static const struct command_registration hl_interface_command_handlers[] = {
{
.name = "hla_device_desc",
@@ -256,6 +285,13 @@ static const struct command_registration hl_interface_command_handlers[] = {
.help = "set the desired stlink api level",
.usage = "api version 1 or 2",
},
+ {
+ .name = "trace",
+ .handler = &interface_handle_trace_command,
+ .mode = COMMAND_CONFIG,
+ .help = "configure trace reception",
+ .usage = "destination_path source_lock_hz",
+ },
COMMAND_REGISTRATION_DONE
};