diff python/stlink.py @ 144:59a9a499e518

Added adi class
author Windel Bouwman
date Sat, 09 Feb 2013 16:05:36 +0100
parents 1cc59ac80950
children c694ec551f34
line wrap: on
line diff
--- a/python/stlink.py	Sun Jan 27 13:18:53 2013 +0100
+++ b/python/stlink.py	Sat Feb 09 16:05:36 2013 +0100
@@ -1,6 +1,7 @@
 import struct, time
 from usb import UsbContext, UsbDevice
 from devices import Interface, STLinkException, registerInterface
+import adi
 
 ST_VID, STLINK2_PID = 0x0483, 0x3748
 
@@ -172,6 +173,12 @@
       cmd[0:2] = DEBUG_COMMAND, DEBUG_FORCEDEBUG
       self.send_recv(cmd, 2)
 
+   def traceEnable(self):
+      DEMCR = 0xE000EDFC
+      v = self.read_debug32(DEMCR)
+      v |= (1 << 24)
+      self.write_debug32(DEMCR, v)
+
    # Helper 1 functions:
    def write_debug32(self, address, value):
       cmd = bytearray(16)
@@ -256,6 +263,47 @@
    regs = sl.read_all_regs()
    for i in range(len(regs)):
       print('R{0}=0x{1:X}'.format(i, regs[i]))
+   
+   # Test CoreSight registers:
+   idr4 = sl.read_debug32(0xE0041fd0)
+   print('idr4 =', idr4)
+
+   print('== ADI ==')
+   a = adi.Adi(sl)
+   a.parseRomTable(0xE00FF000) # why is rom table at 0xE00FF000?
+   print('== ADI ==')
+
+   # Detect ROM table:
+   id4 = sl.read_debug32(0xE00FFFD0)
+   id5 = sl.read_debug32(0xE00FFFD4)
+   id6 = sl.read_debug32(0xE00FFFD8)
+   id7 = sl.read_debug32(0xE00FFFDC)
+   id0 = sl.read_debug32(0xE00FFFE0)
+   id1 = sl.read_debug32(0xE00FFFE4)
+   id2 = sl.read_debug32(0xE00FFFE8)
+   id3 = sl.read_debug32(0xE00FFFEC)
+   pIDs = [id0, id1, id2, id3, id4, id5, id6, id7]
+   print(pIDs)
+
+   print('reading from 0xE00FF000')
+   scs = sl.read_debug32(0xE00FF000)
+   print('scs {0:08X}'.format(scs))
+   dwt = sl.read_debug32(0xE00FF004)
+   print('dwt {0:08X}'.format(dwt))
+   fpb = sl.read_debug32(0xE00FF008)
+   print('fpb {0:08X}'.format(fpb))
+   itm = sl.read_debug32(0xE00FF00C)
+   print('itm {0:08X}'.format(itm))
+   tpiu = sl.read_debug32(0xE00FF010)
+   print('tpiu {0:08X}'.format(tpiu))
+   etm = sl.read_debug32(0xE00FF014)
+   print('etm {0:08X}'.format(etm))
+   assert sl.read_debug32(0xE00FF018) == 0x0 # end marker
+
+   devid = sl.read_debug32(0xE0040FC8)
+   print('TPIU_DEVID: {0:X}'.format(devid))
+   devtype = sl.read_debug32(0xE0040FCC)
+   print('TPIU_TYPEID: {0:X}'.format(devtype))
 
    sl.exitDebugMode()
    print('mode at end:', sl.CurrentModeString)