This is an automated email from Gerrit.

Paul Fertser (fercer...@gmail.com) just uploaded a new patch set to Gerrit, 
which you can find at http://openocd.zylin.com/2450

-- gerrit

commit dfb66102c148afbc86c1ec3fc8ecf65867521049
Author: Karl Palsson <ka...@tweak.net.au>
Date:   Thu Dec 18 23:46:52 2014 +0000

    stlink: trace: turn off ITM/DWT meddling
    
    that's not the responsibility of this layer.
    Add some tcl that can be run by the user that can manage the ITM/DWT
    regs instead.
    
    Change-Id: Ieab779c91ed478b0fff1c0891342d7205c305b17
    Signed-off-by: Paul Fertser <fercer...@gmail.com>

diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c
index 7572e87..89737b5 100644
--- a/src/jtag/drivers/stlink_usb.c
+++ b/src/jtag/drivers/stlink_usb.c
@@ -1046,6 +1046,7 @@ static int stlink_configure_target_trace_port(void 
*handle)
 
        /* configure the ITM */
 
+#if OOCD_SHOULD_MEDDLE
        /* unlock access to the ITM registers */
        res = stlink_usb_write_debug_reg(handle, ITM_LAR, 0xC5ACCE55);
        if (res != ERROR_OK)
@@ -1062,6 +1063,7 @@ static int stlink_configure_target_trace_port(void 
*handle)
        res = stlink_usb_write_debug_reg(handle, ITM_TER, (1<<0));
        if (res != ERROR_OK)
                goto out;
+#endif
 
        res = ERROR_OK;
 out:
@@ -1078,7 +1080,7 @@ static void stlink_usb_trace_disable(void *handle)
 
        assert(h->version.jtag >= STLINK_TRACE_MIN_VERSION);
 
-       LOG_DEBUG("Tracing: disable");
+       LOG_INFO("Tracing: disable");
 
        stlink_usb_init_buffer(handle, h->rx_ep, 2);
        h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@@ -1099,6 +1101,7 @@ static int stlink_usb_trace_enable(void *handle)
        struct stlink_usb_handle_s *h = handle;
 
        assert(handle != NULL);
+       LOG_INFO("enabling trace collection from stlink");
 
        if (h->version.jtag >= STLINK_TRACE_MIN_VERSION) {
                uint32_t trace_hz;
diff --git a/tcl/itm_helper.tcl b/tcl/itm_helper.tcl
new file mode 100644
index 0000000..4a12016
--- /dev/null
+++ b/tcl/itm_helper.tcl
@@ -0,0 +1,83 @@
+
+source [find mem_helper.tcl]
+
+# this doesn't work
+if { [info exists TRACE_HZ] } {
+   set _TRACE_HZ $TRACE_HZ
+} else {
+   set _TRACE_HZ 32000000
+}
+
+
+proc hack_enable_trace { } {
+       puts "enabling trace itself"
+    # DBG_DEMCR |= TRCENA
+    mmw 0xE000EDFC [expr (1<<24)] 0
+
+    # DBGMCR_CR |= TRACE_IOEN, DEBUG_STOP, DEBUG_STANDBY, DEBUG_SLEEP
+    mmw 0xe0042004 [expr ((1<<5) | 0x7)] 0
+
+    # ST ref man says we set this to 1 even in async mode, it's still "one" 
pin wide
+    # TPIU_CSPSR = 1
+    mww 0xe0040004 1
+
+    # set TPIU_ACPR
+    # FIXME - need this loaded in somehow.
+    #set prescaler [expr ($TRACE_HZ / 2000000) - 1]
+    set prescaler [expr (24000000 / 2000000) - 1]
+    set prescaler [expr (32000000 / 2000000) - 1]
+    mww 0xE0040010 $prescaler
+
+    # <<<< SWOPY tells stlink to stop/start trace here
+
+    # SPPR = NRZ, should have already been done by oocd,
+    # as that's stlink specific
+    # TPIU_FFCR = 0, (oocd was using bit 8, for triggers?)
+    mww 0xE0040304 0
+}
+
+proc kprof { } {
+    puts "KKK: profile on"
+    hack_enable_trace
+
+    # Unlock ITM
+    mww 0xe0000fb0 0xC5ACCE55
+    # ITM_TCR = use ATB ID #1, txena (from dwt), tpiu sync, enable ITM
+    mww 0xe0000e80 [expr (1<<16) | (1<<3) | (1<<2) | (1 << 0)]
+
+    # DWT_CTRL = PC sampling, slowest sync(tap28), slowest pc csample (tap 10),
+    # slowest pc sampling counter (0xf) and enable cycle counter
+    mww 0xe0001000 [expr ((1<<12) | (3<<10) | (1<<9)|(0xf<<1) | 1)]
+}
+
+proc kstim { stim } {
+    puts "KKK: enabling stim: $stim"
+    hack_enable_trace
+
+    # Unlock ITM
+    mww 0xe0000fb0 0xC5ACCE55
+    # use ATB ID #1, tpiu sync, enable ITM (ITM_TCR)
+    mww 0xe0000e80 [expr (1<<16) | (1<<2) | (1 << 0)]
+    # We wish to use all stimulus ports in user code (ITM_TPR = 0xf)
+    mww 0xe0000e40 0xf
+    # turn on stim ports of desire (ITM_TER = $stim)
+    mww 0xe0000e00 $stim
+
+
+    # TODO - this should be a parameter? Should setup tap sync bits here
+    # DWT_CTRL = syncbits | cyccnt
+    mmw 0xE0001000 [expr ((2 << 10) | 1)] [expr (3<<10)]
+}
+
+proc rstim { } {
+    # Unlock ITM
+    mww 0xe0000fb0 0xC5ACCE55
+    # Read stimulus (ITM_TER)
+    mdw 0xe0000e00
+}
+
+add_help_text kstim "Enable ITM Trace for given Stimulus ports"
+add_help_text rstim "Read the currently enabled ITM Stimulus ports"
+add_help_text kprof "enable profiling"
+
+

-- 

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to