You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

111 lines
2.4 KiB

  1. # Defines basic Tcl procs for OpenOCD flash module
  2. #
  3. # program utility proc
  4. # usage: program filename
  5. # optional args: verify, reset, exit and address
  6. #
  7. proc program_error {description exit} {
  8. if {$exit == 1} {
  9. echo $description
  10. shutdown error
  11. }
  12. error $description
  13. }
  14. proc program {filename args} {
  15. set exit 0
  16. foreach arg $args {
  17. if {[string equal $arg "verify"]} {
  18. set verify 1
  19. } elseif {[string equal $arg "reset"]} {
  20. set reset 1
  21. } elseif {[string equal $arg "exit"]} {
  22. set exit 1
  23. } else {
  24. set address $arg
  25. }
  26. }
  27. # make sure init is called
  28. if {[catch {init}] != 0} {
  29. program_error "** OpenOCD init failed **" 1
  30. }
  31. # reset target and call any init scripts
  32. if {[catch {reset init}] != 0} {
  33. program_error "** Unable to reset target **" $exit
  34. }
  35. # start programming phase
  36. echo "** Programming Started **"
  37. if {[info exists address]} {
  38. set flash_args "$filename $address"
  39. } else {
  40. set flash_args "$filename"
  41. }
  42. if {[catch {eval flash write_image erase $flash_args}] == 0} {
  43. echo "** Programming Finished **"
  44. if {[info exists verify]} {
  45. # verify phase
  46. echo "** Verify Started **"
  47. if {[catch {eval verify_image $flash_args}] == 0} {
  48. echo "** Verified OK **"
  49. } else {
  50. program_error "** Verify Failed **" $exit
  51. }
  52. }
  53. if {[info exists reset]} {
  54. # reset target if requested
  55. # also disable target polling, we are shutting down anyway
  56. poll off
  57. echo "** Resetting Target **"
  58. reset run
  59. }
  60. } else {
  61. program_error "** Programming Failed **" $exit
  62. }
  63. if {$exit == 1} {
  64. shutdown
  65. }
  66. return
  67. }
  68. add_help_text program "write an image to flash, address is only required for binary images. verify, reset, exit are optional"
  69. add_usage_text program "<filename> \[address\] \[verify\] \[reset\] \[exit\]"
  70. # stm32f0x uses the same flash driver as the stm32f1x
  71. # this alias enables the use of either name.
  72. proc stm32f0x args {
  73. eval stm32f1x $args
  74. }
  75. # stm32f3x uses the same flash driver as the stm32f1x
  76. # this alias enables the use of either name.
  77. proc stm32f3x args {
  78. eval stm32f1x $args
  79. }
  80. # stm32f4x uses the same flash driver as the stm32f2x
  81. # this alias enables the use of either name.
  82. proc stm32f4x args {
  83. eval stm32f2x $args
  84. }
  85. # ease migration to updated flash driver
  86. proc stm32x args {
  87. echo "DEPRECATED! use 'stm32f1x $args' not 'stm32x $args'"
  88. eval stm32f1x $args
  89. }
  90. proc stm32f2xxx args {
  91. echo "DEPRECATED! use 'stm32f2x $args' not 'stm32f2xxx $args'"
  92. eval stm32f2x $args
  93. }