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

Subversion Repositories openmsp430

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

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: 77 $
33
# $LastChangedBy: olivier.girard $
34
# $LastChangedDate: 2010-11-21 20:50:55 +0100 (Sun, 21 Nov 2010) $
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 77 olivier.gi
    if {[catch {exec msp430-objcopy -O binary $elf_file_name $bin_file} errMsg]} {
140
        .load.fb.l configure -text "$errMsg" -fg red
141
        return 0
142
    }
143
 
144
    # Wait until bin file is present on the filesystem
145
    set timeout 100
146
    for {set i 0} {$i <= $timeout} {incr i} {
147
        after 500
148
        if {[file exists $bin_file]} {
149
            break
150
        }
151
    }
152
    if {$i>=$timeout} {
153
        .load.fb.l configure -text "Timeout: ELF to BIN file conversion problem with \"msp430-objcopy\" executable" -fg red
154
        return 0
155
    }
156 2 olivier.gi
 
157
    # Read file
158
    set fp [open $bin_file r]
159
    fconfigure $fp -translation binary
160
    binary scan [read $fp] H* hex_data yop
161
    close $fp
162
 
163
    # Cleanup
164
    file delete $bin_file
165
 
166
    # Get program size
167
    set hex_size  [string length $hex_data]
168
    set byte_size [expr $hex_size/2]
169
    set word_size [expr $byte_size/2]
170
 
171 77 olivier.gi
    # Make sure ELF program size is the same as the available program memory
172
    set sizes [GetCPU_ID_SIZE]
173
    if {[lindex $sizes 0] != [expr $hex_size/2]} {
174
        .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
175
        return 0
176
    }
177
 
178 2 olivier.gi
    # Format data
179
    for {set i 0} {$i < $hex_size} {set i [expr $i+4]} {
180
        set hex_msb "[string index $hex_data [expr $i+2]][string index $hex_data [expr $i+3]]"
181
        set hex_lsb "[string index $hex_data [expr $i+0]][string index $hex_data [expr $i+1]]"
182
        lappend DataArray "0x$hex_msb$hex_lsb"
183
    }
184
 
185
    # Load program to openmsp430 target
186
    #-----------------------------------
187
 
188
    # Reset & Stop CPU
189
    ExecutePOR_Halt
190
 
191 35 olivier.gi
    # Load Program Memory
192 2 olivier.gi
    set StartAddr [format "0x%04x" [expr 0x10000-$byte_size]]
193
    .load.fb.l configure -text "Load..." -fg yellow
194
    update
195
    WriteMemQuick $StartAddr $DataArray
196
 
197
    # Check Data
198
    .load.fb.l configure -text "Verify..." -fg yellow
199
    update
200 77 olivier.gi
    if {[VerifyMem $StartAddr $DataArray 1]} {
201 2 olivier.gi
        .load.fb.l configure -text "Done" -fg green
202
    } else {
203
        .load.fb.l configure -text "ERROR" -fg red
204
    }
205
    update
206
 
207
    # Release device if it was not previously stopped
208
    if {$cpu_status} {
209
        ReleaseCPU
210
    }
211
    refreshReg
212
    refreshMem
213
}
214
 
215
proc runCPU {} {
216
    global cpu_status
217
    global reg
218
    global mem
219
 
220
    if {$cpu_status} {
221
        HaltCPU
222
        .cpu.run   configure -text "Run"
223
        .cpu.l3    configure -text "Stopped" -fg yellow
224
        set cpu_status 0
225
    } else {
226
        ReleaseCPU
227
        .cpu.run   configure -text "Stop"
228
        .cpu.l3    configure -text "Running" -fg green
229
        set cpu_status 1
230
    }
231
    refreshReg
232
    refreshMem
233
}
234
 
235
proc resetCPU {} {
236
    global cpu_status
237
    global reg
238
    global mem
239
 
240
    if {$cpu_status} {
241
        ExecutePOR
242
    } else {
243
        ExecutePOR_Halt
244
    }
245
    refreshReg
246
    refreshMem
247
}
248
 
249
proc refreshReg {} {
250
    global reg
251
    global mem
252
 
253
    set new_vals [ReadRegAll]
254
    for {set i 0} {$i<16} {incr i} {
255
        set reg($i) [lindex $new_vals $i]
256
    }
257
}
258
 
259
proc write2Reg {reg_num} {
260
    global reg
261
    global mem
262
 
263
    WriteReg $reg_num $reg($reg_num)
264
    refreshReg
265
    refreshMem
266
}
267
 
