1 |
2 |
olivier.gi |
#!/usr/bin/wish
|
2 |
|
|
#------------------------------------------------------------------------------
|
3 |
|
|
# Copyright (C) 2001 Authors
|
4 |
|
|
#
|
5 |
|
|
# This source file may be used and distributed without restriction provided
|
6 |
|
|
# that this copyright statement is not removed from the file and that any
|
7 |
|
|
# derivative work contains the original copyright notice and the associated
|
8 |
|
|
# disclaimer.
|
9 |
|
|
#
|
10 |
|
|
# This source file is free software; you can redistribute it and/or modify
|
11 |
|
|
# it under the terms of the GNU Lesser General Public License as published
|
12 |
|
|
# by the Free Software Foundation; either version 2.1 of the License, or
|
13 |
|
|
# (at your option) any later version.
|
14 |
|
|
#
|
15 |
|
|
# This source is distributed in the hope that it will be useful, but WITHOUT
|
16 |
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
17 |
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
18 |
|
|
# License for more details.
|
19 |
|
|
#
|
20 |
|
|
# You should have received a copy of the GNU Lesser General Public License
|
21 |
|
|
# along with this source; if not, write to the Free Software Foundation,
|
22 |
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
23 |
|
|
#
|
24 |
|
|
#------------------------------------------------------------------------------
|
25 |
|
|
#
|
26 |
|
|
# File Name: minidebug.tcl
|
27 |
|
|
#
|
28 |
14 |
olivier.gi |
# Author(s):
|
29 |
|
|
# - Olivier Girard, olgirard@gmail.com
|
30 |
|
|
#
|
31 |
2 |
olivier.gi |
#------------------------------------------------------------------------------
|
32 |
14 |
olivier.gi |
# $Rev: 92 $
|
33 |
|
|
# $LastChangedBy: olivier.girard $
|
34 |
|
|
# $LastChangedDate: 2011-02-20 20:57:46 +0100 (Sun, 20 Feb 2011) $
|
35 |
|
|
#------------------------------------------------------------------------------
|
36 |
2 |
olivier.gi |
|
37 |
|
|
###############################################################################
|
38 |
|
|
# #
|
39 |
|
|
# GLOBAL VARIABLES #
|
40 |
|
|
# #
|
41 |
|
|
###############################################################################
|
42 |
|
|
|
43 |
|
|
global serial_baudrate
|
44 |
|
|
global serial_device
|
45 |
|
|
global serial_status
|
46 |
|
|
global cpu_status
|
47 |
|
|
global reg
|
48 |
|
|
global mem
|
49 |
87 |
olivier.gi |
global sr
|
50 |
|
|
global codeSelect
|
51 |
|
|
global binFileType
|
52 |
2 |
olivier.gi |
|
53 |
|
|
# Initializations
|
54 |
87 |
olivier.gi |
set codeSelect 2
|
55 |
2 |
olivier.gi |
set serial_status 0
|
56 |
|
|
set cpu_status 1
|
57 |
|
|
for {set i 0} {$i<16} {incr i} {
|
58 |
|
|
set reg($i) 0x0000
|
59 |
|
|
set mem(address_$i) [format "0x%04x" [expr 0x0200+$i*2]]
|
60 |
|
|
set mem(data_$i) 0x0000
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
###############################################################################
|
64 |
|
|
# #
|
65 |
|
|
# SOURCE LIBRARIES #
|
66 |
|
|
# #
|
67 |
|
|
###############################################################################
|
68 |
|
|
|
69 |
|
|
# Get library path
|
70 |
|
|
set current_file [info script]
|
71 |
|
|
if {[file type $current_file]=="link"} {
|
72 |
|
|
set current_file [file readlink $current_file]
|
73 |
|
|
}
|
74 |
|
|
set lib_path [file dirname $current_file]/../lib/tcl-lib
|
75 |
|
|
|
76 |
|
|
# Source library
|
77 |
|
|
source $lib_path/dbg_functions.tcl
|
78 |
|
|
source $lib_path/combobox.tcl
|
79 |
|
|
package require combobox 2.3
|
80 |
|
|
catch {namespace import combobox::*}
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
###############################################################################
|
84 |
|
|
# #
|
85 |
|
|
# FUNCTIONS #
|
86 |
|
|
# #
|
87 |
|
|
###############################################################################
|
88 |
|
|
|
89 |
|
|
proc connect_openMSP430 {} {
|
90 |
|
|
global serial_status
|
91 |
|
|
global reg
|
92 |
|
|
global mem
|
93 |
|
|
|
94 |
|
|
set serial_status [GetDevice]
|
95 |
|
|
|
96 |
|
|
if {$serial_status} {
|
97 |
|
|
set sizes [GetCPU_ID_SIZE]
|
98 |
|
|
|
99 |
87 |
olivier.gi |
if {[lindex $sizes 0]==-1 | [lindex $sizes 1]==-1} {
|
100 |
|
|
.ctrl.mem_sz.l3 configure -text "Connection problem" -fg red
|
101 |
|
|
|
102 |
|
|
} else {
|
103 |
|
|
|
104 |
|
|
# Disable connection section
|
105 |
|
|
.ctrl.serial.p1 configure -state disabled
|
106 |
|
|
.ctrl.serial.p2 configure -state disabled
|
107 |
|
|
.ctrl.serial.connect configure -state disabled
|
108 |
|
|
.ctrl.mem_sz.l3 configure -text "Connected" -fg green
|
109 |
92 |
olivier.gi |
.ctrl.mem_sz.l8 configure -text [lindex $sizes 1]
|
110 |
|
|
.ctrl.mem_sz.l5 configure -text [lindex $sizes 0]
|
111 |
87 |
olivier.gi |
|
112 |
|
|
# Activate ELF file section
|
113 |
|
|
.ctrl.load.ft.l configure -state normal
|
114 |
|
|
.ctrl.load.ft.file configure -state normal
|
115 |
|
|
.ctrl.load.ft.browse configure -state normal
|
116 |
|
|
.ctrl.load.fb.read configure -state normal
|
117 |
|
|
.ctrl.load.fb.l configure -state normal
|
118 |
|
|
|
119 |
|
|
# Activate CPU control section
|
120 |
|
|
.ctrl.cpu.l1 configure -state normal
|
121 |
|
|
.ctrl.cpu.reset configure -state normal
|
122 |
|
|
.ctrl.cpu.run configure -state normal
|
123 |
|
|
.ctrl.cpu.l2 configure -state normal
|
124 |
|
|
.ctrl.cpu.l3 configure -state normal
|
125 |
|
|
if {[IsHalted]} {
|
126 |
|
|
.ctrl.cpu.step configure -state normal
|
127 |
|
|
.ctrl.cpu.run configure -text "Run"
|
128 |
|
|
.ctrl.cpu.l3 configure -text "Stopped" -fg yellow
|
129 |
|
|
set cpu_status 0
|
130 |
|
|
} else {
|
131 |
|
|
.ctrl.cpu.step configure -state disabled
|
132 |
|
|
.ctrl.cpu.run configure -text "Stop"
|
133 |
|
|
.ctrl.cpu.l3 configure -text "Running" -fg green
|
134 |
|
|
set cpu_status 1
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
# Activate CPU status register section
|
138 |
|
|
.ctrl.reg_stat.l1 configure -state normal
|
139 |
|
|
.ctrl.reg_stat.v configure -state normal
|
140 |
|
|
.ctrl.reg_stat.scg1 configure -state normal
|
141 |
|
|
.ctrl.reg_stat.oscoff configure -state normal
|
142 |
|
|
.ctrl.reg_stat.cpuoff configure -state normal
|
143 |
|
|
.ctrl.reg_stat.gie configure -state normal
|
144 |
|
|
.ctrl.reg_stat.n configure -state normal
|
145 |
|
|
.ctrl.reg_stat.z configure -state normal
|
146 |
|
|
.ctrl.reg_stat.c configure -state normal
|
147 |
|
|
|
148 |
|
|
# Activate CPU registers and memory section
|
149 |
|
|
.ctrl.reg_mem.reg.title.e configure -state normal
|
150 |
|
|
.ctrl.reg_mem.mem.title.l configure -state normal
|
151 |
|
|
.ctrl.reg_mem.mem.title.e configure -state normal
|
152 |
|
|
.ctrl.reg_mem.reg.refresh configure -state normal
|
153 |
|
|
.ctrl.reg_mem.mem.refresh configure -state normal
|
154 |
|
|
for {set i 0} {$i<16} {incr i} {
|
155 |
|
|
.ctrl.reg_mem.reg.f$i.l$i configure -state normal
|
156 |
|
|
.ctrl.reg_mem.reg.f$i.e$i configure -state normal
|
157 |
|
|
.ctrl.reg_mem.mem.f$i.addr_e$i configure -state normal
|
158 |
|
|
.ctrl.reg_mem.mem.f$i.data_e$i configure -state normal
|
159 |
|
|
}
|
160 |
|
|
refreshReg
|
161 |
|
|
refreshMem
|
162 |
|
|
|
163 |
|
|
# Activate Load TCL script section
|
164 |
|
|
.ctrl.tclscript.ft.l configure -state normal
|
165 |
|
|
.ctrl.tclscript.ft.file configure -state normal
|
166 |
|
|
.ctrl.tclscript.ft.browse configure -state normal
|
167 |
|
|
.ctrl.tclscript.fb.read configure -state normal
|
168 |
|
|
|
169 |
|
|
# Activate the code debugger section
|
170 |
|
|
.code.rb.txt configure -state normal
|
171 |
|
|
.code.rb.none configure -state normal
|
172 |
|
|
.code.rb.asm configure -state normal
|
173 |
|
|
.code.rb.mix configure -state normal
|
174 |
2 |
olivier.gi |
}
|
175 |
|
|
|
176 |
|
|
} else {
|
177 |
87 |
olivier.gi |
.ctrl.mem_sz.l3 configure -text "Connection problem" -fg red
|
178 |
2 |
olivier.gi |
}
|
179 |
|
|
}
|
180 |
|
|
|
181 |
87 |
olivier.gi |
proc highlightLine { line } {
|
182 |
|
|
.code.text tag remove highlight 1.0 end
|
183 |
|
|
.code.text tag add highlight $line.0 [expr $line+1].0
|
184 |
|
|
.code.text see $line.0
|
185 |
2 |
olivier.gi |
|
186 |
87 |
olivier.gi |
}
|
187 |
|
|
|
188 |
|
|
proc highlightPC { pc_val } {
|
189 |
|
|
global codeSelect
|
190 |
|
|
|
191 |
|
|
if {$codeSelect!=1} {
|
192 |
|
|
|
193 |
|
|
regsub {0x} $pc_val {} pc_val
|
194 |
|
|
set code_match [.code.text search "$pc_val:" 1.0 end]
|
195 |
|
|
set code_line 1
|
196 |
|
|
regexp {(\d+).(\d+)} $code_match whole_match code_line code_column
|
197 |
|
|
highlightLine $code_line
|
198 |
|
|
}
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
proc updateCodeView { bin_file_name } {
|
202 |
|
|
global codeSelect
|
203 |
|
|
global reg
|
204 |
|
|
global binFileType
|
205 |
|
|
|
206 |
|
|
set temp_elf_file "[clock clicks].elf"
|
207 |
|
|
if {[catch {exec msp430-objcopy -I $binFileType -O elf32-msp430 $bin_file_name $temp_elf_file} debug_info]} {
|
208 |
|
|
.ctrl.load.fb.l configure -text "$debug_info" -fg red
|
209 |
|
|
return 0
|
210 |
2 |
olivier.gi |
}
|
211 |
87 |
olivier.gi |
if {[string eq $binFileType "ihex"]} {
|
212 |
|
|
set dumpOpt "-D"
|
213 |
|
|
} else {
|
214 |
|
|
set dumpOpt "-d"
|
215 |
|
|
}
|
216 |
|
|
|
217 |
|
|
if {$codeSelect==1} {
|
218 |
|
|
set debug_info ""
|
219 |
|
|
|
220 |
|
|
} elseif {$codeSelect==2} {
|
221 |
|
|
if {[catch {exec msp430-objdump $dumpOpt $temp_elf_file} debug_info]} {
|
222 |
|
|
.ctrl.load.fb.l configure -text "$debug_info" -fg red
|
223 |
|
|
return 0
|
224 |
|
|
}
|
225 |
|
|
} elseif {$codeSelect==3} {
|
226 |
|
|
if {[catch {exec msp430-objdump $dumpOpt\S $temp_elf_file} debug_info]} {
|
227 |
|
|
.ctrl.load.fb.l configure -text "$debug_info" -fg red
|
228 |
|
|
return 0
|
229 |
|
|
}
|
230 |
|
|
}
|
231 |
|
|
file delete $temp_elf_file
|
232 |
|
|
|
233 |
|
|
.code.text configure -state normal
|
234 |
|
|
.code.text delete 1.0 end
|
235 |
|
|
.code.text insert end $debug_info
|
236 |
|
|
highlightPC $reg(0)
|
237 |
|
|
.code.text configure -state disabled
|
238 |
|
|
return 1
|
239 |
2 |
olivier.gi |
}
|
240 |
|
|
|
241 |
87 |
olivier.gi |
proc loadProgram {bin_file_name} {
|
242 |
2 |
olivier.gi |
global cpu_status
|
243 |
|
|
global reg
|
244 |
|
|
global mem
|
245 |
87 |
olivier.gi |
global binFileType
|
246 |
2 |
olivier.gi |
|
247 |
87 |
olivier.gi |
# Detect the file format depending on the fil extention
|
248 |
|
|
#--------------------------------------------------------
|
249 |
|
|
set binFileType [file extension $bin_file_name]
|
250 |
|
|
set binFileType [string tolower $binFileType]
|
251 |
|
|
regsub {\.} $binFileType {} binFileType
|
252 |
|
|
|
253 |
|
|
if {![string eq $binFileType "ihex"] & ![string eq $binFileType "hex"] & ![string eq $binFileType "elf"]} {
|
254 |
|
|
.ctrl.load.fb.l configure -text "[string toupper $binFileType] file format not supported\"" -fg red
|
255 |
|
|
return 0
|
256 |
|
|
}
|
257 |
|
|
|
258 |
|
|
# Check if the file exists
|
259 |
|
|
#----------------------------------------
|
260 |
|
|
if {![file exists $bin_file_name]} {
|
261 |
|
|
.ctrl.load.fb.l configure -text "[string toupper $binFileType] file doesn't exists: \"$bin_file_name\"" -fg red
|
262 |
|
|
return 0
|
263 |
|
|
}
|
264 |
|
|
if {[string eq $binFileType "hex"]} {
|
265 |
|
|
set binFileType "ihex"
|
266 |
|
|
}
|
267 |
|
|
if {[string eq $binFileType "elf"]} {
|
268 |
|
|
set binFileType "elf32-msp430"
|
269 |
|
|
}
|
270 |
|
|
|
271 |
|
|
|
272 |
|
|
# Create and read debug informations
|
273 |
|
|
#----------------------------------------
|
274 |
|
|
|
275 |
|
|
updateCodeView $bin_file_name
|
276 |
|
|
|
277 |
2 |
olivier.gi |
# Create and read binary executable file
|
278 |
|
|
#----------------------------------------
|
279 |
|
|
|
280 |
|
|
# Generate binary file
|
281 |
|
|
set bin_file "[clock clicks].bin"
|
282 |
87 |
olivier.gi |
if {[catch {exec msp430-objcopy -I $binFileType -O binary $bin_file_name $bin_file} errMsg]} {
|
283 |
|
|
.ctrl.load.fb.l configure -text "$errMsg" -fg red
|
284 |
77 |
olivier.gi |
return 0
|
285 |
|
|
}
|
286 |
|
|
|
287 |
|
|
# Wait until bin file is present on the filesystem
|
288 |
|
|
set timeout 100
|
289 |
|
|
for {set i 0} {$i <= $timeout} {incr i} {
|
290 |
|
|
after 500
|
291 |
|
|
if {[file exists $bin_file]} {
|
292 |
|
|
break
|
293 |
|
|
}
|
294 |
|
|
}
|
295 |
|
|
if {$i>=$timeout} {
|
296 |
87 |
olivier.gi |
.ctrl.load.fb.l configure -text "Timeout: ELF to BIN file conversion problem with \"msp430-objcopy\" executable" -fg red
|
297 |
77 |
olivier.gi |
return 0
|
298 |
|
|
}
|
299 |
2 |
olivier.gi |
|
300 |
|
|
# Read file
|
301 |
|
|
set fp [open $bin_file r]
|
302 |
|
|
fconfigure $fp -translation binary
|
303 |
|
|
binary scan [read $fp] H* hex_data yop
|
304 |
|
|
close $fp
|
305 |
|
|
|
306 |
|
|
# Cleanup
|
307 |
|
|
file delete $bin_file
|
308 |
|
|
|
309 |
|
|
# Get program size
|
310 |
|
|
set hex_size [string length $hex_data]
|
311 |
|
|
set byte_size [expr $hex_size/2]
|
312 |
|
|
set word_size [expr $byte_size/2]
|
313 |
|
|
|
314 |
77 |
olivier.gi |
# Make sure ELF program size is the same as the available program memory
|
315 |
|
|
set sizes [GetCPU_ID_SIZE]
|
316 |
|
|
if {[lindex $sizes 0] != [expr $hex_size/2]} {
|
317 |
87 |
olivier.gi |
.ctrl.load.fb.l configure -text "ERROR: ELF program size ([expr $hex_size/2] B) is different than the available program memory ([lindex $sizes 0] B)" -fg red
|
318 |
77 |
olivier.gi |
return 0
|
319 |
|
|
}
|
320 |
|
|
|
321 |
2 |
olivier.gi |
# Format data
|
322 |
|
|
for {set i 0} {$i < $hex_size} {set i [expr $i+4]} {
|
323 |
|
|
set hex_msb "[string index $hex_data [expr $i+2]][string index $hex_data [expr $i+3]]"
|
324 |
|
|
set hex_lsb "[string index $hex_data [expr $i+0]][string index $hex_data [expr $i+1]]"
|
325 |
|
|
lappend DataArray "0x$hex_msb$hex_lsb"
|
326 |
|
|
}
|
327 |
|
|
|
328 |
|
|
# Load program to openmsp430 target
|
329 |
|
|
#-----------------------------------
|
330 |
|
|
|
331 |
|
|
# Reset & Stop CPU
|
332 |
|
|
ExecutePOR_Halt
|
333 |
|
|
|
334 |
35 |
olivier.gi |
# Load Program Memory
|
335 |
2 |
olivier.gi |
set StartAddr [format "0x%04x" [expr 0x10000-$byte_size]]
|
336 |
87 |
olivier.gi |
.ctrl.load.fb.l configure -text "Load..." -fg yellow
|
337 |
2 |
olivier.gi |
update
|
338 |
|
|
WriteMemQuick $StartAddr $DataArray
|
339 |
|
|
|
340 |
|
|
# Check Data
|
341 |
87 |
olivier.gi |
.ctrl.load.fb.l configure -text "Verify..." -fg yellow
|
342 |
2 |
olivier.gi |
update
|
343 |
77 |
olivier.gi |
if {[VerifyMem $StartAddr $DataArray 1]} {
|
344 |
87 |
olivier.gi |
.ctrl.load.fb.l configure -text "Done" -fg green
|
345 |
2 |
olivier.gi |
} else {
|
346 |
87 |
olivier.gi |
.ctrl.load.fb.l configure -text "ERROR" -fg red
|
347 |
2 |
olivier.gi |
}
|
348 |
|
|
update
|
349 |
|
|
|
350 |
87 |
olivier.gi |
# Reset & Stop CPU
|
351 |
|
|
ExecutePOR_Halt
|
352 |
|
|
.ctrl.cpu.step configure -state normal
|
353 |
|
|
.ctrl.cpu.run configure -text "Run"
|
354 |
|
|
.ctrl.cpu.l3 configure -text "Stopped" -fg yellow
|
355 |
|
|
set cpu_status 0
|
356 |
2 |
olivier.gi |
refreshReg
|
357 |
|
|
refreshMem
|
358 |
|
|
}
|
359 |
|
|
|
360 |
|
|
proc runCPU {} {
|
361 |
|
|
global cpu_status
|
362 |
|
|
global reg
|
363 |
|
|
global mem
|
364 |
|
|
|
365 |
|
|
if {$cpu_status} {
|
366 |
|
|
HaltCPU
|
367 |
87 |
olivier.gi |
.ctrl.cpu.step configure -state normal
|
368 |
|
|
.ctrl.cpu.run configure -text "Run"
|
369 |
|
|
.ctrl.cpu.l3 configure -text "Stopped" -fg yellow
|
370 |
2 |
olivier.gi |
set cpu_status 0
|
371 |
|
|
} else {
|
372 |
|
|
ReleaseCPU
|
373 |
87 |
olivier.gi |
.ctrl.cpu.step configure -state disabled
|
374 |
|
|
.ctrl.cpu.run configure -text "Stop"
|
375 |
|
|
.ctrl.cpu.l3 configure -text "Running" -fg green
|
376 |
2 |
olivier.gi |
set cpu_status 1
|
377 |
|
|
}
|
378 |
|
|
refreshReg
|
379 |
|
|
refreshMem
|
380 |
|
|
}
|
381 |
|
|
|
382 |
|
|
proc resetCPU {} {
|
383 |
|
|
global cpu_status
|
384 |
|
|
global reg
|
385 |
|
|
global mem
|
386 |
|
|
|
387 |
|
|
if {$cpu_status} {
|
388 |
|
|
ExecutePOR
|
389 |
|
|
} else {
|
390 |
|
|
ExecutePOR_Halt
|
391 |
|
|
}
|
392 |
|
|
refreshReg
|
393 |
|
|
refreshMem
|
394 |
|
|
}
|
395 |
|
|
|
396 |
87 |
olivier.gi |
proc singleStepCPU {} {
|
397 |
|
|
global cpu_status
|
398 |
|
|
global reg
|
399 |
|
|
global mem
|
400 |
|
|
|
401 |
|
|
if {$cpu_status==0} {
|
402 |
|
|
StepCPU
|
403 |
|
|
}
|
404 |
|
|
refreshReg
|
405 |
|
|
refreshMem
|
406 |
|
|
}
|
407 |
|
|
|
408 |
|
|
proc statRegUpdate {} {
|
409 |
|
|
global cpu_status
|
410 |
|
|
global reg
|
411 |
|
|
global mem
|
412 |
|
|
global sr
|
413 |
|
|
|
414 |
|
|
set tmp_reg [expr ($sr(v) * 0x0100) | \
|
415 |
|
|
($sr(scg1) * 0x0080) | \
|
416 |
|
|
($sr(oscoff) * 0x0020) | \
|
417 |
|
|
($sr(cpuoff) * 0x0010) | \
|
418 |
|
|
($sr(gie) * 0x0008) | \
|
419 |
|
|
($sr(n) * 0x0004) | \
|
420 |
|
|
($sr(z) * 0x0002) | \
|
421 |
|
|
($sr(c) * 0x0001)]
|
422 |
|
|
|
423 |
|
|
set reg(2) [format "0x%04x" $tmp_reg]
|
424 |
|
|
|
425 |
|
|
write2Reg 2
|
426 |
|
|
}
|
427 |
|
|
|
428 |
|
|
|
429 |
2 |
olivier.gi |
proc refreshReg {} {
|
430 |
|
|
global reg
|
431 |
|
|
global mem
|
432 |
87 |
olivier.gi |
global sr
|
433 |
2 |
olivier.gi |
|
434 |
87 |
olivier.gi |
# Read register values
|
435 |
2 |
olivier.gi |
set new_vals [ReadRegAll]
|
436 |
|
|
for {set i 0} {$i<16} {incr i} {
|
437 |
|
|
set reg($i) [lindex $new_vals $i]
|
438 |
|
|
}
|
439 |
87 |
olivier.gi |
set sr(c) [expr $reg(2) & 0x0001]
|
440 |
|
|
set sr(z) [expr $reg(2) & 0x0002]
|
441 |
|
|
set sr(n) [expr $reg(2) & 0x0004]
|
442 |
|
|
set sr(gie) [expr $reg(2) & 0x0008]
|
443 |
|
|
set sr(cpuoff) [expr $reg(2) & 0x0010]
|
444 |
|
|
set sr(oscoff) [expr $reg(2) & 0x0020]
|
445 |
|
|
set sr(scg1) [expr $reg(2) & 0x0080]
|
446 |
|
|
set sr(v) [expr $reg(2) & 0x0100]
|
447 |
|
|
|
448 |
|
|
# Update highlighted line in the code view
|
449 |
|
|
highlightPC $reg(0)
|
450 |
2 |
olivier.gi |
}
|
451 |
|
|
|
452 |
|
|
proc write2Reg {reg_num} {
|
453 |
|
|
global reg
|
454 |
|
|
global mem
|
455 |
|
|
|
456 |
|
|
WriteReg $reg_num $reg($reg_num)
|
457 |
|
|
refreshReg
|
458 |
|
|
refreshMem
|
459 |
|
|
}
|
460 |
|
|
|
461 |
|
|
proc refreshMem {} {
|
462 |
|
|
global reg
|
463 |
|
|
global mem
|
464 |
|
|
|
465 |
|
|
for {set i 0} {$i<16} {incr i} {
|
466 |
|
|
# Check if address lay in 16 or 8 bit space
|
467 |
|
|
if {[expr $mem(address_$i)]>=[expr 0x100]} {
|
468 |
|
|
set Format 0
|
469 |
|
|
} else {
|
470 |
|
|
set Format 1
|
471 |
|
|
}
|
472 |
|
|
|
473 |
|
|
# Read data
|
474 |
|
|
set mem(data_$i) [ReadMem $Format $mem(address_$i)]
|
475 |
|
|
}
|
476 |
|
|
}
|
477 |
|
|
|
478 |
|
|
proc write2Mem {mem_num} {
|
479 |
|
|
global reg
|
480 |
|
|
global mem
|
481 |
|
|
|
482 |
|
|
# Check if address lay in 16 or 8 bit space
|
483 |
|
|
if {[expr $mem(address_$mem_num)]>=[expr 0x100]} {
|
484 |
|
|
set Format 0
|
485 |
|
|
} else {
|
486 |
|
|
set Format 1
|
487 |
|
|
}
|
488 |
|
|
|
489 |
|
|
WriteMem $Format $mem(address_$mem_num) $mem(data_$mem_num)
|
490 |
|
|
refreshReg
|
491 |
|
|
refreshMem
|
492 |
|
|
}
|
493 |
|
|
|
494 |
|
|
###############################################################################
|
495 |
|
|
# #
|
496 |
|
|
# CREATE GRAPHICAL INTERFACE #
|
497 |
|
|
# #
|
498 |
|
|
###############################################################################
|
499 |
|
|
|
500 |
|
|
####################################
|
501 |
|
|
# CREATE & PLACE MAIN WIDGETS #
|
502 |
|
|
####################################
|
503 |
|
|
|
504 |
87 |
olivier.gi |
wm title . "openMSP430 mini debugger"
|
505 |
|
|
wm iconname . "openMSP430 mini debugger"
|
506 |
2 |
olivier.gi |
|
507 |
87 |
olivier.gi |
# Create the Main Menu
|
508 |
2 |
olivier.gi |
frame .menu
|
509 |
87 |
olivier.gi |
pack .menu -side top -padx 10 -pady 10 -fill x
|
510 |
2 |
olivier.gi |
|
511 |
87 |
olivier.gi |
# Create the CPU Contorl field
|
512 |
|
|
frame .ctrl
|
513 |
|
|
pack .ctrl -side left -padx 10 -pady 10 -fill x
|
514 |
2 |
olivier.gi |
|
515 |
87 |
olivier.gi |
# Create the Code text field
|
516 |
|
|
frame .code
|
517 |
|
|
pack .code -side right -padx 10 -pady 10 -fill both -expand true
|
518 |
|
|
frame .code.rb
|
519 |
|
|
pack .code.rb -side bottom -padx 10 -pady 10 -fill both
|
520 |
|
|
|
521 |
|
|
# Create the Serial Menu
|
522 |
|
|
frame .ctrl.serial
|
523 |
|
|
pack .ctrl.serial -side top -padx 10 -pady {10 0} -fill x
|
524 |
|
|
|
525 |
|
|
# Create the memory size
|
526 |
|
|
frame .ctrl.mem_sz
|
527 |
|
|
pack .ctrl.mem_sz -side top -padx 10 -pady {10 20} -fill x
|
528 |
|
|
|
529 |
2 |
olivier.gi |
# Create the Load executable field
|
530 |
87 |
olivier.gi |
frame .ctrl.load
|
531 |
|
|
pack .ctrl.load -side top -padx 10 -pady {10 20} -fill x
|
532 |
2 |
olivier.gi |
|
533 |
|
|
# Create the cpu control field
|
534 |
87 |
olivier.gi |
frame .ctrl.cpu
|
535 |
|
|
pack .ctrl.cpu -side top -padx 10 -pady {10 20} -fill x
|
536 |
2 |
olivier.gi |
|
537 |
87 |
olivier.gi |
# Create the cpu status field
|
538 |
|
|
frame .ctrl.reg_stat
|
539 |
|
|
pack .ctrl.reg_stat -side top -padx 10 -pady {10 10} -fill x
|
540 |
|
|
|
541 |
2 |
olivier.gi |
# Create the cpu registers/memory fields
|
542 |
87 |
olivier.gi |
frame .ctrl.reg_mem
|
543 |
|
|
pack .ctrl.reg_mem -side top -padx 10 -pady {5 20} -fill x
|
544 |
|
|
frame .ctrl.reg_mem.reg
|
545 |
|
|
pack .ctrl.reg_mem.reg -side left -padx {10 30} -fill x
|
546 |
|
|
frame .ctrl.reg_mem.mem
|
547 |
|
|
pack .ctrl.reg_mem.mem -side left -padx {30 10} -fill x
|
548 |
2 |
olivier.gi |
|
549 |
87 |
olivier.gi |
# Create the TCL script field
|
550 |
|
|
frame .ctrl.tclscript
|
551 |
|
|
pack .ctrl.tclscript -side top -padx 10 -pady {10 20} -fill x
|
552 |
2 |
olivier.gi |
|
553 |
87 |
olivier.gi |
|
554 |
2 |
olivier.gi |
####################################
|
555 |
87 |
olivier.gi |
# CREATE THE CPU CONTROL SECTION #
|
556 |
2 |
olivier.gi |
####################################
|
557 |
|
|
|
558 |
|
|
# Exit button
|
559 |
87 |
olivier.gi |
button .menu.exit -text "Exit" -command {exit 0}
|
560 |
2 |
olivier.gi |
pack .menu.exit -side left
|
561 |
|
|
|
562 |
|
|
|
563 |
|
|
# Serial Port fields
|
564 |
87 |
olivier.gi |
label .ctrl.serial.l1 -text "Serial Port:" -anchor w
|
565 |
|
|
pack .ctrl.serial.l1 -side left
|
566 |
2 |
olivier.gi |
set serial_device [lindex [dbg_list_uart] end]
|
567 |
87 |
olivier.gi |
combobox .ctrl.serial.p1 -textvariable serial_device -editable true
|
568 |
|
|
eval .ctrl.serial.p1 list insert end [dbg_list_uart]
|
569 |
|
|
pack .ctrl.serial.p1 -side left -padx 5
|
570 |
2 |
olivier.gi |
|
571 |
87 |
olivier.gi |
label .ctrl.serial.l2 -text " Baudrate:" -anchor w
|
572 |
|
|
pack .ctrl.serial.l2 -side left
|
573 |
2 |
olivier.gi |
set serial_baudrate 115200
|
574 |
87 |
olivier.gi |
combobox .ctrl.serial.p2 -textvariable serial_baudrate -editable true
|
575 |
|
|
eval .ctrl.serial.p2 list insert end [list 9600 19200 38400 57600 115200 \
|
576 |
|
|
230400 460800 500000 576000 921600 \
|
577 |
|
|
1000000 1152000]
|
578 |
|
|
pack .ctrl.serial.p2 -side left -padx 5
|
579 |
2 |
olivier.gi |
|
580 |
87 |
olivier.gi |
button .ctrl.serial.connect -text "Connect" -command {connect_openMSP430}
|
581 |
|
|
pack .ctrl.serial.connect -side left -padx 10
|
582 |
2 |
olivier.gi |
|
583 |
87 |
olivier.gi |
# Memory size status
|
584 |
|
|
label .ctrl.mem_sz.l2 -text "CPU Info:" -anchor w
|
585 |
|
|
pack .ctrl.mem_sz.l2 -side left -padx "0 10"
|
586 |
|
|
label .ctrl.mem_sz.l3 -text "Disconnected" -anchor w -fg Red
|
587 |
|
|
pack .ctrl.mem_sz.l3 -side left -padx "0 30"
|
588 |
|
|
label .ctrl.mem_sz.l4 -text "Program Memory size:" -anchor w
|
589 |
|
|
pack .ctrl.mem_sz.l4 -side left
|
590 |
|
|
label .ctrl.mem_sz.l5 -text "--" -anchor w
|
591 |
|
|
pack .ctrl.mem_sz.l5 -side left
|
592 |
|
|
label .ctrl.mem_sz.l6 -text "B" -anchor w
|
593 |
|
|
pack .ctrl.mem_sz.l6 -side left -padx "0 30"
|
594 |
|
|
label .ctrl.mem_sz.l7 -text "Data Memory size:" -anchor w
|
595 |
|
|
pack .ctrl.mem_sz.l7 -side left
|
596 |
|
|
label .ctrl.mem_sz.l8 -text "--" -anchor w
|
597 |
|
|
pack .ctrl.mem_sz.l8 -side left
|
598 |
|
|
label .ctrl.mem_sz.l9 -text "B" -anchor w
|
599 |
|
|
pack .ctrl.mem_sz.l9 -side left
|
600 |
2 |
olivier.gi |
|
601 |
|
|
# Load ELF file fields
|
602 |
87 |
olivier.gi |
frame .ctrl.load.ft
|
603 |
|
|
pack .ctrl.load.ft -side top -fill x
|
604 |
|
|
label .ctrl.load.ft.l -text "ELF file:" -state disabled
|
605 |
|
|
pack .ctrl.load.ft.l -side left -padx "0 10"
|
606 |
|
|
entry .ctrl.load.ft.file -width 58 -relief sunken -textvariable bin_file_name -state disabled
|
607 |
|
|
pack .ctrl.load.ft.file -side left -padx 10
|
608 |
|
|
button .ctrl.load.ft.browse -text "Browse" -state disabled -command {set bin_file_name [tk_getOpenFile -filetypes {{{ELF/Intel-Hex Files} {.elf .ihex .hex}} {{All Files} *}}]}
|
609 |
|
|
pack .ctrl.load.ft.browse -side left -padx 5
|
610 |
|
|
frame .ctrl.load.fb
|
611 |
|
|
pack .ctrl.load.fb -side top -fill x
|
612 |
|
|
button .ctrl.load.fb.read -text "Load ELF File !" -state disabled -command {loadProgram $bin_file_name}
|
613 |
|
|
pack .ctrl.load.fb.read -side left -padx 5 -fill x
|
614 |
|
|
label .ctrl.load.fb.l -text "Not loaded" -anchor w -fg Red -state disabled
|
615 |
|
|
pack .ctrl.load.fb.l -side left
|
616 |
2 |
olivier.gi |
|
617 |
|
|
# CPU Control
|
618 |
87 |
olivier.gi |
label .ctrl.cpu.l1 -text "CPU Control:" -anchor w -state disabled
|
619 |
|
|
pack .ctrl.cpu.l1 -side left
|
620 |
|
|
button .ctrl.cpu.reset -text "Reset" -state disabled -command {resetCPU}
|
621 |
|
|
pack .ctrl.cpu.reset -side left -padx 5 -fill x
|
622 |
|
|
button .ctrl.cpu.run -text "Stop" -state disabled -command {runCPU}
|
623 |
|
|
pack .ctrl.cpu.run -side left -padx 5 -fill x
|
624 |
|
|
button .ctrl.cpu.step -text "Step" -state disabled -command {singleStepCPU}
|
625 |
|
|
pack .ctrl.cpu.step -side left -padx 5 -fill x
|
626 |
|
|
label .ctrl.cpu.l2 -text "CPU Status:" -anchor w -state disabled
|
627 |
|
|
pack .ctrl.cpu.l2 -side left -padx "40 0"
|
628 |
|
|
label .ctrl.cpu.l3 -text "--" -anchor w -state disabled
|
629 |
|
|
pack .ctrl.cpu.l3 -side left
|
630 |
2 |
olivier.gi |
|
631 |
87 |
olivier.gi |
# CPU Status register
|
632 |
|
|
label .ctrl.reg_stat.l1 -text "Status register (r2/sr):" -anchor w -state disabled
|
633 |
|
|
pack .ctrl.reg_stat.l1 -side left
|
634 |
|
|
checkbutton .ctrl.reg_stat.v -variable sr(v) -state disabled -command "statRegUpdate" -text "V"
|
635 |
|
|
pack .ctrl.reg_stat.v -side left -padx "0"
|
636 |
|
|
checkbutton .ctrl.reg_stat.scg1 -variable sr(scg1) -state disabled -command "statRegUpdate" -text "SCG1"
|
637 |
|
|
pack .ctrl.reg_stat.scg1 -side left -padx "0"
|
638 |
|
|
checkbutton .ctrl.reg_stat.oscoff -variable sr(oscoff) -state disabled -command "statRegUpdate" -text "OSCOFF"
|
639 |
|
|
pack .ctrl.reg_stat.oscoff -side left -padx "0"
|
640 |
|
|
checkbutton .ctrl.reg_stat.cpuoff -variable sr(cpuoff) -state disabled -command "statRegUpdate" -text "CPUOFF"
|
641 |
|
|
pack .ctrl.reg_stat.cpuoff -side left -padx "0"
|
642 |
|
|
checkbutton .ctrl.reg_stat.gie -variable sr(gie) -state disabled -command "statRegUpdate" -text "GIE"
|
643 |
|
|
pack .ctrl.reg_stat.gie -side left -padx "0"
|
644 |
|
|
checkbutton .ctrl.reg_stat.n -variable sr(n) -state disabled -command "statRegUpdate" -text "N"
|
645 |
|
|
pack .ctrl.reg_stat.n -side left -padx "0"
|
646 |
|
|
checkbutton .ctrl.reg_stat.z -variable sr(z) -state disabled -command "statRegUpdate" -text "Z"
|
647 |
|
|
pack .ctrl.reg_stat.z -side left -padx "0"
|
648 |
|
|
checkbutton .ctrl.reg_stat.c -variable sr(c) -state disabled -command "statRegUpdate" -text "C"
|
649 |
|
|
pack .ctrl.reg_stat.c -side left -padx "0"
|
650 |
2 |
olivier.gi |
|
651 |
|
|
# CPU Registers
|
652 |
87 |
olivier.gi |
frame .ctrl.reg_mem.reg.title
|
653 |
|
|
pack .ctrl.reg_mem.reg.title -side top
|
654 |
|
|
label .ctrl.reg_mem.reg.title.l -text " " -width 8 -anchor w
|
655 |
|
|
pack .ctrl.reg_mem.reg.title.l -side left
|
656 |
|
|
label .ctrl.reg_mem.reg.title.e -text "Registers" -anchor w -state disabled
|
657 |
|
|
pack .ctrl.reg_mem.reg.title.e -side left
|
658 |
2 |
olivier.gi |
for {set i 0} {$i<16} {incr i} {
|
659 |
|
|
switch $i {
|
660 |
|
|
{0} {set reg_label "r0 (pc):"}
|
661 |
|
|
{1} {set reg_label "r1 (sp):"}
|
662 |
|
|
{2} {set reg_label "r2 (sr):"}
|
663 |
|
|
default {set reg_label "r$i:"}
|
664 |
|
|
}
|
665 |
87 |
olivier.gi |
frame .ctrl.reg_mem.reg.f$i
|
666 |
|
|
pack .ctrl.reg_mem.reg.f$i -side top
|
667 |
|
|
label .ctrl.reg_mem.reg.f$i.l$i -text $reg_label -width 8 -anchor w -state disabled
|
668 |
|
|
pack .ctrl.reg_mem.reg.f$i.l$i -side left
|
669 |
|
|
entry .ctrl.reg_mem.reg.f$i.e$i -textvariable reg($i) -relief sunken -state disabled
|
670 |
|
|
pack .ctrl.reg_mem.reg.f$i.e$i -side left
|
671 |
|
|
bind .ctrl.reg_mem.reg.f$i.e$i <Return> "write2Reg $i"
|
672 |
2 |
olivier.gi |
}
|
673 |
87 |
olivier.gi |
button .ctrl.reg_mem.reg.refresh -text "Refresh Registers" -state disabled -command {refreshReg}
|
674 |
|
|
pack .ctrl.reg_mem.reg.refresh -side top -padx 5 -pady 10 -fill x -expand true
|
675 |
2 |
olivier.gi |
|
676 |
87 |
olivier.gi |
|
677 |
2 |
olivier.gi |
# CPU Memory
|
678 |
87 |
olivier.gi |
frame .ctrl.reg_mem.mem.title
|
679 |
|
|
pack .ctrl.reg_mem.mem.title -side top
|
680 |
|
|
label .ctrl.reg_mem.mem.title.l -text " Address " -anchor w -width 20 -state disabled
|
681 |
|
|
pack .ctrl.reg_mem.mem.title.l -side left -fill x -expand true
|
682 |
|
|
label .ctrl.reg_mem.mem.title.e -text " Data " -anchor w -width 20 -state disabled
|
683 |
|
|
pack .ctrl.reg_mem.mem.title.e -side left -fill x -expand true
|
684 |
|
|
for {set i 0} {$i<16} {incr i} {
|
685 |
|
|
frame .ctrl.reg_mem.mem.f$i
|
686 |
|
|
pack .ctrl.reg_mem.mem.f$i -side top
|
687 |
2 |
olivier.gi |
|
688 |
87 |
olivier.gi |
entry .ctrl.reg_mem.mem.f$i.addr_e$i -textvariable mem(address_$i) -relief sunken -state disabled -width 20
|
689 |
|
|
pack .ctrl.reg_mem.mem.f$i.addr_e$i -side left
|
690 |
|
|
bind .ctrl.reg_mem.mem.f$i.addr_e$i <Return> "refreshMem"
|
691 |
|
|
entry .ctrl.reg_mem.mem.f$i.data_e$i -textvariable mem(data_$i) -relief sunken -state disabled -width 20
|
692 |
|
|
pack .ctrl.reg_mem.mem.f$i.data_e$i -side left
|
693 |
|
|
bind .ctrl.reg_mem.mem.f$i.data_e$i <Return> "write2Mem $i"
|
694 |
|
|
}
|
695 |
|
|
button .ctrl.reg_mem.mem.refresh -text "Refresh Memory" -state disabled -command {refreshMem}
|
696 |
|
|
pack .ctrl.reg_mem.mem.refresh -side top -padx 5 -pady 10 -fill x -expand true
|
697 |
|
|
|
698 |
|
|
|
699 |
|
|
# Load TCL script fields
|
700 |
|
|
frame .ctrl.tclscript.ft
|
701 |
|
|
pack .ctrl.tclscript.ft -side top -fill x
|
702 |
|
|
label .ctrl.tclscript.ft.l -text "TCL script:" -state disabled
|
703 |
|
|
pack .ctrl.tclscript.ft.l -side left -padx "0 10"
|
704 |
|
|
entry .ctrl.tclscript.ft.file -width 58 -relief sunken -textvariable tcl_file_name -state disabled
|
705 |
|
|
pack .ctrl.tclscript.ft.file -side left -padx 10
|
706 |
|
|
button .ctrl.tclscript.ft.browse -text "Browse" -state disabled -command {set tcl_file_name [tk_getOpenFile -filetypes {{{TCL Files} {.tcl}} {{All Files} *}}]}
|
707 |
|
|
pack .ctrl.tclscript.ft.browse -side left -padx 5
|
708 |
|
|
frame .ctrl.tclscript.fb
|
709 |
|
|
pack .ctrl.tclscript.fb -side top -fill x
|
710 |
|
|
button .ctrl.tclscript.fb.read -text "Source TCL script !" -state disabled -command {if {[file exists $tcl_file_name]} {source $tcl_file_name}}
|
711 |
|
|
pack .ctrl.tclscript.fb.read -side left -padx 5 -fill x
|
712 |
|
|
|
713 |
|
|
|
714 |
|
|
####################################
|
715 |
|
|
# CREATE THE CODE SECTION #
|
716 |
|
|
####################################
|
717 |
|
|
|
718 |
|
|
label .code.rb.txt -text "Code View:" -anchor w -state disabled
|
719 |
|
|
pack .code.rb.txt -side left
|
720 |
|
|
radiobutton .code.rb.none -value "1" -text "None" -state disabled -variable codeSelect -command { updateCodeView $bin_file_name }
|
721 |
|
|
pack .code.rb.none -side left
|
722 |
|
|
radiobutton .code.rb.asm -value "2" -text "Assembler" -state disabled -variable codeSelect -command { updateCodeView $bin_file_name }
|
723 |
|
|
pack .code.rb.asm -side left
|
724 |
|
|
radiobutton .code.rb.mix -value "3" -text "C & Assembler" -state disabled -variable codeSelect -command { updateCodeView $bin_file_name }
|
725 |
|
|
pack .code.rb.mix -side left
|
726 |
|
|
|
727 |
|
|
|
728 |
|
|
scrollbar .code.xscroll -orient horizontal -command {.code.text xview}
|
729 |
|
|
pack .code.xscroll -side bottom -fill both
|
730 |
|
|
|
731 |
|
|
scrollbar .code.yscroll -orient vertical -command {.code.text yview}
|
732 |
|
|
pack .code.yscroll -side right -fill both
|
733 |
|
|
|
734 |
|
|
text .code.text -width 80 -borderwidth 2 -state disabled -wrap none -setgrid true -font TkFixedFont \
|
735 |
|
|
-xscrollcommand {.code.xscroll set} -yscrollcommand {.code.yscroll set}
|
736 |
|
|
pack .code.text -side left -fill both -expand true
|
737 |
|
|
|
738 |
|
|
.code.text tag config highlight -background yellow
|