Advertisement
BaSs_HaXoR

STM32F1x.cfg Bluepill STLINK (For 2b model board)

Feb 23rd, 2025 (edited)
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. # script for stm32f1x family
  2.  
  3. #
  4. # stm32 devices support both JTAG and SWD transports.
  5. #
  6. source [find swj-dp.tcl]
  7. source [find mem_helper.tcl]
  8.  
  9. if { [info exists CHIPNAME] } {
  10. set _CHIPNAME $CHIPNAME
  11. } else {
  12. set _CHIPNAME stm32f1x
  13. }
  14.  
  15. if { [info exists CONNECT_UNDER_RESET] } {
  16. set _CONNECT_UNDER_RESET $CONNECT_UNDER_RESET
  17. } else {
  18. set _CONNECT_UNDER_RESET 0
  19. }
  20.  
  21. if { [info exists ENABLE_LOW_POWER] } {
  22. set _ENABLE_LOW_POWER $ENABLE_LOW_POWER
  23. } else {
  24. set _ENABLE_LOW_POWER 0
  25. }
  26.  
  27. if { [info exists STOP_WATCHDOG] } {
  28. set _STOP_WATCHDOG $STOP_WATCHDOG
  29. } else {
  30. set _STOP_WATCHDOG 0
  31. }
  32.  
  33. set _ENDIAN little
  34.  
  35. # Work-area is a space in RAM used for flash programming
  36. # By default use 4kB (as found on some STM32F100s)
  37. if { [info exists WORKAREASIZE] } {
  38. set _WORKAREASIZE $WORKAREASIZE
  39. } else {
  40. set _WORKAREASIZE 0x1000
  41. }
  42.  
  43. #jtag scan chain
  44. if { [info exists CPUTAPID] } {
  45. set _CPUTAPID $CPUTAPID
  46. } else {
  47. if { [using_jtag] } {
  48. # See STM Document RM0008 Section 26.6.3
  49. set _CPUTAPID 0x3ba00477
  50. } {
  51. # this is the SW-DP tap id not the jtag tap id
  52. set _CPUTAPID 0x2ba01477
  53. }
  54. }
  55.  
  56. swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
  57.  
  58. set _TARGETNAME $_CHIPNAME.cpu
  59. target create $_TARGETNAME cortex_m -endian $_ENDIAN -chain-position $_TARGETNAME
  60.  
  61. $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
  62.  
  63. # flash size will be probed
  64. set _FLASHNAME $_CHIPNAME.flash
  65. flash bank $_FLASHNAME stm32f1x 0x08000000 0 0 0 $_TARGETNAME
  66.  
  67. # check for second flash bank
  68. if { [regexp -nocase {stm32f101.g..} $_CHIPNAME] || [regexp -nocase {stm32f101.f..} $_CHIPNAME] || [regexp -nocase {stm32f103.g..} $_CHIPNAME] || [regexp -nocase {stm32f103.f..} $_CHIPNAME] } {
  69. # STM32F101/103xG 1Mo & STM32F101/103xF 768K have a dual bank flash (XL family).
  70. # Add the second flash bank.
  71. set _FLASHNAME $_CHIPNAME.flash1
  72. flash bank $_FLASHNAME stm32f1x 0x08080000 0 0 0 $_TARGETNAME
  73. }
  74.  
  75. if { [info exists CLOCK_FREQ] } {
  76. set _CLOCK_FREQ $CLOCK_FREQ
  77. } else {
  78. set _CLOCK_FREQ 4000
  79. }
  80. adapter_khz $_CLOCK_FREQ
  81.  
  82. adapter_nsrst_delay 100
  83. if {[using_jtag]} {
  84. jtag_ntrst_delay 100
  85. }
  86.  
  87. if {![using_hla]} {
  88. # if srst is not fitted use SYSRESETREQ to
  89. # perform a soft reset
  90. cortex_m reset_config sysresetreq
  91. }
  92.  
  93. $_TARGETNAME configure -event examine-end {
  94. global _ENABLE_LOW_POWER
  95. global _STOP_WATCHDOG
  96.  
  97. if { [expr ($_ENABLE_LOW_POWER == 1)] } {
  98. # Enable debug during low power modes (uses more power)
  99. # DBGMCU_CR |= DBG_STANDBY | DBG_STOP | DBG_SLEEP
  100. mmw 0xE0042004 0x00000007 0
  101. }
  102. if { [expr ($_ENABLE_LOW_POWER == 0)] } {
  103. # Disable debug during low power modes
  104. # DBGMCU_CR |= ~(DBG_STANDBY | DBG_STOP | DBG_SLEEP)
  105. mmw 0xE0042004 0 0x00000007
  106. }
  107. if { [expr ($_STOP_WATCHDOG == 1)] } {
  108. # Stop watchdog counters during halt
  109. # DBGMCU_CR |= DBG_WWDG_STOP | DBG_IWDG_STOP
  110. mmw 0xE0042004 0x00000300 0
  111. }
  112. if { [expr ($_STOP_WATCHDOG == 0)] } {
  113. # Don't stop watchdog counters during halt
  114. # DBGMCU_CR |= ~(DBG_WWDG_STOP | DBG_IWDG_STOP)
  115. mmw 0xE0042004 0 0x00000300
  116. }
  117. }
  118.  
  119. $_TARGETNAME configure -event reset-init {
  120. global _CLOCK_FREQ
  121.  
  122. adapter_khz $_CLOCK_FREQ
  123. }
  124.  
  125. $_TARGETNAME configure -event gdb-attach {
  126. global _CONNECT_UNDER_RESET
  127.  
  128. # Needed to be able to use the connect_assert_srst in reset_config
  129. # otherwise, wrong value when reading device flash size register
  130. if { [expr ($_CONNECT_UNDER_RESET == 1)] } {
  131. reset init
  132. }
  133. }
  134.  
  135. $_TARGETNAME configure -event trace-config {
  136. # Set TRACE_IOEN; TRACE_MODE is set to async; when using sync
  137. # change this value accordingly to configure trace pins
  138. # assignment
  139. mmw 0xE0042004 0x00000020 0
  140. }
  141.  
  142. $_TARGETNAME configure -event gdb-detach {
  143. # to close connection if debug mode entered
  144. shutdown
  145. }
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement