OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [tools/] [bin/] [openmsp430-minidebug.tcl] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.