| 1 |
2 |
olivier.gi |
#!/usr/bin/tclsh
|
| 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: openmsp430-gdbproxy.tcl
|
| 27 |
|
|
#
|
| 28 |
14 |
olivier.gi |
# Author(s):
|
| 29 |
|
|
# - Olivier Girard, olgirard@gmail.com
|
| 30 |
|
|
#
|
| 31 |
2 |
olivier.gi |
#------------------------------------------------------------------------------
|
| 32 |
14 |
olivier.gi |
# $Rev: 110 $
|
| 33 |
|
|
# $LastChangedBy: olivier.girard $
|
| 34 |
|
|
# $LastChangedDate: 2011-05-19 22:33:51 +0200 (Thu, 19 May 2011) $
|
| 35 |
|
|
#------------------------------------------------------------------------------
|
| 36 |
2 |
olivier.gi |
|
| 37 |
|
|
global serial_baudrate
|
| 38 |
|
|
global serial_device
|
| 39 |
|
|
global serial_status
|
| 40 |
|
|
global hw_break
|
| 41 |
|
|
global clients
|
| 42 |
|
|
global server
|
| 43 |
|
|
global verbose
|
| 44 |
|
|
global shell
|
| 45 |
110 |
olivier.gi |
global omsp_info
|
| 46 |
2 |
olivier.gi |
|
| 47 |
|
|
# Initializations
|
| 48 |
|
|
set serial_status 0
|
| 49 |
|
|
|
| 50 |
|
|
|
| 51 |
|
|
###############################################################################
|
| 52 |
|
|
# #
|
| 53 |
|
|
# SOURCE LIBRARIES #
|
| 54 |
|
|
# #
|
| 55 |
|
|
###############################################################################
|
| 56 |
|
|
|
| 57 |
|
|
# Get library path
|
| 58 |
|
|
set current_file [info script]
|
| 59 |
|
|
if {[file type $current_file]=="link"} {
|
| 60 |
|
|
set current_file [file readlink $current_file]
|
| 61 |
|
|
}
|
| 62 |
|
|
set lib_path [file dirname $current_file]/../lib/tcl-lib
|
| 63 |
|
|
|
| 64 |
|
|
# Source library
|
| 65 |
|
|
source $lib_path/dbg_functions.tcl
|
| 66 |
|
|
|
| 67 |
|
|
# Source remaining files
|
| 68 |
|
|
source [file dirname $current_file]/../openmsp430-gdbproxy/server.tcl
|
| 69 |
|
|
source [file dirname $current_file]/../openmsp430-gdbproxy/commands.tcl
|
| 70 |
|
|
|
| 71 |
|
|
|
| 72 |
|
|
###############################################################################
|
| 73 |
|
|
# #
|
| 74 |
|
|
# PARAMETER CHECK #
|
| 75 |
|
|
# #
|
| 76 |
|
|
###############################################################################
|
| 77 |
|
|
|
| 78 |
|
|
proc help {} {
|
| 79 |
|
|
puts ""
|
| 80 |
|
|
puts "USAGE : openmsp430-gdbproxy.tcl \[-device <communication device>\]"
|
| 81 |
|
|
puts " \[-baudrate <communication speed>\]"
|
| 82 |
|
|
puts " \[-port <server port>\]"
|
| 83 |
|
|
puts " \[-shell]"
|
| 84 |
|
|
puts " \[-verbose\]"
|
| 85 |
|
|
puts " \[-help\]"
|
| 86 |
|
|
puts ""
|
| 87 |
|
|
puts "Examples: openmsp430-gdbproxy.tcl -device /dev/ttyUSB0 -baudrate 9600 -port 2000"
|
| 88 |
|
|
puts " openmsp430-gdbproxy.tcl -device COM2: -baudrate 38400 -port 2000"
|
| 89 |
|
|
puts ""
|
| 90 |
|
|
}
|
| 91 |
|
|
|
| 92 |
|
|
# Default values
|
| 93 |
|
|
set serial_device [lindex [dbg_list_uart] end]
|
| 94 |
|
|
set serial_baudrate 115200
|
| 95 |
|
|
set server(port) 2000
|
| 96 |
|
|
set shell 0
|
| 97 |
|
|
set verbose 0
|
| 98 |
|
|
|
| 99 |
|
|
# Parse arguments
|
| 100 |
|
|
for {set i 0} {$i < $argc} {incr i} {
|
| 101 |
|
|
switch -exact -- [lindex $argv $i] {
|
| 102 |
|
|
-device {set serial_device [lindex $argv [expr $i+1]]; incr i}
|
| 103 |
|
|
-baudrate {set serial_baudrate [lindex $argv [expr $i+1]]; incr i}
|
| 104 |
|
|
-port {set server(port) [lindex $argv [expr $i+1]]; incr i}
|
| 105 |
|
|
-shell {set shell 1}
|
| 106 |
|
|
-verbose {set verbose 1}
|
| 107 |
|
|
-h {help; exit 0}
|
| 108 |
|
|
-help {help; exit 0}
|
| 109 |
|
|
default {}
|
| 110 |
|
|
}
|
| 111 |
|
|
}
|
| 112 |
|
|
|
| 113 |
|
|
# Source additional library for graphical interface
|
| 114 |
|
|
if {!$shell} {
|
| 115 |
|
|
source $lib_path/combobox.tcl
|
| 116 |
|
|
package require combobox 2.3
|
| 117 |
|
|
catch {namespace import combobox::*}
|
| 118 |
|
|
}
|
| 119 |
|
|
|
| 120 |
|
|
# Small functions to display messages
|
| 121 |
|
|
proc putsLog {string {nonewline 0}} {
|
| 122 |
|
|
global server
|
| 123 |
|
|
global shell
|
| 124 |
|
|
if {$shell} {
|
| 125 |
|
|
if {$nonewline} {
|
| 126 |
|
|
puts -nonewline $string
|
| 127 |
|
|
} else {
|
| 128 |
|
|
puts $string
|
| 129 |
|
|
}
|
| 130 |
|
|
} else {
|
| 131 |
|
|
if {$nonewline} {
|
| 132 |
|
|
$server(log) insert end "$string"
|
| 133 |
|
|
} else {
|
| 134 |
|
|
$server(log) insert end "$string\n"
|
| 135 |
|
|
}
|
| 136 |
|
|
$server(log) see end
|
| 137 |
|
|
}
|
| 138 |
|
|
}
|
| 139 |
|
|
proc putsVerbose {string} {
|
| 140 |
|
|
global verbose
|
| 141 |
|
|
if {$verbose} {
|
| 142 |
|
|
putsLog "$string"
|
| 143 |
|
|
}
|
| 144 |
|
|
}
|
| 145 |
|
|
|
| 146 |
|
|
###############################################################################
|
| 147 |
|
|
# SHELL MODE #
|
| 148 |
|
|
###############################################################################
|
| 149 |
|
|
if {$shell} {
|
| 150 |
|
|
|
| 151 |
|
|
# Connect to device
|
| 152 |
|
|
if {![GetDevice]} {
|
| 153 |
|
|
puts "ERROR: Could not open $serial_device"
|
| 154 |
|
|
puts "INFO: Available serial ports are:"
|
| 155 |
|
|
foreach port [dbg_list_uart] {
|
| 156 |
|
|
puts "INFO: - $port"
|
| 157 |
|
|
}
|
| 158 |
|
|
exit 1
|
| 159 |
|
|
}
|
| 160 |
|
|
|
| 161 |
|
|
# Display info
|
| 162 |
110 |
olivier.gi |
if {$omsp_info(alias)==""} {
|
| 163 |
|
|
puts "INFO: Sucessfully connected with the openMSP430 target."
|
| 164 |
|
|
} else {
|
| 165 |
|
|
puts "INFO: Sucessfully connected with the openMSP430 target ($omsp_info(alias))."
|
| 166 |
|
|
}
|
| 167 |
2 |
olivier.gi |
set sizes [GetCPU_ID_SIZE]
|
| 168 |
110 |
olivier.gi |
if {$omsp_info(asic)} {
|
| 169 |
|
|
puts "INFO: CPU Version - $omsp_info(cpu_ver) / ASIC"
|
| 170 |
|
|
} else {
|
| 171 |
|
|
puts "INFO: CPU Version - $omsp_info(cpu_ver) / FPGA"
|
| 172 |
|
|
}
|
| 173 |
|
|
puts "INFO: User Version - $omsp_info(user_ver)"
|
| 174 |
|
|
if {$omsp_info(cpu_ver)==1} {
|
| 175 |
|
|
puts "INFO: Hardware Multiplier - --"
|
| 176 |
|
|
} elseif {$omsp_info(mpy)} {
|
| 177 |
|
|
puts "INFO: Hardware Multiplier - Yes"
|
| 178 |
|
|
} else {
|
| 179 |
|
|
puts "INFO: Hardware Multiplier - No"
|
| 180 |
|
|
}
|
| 181 |
|
|
puts "INFO: Program Memory Size - $omsp_info(pmem_size) B"
|
| 182 |
|
|
puts "INFO: Data Memory Size - $omsp_info(dmem_size) B"
|
| 183 |
|
|
puts "INFO: Peripheral Address Space - $omsp_info(per_size) B"
|
| 184 |
2 |
olivier.gi |
puts "INFO: $hw_break(num) Hardware Brea/Watch-point unit(s) detected"
|
| 185 |
|
|
puts ""
|
| 186 |
|
|
|
| 187 |
|
|
# Reset & Stop CPU
|
| 188 |
|
|
ExecutePOR_Halt
|
| 189 |
|
|
|
| 190 |
|
|
# Start server for GDB
|
| 191 |
|
|
if {![startServer]} {
|
| 192 |
|
|
exit 1
|
| 193 |
|
|
}
|
| 194 |
|
|
|
| 195 |
|
|
vwait forever
|
| 196 |
|
|
}
|
| 197 |
|
|
|
| 198 |
|
|
|
| 199 |
|
|
###############################################################################
|
| 200 |
|
|
# GUI MODE #
|
| 201 |
|
|
###############################################################################
|
| 202 |
|
|
|
| 203 |
|
|
####################################
|
| 204 |
|
|
# CREATE & PLACE MAIN WIDGETS #
|
| 205 |
|
|
####################################
|
| 206 |
|
|
|
| 207 |
|
|
wm title . "openMSP430 GDB Proxy"
|
| 208 |
|
|
wm iconname . "openMSP430 GDB Proxy"
|
| 209 |
|
|
|
| 210 |
110 |
olivier.gi |
# Create the Main Menu frame
|
| 211 |
2 |
olivier.gi |
frame .menu
|
| 212 |
|
|
pack .menu -side top -padx 10 -pady 10 -fill x
|
| 213 |
|
|
|
| 214 |
110 |
olivier.gi |
# Create the Connection frame
|
| 215 |
|
|
frame .connect -bd 2 -relief ridge ;# solid
|
| 216 |
|
|
pack .connect -side top -padx 10 -pady {5 0} -fill x
|
| 217 |
2 |
olivier.gi |
|
| 218 |
110 |
olivier.gi |
# Create the Info frame
|
| 219 |
|
|
frame .info -bd 2 -relief ridge ;# solid
|
| 220 |
|
|
pack .info -side top -padx 10 -pady {10 0} -fill x
|
| 221 |
2 |
olivier.gi |
|
| 222 |
110 |
olivier.gi |
# Create the Server frame
|
| 223 |
|
|
frame .server -bd 2 -relief ridge ;# solid
|
| 224 |
|
|
pack .server -side top -padx 10 -pady {10 0} -fill x
|
| 225 |
|
|
|
| 226 |
87 |
olivier.gi |
# Create the TCL script field
|
| 227 |
110 |
olivier.gi |
frame .tclscript -bd 2 -relief ridge ;# solid
|
| 228 |
87 |
olivier.gi |
pack .tclscript -side top -padx 10 -pady 10 -fill x
|
| 229 |
2 |
olivier.gi |
|
| 230 |
87 |
olivier.gi |
|
| 231 |
2 |
olivier.gi |
####################################
|
| 232 |
|
|
# CREATE THE REST #
|
| 233 |
|
|
####################################
|
| 234 |
|
|
|
| 235 |
|
|
# Exit button
|
| 236 |
|
|
button .menu.exit -text "Exit" -command {stopServer; exit 0}
|
| 237 |
|
|
pack .menu.exit -side left
|
| 238 |
|
|
|
| 239 |
110 |
olivier.gi |
# openMSP430 label
|
| 240 |
|
|
label .menu.omsp -text "openMSP430 GDB proxy" -anchor center -fg "\#6a5acd" -font {-weight bold -size 14}
|
| 241 |
|
|
pack .menu.omsp -side right -padx 20
|
| 242 |
2 |
olivier.gi |
|
| 243 |
110 |
olivier.gi |
# Create the Configuration, Start & Info frames
|
| 244 |
|
|
frame .connect.config
|
| 245 |
|
|
pack .connect.config -side left -padx 10 -pady 0 -fill x -expand true
|
| 246 |
|
|
frame .connect.start
|
| 247 |
|
|
pack .connect.start -side right -padx 10 -pady 0 -fill x -expand true
|
| 248 |
|
|
|
| 249 |
2 |
olivier.gi |
# Serial Port fields
|
| 250 |
|
|
set serial_device [lindex [dbg_list_uart] end]
|
| 251 |
110 |
olivier.gi |
frame .connect.config.serial_port
|
| 252 |
|
|
pack .connect.config.serial_port -side top -padx 5 -pady {10 0} -fill x
|
| 253 |
|
|
label .connect.config.serial_port.l1 -text "Serial Port:" -anchor w
|
| 254 |
|
|
pack .connect.config.serial_port.l1 -side left -padx 5
|
| 255 |
|
|
combobox .connect.config.serial_port.p1 -textvariable serial_device -editable true -width 20
|
| 256 |
|
|
eval .connect.config.serial_port.p1 list insert end [dbg_list_uart]
|
| 257 |
|
|
pack .connect.config.serial_port.p1 -side right -padx 20
|
| 258 |
|
|
|
| 259 |
|
|
# Serial Baudrate fields
|
| 260 |
2 |
olivier.gi |
set serial_baudrate 115200
|
| 261 |
110 |
olivier.gi |
frame .connect.config.serial_baudrate
|
| 262 |
|
|
pack .connect.config.serial_baudrate -side top -padx 5 -pady {5 0} -fill x
|
| 263 |
|
|
label .connect.config.serial_baudrate.l2 -text " Baudrate:" -anchor w
|
| 264 |
|
|
pack .connect.config.serial_baudrate.l2 -side left
|
| 265 |
|
|
combobox .connect.config.serial_baudrate.p2 -textvariable serial_baudrate -editable true -width 20
|
| 266 |
|
|
eval .connect.config.serial_baudrate.p2 list insert end [list 9600 19200 38400 57600 115200 \
|
| 267 |
|
|
230400 460800 500000 576000 921600 \
|
| 268 |
|
|
1000000 1152000]
|
| 269 |
|
|
pack .connect.config.serial_baudrate.p2 -side right -padx 20
|
| 270 |
2 |
olivier.gi |
|
| 271 |
|
|
# Server Port field
|
| 272 |
110 |
olivier.gi |
frame .connect.config.server_port
|
| 273 |
|
|
pack .connect.config.server_port -side top -padx 10 -pady {15 10} -fill x
|
| 274 |
|
|
label .connect.config.server_port.l1 -text "Proxy Server Port:" -anchor w
|
| 275 |
|
|
pack .connect.config.server_port.l1 -side left
|
| 276 |
|
|
entry .connect.config.server_port.p -textvariable server(port) -relief sunken -width 20
|
| 277 |
|
|
pack .connect.config.server_port.p -side right -padx 5 -padx 20
|
| 278 |
2 |
olivier.gi |
|
| 279 |
|
|
|
| 280 |
110 |
olivier.gi |
# Connect to CPU & start proxy server
|
| 281 |
|
|
button .connect.start.but -text "Connect to CPU\n and \nStart Proxy Server" -command {startServerGUI}
|
| 282 |
|
|
pack .connect.start.but -side right -padx 30
|
| 283 |
|
|
|
| 284 |
|
|
|
| 285 |
|
|
# CPU Info
|
| 286 |
|
|
frame .info.cpu
|
| 287 |
|
|
pack .info.cpu -side top -padx 10 -pady {5 0} -fill x
|
| 288 |
|
|
label .info.cpu.l -text "CPU Info:" -anchor w
|
| 289 |
|
|
pack .info.cpu.l -side left -padx {10 10}
|
| 290 |
|
|
label .info.cpu.con -text "Disconnected" -anchor w -fg Red
|
| 291 |
|
|
pack .info.cpu.con -side left
|
| 292 |
|
|
button .info.cpu.more -text "More..." -width 9 -command {displayMore} -state disabled
|
| 293 |
|
|
pack .info.cpu.more -side right -padx {0 30}
|
| 294 |
|
|
|
| 295 |
|
|
|
| 296 |
|
|
# Server Info
|
| 297 |
|
|
frame .info.server
|
| 298 |
|
|
pack .info.server -side top -padx 10 -pady {0 10} -fill x
|
| 299 |
|
|
label .info.server.l -text "Server Info:" -anchor w
|
| 300 |
|
|
pack .info.server.l -side left -padx {10 10}
|
| 301 |
|
|
label .info.server.con -text "Not running" -anchor w -fg Red
|
| 302 |
|
|
pack .info.server.con -side left
|
| 303 |
|
|
|
| 304 |
|
|
|
| 305 |
2 |
olivier.gi |
# Create the text widget to log received messages
|
| 306 |
|
|
frame .server.t
|
| 307 |
|
|
pack .server.t -side top -padx 10 -pady 10 -fill x
|
| 308 |
110 |
olivier.gi |
set server(log) [text .server.t.log -width 80 -height 15 -borderwidth 2 \
|
| 309 |
2 |
olivier.gi |
-setgrid true -yscrollcommand {.server.t.scroll set}]
|
| 310 |
|
|
pack .server.t.log -side left -fill both -expand true
|
| 311 |
|
|
scrollbar .server.t.scroll -command {.server.t.log yview}
|
| 312 |
87 |
olivier.gi |
pack .server.t.scroll -side right -fill both
|
| 313 |
2 |
olivier.gi |
|
| 314 |
|
|
|
| 315 |
|
|
# Log commands
|
| 316 |
|
|
frame .server.cmd
|
| 317 |
110 |
olivier.gi |
pack .server.cmd -side top -pady {0 10} -fill x
|
| 318 |
2 |
olivier.gi |
button .server.cmd.clear -text "Clear log" -command {$server(log) delete 1.0 end}
|
| 319 |
|
|
pack .server.cmd.clear -side left -padx 10
|
| 320 |
|
|
checkbutton .server.cmd.verbose -text "Verbose" -variable verbose
|
| 321 |
|
|
pack .server.cmd.verbose -side right -padx 10
|
| 322 |
87 |
olivier.gi |
|
| 323 |
|
|
|
| 324 |
|
|
# Load TCL script fields
|
| 325 |
|
|
frame .tclscript.ft
|
| 326 |
110 |
olivier.gi |
pack .tclscript.ft -side top -padx 10 -pady 10 -fill x
|
| 327 |
87 |
olivier.gi |
label .tclscript.ft.l -text "TCL script:" -state disabled
|
| 328 |
|
|
pack .tclscript.ft.l -side left -padx "0 10"
|
| 329 |
|
|
entry .tclscript.ft.file -width 58 -relief sunken -textvariable tcl_file_name -state disabled
|
| 330 |
|
|
pack .tclscript.ft.file -side left -padx 10
|
| 331 |
|
|
button .tclscript.ft.browse -text "Browse" -state disabled -command {set tcl_file_name [tk_getOpenFile -filetypes {{{TCL Files} {.tcl}} {{All Files} *}}]}
|
| 332 |
|
|
pack .tclscript.ft.browse -side left -padx 5
|
| 333 |
|
|
frame .tclscript.fb
|
| 334 |
|
|
pack .tclscript.fb -side top -fill x
|
| 335 |
|
|
button .tclscript.fb.read -text "Source TCL script !" -state disabled -command {if {[file exists $tcl_file_name]} {source $tcl_file_name}}
|
| 336 |
110 |
olivier.gi |
pack .tclscript.fb.read -side left -padx 20 -pady {0 10} -fill x
|
| 337 |
87 |
olivier.gi |
|
| 338 |
110 |
olivier.gi |
wm resizable . 0 0
|