2009-11-17 10:29:20 -06:00
|
|
|
# Defines basic Tcl procs for OpenOCD flash module
|
|
|
|
|
2013-03-06 09:29:15 -06:00
|
|
|
#
|
|
|
|
# program utility proc
|
|
|
|
# usage: program filename
|
2015-01-23 02:38:31 -06:00
|
|
|
# optional args: verify, reset, exit and address
|
2013-03-06 09:29:15 -06:00
|
|
|
#
|
|
|
|
|
2015-01-23 02:38:31 -06:00
|
|
|
proc program_error {description exit} {
|
|
|
|
if {$exit == 1} {
|
2015-03-13 08:32:53 -05:00
|
|
|
echo $description
|
|
|
|
shutdown error
|
2015-01-23 02:38:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
error $description
|
|
|
|
}
|
|
|
|
|
2013-03-06 09:29:15 -06:00
|
|
|
proc program {filename args} {
|
2015-01-23 02:38:31 -06:00
|
|
|
set exit 0
|
2013-03-06 09:29:15 -06:00
|
|
|
|
|
|
|
foreach arg $args {
|
|
|
|
if {[string equal $arg "verify"]} {
|
|
|
|
set verify 1
|
|
|
|
} elseif {[string equal $arg "reset"]} {
|
|
|
|
set reset 1
|
2015-01-23 02:38:31 -06:00
|
|
|
} elseif {[string equal $arg "exit"]} {
|
|
|
|
set exit 1
|
2013-03-06 09:29:15 -06:00
|
|
|
} else {
|
|
|
|
set address $arg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# make sure init is called
|
|
|
|
if {[catch {init}] != 0} {
|
2015-01-23 02:38:31 -06:00
|
|
|
program_error "** OpenOCD init failed **" 1
|
2013-03-06 09:29:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
# reset target and call any init scripts
|
|
|
|
if {[catch {reset init}] != 0} {
|
2015-01-23 02:38:31 -06:00
|
|
|
program_error "** Unable to reset target **" $exit
|
2013-03-06 09:29:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
# start programming phase
|
|
|
|
echo "** Programming Started **"
|
|
|
|
if {[info exists address]} {
|
|
|
|
set flash_args "$filename $address"
|
|
|
|
} else {
|
|
|
|
set flash_args "$filename"
|
|
|
|
}
|
|
|
|
|
|
|
|
if {[catch {eval flash write_image erase $flash_args}] == 0} {
|
|
|
|
echo "** Programming Finished **"
|
|
|
|
if {[info exists verify]} {
|
|
|
|
# verify phase
|
|
|
|
echo "** Verify Started **"
|
|
|
|
if {[catch {eval verify_image $flash_args}] == 0} {
|
|
|
|
echo "** Verified OK **"
|
|
|
|
} else {
|
2015-01-23 02:38:31 -06:00
|
|
|
program_error "** Verify Failed **" $exit
|
2013-03-06 09:29:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if {[info exists reset]} {
|
|
|
|
# reset target if requested
|
2013-04-12 07:10:35 -05:00
|
|
|
# also disable target polling, we are shutting down anyway
|
|
|
|
poll off
|
2013-03-06 09:29:15 -06:00
|
|
|
echo "** Resetting Target **"
|
|
|
|
reset run
|
|
|
|
}
|
|
|
|
} else {
|
2015-01-23 02:38:31 -06:00
|
|
|
program_error "** Programming Failed **" $exit
|
2013-03-06 09:29:15 -06:00
|
|
|
}
|
|
|
|
|
2015-01-23 02:38:31 -06:00
|
|
|
if {$exit == 1} {
|
|
|
|
shutdown
|
|
|
|
}
|
|
|
|
return
|
2013-03-06 09:29:15 -06:00
|
|
|
}
|
|
|
|
|
2015-01-23 02:38:31 -06:00
|
|
|
add_help_text program "write an image to flash, address is only required for binary images. verify, reset, exit are optional"
|
|
|
|
add_usage_text program "<filename> \[address\] \[verify\] \[reset\] \[exit\]"
|
2013-03-06 09:29:15 -06:00
|
|
|
|
2013-05-30 04:54:54 -05:00
|
|
|
# stm32f0x uses the same flash driver as the stm32f1x
|
|
|
|
# this alias enables the use of either name.
|
|
|
|
proc stm32f0x args {
|
|
|
|
eval stm32f1x $args
|
|
|
|
}
|
|
|
|
|
|
|
|
# stm32f3x uses the same flash driver as the stm32f1x
|
|
|
|
# this alias enables the use of either name.
|
|
|
|
proc stm32f3x args {
|
|
|
|
eval stm32f1x $args
|
|
|
|
}
|
|
|
|
|
|
|
|
# stm32f4x uses the same flash driver as the stm32f2x
|
|
|
|
# this alias enables the use of either name.
|
|
|
|
proc stm32f4x args {
|
|
|
|
eval stm32f2x $args
|
|
|
|
}
|
|
|
|
|
2011-07-28 06:47:49 -05:00
|
|
|
# ease migration to updated flash driver
|
|
|
|
proc stm32x args {
|
|
|
|
echo "DEPRECATED! use 'stm32f1x $args' not 'stm32x $args'"
|
|
|
|
eval stm32f1x $args
|
|
|
|
}
|
|
|
|
|
|
|
|
proc stm32f2xxx args {
|
|
|
|
echo "DEPRECATED! use 'stm32f2x $args' not 'stm32f2xxx $args'"
|
|
|
|
eval stm32f2x $args
|
|
|
|
}
|