stm32h7x.cfg 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. # SPDX-License-Identifier: GPL-2.0-or-later
  2. # script for stm32h7x family
  3. #
  4. # stm32h7 devices support both JTAG and SWD transports.
  5. #
  6. source [find target/swj-dp.tcl]
  7. source [find mem_helper.tcl]
  8. if { [info exists CHIPNAME] } {
  9. set _CHIPNAME $CHIPNAME
  10. } else {
  11. set _CHIPNAME stm32h7x
  12. }
  13. if { [info exists DUAL_BANK] } {
  14. set $_CHIPNAME.DUAL_BANK $DUAL_BANK
  15. unset DUAL_BANK
  16. } else {
  17. set $_CHIPNAME.DUAL_BANK 0
  18. }
  19. if { [info exists DUAL_CORE] } {
  20. set $_CHIPNAME.DUAL_CORE $DUAL_CORE
  21. unset DUAL_CORE
  22. } else {
  23. set $_CHIPNAME.DUAL_CORE 0
  24. }
  25. # Issue a warning when hla is used, and fallback to single core configuration
  26. if { [set $_CHIPNAME.DUAL_CORE] && [using_hla] } {
  27. echo "Warning : hla does not support multicore debugging"
  28. set $_CHIPNAME.DUAL_CORE 0
  29. }
  30. if { [info exists USE_CTI] } {
  31. set $_CHIPNAME.USE_CTI $USE_CTI
  32. unset USE_CTI
  33. } else {
  34. set $_CHIPNAME.USE_CTI 0
  35. }
  36. # Issue a warning when DUAL_CORE=0 and USE_CTI=1, and fallback to USE_CTI=0
  37. if { ![set $_CHIPNAME.DUAL_CORE] && [set $_CHIPNAME.USE_CTI] } {
  38. echo "Warning : could not use CTI with a single core device, CTI is disabled"
  39. set $_CHIPNAME.USE_CTI 0
  40. }
  41. set _ENDIAN little
  42. # Work-area is a space in RAM used for flash programming
  43. # By default use 64kB
  44. if { [info exists WORKAREASIZE] } {
  45. set _WORKAREASIZE $WORKAREASIZE
  46. } else {
  47. set _WORKAREASIZE 0x10000
  48. }
  49. #jtag scan chain
  50. if { [info exists CPUTAPID] } {
  51. set _CPUTAPID $CPUTAPID
  52. } else {
  53. if { [using_jtag] } {
  54. set _CPUTAPID 0x6ba00477
  55. } {
  56. set _CPUTAPID 0x6ba02477
  57. }
  58. }
  59. swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
  60. dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
  61. if {[using_jtag]} {
  62. jtag newtap $_CHIPNAME bs -irlen 5
  63. }
  64. if {![using_hla]} {
  65. # STM32H7 provides an APB-AP at access port 2, which allows the access to
  66. # the debug and trace features on the system APB System Debug Bus (APB-D).
  67. target create $_CHIPNAME.ap2 mem_ap -dap $_CHIPNAME.dap -ap-num 2
  68. swo create $_CHIPNAME.swo -dap $_CHIPNAME.dap -ap-num 2 -baseaddr 0xE00E3000
  69. tpiu create $_CHIPNAME.tpiu -dap $_CHIPNAME.dap -ap-num 2 -baseaddr 0xE00F5000
  70. }
  71. target create $_CHIPNAME.cpu0 cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap -ap-num 0
  72. $_CHIPNAME.cpu0 configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
  73. flash bank $_CHIPNAME.bank1.cpu0 stm32h7x 0x08000000 0 0 0 $_CHIPNAME.cpu0
  74. if {[set $_CHIPNAME.DUAL_BANK]} {
  75. flash bank $_CHIPNAME.bank2.cpu0 stm32h7x 0x08100000 0 0 0 $_CHIPNAME.cpu0
  76. }
  77. if {[set $_CHIPNAME.DUAL_CORE]} {
  78. target create $_CHIPNAME.cpu1 cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap -ap-num 3
  79. $_CHIPNAME.cpu1 configure -work-area-phys 0x38000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
  80. flash bank $_CHIPNAME.bank1.cpu1 stm32h7x 0x08000000 0 0 0 $_CHIPNAME.cpu1
  81. if {[set $_CHIPNAME.DUAL_BANK]} {
  82. flash bank $_CHIPNAME.bank2.cpu1 stm32h7x 0x08100000 0 0 0 $_CHIPNAME.cpu1
  83. }
  84. }
  85. # Make sure that cpu0 is selected
  86. targets $_CHIPNAME.cpu0
  87. if { [info exists QUADSPI] && $QUADSPI } {
  88. set a [llength [flash list]]
  89. set _QSPINAME $_CHIPNAME.qspi
  90. flash bank $_QSPINAME stmqspi 0x90000000 0 0 0 $_CHIPNAME.cpu0 0x52005000
  91. } else {
  92. if { [info exists OCTOSPI1] && $OCTOSPI1 } {
  93. set a [llength [flash list]]
  94. set _OCTOSPINAME1 $_CHIPNAME.octospi1
  95. flash bank $_OCTOSPINAME1 stmqspi 0x90000000 0 0 0 $_CHIPNAME.cpu0 0x52005000
  96. }
  97. if { [info exists OCTOSPI2] && $OCTOSPI2 } {
  98. set b [llength [flash list]]
  99. set _OCTOSPINAME2 $_CHIPNAME.octospi2
  100. flash bank $_OCTOSPINAME2 stmqspi 0x70000000 0 0 0 $_CHIPNAME.cpu0 0x5200A000
  101. }
  102. }
  103. # Clock after reset is HSI at 64 MHz, no need of PLL
  104. adapter speed 1800
  105. adapter srst delay 100
  106. if {[using_jtag]} {
  107. jtag_ntrst_delay 100
  108. }
  109. # use hardware reset
  110. #
  111. # The STM32H7 does not support connect_assert_srst mode because the AXI is
  112. # unavailable while SRST is asserted, and that is used to access the DBGMCU
  113. # component at 0x5C001000 in the examine-end event handler.
  114. #
  115. # It is possible to access the DBGMCU component at 0xE00E1000 via AP2 instead
  116. # of the default AP0, and that works with SRST asserted; however, nonzero AP
  117. # usage does not work with HLA, so is not done by default. That change could be
  118. # made in a local configuration file if connect_assert_srst mode is needed for
  119. # a specific application and a non-HLA adapter is in use.
  120. reset_config srst_nogate
  121. if {![using_hla]} {
  122. # if srst is not fitted use SYSRESETREQ to
  123. # perform a soft reset
  124. $_CHIPNAME.cpu0 cortex_m reset_config sysresetreq
  125. if {[set $_CHIPNAME.DUAL_CORE]} {
  126. $_CHIPNAME.cpu1 cortex_m reset_config sysresetreq
  127. }
  128. # Set CSW[27], which according to ARM ADI v5 appendix E1.4 maps to AHB signal
  129. # HPROT[3], which according to AMBA AHB/ASB/APB specification chapter 3.7.3
  130. # makes the data access cacheable. This allows reading and writing data in the
  131. # CPU cache from the debugger, which is far more useful than going straight to
  132. # RAM when operating on typical variables, and is generally no worse when
  133. # operating on special memory locations.
  134. $_CHIPNAME.dap apcsw 0x08000000 0x08000000
  135. }
  136. $_CHIPNAME.cpu0 configure -event examine-end {
  137. # Enable D3 and D1 DBG clocks
  138. # DBGMCU_CR |= D3DBGCKEN | D1DBGCKEN
  139. stm32h7x_dbgmcu_mmw 0x004 0x00600000 0
  140. # Enable debug during low power modes (uses more power)
  141. # DBGMCU_CR |= DBG_STANDBY | DBG_STOP | DBG_SLEEP D1 Domain
  142. stm32h7x_dbgmcu_mmw 0x004 0x00000007 0
  143. # DBGMCU_CR |= DBG_STANDBY | DBG_STOP | DBG_SLEEP D2 Domain
  144. stm32h7x_dbgmcu_mmw 0x004 0x00000038 0
  145. # Stop watchdog counters during halt
  146. # DBGMCU_APB3FZ1 |= WWDG1
  147. stm32h7x_dbgmcu_mmw 0x034 0x00000040 0
  148. # DBGMCU_APB1LFZ1 |= WWDG2
  149. stm32h7x_dbgmcu_mmw 0x03C 0x00000800 0
  150. # DBGMCU_APB4FZ1 |= WDGLSD1 | WDGLSD2
  151. stm32h7x_dbgmcu_mmw 0x054 0x000C0000 0
  152. # Enable clock for tracing
  153. # DBGMCU_CR |= TRACECLKEN
  154. stm32h7x_dbgmcu_mmw 0x004 0x00100000 0
  155. # RM0399 (id 0x450) M7+M4 with SWO Funnel
  156. # RM0433 (id 0x450) M7 with SWO Funnel
  157. # RM0455 (id 0x480) M7 without SWO Funnel
  158. # RM0468 (id 0x483) M7 without SWO Funnel
  159. # Enable CM7 and CM4 slave ports in SWO trace Funnel
  160. # Works ok also on devices single core and without SWO funnel
  161. # Hack, use stm32h7x_dbgmcu_mmw with big offset to control SWTF
  162. # SWTF_CTRL |= ENS0 | ENS1
  163. stm32h7x_dbgmcu_mmw 0x3000 0x00000003 0
  164. }
  165. $_CHIPNAME.cpu0 configure -event reset-init {
  166. # Clock after reset is HSI at 64 MHz, no need of PLL
  167. adapter speed 4000
  168. }
  169. # get _CHIPNAME from current target
  170. proc stm32h7x_get_chipname {} {
  171. set t [target current]
  172. set sep [string last "." $t]
  173. if {$sep == -1} {
  174. return $t
  175. }
  176. return [string range $t 0 [expr {$sep - 1}]]
  177. }
  178. if {[set $_CHIPNAME.DUAL_CORE]} {
  179. $_CHIPNAME.cpu1 configure -event examine-end {
  180. set _CHIPNAME [stm32h7x_get_chipname]
  181. global $_CHIPNAME.USE_CTI
  182. # Stop watchdog counters during halt
  183. # DBGMCU_APB3FZ2 |= WWDG1
  184. stm32h7x_dbgmcu_mmw 0x038 0x00000040 0
  185. # DBGMCU_APB1LFZ2 |= WWDG2
  186. stm32h7x_dbgmcu_mmw 0x040 0x00000800 0
  187. # DBGMCU_APB4FZ2 |= WDGLSD1 | WDGLSD2
  188. stm32h7x_dbgmcu_mmw 0x058 0x000C0000 0
  189. if {[set $_CHIPNAME.USE_CTI]} {
  190. stm32h7x_cti_start
  191. }
  192. }
  193. }
  194. # like mrw, but with target selection
  195. proc stm32h7x_mrw {used_target reg} {
  196. return [$used_target read_memory $reg 32 1]
  197. }
  198. # like mmw, but with target selection
  199. proc stm32h7x_mmw {used_target reg setbits clearbits} {
  200. set old [stm32h7x_mrw $used_target $reg]
  201. set new [expr {($old & ~$clearbits) | $setbits}]
  202. $used_target mww $reg $new
  203. }
  204. # mmw for dbgmcu component registers, it accepts the register offset from dbgmcu base
  205. # this procedure will use the mem_ap on AP2 whenever possible
  206. proc stm32h7x_dbgmcu_mmw {reg_offset setbits clearbits} {
  207. # use $_CHIPNAME.ap2 if possible, and use the proper dbgmcu base address
  208. if {![using_hla]} {
  209. set _CHIPNAME [stm32h7x_get_chipname]
  210. set used_target $_CHIPNAME.ap2
  211. set reg_addr [expr {0xE00E1000 + $reg_offset}]
  212. } {
  213. set used_target [target current]
  214. set reg_addr [expr {0x5C001000 + $reg_offset}]
  215. }
  216. stm32h7x_mmw $used_target $reg_addr $setbits $clearbits
  217. }
  218. if {[set $_CHIPNAME.USE_CTI]} {
  219. # create CTI instances for both cores
  220. cti create $_CHIPNAME.cti0 -dap $_CHIPNAME.dap -ap-num 0 -baseaddr 0xE0043000
  221. cti create $_CHIPNAME.cti1 -dap $_CHIPNAME.dap -ap-num 3 -baseaddr 0xE0043000
  222. $_CHIPNAME.cpu0 configure -event halted { stm32h7x_cti_prepare_restart_all }
  223. $_CHIPNAME.cpu1 configure -event halted { stm32h7x_cti_prepare_restart_all }
  224. $_CHIPNAME.cpu0 configure -event debug-halted { stm32h7x_cti_prepare_restart_all }
  225. $_CHIPNAME.cpu1 configure -event debug-halted { stm32h7x_cti_prepare_restart_all }
  226. proc stm32h7x_cti_start {} {
  227. set _CHIPNAME [stm32h7x_get_chipname]
  228. # Configure Cores' CTIs to halt each other
  229. # TRIGIN0 (DBGTRIGGER) and TRIGOUT0 (EDBGRQ) at CTM_CHANNEL_0
  230. $_CHIPNAME.cti0 write INEN0 0x1
  231. $_CHIPNAME.cti0 write OUTEN0 0x1
  232. $_CHIPNAME.cti1 write INEN0 0x1
  233. $_CHIPNAME.cti1 write OUTEN0 0x1
  234. # enable CTIs
  235. $_CHIPNAME.cti0 enable on
  236. $_CHIPNAME.cti1 enable on
  237. }
  238. proc stm32h7x_cti_stop {} {
  239. set _CHIPNAME [stm32h7x_get_chipname]
  240. $_CHIPNAME.cti0 enable off
  241. $_CHIPNAME.cti1 enable off
  242. }
  243. proc stm32h7x_cti_prepare_restart_all {} {
  244. stm32h7x_cti_prepare_restart cti0
  245. stm32h7x_cti_prepare_restart cti1
  246. }
  247. proc stm32h7x_cti_prepare_restart {cti} {
  248. set _CHIPNAME [stm32h7x_get_chipname]
  249. # Acknowlodge EDBGRQ at TRIGOUT0
  250. $_CHIPNAME.$cti write INACK 0x01
  251. $_CHIPNAME.$cti write INACK 0x00
  252. }
  253. }