mxs40_common.cfg 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #
  2. # Copyright (C) <2019-2021>
  3. # <Cypress Semiconductor Corporation (an Infineon company)>
  4. #
  5. # Common configuration for MXS40 family of microcontrollers.
  6. #
  7. source [find target/mxs40/migration.cfg]
  8. global _MXS40_COMMON_LOADED
  9. if [info exist _MXS40_COMMON_LOADED] return
  10. source [find mem_helper.tcl]
  11. source [find target/mxs40/cy_get_set_device_param.cfg]
  12. set _MXS40_COMMON_LOADED true
  13. ###############################################################################
  14. # Mapping between DIEs from the MPN database and their configuration files
  15. ###############################################################################
  16. set MXS40_DIE_CONFIG_DICT [dict create \
  17. PSoC6ABLE2 psoc6.cfg \
  18. PSoC6A256K psoc6_256k.cfg \
  19. PSoC6A512K psoc6_512k.cfg \
  20. PSoC6A2M psoc6_2m.cfg \
  21. ]
  22. ###############################################################################
  23. # Default speed an reset settings
  24. ###############################################################################
  25. if {[using_jtag]} {
  26. adapter speed 1000
  27. } else {
  28. adapter speed 2000
  29. }
  30. adapter srst delay 25
  31. adapter srst pulse_width 25
  32. ###############################################################################
  33. # Acquires the device in Test Mode
  34. ###############################################################################
  35. proc mxs40_acquire { target } {
  36. global _ENABLE_ACQUIRE
  37. if { $_ENABLE_ACQUIRE == 0 } {
  38. echo "*******************************************************************"
  39. echo "* Test Mode acquire disabled. Use 'set ENABLE_ACQUIRE 1' to enable"
  40. echo "*******************************************************************"
  41. return
  42. }
  43. # acquire will leave CPU in running state
  44. # openocd does not expect this
  45. # ignore possible error e.g. when listen window is disabled
  46. catch {kitprog3 acquire_psoc}
  47. # we need to re-examine and halt target manually
  48. ${target} arp_examine
  49. ${target} arp_poll
  50. if { [$target curstate] eq "reset" } {
  51. $target arp_poll
  52. }
  53. # Ensure target has stopped on WFI instruction
  54. set loops 2000
  55. while { $loops } {
  56. set sleeping [ expr {[mrw 0xE000EDF0] & 0x00040000} ]
  57. if { $sleeping } break
  58. set loops [ expr {$loops - 1} ]
  59. }
  60. if { $sleeping } {
  61. ${target} arp_halt
  62. ${target} arp_waitstate halted 100
  63. echo "** Device acquired successfully"
  64. return
  65. }
  66. puts stderr "********************************************"
  67. puts stderr "* Failed to acquire the device in Test Mode"
  68. puts stderr "********************************************"
  69. }
  70. add_usage_text mxs40_acquire "target"
  71. add_help_text mxs40_acquire "Acquires the device in Test Mode"
  72. ###############################################################################
  73. # Erases all non-virtual flash banks (in reverse order)
  74. ###############################################################################
  75. proc erase_all {} {
  76. lset banks [flash list]
  77. set banks_count [llength $banks]
  78. for {set i [expr {$banks_count - 1}]} { $i >= 0 } { set i [expr {$i - 1}]} {
  79. set bank [lindex $banks $i]
  80. set bank_name $bank(name)
  81. echo [format "Erasing flash bank \"%s\" (%d of %d)..." $bank_name [expr {$banks_count - $i}] $banks_count ]
  82. if { $bank_name != "virtual" } {
  83. flash erase_sector $i 0 last
  84. } else {
  85. echo "skipped (virtual)"
  86. }
  87. }
  88. }
  89. add_help_text erase_all "Erases all non-virtual flash banks (in reverse order, for SMIF compatibility)"
  90. ###############################################################################
  91. # Utility to make 'reset halt' work as reset;halt on a target
  92. # It does not prevent running code after reset
  93. ###############################################################################
  94. proc mxs40_reset_deassert_post { target_type target } {
  95. global _ENABLE_ACQUIRE
  96. global RESET_MODE
  97. # MXS40 cleared AP registers including TAR during reset
  98. # Force examine to synchronize OpenOCD target status
  99. $target arp_examine
  100. $target arp_poll
  101. # Exit if $target is supposed to be running after Reset
  102. if { $RESET_MODE eq "run" } return
  103. # Check if $target is a primary core (cm0 for TRAVEO™II)
  104. set is_primary_core [string match "*cm0" $target]
  105. if { $is_primary_core } {
  106. if { $_ENABLE_ACQUIRE } {
  107. mxs40_acquire $target
  108. } else {
  109. $target_type reset_halt sysresetreq
  110. }
  111. check_flashboot_version
  112. } else {
  113. if { [$target curstate] eq "reset" } {
  114. $target arp_poll
  115. }
  116. if { [$target curstate] eq "running" } {
  117. echo "** $target: Ran after reset and before halt..."
  118. $target arp_halt
  119. $target arp_waitstate halted 100
  120. }
  121. }
  122. }
  123. # Define check_flashboot_version if not already defined
  124. # It is used on PSoC6 only to detect pre-production chips
  125. if { [info proc check_flashboot_version] eq "" } {
  126. proc check_flashboot_version {} {}
  127. }
  128. ###############################################################################
  129. # Tries to detect SMIF geometry by parsing TOC2
  130. ###############################################################################
  131. proc detect_smif {{sflash_base 0x16000000}} {
  132. set cfg_ptr [mrw [mrw [ expr {$sflash_base + 62 * 512 + 0x0C} ]]]
  133. if { $cfg_ptr == 0 || $cfg_ptr == 0xFFFFFFFF || $cfg_ptr < 0x10000000 || $cfg_ptr > 0x10200000 } {
  134. echo "** SMIF configuration structure not found or invalid"
  135. return
  136. }
  137. set chip_num [mrw $cfg_ptr]
  138. set chip_cfg_arry_p [mrw [expr {$cfg_ptr + 4}]]
  139. echo ""
  140. for {set i 0} {$i < $chip_num} {incr i} {
  141. set chip_cfg [mrw [expr {$chip_cfg_arry_p + 4 * $i}]]
  142. set region_base [mrw [expr {$chip_cfg + 12}]]
  143. set region_size [mrw [expr {$chip_cfg + 16}]]
  144. set phys_cfg [mrw [expr {$chip_cfg + 24}]]
  145. set erase_size [mrw [expr {$phys_cfg + 24}]]
  146. set prgm_size [mrw [expr {$phys_cfg + 36}]]
  147. echo "### SMIF region #${i} - Erase Size: 0x[format %X $erase_size], Program Size: 0x[format %X $prgm_size]"
  148. echo "set SMIF_BANKS {1 {addr 0x[format %08X $region_base] size 0x[format %08X $region_size] psize 0x[format %X $prgm_size] esize 0x[format %X $erase_size]}}"
  149. }
  150. }
  151. add_usage_text detect_smif "sflash_base (optional, 0x16000000 by default)"
  152. add_help_text detect_smif "Detects SMIF regions and displays flash bank configuration"
  153. ###############################################################################
  154. # Overrides default init_reset procedure, stores reset mode in global variable
  155. ###############################################################################
  156. proc init_reset { mode } {
  157. global RESET_MODE
  158. set RESET_MODE $mode
  159. }
  160. ###############################################################################
  161. # Handles GDB extended 'restart' command
  162. ###############################################################################
  163. proc ocd_gdb_restart {target} {
  164. if [string match "*cm0" $target ] {
  165. reset init
  166. psoc6 reset_halt sysresetreq
  167. } else {
  168. reset run
  169. sleep 200
  170. psoc6 reset_halt sysresetreq
  171. }
  172. }
  173. ###############################################################################
  174. # Power dropout/restore handlers
  175. ###############################################################################
  176. proc power_dropout {} {
  177. if { [adapter name] eq "kitprog3" } {
  178. local_echo off
  179. set voltage [regexp -inline -- {[0-9]+\.[0-9]+} [kitprog3 get_power]]
  180. local_echo on
  181. puts stderr "Power dropout, target voltage: $voltage mV"
  182. }
  183. }
  184. proc power_restore {} {
  185. if { [adapter name] eq "kitprog3" } {
  186. local_echo off
  187. set voltage [regexp -inline -- {[0-9]+\.[0-9]+} [kitprog3 get_power]]
  188. local_echo on
  189. puts stderr "Power restore, target voltage: $voltage mV"
  190. }
  191. }
  192. ###############################################################################
  193. # KitProg3 acquire/power control stuff
  194. ###############################################################################
  195. global _ENABLE_ACQUIRE
  196. global _ENABLE_POWER_SUPPLY
  197. if {[using_jtag]} {
  198. set ENABLE_ACQUIRE 0
  199. echo "** Test Mode acquire disabled (not supported in JTAG mode)"
  200. }
  201. if { [adapter name] eq "kitprog3" } {
  202. if { [info exists ENABLE_ACQUIRE] } {
  203. if { ( $ENABLE_ACQUIRE != 0 ) && ( $ENABLE_ACQUIRE != 1 ) && ( $ENABLE_ACQUIRE != 2 ) } {
  204. puts stderr "** Invalid ENABLE_ACQUIRE value ($ENABLE_ACQUIRE). Allowed values are:"
  205. puts stderr "** 0 - Test Mode acquisition is disabled"
  206. puts stderr "** 1 - Enable acquisition using XRES method"
  207. puts stderr "** 2 - Enable acquisition using power-cycle method"
  208. terminate
  209. }
  210. if { $ENABLE_ACQUIRE == 2 && ![info exists ENABLE_POWER_SUPPLY] } {
  211. set ENABLE_POWER_SUPPLY default
  212. }
  213. set _ENABLE_ACQUIRE $ENABLE_ACQUIRE
  214. } else {
  215. set _ENABLE_ACQUIRE 1
  216. }
  217. if { [info exists ENABLE_POWER_SUPPLY] } {
  218. set _ENABLE_POWER_SUPPLY $ENABLE_POWER_SUPPLY
  219. } else {
  220. set _ENABLE_POWER_SUPPLY 0
  221. }
  222. } else {
  223. set _ENABLE_ACQUIRE 0
  224. set _ENABLE_POWER_SUPPLY 0
  225. echo "** Test Mode acquire not supported by selected adapter"
  226. }
  227. if { $_ENABLE_ACQUIRE } {
  228. echo "** Auto-acquire enabled, use \"set ENABLE_ACQUIRE 0\" to disable"
  229. }
  230. if { [string is integer $_ENABLE_POWER_SUPPLY]} {
  231. if { $_ENABLE_POWER_SUPPLY } {
  232. echo "** Enabling target power ($_ENABLE_POWER_SUPPLY mV) \"set ENABLE_POWER_SUPPLY 0\" to disable"
  233. kitprog3 power_config on $_ENABLE_POWER_SUPPLY
  234. }
  235. } elseif { $_ENABLE_POWER_SUPPLY == "default" } {
  236. echo "** Enabling target power (default voltage) \"set ENABLE_POWER_SUPPLY 0\" to disable"
  237. kitprog3 power_config on
  238. } else {
  239. puts stderr "Invalid ENABLE_POWER_SUPPLY value - '$_ENABLE_POWER_SUPPLY' (integer or 'default' expected)"
  240. terminate
  241. }