268
proc refreshMem {} {
269
    global reg
270
    global mem
271
 
272
    for {set i 0} {$i<16} {incr i} {
273
        # Check if address lay in 16 or 8 bit space
274
        if {[expr $mem(address_$i)]>=[expr 0x100]} {
275
            set Format 0
276
        } else {
277
            set Format 1
278
        }
279
 
280
        # Read data
281
        set mem(data_$i) [ReadMem $Format $mem(address_$i)]
282
    }
283
}
284
 
285
proc write2Mem {mem_num} {
286
    global reg
287
    global mem
288
 
289
    # Check if address lay in 16 or 8 bit space
290
    if {[expr $mem(address_$mem_num)]>=[expr 0x100]} {
291
        set Format 0
292
    } else {
293
        set Format 1
294
    }
295
 
296
    WriteMem $Format $mem(address_$mem_num) $mem(data_$mem_num)
297
    refreshReg
298
    refreshMem
299
}
300
 
301
###############################################################################
302
#                                                                             #
303
#                           CREATE GRAPHICAL INTERFACE                        #
304
#                                                                             #
305
###############################################################################
306
 
307
####################################
308
#   CREATE & PLACE MAIN WIDGETS    #
309
####################################
310
 
311
wm title    . "openMSP430 mini debuger"
312
wm iconname . "openMSP430 mini debuger"
313
 
314
# Create the Main Menu budget
315
frame  .menu
316
pack   .menu    -side top -padx 10 -pady 10 -fill x
317
 
318
# Create the Serial Menu budget
319
frame  .serial
320
pack   .serial  -side top -padx 10 -pady 10 -fill x
321
 
322
# Create the Load executable field
323
frame  .load
324
pack   .load    -side top -padx 10 -pady 10 -fill x
325
 
326
# Create the cpu control field
327
frame  .cpu
328
pack   .cpu     -side top -padx 10 -pady 10 -fill x
329
 
330
# Create the cpu registers/memory fields
331
frame  .reg_mem
332
pack   .reg_mem -side top -padx 10 -pady 10 -fill x
333
frame  .reg_mem.reg
334
pack   .reg_mem.reg           -side left -fill x
335
frame  .reg_mem.mem
336
pack   .reg_mem.mem           -side left -fill x
337
 
338
 
339
####################################
340
#  CREATE THE REST                 #
341
####################################
342
 
343
# Exit button
344
button .menu.exit      -text "Exit" -command {disconnect_openMSP430; exit 0}
345
pack   .menu.exit      -side left
346
 
347
 
348
# Serial Port fields
349
label  .serial.l1      -text "Serial Port:"  -anchor w
350
pack   .serial.l1      -side left
351
set serial_device      [lindex [dbg_list_uart] end]
352
combobox .serial.p1    -textvariable serial_device -editable true
353
eval     .serial.p1    list insert end [dbg_list_uart]
354
pack   .serial.p1      -side left -padx 5
355
 
356
label  .serial.l2      -text "  Baudrate:" -anchor w
357
pack   .serial.l2      -side left
358
set serial_baudrate    115200
359
combobox .serial.p2    -textvariable serial_baudrate -editable true
360
eval     .serial.p2    list insert end [list    9600   19200  38400  57600 115200 \
361
                                              230400  460800 500000 576000 921600 \
362
                                             1000000 1152000]
363
pack   .serial.p2      -side left -padx 5
364
 
365
button .serial.connect -text "Connect" -command {connect_openMSP430}
366
pack   .serial.connect -side left -padx 10
367
label  .serial.l3      -text "Disconnected" -anchor w -fg Red
368
pack   .serial.l3      -side left
369
 
370
 
371
# Load ELF file fields
372
frame  .load.ft
373
pack   .load.ft        -side top -fill x
374
label  .load.ft.l      -text "ELF file:"
375
pack   .load.ft.l      -side left -padx 5
376
entry  .load.ft.file   -width 58 -relief sunken -textvariable elf_file_name -state disabled
377
pack   .load.ft.file   -side left -padx 5
378
button .load.ft.browse -text "Browse" -state disabled -command {set elf_file_name [tk_getOpenFile]}
379
pack   .load.ft.browse -side left -padx 5
380
frame  .load.fb
381
pack   .load.fb        -side top -fill x
382
button .load.fb.read   -text "Load ELF File !" -state disabled -command {loadProgram $elf_file_name}
383
pack   .load.fb.read   -side left -padx 5 -fill x
384
label  .load.fb.l      -text "Not loaded" -anchor w -fg Red
385
pack   .load.fb.l      -side left
386
 
