annotate python/utils/stlink.py @ 302:2ef2247f8dda

Added screenshot application
author Windel Bouwman
date Fri, 06 Dec 2013 12:09:35 +0100
parents 534b94b40aa8
children
rev   line source
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
1 import struct, time
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 128
diff changeset
2 from usb import UsbContext, UsbDevice
128
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents: 124
diff changeset
3 from devices import Interface, STLinkException, registerInterface
144
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
4 import adi
113
1f40be088ee8 Added first start stlink
Windel Bouwman
parents:
diff changeset
5
178
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
6 """
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
7 More or less copied from:
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
8 https://github.com/texane/stlink
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
9 Tracing from:
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
10 https://github.com/obe1line/stlink-trace
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
11
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
12 """
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
13 ST_VID, STLINK2_PID = 0x0483, 0x3748
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
14
113
1f40be088ee8 Added first start stlink
Windel Bouwman
parents:
diff changeset
15 def checkDevice(device):
1f40be088ee8 Added first start stlink
Windel Bouwman
parents:
diff changeset
16 return device.VendorId == ST_VID and device.ProductId == STLINK2_PID
1f40be088ee8 Added first start stlink
Windel Bouwman
parents:
diff changeset
17
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
18 DFU_MODE, MASS_MODE, DEBUG_MODE = 0, 1, 2
117
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
19
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
20 CORE_RUNNING = 0x80
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
21 CORE_HALTED = 0x81
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
22
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
23 # Commands:
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
24 GET_VERSION = 0xf1
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
25 DEBUG_COMMAND = 0xf2
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
26 DFU_COMMAND = 0xf3
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
27 GET_CURRENT_MODE = 0xf5
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
28
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
29 # dfu commands:
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
30 DFU_EXIT = 0x7
113
1f40be088ee8 Added first start stlink
Windel Bouwman
parents:
diff changeset
31
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
32 # debug commands:
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
33 DEBUG_ENTER = 0x20
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
34 DEBUG_EXIT = 0x21
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
35 DEBUG_ENTER_SWD = 0xa3
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
36 DEBUG_GETSTATUS = 0x01
143
1cc59ac80950 Fixed halt button
Windel Bouwman
parents: 138
diff changeset
37 DEBUG_FORCEDEBUG = 0x02
116
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
38 DEBUG_RESETSYS = 0x03
124
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
39 DEBUG_READALLREGS = 0x04
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
40 DEBUG_READREG = 0x5
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
41 DEBUG_WRITEREG = 0x6
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
42 DEBUG_READMEM_32BIT = 0x7
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
43 DEBUG_WRITEMEM_32BIT = 0x8
117
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
44 DEBUG_RUNCORE = 0x9
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
45 DEBUG_STEPCORE = 0xa
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
46
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
47 JTAG_WRITEDEBUG_32BIT = 0x35
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
48 JTAG_READDEBUG_32BIT = 0x36
178
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
49 TRACE_GET_BYTE_COUNT = 0x42
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
50
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
51 # cortex M3
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
52 CM3_REG_CPUID = 0xE000ED00
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
53
128
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents: 124
diff changeset
54 @registerInterface((ST_VID, STLINK2_PID))
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents: 124
diff changeset
55 class STLink2(Interface):
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents: 124
diff changeset
56 """ STlink2 interface implementation. """
119
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
57 def __init__(self, stlink2=None):
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 128
diff changeset
58 self.devHandle = None
119
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
59 if not stlink2:
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
60 context = UsbContext()
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
61 stlink2s = list(filter(checkDevice, context.DeviceList))
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
62 if not stlink2s:
128
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents: 124
diff changeset
63 raise STLinkException('Could not find an ST link 2 interface')
119
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
64 if len(stlink2s) > 1:
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
65 print('More then one stlink2 found, picking first one')
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
66 stlink2 = stlink2s[0]
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 128
diff changeset
67 assert isinstance(stlink2, UsbDevice) # Nifty type checking
124
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
68 assert checkDevice(stlink2)
119
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
69 self.stlink2 = stlink2
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
70 def __del__(self):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
71 if self.IsOpen:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
72 if self.CurrentMode == DEBUG_MODE:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
73 self.exitDebugMode()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
74 self.close()
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 128
diff changeset
75 def __str__(self):
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
76 if self.IsOpen:
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 128
diff changeset
77 return 'STlink2 device version {0}'.format(self.Version)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 128
diff changeset
78 else:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 128
diff changeset
79 return 'STlink2 device'
113
1f40be088ee8 Added first start stlink
Windel Bouwman
parents:
diff changeset
80 def open(self):
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
81 if self.IsOpen:
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 128
diff changeset
82 return
119
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
83 self.devHandle = self.stlink2.open()
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
84 if self.devHandle.Configuration != 1:
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
85 self.devHandle.Configuration = 1
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
86 self.devHandle.claimInterface(0)
116
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
87
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
88 # First initialization:
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
89 if self.CurrentMode == DFU_MODE:
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
90 self.exitDfuMode()
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
91 if self.CurrentMode != DEBUG_MODE:
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
92 self.enterSwdMode()
132
205578c96a79 Moved hexview to seperate class
Windel Bouwman
parents: 130
diff changeset
93 #self.reset()
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
94 def close(self):
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
95 if self.IsOpen:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
96 self.devHandle.close()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
97 self.devHandle = None
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
98 @property
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
99 def IsOpen(self):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
100 return self.devHandle != None
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
101 # modes:
113
1f40be088ee8 Added first start stlink
Windel Bouwman
parents:
diff changeset
102 def getCurrentMode(self):
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
103 cmd = bytearray(16)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
104 cmd[0] = GET_CURRENT_MODE
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
105 reply = self.send_recv(cmd, 2) # Expect 2 bytes back
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
106 return reply[0]
113
1f40be088ee8 Added first start stlink
Windel Bouwman
parents:
diff changeset
107 CurrentMode = property(getCurrentMode)
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
108 @property
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
109 def CurrentModeString(self):
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
110 modes = {DFU_MODE: 'dfu', MASS_MODE: 'massmode', DEBUG_MODE:'debug'}
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
111 return modes[self.CurrentMode]
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
112 def exitDfuMode(self):
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
113 cmd = bytearray(16)
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
114 cmd[0:2] = DFU_COMMAND, DFU_EXIT
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
115 self.send_recv(cmd)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
116 def enterSwdMode(self):
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
117 cmd = bytearray(16)
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
118 cmd[0:3] = DEBUG_COMMAND, DEBUG_ENTER, DEBUG_ENTER_SWD
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
119 self.send_recv(cmd)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
120 def exitDebugMode(self):
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
121 cmd = bytearray(16)
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
122 cmd[0:2] = DEBUG_COMMAND, DEBUG_EXIT
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
123 self.send_recv(cmd)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
124
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
125 def getVersion(self):
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
126 cmd = bytearray(16)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
127 cmd[0] = GET_VERSION
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
128 data = self.send_recv(cmd, 6) # Expect 6 bytes back
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
129 # Parse 6 bytes into various versions:
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
130 b0, b1, b2, b3, b4, b5 = data
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
131 stlink_v = b0 >> 4
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
132 jtag_v = ((b0 & 0xf) << 2) | (b1 >> 6)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
133 swim_v = b1 & 0x3f
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
134 vid = (b3 << 8) | b2
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
135 pid = (b5 << 8) | b4
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
136 return 'stlink={0} jtag={1} swim={2} vid:pid={3:04X}:{4:04X}'.format(\
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
137 stlink_v, jtag_v, swim_v, vid, pid)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
138 Version = property(getVersion)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
139
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
140 @property
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
141 def ChipId(self):
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
142 return self.read_debug32(0xE0042000)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
143 @property
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
144 def CpuId(self):
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
145 u32 = self.read_debug32(CM3_REG_CPUID)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
146 implementer_id = (u32 >> 24) & 0x7f
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
147 variant = (u32 >> 20) & 0xf
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
148 part = (u32 >> 4) & 0xfff
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
149 revision = u32 & 0xf
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
150 return implementer_id, variant, part, revision
117
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
151 def getStatus(self):
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
152 cmd = bytearray(16)
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
153 cmd[0:2] = DEBUG_COMMAND, DEBUG_GETSTATUS
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
154 reply = self.send_recv(cmd, 2)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
155 return reply[0]
117
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
156 Status = property(getStatus)
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
157 @property
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
158 def StatusString(self):
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
159 s = self.Status
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
160 statii = {CORE_RUNNING: 'CORE RUNNING', CORE_HALTED: 'CORE HALTED'}
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
161 if s in statii:
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
162 return statii[s]
132
205578c96a79 Moved hexview to seperate class
Windel Bouwman
parents: 130
diff changeset
163 return 'Unknown status'
117
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
164
116
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
165 def reset(self):
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
166 cmd = bytearray(16)
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
167 cmd[0:2] = DEBUG_COMMAND, DEBUG_RESETSYS
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
168 self.send_recv(cmd, 2)
113
1f40be088ee8 Added first start stlink
Windel Bouwman
parents:
diff changeset
169
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
170 # debug commands:
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
171 def step(self):
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
172 cmd = bytearray(16)
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
173 cmd[0:2] = DEBUG_COMMAND, DEBUG_STEPCORE
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
174 self.send_recv(cmd, 2)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
175 def run(self):
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
176 cmd = bytearray(16)
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
177 cmd[0:2] = DEBUG_COMMAND, DEBUG_RUNCORE
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
178 self.send_recv(cmd, 2)
138
14e739ed03ab Added halt stub
Windel Bouwman
parents: 132
diff changeset
179 def halt(self):
143
1cc59ac80950 Fixed halt button
Windel Bouwman
parents: 138
diff changeset
180 cmd = bytearray(16)
1cc59ac80950 Fixed halt button
Windel Bouwman
parents: 138
diff changeset
181 cmd[0:2] = DEBUG_COMMAND, DEBUG_FORCEDEBUG
1cc59ac80950 Fixed halt button
Windel Bouwman
parents: 138
diff changeset
182 self.send_recv(cmd, 2)
178
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
183
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
184 # Tracing:
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
185 def traceEnable(self):
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
186 self.write_debug32(0xE000EDF0, 0xA05F0003)
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
187
178
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
188 # Enable TRCENA:
144
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
189 DEMCR = 0xE000EDFC
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
190 v = self.read_debug32(DEMCR)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
191 v |= (1 << 24)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
192 self.write_debug32(DEMCR, v)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
193
178
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
194 # ?? Enable write??
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
195 self.write_debug32(0xE0002000, 0x2) #
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
196
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
197 # DBGMCU_CR:
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
198 self.write_debug32(0xE0042004, 0x27) # Enable trace in async mode
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
199
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
200 # TPIU config:
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
201 self.write_debug32(0xE0040004, 0x00000001) # current port size register --> 1 == port size = 1
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
202 self.write_debug32(0xE0040010, 0x23) # random clock divider??
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
203 self.write_debug32(0xE00400F0, 0x2) # selected pin protocol (2 == NRZ)
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
204 self.write_debug32(0xE0040304, 0x100) # continuous formatting
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
205
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
206 # ITM config:
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
207 self.write_debug32(0xE0000FB0, 0xC5ACCE55) # Unlock write access to ITM
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
208 self.write_debug32(0xE0000F80, 0x00010005) # ITM Enable, sync enable, ATB=1
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
209 self.write_debug32(0xE0000E00, 0xFFFFFFFF) # Enable all trace ports in ITM
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
210 self.write_debug32(0xE0000E40, 0x0000000F) # Set privilege mask for all 32 ports.
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
211 def writePort0(self, v32):
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
212 self.write_debug32(0xE0000000, v32)
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
213 def getTraceByteCount(self):
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
214 cmd = bytearray(16)
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
215 cmd[0:2] = DEBUG_COMMAND, 0x42
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
216 reply = self.send_recv(cmd, 2)
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
217 return struct.unpack('<H', reply[0:2])[0]
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
218 def readTraceData(self):
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
219 bsize = self.getTraceByteCount()
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
220 if bsize > 0:
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
221 td = self.recv_ep3(bsize)
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
222 print(td)
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
223 else:
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
224 print('no trace data')
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
225
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
226 # Helper 1 functions:
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
227 def write_debug32(self, address, value):
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
228 cmd = bytearray(16)
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
229 cmd[0:2] = DEBUG_COMMAND, JTAG_WRITEDEBUG_32BIT
119
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
230 cmd[2:10] = struct.pack('<II', address, value)
178
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
231 r = self.send_recv(cmd, 2)
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
232 def read_debug32(self, address):
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
233 cmd = bytearray(16)
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
234 cmd[0:2] = DEBUG_COMMAND, JTAG_READDEBUG_32BIT
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
235 cmd[2:6] = struct.pack('<I', address) # pack into u32 little endian
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
236 reply = self.send_recv(cmd, 8)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
237 return struct.unpack('<I', reply[4:8])[0]
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
238 def write_reg(self, reg, value):
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
239 cmd = bytearray(16)
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
240 cmd[0:3] = DEBUG_COMMAND, DEBUG_WRITEREG, reg
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
241 cmd[3:7] = struct.pack('<I', value)
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
242 r = self.send_recv(cmd, 2)
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
243 def read_reg(self, reg):
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
244 cmd = bytearray(16)
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
245 cmd[0:3] = DEBUG_COMMAND, DEBUG_READREG, reg
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
246 reply = self.send_recv(cmd, 4)
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
247 return struct.unpack('<I', reply)[0]
124
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
248 def read_all_regs(self):
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
249 cmd = bytearray(16)
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
250 cmd[0:2] = DEBUG_COMMAND, DEBUG_READALLREGS
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
251 reply = self.send_recv(cmd, 84)
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
252 fmt = '<' + 'I' * 21 # unpack 21 register values
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
253 return list(struct.unpack(fmt, reply))
116
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
254 def write_mem32(self, address, content):
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
255 assert len(content) % 4 == 0
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
256 cmd = bytearray(16)
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
257 cmd[0:2] = DEBUG_COMMAND, DEBUG_WRITEMEM_32BIT
119
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
258 cmd[2:8] = struct.pack('<IH', address, len(content))
116
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
259 self.send_recv(cmd)
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
260 self.send_recv(content)
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
261 def read_mem32(self, address, length):
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
262 assert length % 4 == 0
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
263 cmd = bytearray(16)
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
264 cmd[0:2] = DEBUG_COMMAND, DEBUG_READMEM_32BIT
119
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
265 cmd[2:8] = struct.pack('<IH', address, length)
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
266 reply = self.send_recv(cmd, length) # expect memory back!
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
267 return reply
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
268
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
269 # Helper 2 functions:
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
270 def send_recv(self, tx, rxsize=0):
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
271 """ Helper function that transmits and receives data in bulk mode. """
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
272 # TODO: we could use here the non-blocking libusb api.
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
273 tx = bytes(tx)
116
90b03bc018cf Added loader code from openocd
Windel Bouwman
parents: 115
diff changeset
274 #assert len(tx) == 16
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
275 self.devHandle.bulkWrite(2, tx) # write to endpoint 2
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
276 if rxsize > 0:
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
277 return self.devHandle.bulkRead(1, rxsize) # read from endpoint 1
178
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
278 def recv_ep3(self, rxsize):
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
279 return self.devHandle.bulkRead(3, rxsize)
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
280
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
281 if __name__ == '__main__':
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
282 # Test program
128
51cc127648e4 Splitup in interface and device
Windel Bouwman
parents: 124
diff changeset
283 sl = STLink2()
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
284 sl.open()
132
205578c96a79 Moved hexview to seperate class
Windel Bouwman
parents: 130
diff changeset
285 sl.reset()
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
286 print('version:', sl.Version)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
287 print('mode before doing anything:', sl.CurrentModeString)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
288 if sl.CurrentMode == DFU_MODE:
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
289 sl.exitDfuMode()
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
290 sl.enterSwdMode()
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
291 print('mode after entering swd mode:', sl.CurrentModeString)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
292
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
293 i = sl.ChipId
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 128
diff changeset
294 print('chip id: 0x{0:X}'.format(i))
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
295 print('cpu: {0}'.format(sl.CpuId))
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
296
117
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
297 print('status: {0}'.format(sl.StatusString))
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
298
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
299 # test registers:
124
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
300 sl.write_reg(0, 0xdeadbeef)
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
301 sl.write_reg(1, 0xcafebabe)
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
302 sl.write_reg(2, 0xc0ffee)
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
303 sl.write_reg(3, 0x1337)
124
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
304 sl.write_reg(5, 0x1332)
117
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
305 sl.write_reg(6, 0x12345)
115
92b2bf0da1ec Added erase and verify
Windel Bouwman
parents: 114
diff changeset
306 assert sl.read_reg(3) == 0x1337
124
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
307 assert sl.read_reg(5) == 0x1332
117
f2b37d78082d Flash write improvements
Windel Bouwman
parents: 116
diff changeset
308 assert sl.read_reg(6) == 0x12345
124
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
309 regs = sl.read_all_regs()
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
310 for i in range(len(regs)):
d38729d35c4d New implementation of hexfile viewer
Windel Bouwman
parents: 123
diff changeset
311 print('R{0}=0x{1:X}'.format(i, regs[i]))
178
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
312
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
313 print('tracing')
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
314 sl.traceEnable()
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
315 sl.run()
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
316 sl.writePort0(0x1337) # For test
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
317 time.sleep(0.1)
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
318 td = sl.readTraceData()
c694ec551f34 Added lex yacc test scripts
Windel Bouwman
parents: 144
diff changeset
319 print('trace data:', td)
144
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
320
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
321 # Test CoreSight registers:
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
322 idr4 = sl.read_debug32(0xE0041fd0)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
323 print('idr4 =', idr4)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
324
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
325 print('== ADI ==')
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
326 a = adi.Adi(sl)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
327 a.parseRomTable(0xE00FF000) # why is rom table at 0xE00FF000?
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
328 print('== ADI ==')
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
329
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
330 # Detect ROM table:
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
331 id4 = sl.read_debug32(0xE00FFFD0)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
332 id5 = sl.read_debug32(0xE00FFFD4)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
333 id6 = sl.read_debug32(0xE00FFFD8)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
334 id7 = sl.read_debug32(0xE00FFFDC)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
335 id0 = sl.read_debug32(0xE00FFFE0)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
336 id1 = sl.read_debug32(0xE00FFFE4)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
337 id2 = sl.read_debug32(0xE00FFFE8)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
338 id3 = sl.read_debug32(0xE00FFFEC)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
339 pIDs = [id0, id1, id2, id3, id4, id5, id6, id7]
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
340 print(pIDs)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
341
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
342 print('reading from 0xE00FF000')
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
343 scs = sl.read_debug32(0xE00FF000)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
344 print('scs {0:08X}'.format(scs))
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
345 dwt = sl.read_debug32(0xE00FF004)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
346 print('dwt {0:08X}'.format(dwt))
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
347 fpb = sl.read_debug32(0xE00FF008)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
348 print('fpb {0:08X}'.format(fpb))
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
349 itm = sl.read_debug32(0xE00FF00C)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
350 print('itm {0:08X}'.format(itm))
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
351 tpiu = sl.read_debug32(0xE00FF010)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
352 print('tpiu {0:08X}'.format(tpiu))
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
353 etm = sl.read_debug32(0xE00FF014)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
354 print('etm {0:08X}'.format(etm))
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
355 assert sl.read_debug32(0xE00FF018) == 0x0 # end marker
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
356
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
357 devid = sl.read_debug32(0xE0040FC8)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
358 print('TPIU_DEVID: {0:X}'.format(devid))
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
359 devtype = sl.read_debug32(0xE0040FCC)
59a9a499e518 Added adi class
Windel Bouwman
parents: 143
diff changeset
360 print('TPIU_TYPEID: {0:X}'.format(devtype))
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
361
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
362 sl.exitDebugMode()
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
363 print('mode at end:', sl.CurrentModeString)
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
364
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
365 sl.close()
119
f51791638cae Simplified flashing
Windel Bouwman
parents: 117
diff changeset
366 print('Test succes!')
114
f42268da614f Connected to stm32f4discovery
Windel Bouwman
parents: 113
diff changeset
367