This is an automated email from Gerrit.

Marc Schink ([email protected]) just uploaded a new patch set to Gerrit, which you 
can find at http://openocd.zylin.com/5353

-- gerrit

commit c1b92837f59d4e8b31ec692beb864bf5f0392a17
Author: Marc Schink <[email protected]>
Date:   Thu Nov 28 18:00:11 2019 +0100

    tcl/tools: Add function to measure the speed of ARM Cortex-M devices
    
    Tested on a EFM32PG12 Starter Kit.
    
    Change-Id: I2cbc36fe0d2ad2089bf8c1e7d2260daaae4ddbb4
    Signed-off-by: Marc Schink <[email protected]>

diff --git a/tcl/tools/test_cpu_speed.tcl b/tcl/tools/test_cpu_speed.tcl
new file mode 100644
index 0000000..5c02eb8
--- /dev/null
+++ b/tcl/tools/test_cpu_speed.tcl
@@ -0,0 +1,34 @@
+# Description:
+#  Measure the CPU clock frequency of an ARM Cortex-M based device.
+#
+# Return:
+#  The CPU clock frequency in Hz.
+#
+# Note:
+#  You may need to adapt the number of cycles for your device.
+#
+proc cortex_m_test_cpu_speed { address { timeout 200 } { cycles_per_loop 4 } } 
{
+       set loop_counter_start 0xffffffff
+
+       halt
+
+       # We place the following code at the given address to measure the
+       # CPU clock frequency:
+       #
+       # 3801: subs r0, #1
+       # d1fd: bne #-2
+       # e7fe: b #-4
+       array set loop_code {0 0xd1fd3801 1 0x0000e7fe}
+       array2mem loop_code 32 $address 2
+
+       reg pc $address
+       reg r0 $loop_counter_start
+       resume
+       sleep $timeout
+       halt
+
+       set loop_counter_end [string range [reg r0] 10 end]
+       set loop_counter_diff [expr $loop_counter_start - $loop_counter_end]
+
+       return [expr double($loop_counter_diff) * $cycles_per_loop / $timeout * 
1000 ]
+}

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to