From b13825f45d1b11059bc25d926704e7e53d646c55 Mon Sep 17 00:00:00 2001 From: Enrico Pozzobon Date: Fri, 26 Jul 2019 14:12:06 +0200 Subject: [PATCH] f7 scripts for measuring ram utilization --- templates/f7/ram_pattern.bin | Bin 0 -> 327680 bytes templates/f7/test | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------ test.py | 49 ++++++------------------------------------------- 3 files changed, 78 insertions(+), 55 deletions(-) create mode 100644 templates/f7/ram_pattern.bin diff --git a/templates/f7/ram_pattern.bin b/templates/f7/ram_pattern.bin new file mode 100644 index 0000000..0afb316 Binary files /dev/null and b/templates/f7/ram_pattern.bin differ diff --git a/templates/f7/test b/templates/f7/test index 6c58892..27cada9 100755 --- a/templates/f7/test +++ b/templates/f7/test @@ -8,17 +8,52 @@ import serial import subprocess +RAM_SIZE = 0x50000 def eprint(*args, **kargs): print(*args, file=sys.stderr, **kargs) -def flash(): +def popen_jlink(): pipe = subprocess.PIPE - cmd = ['JLinkExe', 'flash.jlink'] - p = subprocess.Popen(cmd, - stdout=sys.stderr, stdin=pipe) - stdout, stderr = p.communicate("") + cmd = ['JLinkExe'] + cmd.extend(['-autoconnect', '1']) + cmd.extend(['-device', 'STM32F746ZG']) + cmd.extend(['-if', 'swd']) + cmd.extend(['-speed', '4000']) + return subprocess.Popen(cmd, stdout=sys.stderr, stdin=pipe) + + +def flash(): + p = popen_jlink() + return p.communicate((""" +loadbin build/f7.bin 0x8000000 +r +g +exit + """).encode('ascii')) + + +def fill_ram(): + p = popen_jlink() + return p.communicate((""" +h +loadbin ram_pattern.bin 0x20000000 +savebin ram_copy.bin 0x20000000 0x%x +r +g +exit + """ % RAM_SIZE).encode('ascii')) + + +def dump_ram(): + p = popen_jlink() + return p.communicate((""" +h +savebin ram_dump.bin 0x20000000 0x%x +exit + """ % RAM_SIZE).encode('ascii')) + def get_serial(): import serial.tools.list_ports @@ -113,16 +148,10 @@ def main(argv): uartp = UARTP(ser) flash() + fill_ram() eprint("Flashed") time.sleep(0.1) - ser.setDTR(False) # IO0=HIGH - ser.setRTS(True) # EN=LOW, chip in reset - time.sleep(0.1) - ser.setDTR(False) # IO0=HIGH - ser.setRTS(False) # EN=HIGH, chip out of reset - time.sleep(1) - def stdin_read(n): b = sys.stdin.buffer.read(n) if len(b) != n: @@ -176,6 +205,37 @@ def main(argv): raise Exception("Unacknowledged variable transfer") eprint("Operation %c completed successfully" % action) + elif action in b"u": + dump_ram() + with open("ram_copy.bin", 'rb') as dump: + dump_a = dump.read() + with open("ram_dump.bin", 'rb') as dump: + dump_b = dump.read() + + if len(dump_a) != RAM_SIZE or len(dump_b) != RAM_SIZE: + raise Exception("Wrong dump sizes: 0x%x, 0x%x" % (len(dump_a), len(dump_b))) + + streaks = [] + streak_beg = 0 + streak_end = 0 + for i in range(len(dump_a)): + if dump_a[i] == dump_b[i]: + streak_end = i + else: + if streak_end != streak_beg: + streaks.append((streak_beg, streak_end)) + streak_beg = i + streak_end = i + + for b, e in streaks: + eprint("equal bytes from 0x%x to 0x%x (length: %d)" % (b, e, e-b)) + + b, e = max(streaks, key=lambda a: a[1]-a[0]) + eprint("longest equal bytes streak from 0x%x to 0x%x (length: %d)" % (b, e, e-b)) + v = struct.pack(" %s\n" % (' '.join(sys.argv), outfile)) - mdbfile.close() - return 0 - raise Exception("Capture didn't complete successfully") - if __name__ == "__main__": sys.exit(main(sys.argv)) -- libgit2 0.26.0