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 |
|
|
#------------------------------------------------------------------------------
|
29 |
|
|
|
30 |
|
|
###############################################################################
|
31 |
|
|
# #
|
32 |
|
|
# GLOBAL VARIABLES #
|
33 |
|
|
# #
|
34 |
|
|
###############################################################################
|
35 |
|
|
|
36 |
|
|
global serial_baudrate
|
37 |
|
|
global serial_device
|
38 |
|
|
global serial_status
|
39 |
|
|
global cpu_status
|
40 |
|
|
global reg
|
41 |
|
|
global mem
|
42 |
|
|
|
43 |
|
|
# Initializations
|
44 |
|
|
set serial_status 0
|
45 |
|
|
set cpu_status 1
|
46 |
|
|
for {set i 0} {$i<16} {incr i} {
|
47 |
|
|
set reg($i) 0x0000
|
48 |
|
|
set mem(address_$i) [format "0x%04x" [expr 0x0200+$i*2]]
|
49 |
|
|
set mem(data_$i) 0x0000
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
###############################################################################
|
53 |
|
|
# #
|
54 |
|
|
# SOURCE LIBRARIES #
|
55 |
|
|
# #
|
56 |
|
|
###############################################################################
|
57 |
|
|
|
58 |
|
|
# Get library path
|
59 |
|
|
set current_file [info script]
|
60 |
|
|
if {[file type $current_file]=="link"} {
|
61 |
|
|
set current_file [file readlink $current_file]
|
62 |
|
|
}
|
63 |
|
|
set lib_path [file dirname $current_file]/../lib/tcl-lib
|
64 |
|
|
|
65 |
|
|
# Source library
|
66 |
|
|
source $lib_path/dbg_functions.tcl
|
67 |
|
|
source $lib_path/combobox.tcl
|
68 |
|
|
package require combobox 2.3
|
69 |
|
|
catch {namespace import combobox::*}
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
###############################################################################
|
73 |
|
|
# #
|
74 |
|
|
# FUNCTIONS #
|
75 |
|
|
# #
|
76 |
|
|
###############################################################################
|
77 |
|
|
|
78 |
|
|
proc connect_openMSP430 {} {
|
79 |
|
|
global serial_status
|
80 |
|
|
global reg
|
81 |
|
|
global mem
|
82 |
|
|
|
83 |
|
|
set serial_status [GetDevice]
|
84 |
|
|
|
85 |
|
|
if {$serial_status} {
|
86 |
|
|
set sizes [GetCPU_ID_SIZE]
|
87 |
|
|
|
88 |
|
|
.serial.p1 configure -state disabled
|
89 |
|
|
.serial.p2 configure -state disabled
|
90 |
|
|
.serial.connect configure -state disabled
|
91 |
|
|
.serial.l3 configure -text "Connected" -fg green
|
92 |
|
|
.load.ft.file configure -state normal
|
93 |
|
|
.load.ft.browse configure -state normal
|
94 |
|
|
.load.fb.read configure -state normal
|
95 |
|
|
.cpu.reset configure -state normal
|
96 |
|
|
.cpu.run configure -state normal
|
97 |
|
|
.cpu.l7 configure -text [lindex $sizes 0]
|
98 |
|
|
.cpu.l5 configure -text [lindex $sizes 1]
|
99 |
|
|
.reg_mem.reg.cmd.refresh configure -state normal
|
100 |
|
|
.reg_mem.mem.cmd.refresh configure -state normal
|
101 |
|
|
for {set i 0} {$i<16} {incr i} {
|
102 |
|
|
.reg_mem.reg.entries.e$i configure -state normal
|
103 |
|
|
.reg_mem.mem.address.e$i configure -state normal
|
104 |
|
|
.reg_mem.mem.data.e$i configure -state normal
|
105 |
|
|
}
|
106 |
|
|
refreshReg
|
107 |
|
|
refreshMem
|
108 |
|
|
|
109 |
|
|
} else {
|
110 |
|
|
.serial.l3 configure -text "Connection problem" -fg red
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
proc disconnect_openMSP430 {} {
|
115 |
|
|
global serial_status
|
116 |
|
|
|
117 |
|
|
if {$serial_status} {
|
118 |
|
|
ReleaseDevice 0xfffe
|
119 |
|
|
}
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
proc loadProgram {elf_file_name} {
|
123 |
|
|
global cpu_status
|
124 |
|
|
global reg
|
125 |
|
|
global mem
|
126 |
|
|
|
127 |
|
|
# Create and read binary executable file
|
128 |
|
|
#----------------------------------------
|
129 |
|
|
|
130 |
|
|
# Generate binary file
|
131 |
|
|
set bin_file "[clock clicks].bin"
|
132 |
|
|
catch {exec msp430-objcopy -O binary $elf_file_name $bin_file}
|
133 |
|
|
|
134 |
|
|
# Read file
|
135 |
|
|
set fp [open $bin_file r]
|
136 |
|
|
fconfigure $fp -translation binary
|
137 |
|
|
binary scan [read $fp] H* hex_data yop
|
138 |
|
|
close $fp
|
139 |
|
|
|
140 |
|
|
# Cleanup
|
141 |
|
|
file delete $bin_file
|
142 |
|
|
|
143 |
|
|
# Get program size
|
144 |
|
|
set hex_size [string length $hex_data]
|
145 |
|
|
set byte_size [expr $hex_size/2]
|
146 |
|
|
set word_size [expr $byte_size/2]
|
147 |
|
|
|
148 |
|
|
# Format data
|
149 |
|
|
for {set i 0} {$i < $hex_size} {set i [expr $i+4]} {
|
150 |
|
|
set hex_msb "[string index $hex_data [expr $i+2]][string index $hex_data [expr $i+3]]"
|
151 |
|
|
set hex_lsb "[string index $hex_data [expr $i+0]][string index $hex_data [expr $i+1]]"
|
152 |
|
|
lappend DataArray "0x$hex_msb$hex_lsb"
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
# Load program to openmsp430 target
|
156 |
|
|
#-----------------------------------
|
157 |
|
|
|
158 |
|
|
# Reset & Stop CPU
|
159 |
|
|
ExecutePOR_Halt
|
160 |
|
|
|
161 |
|
|
# Load ROM
|
162 |
|
|
set StartAddr [format "0x%04x" [expr 0x10000-$byte_size]]
|
163 |
|
|
.load.fb.l configure -text "Load..." -fg yellow
|
164 |
|
|
update
|
165 |
|
|
WriteMemQuick $StartAddr $DataArray
|
166 |
|
|
|
167 |
|
|
# Check Data
|
168 |
|
|
.load.fb.l configure -text "Verify..." -fg yellow
|
169 |
|
|
update
|
170 |
|
|
if {[VerifyMem $StartAddr $DataArray]} {
|
171 |
|
|
.load.fb.l configure -text "Done" -fg green
|
172 |
|
|
} else {
|
173 |
|
|
.load.fb.l configure -text "ERROR" -fg red
|
174 |
|
|
}
|
175 |
|
|
update
|
176 |
|
|
|
177 |
|
|
# Release device if it was not previously stopped
|
178 |
|
|
if {$cpu_status} {
|
179 |
|
|
ReleaseCPU
|
180 |
|
|
}
|
181 |
|
|
refreshReg
|
182 |
|
|
refreshMem
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
proc runCPU {} {
|
186 |
|
|
global cpu_status
|
187 |
|
|
global reg
|
188 |
|
|
global mem
|
189 |
|
|
|
190 |
|
|
if {$cpu_status} {
|
191 |
|
|
HaltCPU
|
192 |
|
|
.cpu.run configure -text "Run"
|
193 |
|
|
.cpu.l3 configure -text "Stopped" -fg yellow
|
194 |
|
|
set cpu_status 0
|
195 |
|
|
} else {
|
196 |
|
|
ReleaseCPU
|
197 |
|
|
.cpu.run configure -text "Stop"
|
198 |
|
|
.cpu.l3 configure -text "Running" -fg green
|
199 |
|
|
set cpu_status 1
|
200 |
|
|
}
|
201 |
|
|
refreshReg
|
202 |
|
|
refreshMem
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
proc resetCPU {} {
|
206 |
|
|
global cpu_status
|
207 |
|
|
global reg
|
208 |
|
|
global mem
|
209 |
|
|
|
210 |
|
|
if {$cpu_status} {
|
211 |
|
|
ExecutePOR
|
212 |
|
|
} else {
|
213 |
|
|
ExecutePOR_Halt
|
214 |
|
|
}
|
215 |
|
|
refreshReg
|
216 |
|
|
refreshMem
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
proc refreshReg {} {
|
220 |
|
|
global reg
|
221 |
|
|
global mem
|
222 |
|
|
|
223 |
|
|
set new_vals [ReadRegAll]
|
224 |
|
|
for {set i 0} {$i<16} {incr i} {
|
225 |
|
|
set reg($i) [lindex $new_vals $i]
|
226 |
|
|
}
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
proc write2Reg {reg_num} {
|
230 |
|
|
global reg
|
231 |
|
|
global mem
|
232 |
|
|
|
233 |
|
|
WriteReg $reg_num $reg($reg_num)
|
234 |
|
|
refreshReg
|
235 |
|
|
refreshMem
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
proc refreshMem {} {
|
239 |
|
|
global reg
|
240 |
|
|
global mem
|
241 |
|
|
|
242 |
|
|
for {set i 0} {$i<16} {incr i} {
|
243 |
|
|
# Check if address lay in 16 or 8 bit space
|
244 |
|
|
if {[expr $mem(address_$i)]>=[expr 0x100]} {
|
245 |
|
|
set Format 0
|
246 |
|
|
} else {
|
247 |
|
|
set Format 1
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
# Read data
|
251 |
|
|
set mem(data_$i) [ReadMem $Format $mem(address_$i)]
|
252 |
|
|
}
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
proc write2Mem {mem_num} {
|
256 |
|
|
global reg
|
257 |
|
|
global mem
|
258 |
|
|
|
259 |
|
|
# Check if address lay in 16 or 8 bit space
|
260 |
|
|
if {[expr $mem(address_$mem_num)]>=[expr 0x100]} {
|
261 |
|
|
set Format 0
|
262 |
|
|
} else {
|
263 |
|
|
set Format 1
|
264 |
|
|
}
|
265 |
|
|
|
266 |
|
|
WriteMem $Format $mem(address_$mem_num) $mem(data_$mem_num)
|
267 |
|
|
refreshReg
|
268 |
|
|
refreshMem
|
269 |
|
|
}
|
270 |
|
|
|
271 |
|
|
###############################################################################
|
272 |
|
|
# #
|
273 |
|
|
# CREATE GRAPHICAL INTERFACE #
|
274 |
|
|
# #
|
275 |
|
|
###############################################################################
|
276 |
|
|
|
277 |
|
|
####################################
|
278 |
|
|
# CREATE & PLACE MAIN WIDGETS #
|
279 |
|
|
####################################
|
280 |
|
|
|
281 |
|
|
wm title . "openMSP430 mini debuger"
|
282 |
|
|
wm iconname . "openMSP430 mini debuger"
|
283 |
|
|
|
284 |
|
|
# Create the Main Menu budget
|
285 |
|
|
frame .menu
|
286 |
|
|
pack .menu -side top -padx 10 -pady 10 -fill x
|
287 |
|
|
|
288 |
|
|
# Create the Serial Menu budget
|
289 |
|
|
frame .serial
|
290 |
|
|
pack .serial -side top -padx 10 -pady 10 -fill x
|
291 |
|
|
|
292 |
|
|
# Create the Load executable field
|
293 |
|
|
frame .load
|
294 |
|
|
pack .load -side top -padx 10 -pady 10 -fill x
|
295 |
|
|
|
296 |
|
|
# Create the cpu control field
|
297 |
|
|
frame .cpu
|
298 |
|
|
pack .cpu -side top -padx 10 -pady 10 -fill x
|
299 |
|
|
|
300 |
|
|
# Create the cpu registers/memory fields
|
301 |
|
|
frame .reg_mem
|
302 |
|
|
pack .reg_mem -side top -padx 10 -pady 10 -fill x
|
303 |
|
|
frame .reg_mem.reg
|
304 |
|
|
pack .reg_mem.reg -side left -fill x
|
305 |
|
|
frame .reg_mem.mem
|
306 |
|
|
pack .reg_mem.mem -side left -fill x
|
307 |
|
|
|
308 |
|
|
|
309 |
|
|
####################################
|
310 |
|
|
# CREATE THE REST #
|
311 |
|
|
####################################
|
312 |
|
|
|
313 |
|
|
# Exit button
|
314 |
|
|
button .menu.exit -text "Exit" -command {disconnect_openMSP430; exit 0}
|
315 |
|
|
pack .menu.exit -side left
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
# Serial Port fields
|
319 |
|
|
label .serial.l1 -text "Serial Port:" -anchor w
|
320 |
|
|
pack .serial.l1 -side left
|
321 |
|
|
set serial_device [lindex [dbg_list_uart] end]
|
322 |
|
|
combobox .serial.p1 -textvariable serial_device -editable true
|
323 |
|
|
eval .serial.p1 list insert end [dbg_list_uart]
|
324 |
|
|
pack .serial.p1 -side left -padx 5
|
325 |
|
|
|
326 |
|
|
label .serial.l2 -text " Baudrate:" -anchor w
|
327 |
|
|
pack .serial.l2 -side left
|
328 |
|
|
set serial_baudrate 115200
|
329 |
|
|
combobox .serial.p2 -textvariable serial_baudrate -editable true
|
330 |
|
|
eval .serial.p2 list insert end [list 9600 19200 38400 57600 115200 \
|
331 |
|
|
230400 460800 500000 576000 921600 \
|
332 |
|
|
1000000 1152000]
|
333 |
|
|
pack .serial.p2 -side left -padx 5
|
334 |
|
|
|
335 |
|
|
button .serial.connect -text "Connect" -command {connect_openMSP430}
|
336 |
|
|
pack .serial.connect -side left -padx 10
|
337 |
|
|
label .serial.l3 -text "Disconnected" -anchor w -fg Red
|
338 |
|
|
pack .serial.l3 -side left
|
339 |
|
|
|
340 |
|
|
|
341 |
|
|
# Load ELF file fields
|
342 |
|
|
frame .load.ft
|
343 |
|
|
pack .load.ft -side top -fill x
|
344 |
|
|
label .load.ft.l -text "ELF file:"
|
345 |
|
|
pack .load.ft.l -side left -padx 5
|
346 |
|
|
entry .load.ft.file -width 58 -relief sunken -textvariable elf_file_name -state disabled
|
347 |
|
|
pack .load.ft.file -side left -padx 5
|
348 |
|
|
button .load.ft.browse -text "Browse" -state disabled -command {set elf_file_name [tk_getOpenFile]}
|
349 |
|
|
pack .load.ft.browse -side left -padx 5
|
350 |
|
|
frame .load.fb
|
351 |
|
|
pack .load.fb -side top -fill x
|
352 |
|
|
button .load.fb.read -text "Load ELF File !" -state disabled -command {loadProgram $elf_file_name}
|
353 |
|
|
pack .load.fb.read -side left -padx 5 -fill x
|
354 |
|
|
label .load.fb.l -text "Not loaded" -anchor w -fg Red
|
355 |
|
|
pack .load.fb.l -side left
|
356 |
|
|
|
357 |
|
|
|
358 |
|
|
# CPU Control
|
359 |
|
|
label .cpu.l1 -text "Control CPU:" -anchor w
|
360 |
|
|
pack .cpu.l1 -side left
|
361 |
|
|
button .cpu.reset -text "Reset" -state disabled -command {resetCPU}
|
362 |
|
|
pack .cpu.reset -side left -padx 5 -fill x
|
363 |
|
|
button .cpu.run -text "Stop" -state disabled -command {runCPU}
|
364 |
|
|
pack .cpu.run -side left -padx 5 -fill x
|
365 |
|
|
label .cpu.l2 -text "CPU Status:" -anchor w
|
366 |
|
|
pack .cpu.l2 -side left
|
367 |
|
|
label .cpu.l3 -text "Running" -anchor w -fg green
|
368 |
|
|
pack .cpu.l3 -side left
|
369 |
|
|
|
370 |
|
|
label .cpu.l4 -text "B)" -anchor w
|
371 |
|
|
pack .cpu.l4 -side right
|
372 |
|
|
label .cpu.l5 -text "--" -anchor w
|
373 |
|
|
pack .cpu.l5 -side right
|
374 |
|
|
label .cpu.l6 -text "B; RAM size:" -anchor w
|
375 |
|
|
pack .cpu.l6 -side right
|
376 |
|
|
label .cpu.l7 -text "--" -anchor w
|
377 |
|
|
pack .cpu.l7 -side right
|
378 |
|
|
label .cpu.l8 -text "(ROM size:" -anchor w
|
379 |
|
|
pack .cpu.l8 -side right
|
380 |
|
|
|
381 |
|
|
|
382 |
|
|
# CPU Registers
|
383 |
|
|
frame .reg_mem.reg.labels
|
384 |
|
|
pack .reg_mem.reg.labels -side left -fill x
|
385 |
|
|
frame .reg_mem.reg.entries
|
386 |
|
|
pack .reg_mem.reg.entries -side left -fill x
|
387 |
|
|
for {set i 0} {$i<16} {incr i} {
|
388 |
|
|
switch $i {
|
389 |
|
|
{0} {set reg_label "r0 (pc):"}
|
390 |
|
|
{1} {set reg_label "r1 (sp):"}
|
391 |
|
|
{2} {set reg_label "r2 (sr):"}
|
392 |
|
|
default {set reg_label "r$i:"}
|
393 |
|
|
}
|
394 |
|
|
label .reg_mem.reg.labels.l$i -text $reg_label -anchor w
|
395 |
|
|
pack .reg_mem.reg.labels.l$i -side top -padx 5 -pady 1
|
396 |
|
|
entry .reg_mem.reg.entries.e$i -textvariable reg($i) -relief sunken -state disabled
|
397 |
|
|
pack .reg_mem.reg.entries.e$i -side top
|
398 |
|
|
bind .reg_mem.reg.entries.e$i <Return> "write2Reg $i"
|
399 |
|
|
}
|
400 |
|
|
frame .reg_mem.reg.cmd
|
401 |
|
|
pack .reg_mem.reg.cmd -side left -fill x
|
402 |
|
|
button .reg_mem.reg.cmd.refresh -text "Refresh\nRegisters" -state disabled -command {refreshReg}
|
403 |
|
|
pack .reg_mem.reg.cmd.refresh -side top -padx 5 -fill x
|
404 |
|
|
|
405 |
|
|
# CPU Memory
|
406 |
|
|
frame .reg_mem.mem.cmd
|
407 |
|
|
pack .reg_mem.mem.cmd -side left -fill x
|
408 |
|
|
button .reg_mem.mem.cmd.refresh -text "Refresh\nMemory" -state disabled -command {refreshMem}
|
409 |
|
|
pack .reg_mem.mem.cmd.refresh -side top -padx 5 -fill x
|
410 |
|
|
frame .reg_mem.mem.address
|
411 |
|
|
pack .reg_mem.mem.address -side left -fill x
|
412 |
|
|
frame .reg_mem.mem.data
|
413 |
|
|
pack .reg_mem.mem.data -side left -fill x
|
414 |
|
|
label .reg_mem.mem.address.l -text "Address" -anchor w
|
415 |
|
|
pack .reg_mem.mem.address.l -side top -padx 5
|
416 |
|
|
label .reg_mem.mem.data.l -text "Data" -anchor w
|
417 |
|
|
pack .reg_mem.mem.data.l -side top -padx 5
|
418 |
|
|
|
419 |
|
|
for {set i 0} {$i<16} {incr i} {
|
420 |
|
|
entry .reg_mem.mem.address.e$i -textvariable mem(address_$i) -relief sunken -state disabled
|
421 |
|
|
pack .reg_mem.mem.address.e$i -side top
|
422 |
|
|
bind .reg_mem.mem.address.e$i <Return> "refreshMem"
|
423 |
|
|
entry .reg_mem.mem.data.e$i -textvariable mem(data_$i) -relief sunken -state disabled
|
424 |
|
|
pack .reg_mem.mem.data.e$i -side top
|
425 |
|
|
bind .reg_mem.mem.data.e$i <Return> "write2Mem $i"
|
426 |
|
|
}
|