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.
 
 
 
 
 
 

142 lines
3.9 KiB

  1. # script for stm32f4x family
  2. #
  3. # stm32 devices support both JTAG and SWD transports.
  4. #
  5. source [find target/swj-dp.tcl]
  6. source [find mem_helper.tcl]
  7. if { [info exists CHIPNAME] } {
  8. set _CHIPNAME $CHIPNAME
  9. } else {
  10. set _CHIPNAME stm32f4x
  11. }
  12. set _ENDIAN little
  13. # Work-area is a space in RAM used for flash programming
  14. # By default use 32kB (Available RAM in smallest device STM32F410)
  15. if { [info exists WORKAREASIZE] } {
  16. set _WORKAREASIZE $WORKAREASIZE
  17. } else {
  18. set _WORKAREASIZE 0x8000
  19. }
  20. #jtag scan chain
  21. if { [info exists CPUTAPID] } {
  22. set _CPUTAPID $CPUTAPID
  23. } else {
  24. if { [using_jtag] } {
  25. # See STM Document RM0090
  26. # Section 38.6.3 - corresponds to Cortex-M4 r0p1
  27. set _CPUTAPID 0x4ba00477
  28. } {
  29. set _CPUTAPID 0x2ba01477
  30. }
  31. }
  32. swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
  33. dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
  34. tpiu create $_CHIPNAME.tpiu -dap $_CHIPNAME.dap -ap-num 0 -baseaddr 0xE0040000
  35. if {[using_jtag]} {
  36. jtag newtap $_CHIPNAME bs -irlen 5
  37. }
  38. set _TARGETNAME $_CHIPNAME.cpu
  39. target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap
  40. $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
  41. set _FLASHNAME $_CHIPNAME.flash
  42. flash bank $_FLASHNAME stm32f2x 0 0 0 0 $_TARGETNAME
  43. flash bank $_CHIPNAME.otp stm32f2x 0x1fff7800 0 0 0 $_TARGETNAME
  44. if { [info exists QUADSPI] && $QUADSPI } {
  45. set a [llength [flash list]]
  46. set _QSPINAME $_CHIPNAME.qspi
  47. flash bank $_QSPINAME stmqspi 0x90000000 0 0 0 $_TARGETNAME 0xA0001000
  48. }
  49. # JTAG speed should be <= F_CPU/6. F_CPU after reset is 16MHz, so use F_JTAG = 2MHz
  50. #
  51. # Since we may be running of an RC oscilator, we crank down the speed a
  52. # bit more to be on the safe side. Perhaps superstition, but if are
  53. # running off a crystal, we can run closer to the limit. Note
  54. # that there can be a pretty wide band where things are more or less stable.
  55. adapter speed 2000
  56. adapter srst delay 100
  57. if {[using_jtag]} {
  58. jtag_ntrst_delay 100
  59. }
  60. reset_config srst_nogate
  61. if {![using_hla]} {
  62. # if srst is not fitted use SYSRESETREQ to
  63. # perform a soft reset
  64. cortex_m reset_config sysresetreq
  65. }
  66. $_TARGETNAME configure -event examine-end {
  67. # Enable debug during low power modes (uses more power)
  68. # DBGMCU_CR |= DBG_STANDBY | DBG_STOP | DBG_SLEEP
  69. mmw 0xE0042004 0x00000007 0
  70. # Stop watchdog counters during halt
  71. # DBGMCU_APB1_FZ |= DBG_IWDG_STOP | DBG_WWDG_STOP
  72. mmw 0xE0042008 0x00001800 0
  73. }
  74. proc proc_post_enable {_chipname} {
  75. targets $_chipname.cpu
  76. if { [$_chipname.tpiu cget -protocol] eq "sync" } {
  77. switch [$_chipname.tpiu cget -port-width] {
  78. 1 {
  79. mmw 0xE0042004 0x00000060 0x000000c0
  80. mmw 0x40021020 0x00000000 0x0000ff00
  81. mmw 0x40021000 0x000000a0 0x000000f0
  82. mmw 0x40021008 0x000000f0 0x00000000
  83. }
  84. 2 {
  85. mmw 0xE0042004 0x000000a0 0x000000c0
  86. mmw 0x40021020 0x00000000 0x000fff00
  87. mmw 0x40021000 0x000002a0 0x000003f0
  88. mmw 0x40021008 0x000003f0 0x00000000
  89. }
  90. 4 {
  91. mmw 0xE0042004 0x000000e0 0x000000c0
  92. mmw 0x40021020 0x00000000 0x0fffff00
  93. mmw 0x40021000 0x00002aa0 0x00003ff0
  94. mmw 0x40021008 0x00003ff0 0x00000000
  95. }
  96. }
  97. } else {
  98. mmw 0xE0042004 0x00000020 0x000000c0
  99. }
  100. }
  101. $_CHIPNAME.tpiu configure -event post-enable "proc_post_enable $_CHIPNAME"
  102. $_TARGETNAME configure -event reset-init {
  103. # Configure PLL to boost clock to HSI x 4 (64 MHz)
  104. mww 0x40023804 0x08012008 ;# RCC_PLLCFGR 16 Mhz /8 (M) * 128 (N) /4(P)
  105. mww 0x40023C00 0x00000102 ;# FLASH_ACR = PRFTBE | 2(Latency)
  106. mmw 0x40023800 0x01000000 0 ;# RCC_CR |= PLLON
  107. sleep 10 ;# Wait for PLL to lock
  108. mmw 0x40023808 0x00001000 0 ;# RCC_CFGR |= RCC_CFGR_PPRE1_DIV2
  109. mmw 0x40023808 0x00000002 0 ;# RCC_CFGR |= RCC_CFGR_SW_PLL
  110. # Boost JTAG frequency
  111. adapter speed 8000
  112. }
  113. $_TARGETNAME configure -event reset-start {
  114. # Reduce speed since CPU speed will slow down to 16MHz with the reset
  115. adapter speed 2000
  116. }