comparison python/stlink.py @ 144:59a9a499e518

Added adi class
author Windel Bouwman
date Sat, 09 Feb 2013 16:05:36 +0100
parents 1cc59ac80950
children c694ec551f34
comparison
equal deleted inserted replaced
143:1cc59ac80950 144:59a9a499e518
1 import struct, time 1 import struct, time
2 from usb import UsbContext, UsbDevice 2 from usb import UsbContext, UsbDevice
3 from devices import Interface, STLinkException, registerInterface 3 from devices import Interface, STLinkException, registerInterface
4 import adi
4 5
5 ST_VID, STLINK2_PID = 0x0483, 0x3748 6 ST_VID, STLINK2_PID = 0x0483, 0x3748
6 7
7 def checkDevice(device): 8 def checkDevice(device):
8 return device.VendorId == ST_VID and device.ProductId == STLINK2_PID 9 return device.VendorId == ST_VID and device.ProductId == STLINK2_PID
170 def halt(self): 171 def halt(self):
171 cmd = bytearray(16) 172 cmd = bytearray(16)
172 cmd[0:2] = DEBUG_COMMAND, DEBUG_FORCEDEBUG 173 cmd[0:2] = DEBUG_COMMAND, DEBUG_FORCEDEBUG
173 self.send_recv(cmd, 2) 174 self.send_recv(cmd, 2)
174 175
176 def traceEnable(self):
177 DEMCR = 0xE000EDFC
178 v = self.read_debug32(DEMCR)
179 v |= (1 << 24)
180 self.write_debug32(DEMCR, v)
181
175 # Helper 1 functions: 182 # Helper 1 functions:
176 def write_debug32(self, address, value): 183 def write_debug32(self, address, value):
177 cmd = bytearray(16) 184 cmd = bytearray(16)
178 cmd[0:2] = DEBUG_COMMAND, JTAG_WRITEDEBUG_32BIT 185 cmd[0:2] = DEBUG_COMMAND, JTAG_WRITEDEBUG_32BIT
179 cmd[2:10] = struct.pack('<II', address, value) 186 cmd[2:10] = struct.pack('<II', address, value)
254 assert sl.read_reg(5) == 0x1332 261 assert sl.read_reg(5) == 0x1332
255 assert sl.read_reg(6) == 0x12345 262 assert sl.read_reg(6) == 0x12345
256 regs = sl.read_all_regs() 263 regs = sl.read_all_regs()
257 for i in range(len(regs)): 264 for i in range(len(regs)):
258 print('R{0}=0x{1:X}'.format(i, regs[i])) 265 print('R{0}=0x{1:X}'.format(i, regs[i]))
266
267 # Test CoreSight registers:
268 idr4 = sl.read_debug32(0xE0041fd0)
269 print('idr4 =', idr4)
270
271 print('== ADI ==')
272 a = adi.Adi(sl)
273 a.parseRomTable(0xE00FF000) # why is rom table at 0xE00FF000?
274 print('== ADI ==')
275
276 # Detect ROM table:
277 id4 = sl.read_debug32(0xE00FFFD0)
278 id5 = sl.read_debug32(0xE00FFFD4)
279 id6 = sl.read_debug32(0xE00FFFD8)
280 id7 = sl.read_debug32(0xE00FFFDC)
281 id0 = sl.read_debug32(0xE00FFFE0)
282 id1 = sl.read_debug32(0xE00FFFE4)
283 id2 = sl.read_debug32(0xE00FFFE8)
284 id3 = sl.read_debug32(0xE00FFFEC)
285 pIDs = [id0, id1, id2, id3, id4, id5, id6, id7]
286 print(pIDs)
287
288 print('reading from 0xE00FF000')
289 scs = sl.read_debug32(0xE00FF000)
290 print('scs {0:08X}'.format(scs))
291 dwt = sl.read_debug32(0xE00FF004)
292 print('dwt {0:08X}'.format(dwt))
293 fpb = sl.read_debug32(0xE00FF008)
294 print('fpb {0:08X}'.format(fpb))
295 itm = sl.read_debug32(0xE00FF00C)
296 print('itm {0:08X}'.format(itm))
297 tpiu = sl.read_debug32(0xE00FF010)
298 print('tpiu {0:08X}'.format(tpiu))
299 etm = sl.read_debug32(0xE00FF014)
300 print('etm {0:08X}'.format(etm))
301 assert sl.read_debug32(0xE00FF018) == 0x0 # end marker
302
303 devid = sl.read_debug32(0xE0040FC8)
304 print('TPIU_DEVID: {0:X}'.format(devid))
305 devtype = sl.read_debug32(0xE0040FCC)
306 print('TPIU_TYPEID: {0:X}'.format(devtype))
259 307
260 sl.exitDebugMode() 308 sl.exitDebugMode()
261 print('mode at end:', sl.CurrentModeString) 309 print('mode at end:', sl.CurrentModeString)
262 310
263 sl.close() 311 sl.close()