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.
 
 
 
 
 
 

129 lines
2.9 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. set needsflash 1
  17. foreach arg $args {
  18. if {[string equal $arg "preverify"]} {
  19. set preverify 1
  20. } elseif {[string equal $arg "verify"]} {
  21. set verify 1
  22. } elseif {[string equal $arg "reset"]} {
  23. set reset 1
  24. } elseif {[string equal $arg "exit"]} {
  25. set exit 1
  26. } else {
  27. set address $arg
  28. }
  29. }
  30. # Set variables
  31. set filename \{$filename\}
  32. if {[info exists address]} {
  33. set flash_args "$filename $address"
  34. } else {
  35. set flash_args "$filename"
  36. }
  37. # make sure init is called
  38. if {[catch {init}] != 0} {
  39. program_error "** OpenOCD init failed **" 1
  40. }
  41. # reset target and call any init scripts
  42. if {[catch {reset init}] != 0} {
  43. program_error "** Unable to reset target **" $exit
  44. }
  45. # Check whether programming is needed
  46. if {[info exists preverify]} {
  47. echo "**pre-verifying**"
  48. if {[catch {eval verify_image $flash_args}] == 0} {
  49. echo "**Verified OK - No flashing**"
  50. set needsflash 0
  51. }
  52. }
  53. # start programming phase
  54. if {$needsflash == 1} {
  55. echo "** Programming Started **"
  56. if {[catch {eval flash write_image erase $flash_args}] == 0} {
  57. echo "** Programming Finished **"
  58. if {[info exists verify]} {
  59. # verify phase
  60. echo "** Verify Started **"
  61. if {[catch {eval verify_image $flash_args}] == 0} {
  62. echo "** Verified OK **"
  63. } else {
  64. program_error "** Verify Failed **" $exit
  65. }
  66. }
  67. } else {
  68. program_error "** Programming Failed **" $exit
  69. }
  70. }
  71. if {[info exists reset]} {
  72. # reset target if requested
  73. if {$exit == 1} {
  74. # also disable target polling, we are shutting down anyway
  75. poll off
  76. }
  77. echo "** Resetting Target **"
  78. reset run
  79. }
  80. if {$exit == 1} {
  81. shutdown
  82. }
  83. return
  84. }
  85. add_help_text program "write an image to flash, address is only required for binary images. verify, reset, exit are optional"
  86. add_usage_text program "<filename> \[address\] \[pre-verify\] \[verify\] \[reset\] \[exit\]"
  87. # stm32[f0x|f3x] uses the same flash driver as the stm32f1x
  88. proc stm32f0x args { eval stm32f1x $args }
  89. proc stm32f3x args { eval stm32f1x $args }
  90. # stm32[f4x|f7x] uses the same flash driver as the stm32f2x
  91. proc stm32f4x args { eval stm32f2x $args }
  92. proc stm32f7x args { eval stm32f2x $args }
  93. # stm32lx driver supports both STM32 L0 and L1 devices
  94. proc stm32l0x args { eval stm32lx $args }
  95. proc stm32l1x args { eval stm32lx $args }
  96. # stm32wb uses the same flash driver as the stm32l4x
  97. proc stm32wbx args { eval stm32l4x $args }
  98. # ease migration to updated flash driver
  99. proc stm32x args {
  100. echo "DEPRECATED! use 'stm32f1x $args' not 'stm32x $args'"
  101. eval stm32f1x $args
  102. }
  103. proc stm32f2xxx args {
  104. echo "DEPRECATED! use 'stm32f2x $args' not 'stm32f2xxx $args'"
  105. eval stm32f2x $args
  106. }