tcl/tools: Add function to measure the speed of ARM Cortex-M devices 53/5353/11
authorMarc Schink <dev@zapb.de>
Thu, 28 Nov 2019 17:00:11 +0000 (18:00 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 26 Mar 2022 13:22:32 +0000 (13:22 +0000)
Tested on an EFM32PG12 Starter Kit.

Change-Id: I2cbc36fe0d2ad2089bf8c1e7d2260daaae4ddbb4
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/5353
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
tcl/tools/test_cpu_speed.tcl [new file with mode: 0644]

diff --git a/tcl/tools/test_cpu_speed.tcl b/tcl/tools/test_cpu_speed.tcl
new file mode 100644 (file)
index 0000000..cef2bbb
--- /dev/null
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# Description:
+#  Measure the CPU clock frequency of an ARM Cortex-M based device.
+#
+# Return:
+#  The CPU clock frequency in Hz. A negative value indicates that the loop
+#  counter was saturated.
+#
+# Note:
+#  You may need to adapt the number of cycles for your device.
+#
+add_help_text cortex_m_test_cpu_speed "Measure the CPU clock frequency of an ARM Cortex-M based device"
+add_usage_text cortex_m_test_cpu_speed {address [timeout [cycles_per_loop]]}
+proc cortex_m_test_cpu_speed { address { timeout 200 } { cycles_per_loop 4 } } {
+       set loop_counter_start 0xffffffff
+
+       halt
+
+       # Backup registers and memory.
+       set backup_regs [get_reg -force {pc r0 xPSR}]
+       set backup_mem [read_memory $address 16 3]
+
+       # 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
+       write_memory $address 16 {0x3801 0xd1fd 0xe7fe}
+
+       set_reg "pc $address r0 $loop_counter_start"
+       resume
+       sleep $timeout
+       halt
+
+       # Get the loop counter value from register r0.
+       set loop_counter_end [dict values [get_reg r0]]
+       set loop_counter_diff [expr {$loop_counter_start - $loop_counter_end}]
+
+       # Restore registers and memory.
+       set_reg $backup_regs
+       write_memory $address 16 $backup_mem
+
+       if { [expr {$loop_counter_end == 0}] } {
+               return -1
+       }
+
+       return [expr {double($loop_counter_diff) * $cycles_per_loop / $timeout * 1000}]
+}

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)