387
 
388
# CPU Control
389
label  .cpu.l1         -text "Control CPU:" -anchor w
390
pack   .cpu.l1         -side left
391
button .cpu.reset      -text "Reset" -state disabled -command {resetCPU}
392
pack   .cpu.reset      -side left -padx 5 -fill x
393
button .cpu.run        -text "Stop"  -state disabled -command {runCPU}
394
pack   .cpu.run        -side left -padx 5 -fill x
395
label  .cpu.l2         -text "CPU Status:" -anchor w
396
pack   .cpu.l2         -side left
397
label  .cpu.l3         -text "Running" -anchor w -fg green
398
pack   .cpu.l3         -side left
399
 
400
label  .cpu.l4         -text "B)"        -anchor w
401
pack   .cpu.l4         -side right
402
label  .cpu.l5         -text "--"        -anchor w
403
pack   .cpu.l5         -side right
404 35 olivier.gi
label  .cpu.l6         -text "B; Data Memory size:" -anchor w
405 2 olivier.gi
pack   .cpu.l6         -side right
406
label  .cpu.l7         -text "--"        -anchor w
407
pack   .cpu.l7         -side right
408 35 olivier.gi
label  .cpu.l8         -text "(Program Memory size:" -anchor w
409 2 olivier.gi
pack   .cpu.l8         -side right
410
 
411
 
412
# CPU Registers
413
frame  .reg_mem.reg.labels
414
pack   .reg_mem.reg.labels     -side left -fill x
415
frame  .reg_mem.reg.entries
416
pack   .reg_mem.reg.entries    -side left -fill x
417
for {set i 0} {$i<16} {incr i} {
418
    switch $i {
419
        {0}     {set reg_label "r0 (pc):"}
420
        {1}     {set reg_label "r1 (sp):"}
421
        {2}     {set reg_label "r2 (sr):"}
422
        default {set reg_label "r$i:"}
423
    }
424
    label  .reg_mem.reg.labels.l$i    -text $reg_label -anchor w
425
    pack   .reg_mem.reg.labels.l$i    -side top -padx 5 -pady 1
426
    entry  .reg_mem.reg.entries.e$i   -textvariable reg($i) -relief sunken -state disabled
427
    pack   .reg_mem.reg.entries.e$i   -side top
428
    bind   .reg_mem.reg.entries.e$i   <Return> "write2Reg $i"
429
}
430
frame  .reg_mem.reg.cmd
431
pack   .reg_mem.reg.cmd               -side left -fill x
432
button .reg_mem.reg.cmd.refresh       -text "Refresh\nRegisters"  -state disabled -command {refreshReg}
433
pack   .reg_mem.reg.cmd.refresh       -side top -padx 5 -fill x
434
 
435
# CPU Memory
436
frame  .reg_mem.mem.cmd
437
pack   .reg_mem.mem.cmd               -side left -fill x
438
button .reg_mem.mem.cmd.refresh       -text "Refresh\nMemory"  -state disabled -command {refreshMem}
439
pack   .reg_mem.mem.cmd.refresh       -side top -padx 5 -fill x
440
frame  .reg_mem.mem.address
441
pack   .reg_mem.mem.address           -side left -fill x
442
frame  .reg_mem.mem.data
443
pack   .reg_mem.mem.data              -side left -fill x
444
label  .reg_mem.mem.address.l         -text "Address" -anchor w
445
pack   .reg_mem.mem.address.l         -side top -padx 5
446
label  .reg_mem.mem.data.l            -text "Data"   -anchor w
447
pack   .reg_mem.mem.data.l            -side top -padx 5
448
 
449
for {set i 0} {$i<16} {incr i} {
450
    entry  .reg_mem.mem.address.e$i    -textvariable mem(address_$i) -relief sunken -state disabled
451
    pack   .reg_mem.mem.address.e$i    -side top
452
    bind   .reg_mem.mem.address.e$i    <Return> "refreshMem"
453
    entry  .reg_mem.mem.data.e$i       -textvariable mem(data_$i) -relief sunken -state disabled
454
    pack   .reg_mem.mem.data.e$i       -side top
455
    bind   .reg_mem.mem.data.e$i       <Return> "write2Mem $i"
456
}

powered by: WebSVN 2.1.0

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